blob: 68be61e376ba1678363dfb517d071b41213dcdde [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
jge62037862016-12-09 10:44:33 +08002 * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
Mohit Khannafa99aea2016-05-12 21:43:13 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +053051#include <ol_txrx.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070052#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053
54#include "cds_sched.h"
55
56#include "wma.h"
57#include "wma_api.h"
Prakash Dhavali87b38e32016-11-14 16:22:53 -080058#include "wal_rx_desc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
Dhanashri Atreb08959a2016-03-01 17:28:03 -080060#include "cdp_txrx_ipa.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080061#include <cdp_txrx_handle.h>
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080062#include "wlan_policy_mgr_api.h"
63
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064#define HDD_IPA_DESC_BUFFER_RATIO 4
65#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
66#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
67
68#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
70/* WDI TX and RX PIPE */
71#define HDD_IPA_UC_NUM_WDI_PIPE 2
72#define HDD_IPA_UC_MAX_PENDING_EVENT 33
73
74#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
75#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
76#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
77#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
78
79#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
80#define HDD_IPA_MAX_IFACE 3
81#define HDD_IPA_MAX_SYSBAM_PIPE 4
82#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
83#define HDD_IPA_ENABLE_MASK BIT(0)
84#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
85#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
86#define HDD_IPA_RM_ENABLE_MASK BIT(3)
87#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
88#define HDD_IPA_UC_ENABLE_MASK BIT(5)
89#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
90#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
91
Yun Parkf19e07d2015-11-20 11:34:27 -080092#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
93
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070094enum hdd_ipa_uc_op_code {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
96 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
97 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
98 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
99 HDD_IPA_UC_OPCODE_STATS = 4,
Yun Park637d6482016-10-05 10:51:33 -0700100#ifdef FEATURE_METERING
101 HDD_IPA_UC_OPCODE_SHARING_STATS = 5,
102 HDD_IPA_UC_OPCODE_QUOTA_RSP = 6,
103 HDD_IPA_UC_OPCODE_QUOTA_IND = 7,
104#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800105 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800106 /* keep this last */
107 HDD_IPA_UC_OPCODE_MAX
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700108};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800109
110/**
111 * enum - Reason codes for stat query
112 *
113 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
114 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
115 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800116 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800117 */
118enum {
119 HDD_IPA_UC_STAT_REASON_NONE,
120 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -0800121 HDD_IPA_UC_STAT_REASON_BW_CAL,
122 HDD_IPA_UC_STAT_REASON_DUMP_INFO
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800123};
124
125/**
126 * enum hdd_ipa_rm_state - IPA resource manager state
127 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
128 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
129 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
130 */
131enum hdd_ipa_rm_state {
132 HDD_IPA_RM_RELEASED,
133 HDD_IPA_RM_GRANT_PENDING,
134 HDD_IPA_RM_GRANTED,
135};
136
137struct llc_snap_hdr {
138 uint8_t dsap;
139 uint8_t ssap;
140 uint8_t resv[4];
141 __be16 eth_type;
142} __packed;
143
Leo Chang3bc8fed2015-11-13 10:59:47 -0800144/**
145 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
146 * @eth: ether II header
147 * @llc_snap: LLC snap header
148 *
149 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150struct hdd_ipa_tx_hdr {
151 struct ethhdr eth;
152 struct llc_snap_hdr llc_snap;
153} __packed;
154
Leo Chang3bc8fed2015-11-13 10:59:47 -0800155/**
156 * struct frag_header - fragment header type registered to IPA hardware
157 * @length: fragment length
158 * @reserved1: Reserved not used
159 * @reserved2: Reserved not used
160 *
161 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800162struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800163 uint16_t length;
164 uint32_t reserved1;
165 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166} __packed;
167
Leo Chang3bc8fed2015-11-13 10:59:47 -0800168/**
169 * struct ipa_header - ipa header type registered to IPA hardware
170 * @vdev_id: vdev id
171 * @reserved: Reserved not used
172 *
173 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174struct ipa_header {
175 uint32_t
176 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
177 reserved:24;
178} __packed;
179
Leo Chang3bc8fed2015-11-13 10:59:47 -0800180/**
181 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
182 * @frag_hd: fragment header
183 * @ipa_hd: ipa header
184 * @eth: ether II header
185 *
186 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800187struct hdd_ipa_uc_tx_hdr {
188 struct frag_header frag_hd;
189 struct ipa_header ipa_hd;
190 struct ethhdr eth;
191} __packed;
192
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800193/**
194 * struct hdd_ipa_cld_hdr - IPA CLD Header
195 * @reserved: reserved fields
196 * @iface_id: interface ID
197 * @sta_id: Station ID
198 *
199 * Packed 32-bit structure
200 * +----------+----------+--------------+--------+
201 * | Reserved | QCMAP ID | interface id | STA ID |
202 * +----------+----------+--------------+--------+
203 */
204struct hdd_ipa_cld_hdr {
205 uint8_t reserved[2];
206 uint8_t iface_id;
207 uint8_t sta_id;
208} __packed;
209
210struct hdd_ipa_rx_hdr {
211 struct hdd_ipa_cld_hdr cld_hdr;
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700216 bool exception;
217 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218 struct hdd_ipa_iface_context *iface_context;
219 struct ipa_rx_data *ipa_tx_desc;
220};
221
222struct hdd_ipa_uc_rx_hdr {
223 struct ethhdr eth;
224} __packed;
225
226struct hdd_ipa_sys_pipe {
227 uint32_t conn_hdl;
228 uint8_t conn_hdl_valid;
229 struct ipa_sys_connect_params ipa_sys_params;
230};
231
232struct hdd_ipa_iface_stats {
233 uint64_t num_tx;
234 uint64_t num_tx_drop;
235 uint64_t num_tx_err;
236 uint64_t num_tx_cac_drop;
237 uint64_t num_rx_prefilter;
238 uint64_t num_rx_ipa_excep;
239 uint64_t num_rx_recv;
240 uint64_t num_rx_recv_mul;
241 uint64_t num_rx_send_desc_err;
242 uint64_t max_rx_mul;
243};
244
245struct hdd_ipa_priv;
246
247struct hdd_ipa_iface_context {
248 struct hdd_ipa_priv *hdd_ipa;
249 hdd_adapter_t *adapter;
250 void *tl_context;
251
252 enum ipa_client_type cons_client;
253 enum ipa_client_type prod_client;
254
255 uint8_t iface_id; /* This iface ID */
256 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530257 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258 uint32_t ifa_address;
259 struct hdd_ipa_iface_stats stats;
260};
261
262struct hdd_ipa_stats {
263 uint32_t event[IPA_WLAN_EVENT_MAX];
264 uint64_t num_send_msg;
265 uint64_t num_free_msg;
266
267 uint64_t num_rm_grant;
268 uint64_t num_rm_release;
269 uint64_t num_rm_grant_imm;
270 uint64_t num_cons_perf_req;
271 uint64_t num_prod_perf_req;
272
273 uint64_t num_rx_drop;
274 uint64_t num_rx_ipa_tx_dp;
275 uint64_t num_rx_ipa_splice;
276 uint64_t num_rx_ipa_loop;
277 uint64_t num_rx_ipa_tx_dp_err;
278 uint64_t num_rx_ipa_write_done;
279 uint64_t num_max_ipa_tx_mul;
280 uint64_t num_rx_ipa_hw_maxed_out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281
Yun Park52b2b992016-09-22 15:49:51 -0700282 uint64_t num_tx_desc_q_cnt;
283 uint64_t num_tx_desc_error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800284 uint64_t num_tx_comp_cnt;
285 uint64_t num_tx_queued;
286 uint64_t num_tx_dequeued;
287 uint64_t num_max_pm_queue;
288
289 uint64_t num_freeq_empty;
290 uint64_t num_pri_freeq_empty;
291 uint64_t num_rx_excep;
Yun Parkb187d542016-11-14 18:10:04 -0800292 uint64_t num_tx_fwd_ok;
293 uint64_t num_tx_fwd_err;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800294};
295
296struct ipa_uc_stas_map {
297 bool is_reserved;
298 uint8_t sta_id;
299};
300struct op_msg_type {
301 uint8_t msg_t;
302 uint8_t rsvd;
303 uint16_t op_code;
304 uint16_t len;
305 uint16_t rsvd_snd;
306};
307
308struct ipa_uc_fw_stats {
309 uint32_t tx_comp_ring_base;
310 uint32_t tx_comp_ring_size;
311 uint32_t tx_comp_ring_dbell_addr;
312 uint32_t tx_comp_ring_dbell_ind_val;
313 uint32_t tx_comp_ring_dbell_cached_val;
314 uint32_t tx_pkts_enqueued;
315 uint32_t tx_pkts_completed;
316 uint32_t tx_is_suspend;
317 uint32_t tx_reserved;
318 uint32_t rx_ind_ring_base;
319 uint32_t rx_ind_ring_size;
320 uint32_t rx_ind_ring_dbell_addr;
321 uint32_t rx_ind_ring_dbell_ind_val;
322 uint32_t rx_ind_ring_dbell_ind_cached_val;
323 uint32_t rx_ind_ring_rdidx_addr;
324 uint32_t rx_ind_ring_rd_idx_cached_val;
325 uint32_t rx_refill_idx;
326 uint32_t rx_num_pkts_indicated;
327 uint32_t rx_buf_refilled;
328 uint32_t rx_num_ind_drop_no_space;
329 uint32_t rx_num_ind_drop_no_buf;
330 uint32_t rx_is_suspend;
331 uint32_t rx_reserved;
332};
333
334struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530335 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336 hdd_adapter_t *adapter;
337 enum ipa_wlan_event type;
338 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530339 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340};
341
342/**
343 * struct uc_rm_work_struct
344 * @work: uC RM work
345 * @event: IPA RM event
346 */
347struct uc_rm_work_struct {
348 struct work_struct work;
349 enum ipa_rm_event event;
350};
351
352/**
353 * struct uc_op_work_struct
354 * @work: uC OP work
355 * @msg: OP message
356 */
357struct uc_op_work_struct {
358 struct work_struct work;
359 struct op_msg_type *msg;
360};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800361
362/**
363 * struct uc_rt_debug_info
364 * @time: system time
365 * @ipa_excep_count: IPA exception packet count
366 * @rx_drop_count: IPA Rx drop packet count
367 * @net_sent_count: IPA Rx packet sent to network stack count
368 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800369 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800370 * @tx_fwd_count: IPA Tx forward packet count
371 * @rx_destructor_call: IPA Rx packet destructor count
372 */
373struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530374 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800375 uint64_t ipa_excep_count;
376 uint64_t rx_drop_count;
377 uint64_t net_sent_count;
378 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800379 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 uint64_t tx_fwd_count;
381 uint64_t rx_destructor_call;
382};
383
Yun Park637d6482016-10-05 10:51:33 -0700384#ifdef FEATURE_METERING
385struct ipa_uc_sharing_stats {
386 uint64_t ipv4_rx_packets;
387 uint64_t ipv4_rx_bytes;
388 uint64_t ipv6_rx_packets;
389 uint64_t ipv6_rx_bytes;
390 uint64_t ipv4_tx_packets;
391 uint64_t ipv4_tx_bytes;
392 uint64_t ipv6_tx_packets;
393 uint64_t ipv6_tx_bytes;
394};
395
396struct ipa_uc_quota_rsp {
397 uint8_t success;
398 uint8_t reserved[3];
399 uint32_t quota_lo; /* quota limit low bytes */
400 uint32_t quota_hi; /* quota limit high bytes */
401};
402
403struct ipa_uc_quota_ind {
404 uint64_t quota_bytes; /* quota limit in bytes */
405};
406#endif
407
Yun Park52b2b992016-09-22 15:49:51 -0700408/**
409 * struct hdd_ipa_tx_desc
410 * @link: link to list head
411 * @priv: pointer to priv list entry
412 * @id: Tx desc idex
413 * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
414 */
415struct hdd_ipa_tx_desc {
416 struct list_head link;
417 void *priv;
418 uint32_t id;
419 struct ipa_rx_data *ipa_tx_desc_ptr;
420};
421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800422struct hdd_ipa_priv {
423 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
424 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
425 uint8_t num_iface;
426 enum hdd_ipa_rm_state rm_state;
427 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530428 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800429 * APIs as it is taken care gracefully. Without this, kernel would throw
430 * an warning if spin_lock_bh is used while IRQ is disabled
431 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530432 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 struct uc_rm_work_struct uc_rm_work;
434 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530435 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800436 struct delayed_work wake_lock_work;
437 bool wake_lock_released;
438
439 enum ipa_client_type prod_client;
440
441 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530442 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800443 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530444 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800445 bool suspended;
446
Yun Park52b2b992016-09-22 15:49:51 -0700447 qdf_spinlock_t q_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800449 struct list_head pend_desc_head;
Yun Park52b2b992016-09-22 15:49:51 -0700450 struct hdd_ipa_tx_desc *tx_desc_list;
451 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452
453 hdd_context_t *hdd_ctx;
454
455 struct dentry *debugfs_dir;
456 struct hdd_ipa_stats stats;
457
458 struct notifier_block ipv4_notifier;
459 uint32_t curr_prod_bw;
460 uint32_t curr_cons_bw;
461
462 uint8_t activated_fw_pipe;
463 uint8_t sap_num_connected_sta;
464 uint8_t sta_connected;
465 uint32_t tx_pipe_handle;
466 uint32_t rx_pipe_handle;
467 bool resource_loading;
468 bool resource_unloading;
469 bool pending_cons_req;
470 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530471 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530472 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700473 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800474 uint32_t ipa_tx_packets_diff;
475 uint32_t ipa_rx_packets_diff;
476 uint32_t ipa_p_tx_packets;
477 uint32_t ipa_p_rx_packets;
478 uint32_t stat_req_reason;
479 uint64_t ipa_tx_forward;
480 uint64_t ipa_rx_discard;
481 uint64_t ipa_rx_net_send_count;
482 uint64_t ipa_rx_internel_drop_count;
483 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530484 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800485 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
486 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800487 struct ipa_wdi_in_params cons_pipe_in;
488 struct ipa_wdi_in_params prod_pipe_in;
489 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800490 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530491 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530492 qdf_mutex_t rt_debug_lock;
493 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800494 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800495 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530496 qdf_dma_addr_t tx_comp_doorbell_paddr;
497 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800498 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
499 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700500#ifdef FEATURE_METERING
501 struct ipa_uc_sharing_stats ipa_sharing_stats;
502 struct ipa_uc_quota_rsp ipa_quota_rsp;
503 struct ipa_uc_quota_ind ipa_quota_ind;
504 struct completion ipa_uc_sharing_stats_comp;
505 struct completion ipa_uc_set_quota_comp;
506#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507};
508
Leo Changcc923e22016-06-16 15:29:03 -0700509#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
510#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
512#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
513#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
514#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
515#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
516#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700517#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
518 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519
520#define HDD_IPA_GET_IFACE_ID(_data) \
521 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
522
523#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530524 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 "%s:%d: "fmt, __func__, __LINE__, ## args)
526
Govind Singhb6a89772016-08-12 11:23:35 +0530527#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
528 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
529 "%s:%d: "fmt, __func__, __LINE__, ## args)
530
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
532 do { \
Yun Parkec845302016-12-15 09:22:57 -0800533 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
534 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800535 } while (0)
536
537#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
538 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
539
540#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
541 do { \
542 hdd_ipa->ipa_rx_internel_drop_count++; \
543 } while (0)
544#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
545 do { \
546 hdd_ipa->ipa_rx_net_send_count++; \
547 } while (0)
548#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
549
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700550#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800551#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
552do { \
553 pipe_in.u.ul.rdy_ring_rp_va = \
554 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
555 pipe_in.u.ul.rdy_comp_ring_base_pa = \
556 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
557 pipe_in.u.ul.rdy_comp_ring_size = \
558 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
559 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
560 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
561 pipe_in.u.ul.rdy_comp_ring_wp_va = \
562 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800563} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700564
565#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800566#else
567/* Do nothing */
568#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700569#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700570#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800571
Yun Parkb187d542016-11-14 18:10:04 -0800572#define HDD_IPA_DBG_DUMP_RX_LEN 32
573#define HDD_IPA_DBG_DUMP_TX_LEN 48
574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575static struct hdd_ipa_adapter_2_client {
576 enum ipa_client_type cons_client;
577 enum ipa_client_type prod_client;
578} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
579 {
580 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
581 }, {
582 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
583 }, {
584 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
585 },
586};
587
588/* For Tx pipes, use Ethernet-II Header format */
589struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
590 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800591 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 0x00000000,
593 0x00000000
594 },
595 {
596 0x00000000
597 },
598 {
599 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
600 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
601 0x0008
602 }
603};
604
605/* For Tx pipes, use 802.3 Header format */
606static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
607 {
608 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
609 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
610 0x00 /* length can be zero */
611 },
612 {
613 /* LLC SNAP header 8 bytes */
614 0xaa, 0xaa,
615 {0x03, 0x00, 0x00, 0x00},
616 0x0008 /* type value(2 bytes) ,filled by wlan */
617 /* 0x0800 - IPV4, 0x86dd - IPV6 */
618 }
619};
620
Yun Park637d6482016-10-05 10:51:33 -0700621#ifdef FEATURE_METERING
622#define IPA_UC_SHARING_STATES_WAIT_TIME 500
623#define IPA_UC_SET_QUOTA_WAIT_TIME 500
624#endif
625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626static struct hdd_ipa_priv *ghdd_ipa;
627
628/* Local Function Prototypes */
629static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
630 unsigned long data);
631static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
632 unsigned long data);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800633static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800634
635static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700636static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800638#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
639 defined(IPA_CLIENT_IS_MHI_CONS))
640/**
641 * hdd_ipa_uc_get_db_paddr() - Get Doorbell physical address
642 * @db_paddr: Doorbell physical address should be given bu IPA
643 * @client: IPA client type
644 *
645 * Query doorbell physical address from IPA
646 * IPA will give physical address for TX COMP and RX READY
647 *
648 * Return: None
649 */
650static void hdd_ipa_uc_get_db_paddr(qdf_dma_addr_t *db_paddr,
651 enum ipa_client_type client)
652{
653 struct ipa_wdi_db_params dbpa;
654
655 dbpa.client = client;
656 ipa_uc_wdi_get_dbpa(&dbpa);
657 *db_paddr = dbpa.uc_door_bell_pa;
Srinivas Girigowda97852372017-03-06 16:52:59 -0800658 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s PROD DB get dbpa 0x%x",
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800659 __func__, (unsigned int)dbpa.uc_door_bell_pa);
660}
661
662/**
663 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
664 * @priv_ctxt: hdd ipa local context
665 *
666 * Will be called by IPA context.
667 * It's atomic context, then should be scheduled to kworker thread
668 *
669 * Return: None
670 */
671static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
672{
673 struct hdd_ipa_priv *hdd_ipa;
674 struct op_msg_type *msg;
675 struct uc_op_work_struct *uc_op_work;
676
677 if (priv_ctxt == NULL) {
678 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
679 return;
680 }
681
682 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
683 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
684 if (!msg) {
685 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
686 return;
687 }
688
689 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
690
691 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
692
693 /* When the same uC OPCODE is already pended, just return */
694 if (uc_op_work->msg)
695 return;
696
697 uc_op_work->msg = msg;
698 schedule_work(&uc_op_work->work);
699}
700
701/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800702 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
703 * @ctrl: WDI control value
704 *
705 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
706 *
707 * Return: 0 on message send to ipa, -1 on failure
708 */
709static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
710{
711 struct ipa_msg_meta meta;
712 struct ipa_wlan_msg *ipa_msg;
713 int ret = 0;
714
715 /* WDI enable message to IPA */
716 meta.msg_len = sizeof(*ipa_msg);
717 ipa_msg = qdf_mem_malloc(meta.msg_len);
718 if (ipa_msg == NULL) {
719 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
720 "msg allocation failed");
721 return -ENOMEM;
722 }
723
724 if (ctrl == true)
725 meta.msg_type = WLAN_WDI_ENABLE;
726 else
727 meta.msg_type = WLAN_WDI_DISABLE;
728
Srinivas Girigowda97852372017-03-06 16:52:59 -0800729 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800730 "ipa_send_msg(Evt:%d)", meta.msg_type);
731 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
732 if (ret) {
733 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
734 "ipa_send_msg(Evt:%d)-fail=%d",
735 meta.msg_type, ret);
736 qdf_mem_free(ipa_msg);
737 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800738 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800739}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800740
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800741/**
742 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
743 * @hdd_ipa: HDD IPA local context
744 *
745 * Register IPA UC ready callback function to IPA kernel driver
746 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
747 * open WDI pipe after WLAN driver loading finished
748 *
749 * Return: 0 Success
750 * -EPERM Registration fail
751 */
752static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
753{
754 struct ipa_wdi_uc_ready_params uc_ready_param;
755 int ret = 0;
756
757 hdd_ipa->uc_loaded = false;
758 uc_ready_param.priv = (void *)hdd_ipa;
759 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
760 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
761 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
762 "UC Ready CB register fail");
763 return -EPERM;
764 }
765 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700766 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800767 hdd_ipa->uc_loaded = true;
768 } else {
769 ret = hdd_ipa_uc_send_wdi_control_msg(false);
770 }
771
772 return ret;
773}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800774#else
775static void hdd_ipa_uc_get_db_paddr(qdf_dma_addr_t *db_paddr,
776 enum ipa_client_type client)
777{
778 /* Do nothing */
779}
780
781static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
782{
783 hdd_ipa->uc_loaded = true;
784 return 0;
785}
786
787static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
788{
789 return 0;
790}
791#endif
792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793/**
794 * hdd_ipa_is_enabled() - Is IPA enabled?
795 * @hdd_ctx: Global HDD context
796 *
797 * Return: true if IPA is enabled, false otherwise
798 */
799bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
800{
801 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
802}
803
804/**
805 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
806 * @hdd_ctx: Global HDD context
807 *
808 * Return: true if IPA uC offload is enabled, false otherwise
809 */
810bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
811{
812 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
813}
814
815/**
816 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
817 * @hdd_ctx: Global HDD context
818 *
819 * Return: true if STA mode IPA uC offload is enabled, false otherwise
820 */
821static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
822{
823 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
824}
825
826/**
Guolei Bianca144d82016-11-10 11:07:42 +0800827 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
828 * @hdd_ipa: Global HDD IPA context
829 *
830 * Return: None
831 */
Guolei Bianca144d82016-11-10 11:07:42 +0800832static inline void hdd_ipa_uc_sta_reset_sta_connected(
833 struct hdd_ipa_priv *hdd_ipa)
834{
Yun Park637d6482016-10-05 10:51:33 -0700835 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800836 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700837 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800838}
Guolei Bianca144d82016-11-10 11:07:42 +0800839
840/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
842 * @hdd_ipa: Global HDD IPA context
843 *
844 * Return: true if pre-filter is enabled, otherwise false
845 */
846static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
847{
848 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
849 HDD_IPA_PRE_FILTER_ENABLE_MASK);
850}
851
852/**
853 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
854 * @hdd_ipa: Global HDD IPA context
855 *
856 * Return: true if IPv6 is enabled, otherwise false
857 */
858static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
859{
860 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
861}
862
863/**
864 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
865 * @hdd_ipa: Global HDD IPA context
866 *
867 * Return: true if resource manager is enabled, otherwise false
868 */
869static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
870{
871 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
872}
873
874/**
875 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
876 * @hdd_ipa: Global HDD IPA context
877 *
878 * Return: true if resource manager is enabled, otherwise false
879 */
880static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
881{
882 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
883}
884
885/**
886 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
887 * @hdd_ipa: Global HDD IPA context
888 *
889 * Return: true if clock scaling is enabled, otherwise false
890 */
891static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
892{
893 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
894 HDD_IPA_CLK_SCALING_ENABLE_MASK |
895 HDD_IPA_RM_ENABLE_MASK);
896}
897
898/**
899 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
900 * @ctext: pointer to hdd context.
901 *
902 * If rt debug enabled, periodically called, and fill debug buffer
903 *
904 * Return: none
905 */
906static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
907{
908 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
909 struct hdd_ipa_priv *hdd_ipa;
910 struct uc_rt_debug_info *dump_info = NULL;
911
912 if (wlan_hdd_validate_context(hdd_ctx))
913 return;
914
915 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -0800916 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 "%s: IPA UC is not enabled", __func__);
918 return;
919 }
920
921 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
922
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530923 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 dump_info = &hdd_ipa->rt_bug_buffer[
925 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
926
Deepthi Gowri6acee342016-10-28 15:00:38 +0530927 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
929 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
930 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800932 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
933 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800934 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
935 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530936 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937
Anurag Chouhan210db072016-02-22 18:42:15 +0530938 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
940}
941
942/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700943 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800944 * @hdd_ctx: pointer to hdd context.
945 *
946 * If rt debug enabled, dump debug buffer contents based on requirement
947 *
948 * Return: none
949 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700950static void __hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951{
952 struct hdd_ipa_priv *hdd_ipa;
953 unsigned int dump_count;
954 unsigned int dump_index;
955 struct uc_rt_debug_info *dump_info = NULL;
956
957 if (wlan_hdd_validate_context(hdd_ctx))
958 return;
959
960 hdd_ipa = hdd_ctx->hdd_ipa;
961 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -0800962 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 "%s: IPA UC is not enabled", __func__);
964 return;
965 }
966
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530967 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530969 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800970 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530972 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 for (dump_count = 0;
974 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
975 dump_count++) {
976 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
977 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
978 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530979 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530980 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 dump_info->time, dump_info->ipa_excep_count,
982 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800983 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 dump_info->rx_destructor_call,
985 dump_info->rx_discard_count);
986 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530987 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530988 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
990}
991
992/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700993 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
994 * __hdd_ipa_uc_rt_debug_host_dump
995 * @hdd_ctx: pointer to hdd context.
996 *
997 * If rt debug enabled, dump debug buffer contents based on requirement
998 *
999 * Return: none
1000 */
1001void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
1002{
1003 cds_ssr_protect(__func__);
1004 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
1005 cds_ssr_unprotect(__func__);
1006}
1007
1008/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
1010 * @ctext: pointer to hdd context.
1011 *
1012 * periodically called by timer expire
1013 * will try to alloc dummy memory and detect out of memory condition
1014 * if out of memory detected, dump wlan-ipa stats
1015 *
1016 * Return: none
1017 */
1018static void hdd_ipa_uc_rt_debug_handler(void *ctext)
1019{
1020 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001021 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 void *dummy_ptr = NULL;
1023
1024 if (wlan_hdd_validate_context(hdd_ctx))
1025 return;
1026
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001027 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001030 hdd_debug("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 return;
1032 }
1033
1034 /* Allocate dummy buffer periodically and free immediately. this will
1035 * proactively detect OOM and if allocation fails dump ipa stats
1036 */
1037 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
1038 GFP_KERNEL | GFP_ATOMIC);
1039 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
1041 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -07001042 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
1043 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 } else {
1045 kfree(dummy_ptr);
1046 }
1047
Anurag Chouhan210db072016-02-22 18:42:15 +05301048 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001049 HDD_IPA_UC_RT_DEBUG_PERIOD);
1050}
1051
1052/**
Yun Parkb187d542016-11-14 18:10:04 -08001053 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 * @skb: packet pinter
1055 *
1056 * when free data packet, will be invoked by wlan client and will increase
1057 * free counter
1058 *
1059 * Return: none
1060 */
Jeff Johnsond7720632016-10-05 16:04:32 -07001061static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001062{
1063 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301064 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 "%s: invalid hdd context", __func__);
1066 return;
1067 }
1068
1069 ghdd_ipa->ipa_rx_destructor_count++;
1070}
1071
1072/**
Yun Parkb187d542016-11-14 18:10:04 -08001073 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 * @hdd_ctx: hdd main context
1075 *
1076 * free all rt debugging resources
1077 *
1078 * Return: none
1079 */
1080static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
1081{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001082 struct hdd_ipa_priv *hdd_ipa;
1083
1084 if (wlan_hdd_validate_context(hdd_ctx))
1085 return;
1086
1087 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301089 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090
1091 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001092 hdd_debug("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 return;
1094 }
1095
Anurag Chouhan210db072016-02-22 18:42:15 +05301096 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001097 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1098 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1099 }
1100 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1101
1102 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301103 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1104 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301106 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107}
1108
1109/**
Yun Parkb187d542016-11-14 18:10:04 -08001110 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 * @hdd_ctx: hdd main context
1112 *
1113 * alloc and initialize all rt debugging resources
1114 *
1115 * Return: none
1116 */
1117static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
1118{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001119 struct hdd_ipa_priv *hdd_ipa;
1120
1121 if (wlan_hdd_validate_context(hdd_ctx))
1122 return;
1123
1124 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301126 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301128 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 sizeof(struct uc_rt_debug_info) *
1130 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1131 hdd_ipa->ipa_tx_forward = 0;
1132 hdd_ipa->ipa_rx_discard = 0;
1133 hdd_ipa->ipa_rx_net_send_count = 0;
1134 hdd_ipa->ipa_rx_internel_drop_count = 0;
1135 hdd_ipa->ipa_rx_destructor_count = 0;
1136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001137 /* Reatime debug enable on feature enable */
1138 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001139 hdd_debug("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001140 return;
1141 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001142
1143 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1144 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1145 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1146 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1147
Anurag Chouhan210db072016-02-22 18:42:15 +05301148 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001149 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301150 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 HDD_IPA_UC_RT_DEBUG_PERIOD);
1152
1153}
1154
1155/**
Yun Parkb187d542016-11-14 18:10:04 -08001156 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1157 * @hdd_ipa: HDD IPA struct
1158 *
1159 * Dump entries in struct hdd_ipa
1160 *
1161 * Return: none
1162 */
1163static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1164{
1165 int i;
1166
1167 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001168 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001169 "num_iface: %d\n"
1170 "rm_state: %d\n"
1171 "rm_lock: %p\n"
1172 "uc_rm_work: %p\n"
1173 "uc_op_work: %p\n"
1174 "wake_lock: %p\n"
1175 "wake_lock_work: %p\n"
1176 "wake_lock_released: %d\n"
1177 "prod_client: %d\n"
1178 "tx_ref_cnt: %d\n"
1179 "pm_queue_head----\n"
1180 "\thead: %p\n"
1181 "\ttail: %p\n"
1182 "\tqlen: %d\n"
1183 "pm_work: %p\n"
1184 "pm_lock: %p\n"
1185 "suspended: %d\n",
1186 hdd_ipa->num_iface,
1187 hdd_ipa->rm_state,
1188 &hdd_ipa->rm_lock,
1189 &hdd_ipa->uc_rm_work,
1190 &hdd_ipa->uc_op_work,
1191 &hdd_ipa->wake_lock,
1192 &hdd_ipa->wake_lock_work,
1193 hdd_ipa->wake_lock_released,
1194 hdd_ipa->prod_client,
1195 hdd_ipa->tx_ref_cnt.counter,
1196 hdd_ipa->pm_queue_head.head,
1197 hdd_ipa->pm_queue_head.tail,
1198 hdd_ipa->pm_queue_head.qlen,
1199 &hdd_ipa->pm_work,
1200 &hdd_ipa->pm_lock,
1201 hdd_ipa->suspended);
Yun Park52b2b992016-09-22 15:49:51 -07001202 hdd_err("\nq_lock: %p\n"
Yun Parkb187d542016-11-14 18:10:04 -08001203 "pend_desc_head----\n"
1204 "\tnext: %p\n"
1205 "\tprev: %p\n"
1206 "hdd_ctx: %p\n"
1207 "debugfs_dir: %p\n"
1208 "stats: %p\n"
1209 "ipv4_notifier: %p\n"
1210 "curr_prod_bw: %d\n"
1211 "curr_cons_bw: %d\n"
1212 "activated_fw_pipe: %d\n"
1213 "sap_num_connected_sta: %d\n"
1214 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001215 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001216 hdd_ipa->pend_desc_head.next,
1217 hdd_ipa->pend_desc_head.prev,
1218 hdd_ipa->hdd_ctx,
1219 hdd_ipa->debugfs_dir,
1220 &hdd_ipa->stats,
1221 &hdd_ipa->ipv4_notifier,
1222 hdd_ipa->curr_prod_bw,
1223 hdd_ipa->curr_cons_bw,
1224 hdd_ipa->activated_fw_pipe,
1225 hdd_ipa->sap_num_connected_sta,
1226 (unsigned int)hdd_ipa->sta_connected
1227 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001228 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001229 "rx_pipe_handle: 0x%x\n"
1230 "resource_loading: %d\n"
1231 "resource_unloading: %d\n"
1232 "pending_cons_req: %d\n"
1233 "pending_event----\n"
1234 "\tanchor.next: %p\n"
1235 "\tanchor.prev: %p\n"
1236 "\tcount: %d\n"
1237 "\tmax_size: %d\n"
1238 "event_lock: %p\n"
1239 "ipa_tx_packets_diff: %d\n"
1240 "ipa_rx_packets_diff: %d\n"
1241 "ipa_p_tx_packets: %d\n"
1242 "ipa_p_rx_packets: %d\n"
1243 "stat_req_reason: %d\n",
1244 hdd_ipa->tx_pipe_handle,
1245 hdd_ipa->rx_pipe_handle,
1246 hdd_ipa->resource_loading,
1247 hdd_ipa->resource_unloading,
1248 hdd_ipa->pending_cons_req,
1249 hdd_ipa->pending_event.anchor.next,
1250 hdd_ipa->pending_event.anchor.prev,
1251 hdd_ipa->pending_event.count,
1252 hdd_ipa->pending_event.max_size,
1253 &hdd_ipa->event_lock,
1254 hdd_ipa->ipa_tx_packets_diff,
1255 hdd_ipa->ipa_rx_packets_diff,
1256 hdd_ipa->ipa_p_tx_packets,
1257 hdd_ipa->ipa_p_rx_packets,
1258 hdd_ipa->stat_req_reason);
1259
Srinivas Girigowda97852372017-03-06 16:52:59 -08001260 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001261 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001262 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001263 hdd_ipa->assoc_stas_map[i].is_reserved,
1264 hdd_ipa->assoc_stas_map[i].sta_id);
1265 }
1266}
1267
1268/**
1269 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1270 * @hdd_ipa: HDD IPA struct
1271 *
1272 * Dump entire struct hdd_ipa_sys_pipe
1273 *
1274 * Return: none
1275 */
1276static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1277{
1278 int i;
1279
1280 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001281 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001282
1283 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1284 struct hdd_ipa_sys_pipe *sys_pipe;
1285 struct ipa_sys_connect_params *ipa_sys_params;
1286
1287 sys_pipe = &hdd_ipa->sys_pipe[i];
1288 ipa_sys_params = &sys_pipe->ipa_sys_params;
1289
Srinivas Girigowda97852372017-03-06 16:52:59 -08001290 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001291 "\tconn_hdl: 0x%x\n"
1292 "\tconn_hdl_valid: %d\n"
1293 "\tnat_en: %d\n"
1294 "\thdr_len %d\n"
1295 "\thdr_additional_const_len: %d\n"
1296 "\thdr_ofst_pkt_size_valid: %d\n"
1297 "\thdr_ofst_pkt_size: %d\n"
1298 "\thdr_little_endian: %d\n"
1299 "\tmode: %d\n"
1300 "\tclient: %d\n"
1301 "\tdesc_fifo_sz: %d\n"
1302 "\tpriv: %p\n"
1303 "\tnotify: %p\n"
1304 "\tskip_ep_cfg: %d\n"
1305 "\tkeep_ipa_awake: %d\n",
1306 i,
1307 sys_pipe->conn_hdl,
1308 sys_pipe->conn_hdl_valid,
1309 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1310 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1311 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1312 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1313 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1314 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1315 ipa_sys_params->ipa_ep_cfg.mode.mode,
1316 ipa_sys_params->client,
1317 ipa_sys_params->desc_fifo_sz,
1318 ipa_sys_params->priv,
1319 ipa_sys_params->notify,
1320 ipa_sys_params->skip_ep_cfg,
1321 ipa_sys_params->keep_ipa_awake);
1322 }
1323}
1324
1325/**
1326 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1327 * @hdd_ipa: HDD IPA struct
1328 *
1329 * Dump entire struct hdd_ipa_iface_context
1330 *
1331 * Return: none
1332 */
1333static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1334{
1335 int i;
1336
1337 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001338 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001339
1340 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1341 struct hdd_ipa_iface_context *iface_context;
1342
1343 iface_context = &hdd_ipa->iface_context[i];
1344
Srinivas Girigowda97852372017-03-06 16:52:59 -08001345 hdd_info("iface_context[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001346 "\thdd_ipa: %p\n"
1347 "\tadapter: %p\n"
1348 "\ttl_context: %p\n"
1349 "\tcons_client: %d\n"
1350 "\tprod_client: %d\n"
1351 "\tiface_id: %d\n"
1352 "\tsta_id: %d\n"
1353 "\tinterface_lock: %p\n"
1354 "\tifa_address: 0x%x\n",
1355 i,
1356 iface_context->hdd_ipa,
1357 iface_context->adapter,
1358 iface_context->tl_context,
1359 iface_context->cons_client,
1360 iface_context->prod_client,
1361 iface_context->iface_id,
1362 iface_context->sta_id,
1363 &iface_context->interface_lock,
1364 iface_context->ifa_address);
1365 }
1366}
1367
1368/**
1369 * hdd_ipa_dump_info() - dump HDD IPA struct
1370 * @pHddCtx: hdd main context
1371 *
1372 * Dump entire struct hdd_ipa
1373 *
1374 * Return: none
1375 */
1376void hdd_ipa_dump_info(hdd_context_t *hdd_ctx)
1377{
1378 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1379
1380 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1381 hdd_ipa_dump_sys_pipe(hdd_ipa);
1382 hdd_ipa_dump_iface_context(hdd_ipa);
1383}
1384
1385/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001386 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1387 * enabled
1388 *
1389 * This routine is called to set TX flow info if IPA is enabled
1390 *
1391 * Return: None
1392 */
1393void hdd_ipa_set_tx_flow_info(void)
1394{
1395 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1396 QDF_STATUS status;
1397 hdd_adapter_t *adapter;
1398 hdd_station_ctx_t *pHddStaCtx;
1399 hdd_ap_ctx_t *hdd_ap_ctx;
1400 hdd_hostapd_state_t *hostapd_state;
1401 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1402 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1403 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1404 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1405 const char *p2pMode = "DEV";
1406 hdd_context_t *hdd_ctx;
1407 cds_context_type *cds_ctx;
1408#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1409 uint8_t targetChannel = 0;
1410 uint8_t preAdapterChannel = 0;
1411 uint8_t channel24;
1412 uint8_t channel5;
1413 hdd_adapter_t *preAdapterContext = NULL;
1414 hdd_adapter_t *adapter2_4 = NULL;
1415 hdd_adapter_t *adapter5 = NULL;
1416 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1417#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1418 struct wlan_objmgr_psoc *psoc;
1419
1420 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1421 if (!hdd_ctx) {
1422 cds_err("HDD context is NULL");
1423 return;
1424 }
1425
1426 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1427 if (!cds_ctx) {
1428 cds_err("Invalid CDS Context");
1429 return;
1430 }
1431
1432 psoc = hdd_ctx->hdd_psoc;
1433 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1434 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1435 adapter = adapterNode->pAdapter;
1436 switch (adapter->device_mode) {
1437 case QDF_STA_MODE:
1438 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1439 if (eConnectionState_Associated ==
1440 pHddStaCtx->conn_info.connState) {
1441 staChannel =
1442 pHddStaCtx->conn_info.operationChannel;
1443 qdf_copy_macaddr(&staBssid,
1444 &pHddStaCtx->conn_info.bssId);
1445#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1446 targetChannel = staChannel;
1447#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1448 }
1449 break;
1450 case QDF_P2P_CLIENT_MODE:
1451 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1452 if (eConnectionState_Associated ==
1453 pHddStaCtx->conn_info.connState) {
1454 p2pChannel =
1455 pHddStaCtx->conn_info.operationChannel;
1456 qdf_copy_macaddr(&p2pBssid,
1457 &pHddStaCtx->conn_info.bssId);
1458 p2pMode = "CLI";
1459#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1460 targetChannel = p2pChannel;
1461#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1462 }
1463 break;
1464 case QDF_P2P_GO_MODE:
1465 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1466 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1467 if (hostapd_state->bssState == BSS_START
1468 && hostapd_state->qdf_status ==
1469 QDF_STATUS_SUCCESS) {
1470 p2pChannel = hdd_ap_ctx->operatingChannel;
1471 qdf_copy_macaddr(&p2pBssid,
1472 &adapter->macAddressCurrent);
1473#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1474 targetChannel = p2pChannel;
1475#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1476 }
1477 p2pMode = "GO";
1478 break;
1479 case QDF_SAP_MODE:
1480 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1481 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1482 if (hostapd_state->bssState == BSS_START
1483 && hostapd_state->qdf_status ==
1484 QDF_STATUS_SUCCESS) {
1485 apChannel = hdd_ap_ctx->operatingChannel;
1486 qdf_copy_macaddr(&apBssid,
1487 &adapter->macAddressCurrent);
1488#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1489 targetChannel = apChannel;
1490#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1491 }
1492 break;
1493 case QDF_IBSS_MODE:
1494 default:
1495 break;
1496 }
1497#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1498 if (targetChannel) {
1499 /*
1500 * This is first adapter detected as active
1501 * set as default for none concurrency case
1502 */
1503 if (!preAdapterChannel) {
1504 /* If IPA UC data path is enabled,
1505 * target should reserve extra tx descriptors
1506 * for IPA data path.
1507 * Then host data path should allow less TX
1508 * packet pumping in case IPA
1509 * data path enabled
1510 */
1511 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1512 (QDF_SAP_MODE == adapter->device_mode)) {
1513 adapter->tx_flow_low_watermark =
1514 hdd_ctx->config->TxFlowLowWaterMark +
1515 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1516 } else {
1517 adapter->tx_flow_low_watermark =
1518 hdd_ctx->config->
1519 TxFlowLowWaterMark;
1520 }
1521 adapter->tx_flow_high_watermark_offset =
1522 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1523 cdp_fc_ll_set_tx_pause_q_depth(soc,
1524 adapter->sessionId,
1525 hdd_ctx->config->TxFlowMaxQueueDepth);
1526 cds_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
1527 adapter->device_mode,
1528 targetChannel,
1529 adapter->tx_flow_low_watermark,
1530 adapter->tx_flow_low_watermark +
1531 adapter->tx_flow_high_watermark_offset,
1532 hdd_ctx->config->TxFlowMaxQueueDepth);
1533 preAdapterChannel = targetChannel;
1534 preAdapterContext = adapter;
1535 } else {
1536 /*
1537 * SCC, disable TX flow control for both
1538 * SCC each adapter cannot reserve dedicated
1539 * channel resource, as a result, if any adapter
1540 * blocked OS Q by flow control,
1541 * blocked adapter will lost chance to recover
1542 */
1543 if (preAdapterChannel == targetChannel) {
1544 /* Current adapter */
1545 adapter->tx_flow_low_watermark = 0;
1546 adapter->
1547 tx_flow_high_watermark_offset = 0;
1548 cdp_fc_ll_set_tx_pause_q_depth(soc,
1549 adapter->sessionId,
1550 hdd_ctx->config->
1551 TxHbwFlowMaxQueueDepth);
1552 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1553 hdd_device_mode_to_string(
1554 adapter->device_mode),
1555 adapter->device_mode,
1556 targetChannel,
1557 adapter->tx_flow_low_watermark,
1558 adapter->tx_flow_low_watermark +
1559 adapter->
1560 tx_flow_high_watermark_offset,
1561 hdd_ctx->config->
1562 TxHbwFlowMaxQueueDepth);
1563
1564 if (!preAdapterContext) {
1565 cds_err("SCC: Previous adapter context NULL");
1566 continue;
1567 }
1568
1569 /* Previous adapter */
1570 preAdapterContext->
1571 tx_flow_low_watermark = 0;
1572 preAdapterContext->
1573 tx_flow_high_watermark_offset = 0;
1574 cdp_fc_ll_set_tx_pause_q_depth(soc,
1575 preAdapterContext->sessionId,
1576 hdd_ctx->config->
1577 TxHbwFlowMaxQueueDepth);
1578 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1579 hdd_device_mode_to_string(
1580 preAdapterContext->device_mode
1581 ),
1582 preAdapterContext->device_mode,
1583 targetChannel,
1584 preAdapterContext->
1585 tx_flow_low_watermark,
1586 preAdapterContext->
1587 tx_flow_low_watermark +
1588 preAdapterContext->
1589 tx_flow_high_watermark_offset,
1590 hdd_ctx->config->
1591 TxHbwFlowMaxQueueDepth);
1592 }
1593 /*
1594 * MCC, each adapter will have dedicated
1595 * resource
1596 */
1597 else {
1598 /* current channel is 2.4 */
1599 if (targetChannel <=
1600 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1601 channel24 = targetChannel;
1602 channel5 = preAdapterChannel;
1603 adapter2_4 = adapter;
1604 adapter5 = preAdapterContext;
1605 } else {
1606 /* Current channel is 5 */
1607 channel24 = preAdapterChannel;
1608 channel5 = targetChannel;
1609 adapter2_4 = preAdapterContext;
1610 adapter5 = adapter;
1611 }
1612
1613 if (!adapter5) {
1614 cds_err("MCC: 5GHz adapter context NULL");
1615 continue;
1616 }
1617 adapter5->tx_flow_low_watermark =
1618 hdd_ctx->config->
1619 TxHbwFlowLowWaterMark;
1620 adapter5->
1621 tx_flow_high_watermark_offset =
1622 hdd_ctx->config->
1623 TxHbwFlowHighWaterMarkOffset;
1624 cdp_fc_ll_set_tx_pause_q_depth(soc,
1625 adapter5->sessionId,
1626 hdd_ctx->config->
1627 TxHbwFlowMaxQueueDepth);
1628 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1629 hdd_device_mode_to_string(
1630 adapter5->device_mode),
1631 adapter5->device_mode,
1632 channel5,
1633 adapter5->tx_flow_low_watermark,
1634 adapter5->
1635 tx_flow_low_watermark +
1636 adapter5->
1637 tx_flow_high_watermark_offset,
1638 hdd_ctx->config->
1639 TxHbwFlowMaxQueueDepth);
1640
1641 if (!adapter2_4) {
1642 cds_err("MCC: 2.4GHz adapter context NULL");
1643 continue;
1644 }
1645 adapter2_4->tx_flow_low_watermark =
1646 hdd_ctx->config->
1647 TxLbwFlowLowWaterMark;
1648 adapter2_4->
1649 tx_flow_high_watermark_offset =
1650 hdd_ctx->config->
1651 TxLbwFlowHighWaterMarkOffset;
1652 cdp_fc_ll_set_tx_pause_q_depth(soc,
1653 adapter2_4->sessionId,
1654 hdd_ctx->config->
1655 TxLbwFlowMaxQueueDepth);
1656 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1657 hdd_device_mode_to_string(
1658 adapter2_4->device_mode),
1659 adapter2_4->device_mode,
1660 channel24,
1661 adapter2_4->
1662 tx_flow_low_watermark,
1663 adapter2_4->
1664 tx_flow_low_watermark +
1665 adapter2_4->
1666 tx_flow_high_watermark_offset,
1667 hdd_ctx->config->
1668 TxLbwFlowMaxQueueDepth);
1669
1670 }
1671 }
1672 }
1673 targetChannel = 0;
1674#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1675 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1676 adapterNode = pNext;
1677 }
1678 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1679}
1680
1681/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001682 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001684 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1685 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001686 *
1687 * Return: true if IPA is enabled, false otherwise
1688 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001689static void __hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1691{
1692 struct hdd_ipa_priv *hdd_ipa;
1693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 *ipa_tx_diff = 0;
1695 *ipa_rx_diff = 0;
1696
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001697 if (wlan_hdd_validate_context(hdd_ctx))
1698 return;
1699
1700 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1701
1702 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1703 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 return;
1705 }
1706
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301707 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1709 (false == hdd_ipa->resource_loading)) {
1710 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1711 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001712 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001713 *ipa_tx_diff, *ipa_rx_diff);
1714 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301715 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716}
1717
1718/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001719 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1720 * @hdd_ctx: Global HDD context
1721 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1722 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1723 *
1724 * Return: true if IPA is enabled, false otherwise
1725 */
1726void hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
1727 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1728{
1729 cds_ssr_protect(__func__);
1730 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1731 cds_ssr_unprotect(__func__);
1732}
1733
1734/**
1735 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001736 * @adapter: network adapter
1737 * @reason: STAT REQ Reason
1738 *
1739 * Return: None
1740 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001741static void __hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001742{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001743 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744 struct hdd_ipa_priv *hdd_ipa;
1745
Yun Park637d6482016-10-05 10:51:33 -07001746 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001748
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001749 hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
1750
1751 if (wlan_hdd_validate_context(hdd_ctx))
1752 return;
1753
1754 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1755 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1756 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 return;
1758 }
1759
Yun Parkb187d542016-11-14 18:10:04 -08001760 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301761 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001762 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1763 (false == hdd_ipa->resource_loading)) {
1764 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001765 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766 wma_cli_set_command(
1767 (int)adapter->sessionId,
1768 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
1769 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001770 } else {
1771 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773}
1774
1775/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001776 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1777 * @adapter: network adapter
1778 * @reason: STAT REQ Reason
1779 *
1780 * Return: None
1781 */
1782void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
1783{
1784 cds_ssr_protect(__func__);
1785 __hdd_ipa_uc_stat_request(adapter, reason);
1786 cds_ssr_unprotect(__func__);
1787}
1788
Yun Park637d6482016-10-05 10:51:33 -07001789#ifdef FEATURE_METERING
1790/**
1791 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1792 * @adapter: network adapter
1793 * @reset_stats: reset stat countis after response
1794 *
1795 * Return: None
1796 */
1797void hdd_ipa_uc_sharing_stats_request(hdd_adapter_t *adapter,
1798 uint8_t reset_stats)
1799{
1800 hdd_context_t *pHddCtx;
1801 struct hdd_ipa_priv *hdd_ipa;
1802
1803 if (!adapter)
1804 return;
1805
1806 pHddCtx = adapter->pHddCtx;
1807 hdd_ipa = pHddCtx->hdd_ipa;
1808 if (!hdd_ipa_is_enabled(pHddCtx) ||
1809 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1810 return;
1811 }
1812
1813 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1814 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001815 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001816 qdf_mutex_release(&hdd_ipa->ipa_lock);
1817 wma_cli_set_command(
1818 (int)adapter->sessionId,
1819 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1820 reset_stats, VDEV_CMD);
1821 } else {
1822 qdf_mutex_release(&hdd_ipa->ipa_lock);
1823 }
1824}
1825
1826/**
1827 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1828 * @adapter: network adapter
1829 * @set_quota: when 1, FW starts quota monitoring
1830 * @quota_bytes: quota limit in bytes
1831 *
1832 * Return: None
1833 */
1834void hdd_ipa_uc_set_quota(hdd_adapter_t *adapter, uint8_t set_quota,
1835 uint64_t quota_bytes)
1836{
1837 hdd_context_t *pHddCtx;
1838 struct hdd_ipa_priv *hdd_ipa;
1839
1840 if (!adapter)
1841 return;
1842
1843 pHddCtx = adapter->pHddCtx;
1844 hdd_ipa = pHddCtx->hdd_ipa;
1845 if (!hdd_ipa_is_enabled(pHddCtx) ||
1846 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1847 return;
1848 }
1849
1850 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1851 set_quota, quota_bytes);
1852
1853 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001854 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001855 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001856 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001857 (int)adapter->sessionId,
1858 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001859 (set_quota ? quota_bytes&0xffffffff : 0),
1860 (set_quota ? quota_bytes>>32 : 0),
1861 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001862 } else {
1863 qdf_mutex_release(&hdd_ipa->ipa_lock);
1864 }
1865}
1866#endif
1867
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001868/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1870 * @hdd_ipa: Global HDD IPA context
1871 * @sta_add: Should station be added
1872 * @sta_id: ID of the station being queried
1873 *
1874 * Return: true if the station was found
1875 */
1876static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1877 bool sta_add, uint8_t sta_id)
1878{
1879 bool sta_found = false;
1880 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001881
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001882 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1883 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1884 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1885 sta_found = true;
1886 break;
1887 }
1888 }
1889 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301890 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 "%s: STA ID %d already exist, cannot add",
1892 __func__, sta_id);
1893 return sta_found;
1894 }
1895 if (sta_add) {
1896 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1897 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1898 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1899 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1900 return sta_found;
1901 }
1902 }
1903 }
1904 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301905 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906 "%s: STA ID %d does not exist, cannot delete",
1907 __func__, sta_id);
1908 return sta_found;
1909 }
1910 if (!sta_add) {
1911 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1912 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1913 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1914 hdd_ipa->assoc_stas_map[idx].is_reserved =
1915 false;
1916 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1917 return sta_found;
1918 }
1919 }
1920 }
1921 return sta_found;
1922}
1923
1924/**
1925 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1926 * @hdd_ipa: Global HDD IPA context
1927 *
1928 * Return: 0 on success, negative errno if error
1929 */
1930static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1931{
1932 int result;
1933 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001934 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935
1936 /* ACTIVATE TX PIPE */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001937 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park4cab6ee2015-10-27 11:43:40 -07001938 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1939 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1941 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301942 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001943 "%s: Enable TX PIPE fail, code %d",
1944 __func__, result);
1945 return result;
1946 }
1947 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1948 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301949 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 "%s: Resume TX PIPE fail, code %d",
1951 __func__, result);
1952 return result;
1953 }
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001954 cdp_ipa_set_active(soc,
1955 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
1956 true, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957
1958 /* ACTIVATE RX PIPE */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001959 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park4cab6ee2015-10-27 11:43:40 -07001960 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1961 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001962 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1963 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301964 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001965 "%s: Enable RX PIPE fail, code %d",
1966 __func__, result);
1967 return result;
1968 }
1969 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1970 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301971 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972 "%s: Resume RX PIPE fail, code %d",
1973 __func__, result);
1974 return result;
1975 }
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001976 cdp_ipa_set_active(soc,
1977 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
1978 true, false);
Leo Change3e49442015-10-26 20:07:13 -07001979 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001980 return 0;
1981}
1982
1983/**
1984 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1985 * @hdd_ipa: Global HDD IPA context
1986 *
1987 * Return: 0 on success, negative errno if error
1988 */
1989static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1990{
1991 int result;
1992
Leo Change3e49442015-10-26 20:07:13 -07001993 hdd_ipa->ipa_pipes_down = true;
1994
Srinivas Girigowda97852372017-03-06 16:52:59 -08001995 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1997 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301998 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 "%s: Suspend RX PIPE fail, code %d",
2000 __func__, result);
2001 return result;
2002 }
2003 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
2004 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302005 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 "%s: Disable RX PIPE fail, code %d",
2007 __func__, result);
2008 return result;
2009 }
2010
Srinivas Girigowda97852372017-03-06 16:52:59 -08002011 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
2013 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302014 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 "%s: Suspend TX PIPE fail, code %d",
2016 __func__, result);
2017 return result;
2018 }
2019 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
2020 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302021 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002022 "%s: Disable TX PIPE fail, code %d",
2023 __func__, result);
2024 return result;
2025 }
2026
2027 return 0;
2028}
2029
2030/**
2031 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
2032 * @hdd_ipa: Global HDD IPA context
2033 *
2034 * Return: 0 on success, negative errno if error
2035 */
2036static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
2037{
2038 hdd_ipa->activated_fw_pipe = 0;
2039 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07002040
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041 /* If RM feature enabled
2042 * Request PROD Resource first
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002043 * PROD resource may return sync or async manners
2044 */
Yun Park4cab6ee2015-10-27 11:43:40 -07002045 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
2046 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
2047 /* RM PROD request sync return
2048 * enable pipe immediately
2049 */
2050 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302051 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07002052 "%s: IPA WDI Pipe activation failed",
2053 __func__);
2054 hdd_ipa->resource_loading = false;
2055 return -EBUSY;
2056 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002057 }
2058 } else {
2059 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07002060 * Just enabled all the PIPEs
2061 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302063 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07002064 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 __func__);
2066 hdd_ipa->resource_loading = false;
2067 return -EBUSY;
2068 }
2069 hdd_ipa->resource_loading = false;
2070 }
Yun Park4cab6ee2015-10-27 11:43:40 -07002071
Srinivas Girigowda97852372017-03-06 16:52:59 -08002072 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park4cab6ee2015-10-27 11:43:40 -07002073 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002074 return 0;
2075}
2076
2077/**
2078 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
2079 * @hdd_ipa: Global HDD IPA context
2080 *
2081 * Return: None
2082 */
2083static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
2084{
2085 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07002086 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002087
Yun Park7c4f31b2016-11-30 10:09:21 -08002088 if (!cds_ctx || !cds_ctx->pdev_txrx_ctx) {
2089 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
2090 QDF_ASSERT(0);
2091 return;
2092 }
2093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002094 hdd_ipa->resource_unloading = true;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002095 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable FW RX PIPE", __func__);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08002096 cdp_ipa_set_active(soc,
2097 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
2098 false, false);
Srinivas Girigowda97852372017-03-06 16:52:59 -08002099 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable FW TX PIPE", __func__);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08002100 cdp_ipa_set_active(soc,
2101 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
2102 false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002103}
2104
2105/**
2106 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2107 * @context: User context registered with TL (the IPA Global context is
2108 * registered
2109 * @rxpkt: Packet containing the notification
2110 * @staid: ID of the station associated with the packet
2111 *
2112 * Return: None
2113 */
2114static void
2115hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
2116{
2117 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302118 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119
2120 /*
2121 * When SSR is going on or driver is unloading, just return.
2122 */
2123 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302124 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002125 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126
2127 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2128 return;
2129
Srinivas Girigowda97852372017-03-06 16:52:59 -08002130 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131 __func__, event);
2132
2133 switch (event) {
2134 case IPA_RM_RESOURCE_GRANTED:
2135 /* Differed RM Granted */
2136 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302137 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138 if ((false == hdd_ipa->resource_unloading) &&
2139 (!hdd_ipa->activated_fw_pipe)) {
2140 hdd_ipa_uc_enable_pipes(hdd_ipa);
2141 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302142 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002143 break;
2144
2145 case IPA_RM_RESOURCE_RELEASED:
2146 /* Differed RM Released */
2147 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148 break;
2149
2150 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302151 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152 "%s, invalid event code %d", __func__, event);
2153 break;
2154 }
2155}
2156
2157/**
2158 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2159 * @hdd_ipa: Global HDD IPA context
2160 * @event: IPA resource manager event to be deferred
2161 *
2162 * This function is called when a resource manager event is received
2163 * from firmware in interrupt context. This function will defer the
2164 * handling to the OL RX thread
2165 *
2166 * Return: None
2167 */
2168static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2169{
2170 enum ipa_rm_event event;
2171 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2172 struct uc_rm_work_struct, work);
2173 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2174 struct hdd_ipa_priv, uc_rm_work);
2175
2176 cds_ssr_protect(__func__);
2177 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002178 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179 "%s, posted event %d", __func__, event);
2180
2181 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2182 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002183}
2184
2185/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002186 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
2187 * @ipa_ctxt: hdd ipa local context
2188 *
2189 * Will handle IPA UC image loaded indication comes from IPA kernel
2190 *
2191 * Return: None
2192 */
2193static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *ipa_ctxt)
2194{
2195 struct ipa_wdi_out_params pipe_out;
2196
2197 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
2198 if (true == ipa_ctxt->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002199 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002200 __func__);
2201 return;
2202 }
2203
2204 ipa_ctxt->uc_loaded = true;
2205 /* Connect pipe */
2206 ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
2207 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
2208 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
2209 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2210 "%s : TX PIPE Handle %d, DBPA 0x%llx",
2211 __func__, ipa_ctxt->tx_pipe_handle,
2212 (unsigned long long) pipe_out.uc_door_bell_pa);
2213
2214 ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
2215 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
2216 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
2217 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2218 "%s : RX PIPE Handle %d, DBPA 0x%llx",
2219 __func__, ipa_ctxt->rx_pipe_handle,
2220 (unsigned long long) pipe_out.uc_door_bell_pa);
2221
2222 /* If already any STA connected, enable IPA/FW PIPEs */
2223 if (ipa_ctxt->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002224 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002225 "Client already connected, enable IPA/FW PIPEs");
2226 hdd_ipa_uc_handle_first_con(ipa_ctxt);
2227 }
2228}
2229
2230/**
Yun Park637d6482016-10-05 10:51:33 -07002231 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2232 * @hdd_ctx: Global HDD context
2233 * @op_msg: operation message received from firmware
2234 *
2235 * Return: QDF_STATUS enumeration
2236 */
2237#ifdef FEATURE_METERING
2238static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2239 struct op_msg_type *op_msg)
2240{
2241 struct op_msg_type *msg = op_msg;
2242 struct ipa_uc_sharing_stats *uc_sharing_stats;
2243 struct ipa_uc_quota_rsp *uc_quota_rsp;
2244 struct ipa_uc_quota_ind *uc_quota_ind;
2245 struct hdd_ipa_priv *hdd_ipa;
2246 hdd_adapter_t *adapter;
2247
2248 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2249
2250 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2251 /* fill-up ipa_uc_sharing_stats structure from FW */
2252 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2253 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2254
2255 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2256 sizeof(struct ipa_uc_sharing_stats));
2257
2258 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2259
2260 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2261 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2262 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2263 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2264 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2265 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2266 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2267 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2268 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2269 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2270 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2271 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2272 /* received set quota response */
2273 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2274 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2275
2276 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2277 sizeof(struct ipa_uc_quota_rsp));
2278
2279 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2280 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2281 "%s: success=%d, quota_bytes=%llu",
2282 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2283 hdd_ipa->ipa_quota_rsp.success,
2284 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2285 hdd_ipa->ipa_quota_rsp.quota_lo);
2286 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2287 /* hit quota limit */
2288 uc_quota_ind = (struct ipa_uc_quota_ind *)
2289 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2290
2291 hdd_ipa->ipa_quota_ind.quota_bytes =
2292 uc_quota_ind->quota_bytes;
2293
2294 /* send quota exceeded indication to IPA */
2295 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2296 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2297 hdd_ipa->ipa_quota_ind.quota_bytes);
2298
2299 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2300 if (adapter)
2301 ipa_broadcast_wdi_quota_reach_ind(
2302 adapter->dev->ifindex,
2303 uc_quota_ind->quota_bytes);
2304 else
2305 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2306 "Failed quota_reach_ind: NULL adapter");
2307 } else {
2308 return QDF_STATUS_E_INVAL;
2309 }
2310
2311 return QDF_STATUS_SUCCESS;
2312}
2313#else
2314static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2315 struct op_msg_type *op_msg)
2316{
2317 return QDF_STATUS_E_INVAL;
2318}
2319#endif
2320
2321/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002322 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2323 * @op_msg: operation message received from firmware
2324 * @usr_ctxt: user context registered with TL (we register the HDD Global
2325 * context)
2326 *
2327 * Return: None
2328 */
2329static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2330{
2331 struct op_msg_type *msg = op_msg;
2332 struct ipa_uc_fw_stats *uc_fw_stat;
2333 struct IpaHwStatsWDIInfoData_t ipa_stat;
2334 struct hdd_ipa_priv *hdd_ipa;
2335 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302336 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002337
2338 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302339 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002340 return;
2341 }
2342
2343 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302344 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002345 "%s, INVALID OPCODE %d", __func__, msg->op_code);
2346 return;
2347 }
2348
2349 hdd_ctx = (hdd_context_t *) usr_ctxt;
2350
2351 /*
2352 * When SSR is going on or driver is unloading, just return.
2353 */
2354 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302355 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302356 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002357 return;
2358 }
2359
2360 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2361
Govind Singhb6a89772016-08-12 11:23:35 +05302362 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002363 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002364
2365 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2366 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302367 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 hdd_ipa->activated_fw_pipe++;
2369 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2370 hdd_ipa->resource_loading = false;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002371 if (hdd_ipa->wdi_enabled == false) {
2372 hdd_ipa->wdi_enabled = true;
2373 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2374 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2375 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002376 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002377 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002378 if (hdd_ipa->pending_cons_req)
2379 ipa_rm_notify_completion(
2380 IPA_RM_RESOURCE_GRANTED,
2381 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002382 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002383 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302384 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002385 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002386 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302387 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002388 hdd_ipa->activated_fw_pipe--;
2389 if (!hdd_ipa->activated_fw_pipe) {
2390 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002391 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2392 ipa_rm_release_resource(
2393 IPA_RM_RESOURCE_WLAN_PROD);
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002394 /*
2395 * Sync return success from IPA
2396 * Enable/resume all the PIPEs
2397 */
Yun Park5b635012015-12-02 15:05:01 -08002398 hdd_ipa->resource_unloading = false;
2399 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2400 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002401 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302402 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002403 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002405 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002406 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302407 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002408 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002409 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410 "CE RING SIZE: %d\n"
2411 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002412 (unsigned long long)res->ce_sr_base_paddr,
2413 res->ce_sr_ring_size,
2414 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302415 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002417 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002418 "COMP RING SIZE: %d\n"
2419 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002420 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002421 (unsigned long long)res->tx_comp_ring_base_paddr,
2422 res->tx_comp_ring_size,
2423 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08002424 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302425 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002426 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002427 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002428 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002429 "IND RING DBELL : 0x%llx\n"
2430 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002431 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002432 "NUM TX FWD OK : %llu\n"
2433 "NUM TX FWD ERR : %llu",
Yun Park8b2bc4b2016-12-18 16:58:33 -08002434 (unsigned long long)res->rx_rdy_ring_base_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002435 res->rx_rdy_ring_size,
Yun Park8b2bc4b2016-12-18 16:58:33 -08002436 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
2437 (unsigned long long)res->rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002438 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002439 hdd_ipa->stats.num_tx_fwd_ok,
2440 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302441 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2443 "SAP NUM STAs: %d\n"
2444 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002445 "CONCURRENT MODE: %s\n"
2446 "TX PIPE HDL: 0x%x\n"
2447 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002448 "RSC LOADING : %d\n"
2449 "RSC UNLOADING : %d\n"
2450 "PNDNG CNS RQT : %d",
2451 hdd_ipa->sap_num_connected_sta,
2452 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002453 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002454 hdd_ipa->tx_pipe_handle,
2455 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002456 hdd_ipa->resource_loading,
2457 hdd_ipa->resource_unloading,
2458 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002459
2460 /* STATs from FW */
2461 uc_fw_stat = (struct ipa_uc_fw_stats *)
2462 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302463 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002464 "==== IPA_UC WLAN_FW TX ====\n"
2465 "COMP RING BASE: 0x%x\n"
2466 "COMP RING SIZE: %d\n"
2467 "COMP RING DBELL : 0x%x\n"
2468 "COMP RING DBELL IND VAL : %d\n"
2469 "COMP RING DBELL CACHED VAL : %d\n"
2470 "COMP RING DBELL CACHED VAL : %d\n"
2471 "PKTS ENQ : %d\n"
2472 "PKTS COMP : %d\n"
2473 "IS SUSPEND : %d\n"
2474 "RSVD : 0x%x",
2475 uc_fw_stat->tx_comp_ring_base,
2476 uc_fw_stat->tx_comp_ring_size,
2477 uc_fw_stat->tx_comp_ring_dbell_addr,
2478 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2479 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2480 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2481 uc_fw_stat->tx_pkts_enqueued,
2482 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002483 uc_fw_stat->tx_is_suspend,
2484 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302485 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002486 "==== IPA_UC WLAN_FW RX ====\n"
2487 "IND RING BASE: 0x%x\n"
2488 "IND RING SIZE: %d\n"
2489 "IND RING DBELL : 0x%x\n"
2490 "IND RING DBELL IND VAL : %d\n"
2491 "IND RING DBELL CACHED VAL : %d\n"
2492 "RDY IND ADDR : 0x%x\n"
2493 "RDY IND CACHE VAL : %d\n"
2494 "RFIL IND : %d\n"
2495 "NUM PKT INDICAT : %d\n"
2496 "BUF REFIL : %d\n"
2497 "NUM DROP NO SPC : %d\n"
2498 "NUM DROP NO BUF : %d\n"
2499 "IS SUSPND : %d\n"
2500 "RSVD : 0x%x\n",
2501 uc_fw_stat->rx_ind_ring_base,
2502 uc_fw_stat->rx_ind_ring_size,
2503 uc_fw_stat->rx_ind_ring_dbell_addr,
2504 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2505 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2506 uc_fw_stat->rx_ind_ring_rdidx_addr,
2507 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2508 uc_fw_stat->rx_refill_idx,
2509 uc_fw_stat->rx_num_pkts_indicated,
2510 uc_fw_stat->rx_buf_refilled,
2511 uc_fw_stat->rx_num_ind_drop_no_space,
2512 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002513 uc_fw_stat->rx_is_suspend,
2514 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002515 /* STATs from IPA */
2516 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302517 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002518 "==== IPA_UC IPA TX ====\n"
2519 "NUM PROCD : %d\n"
2520 "CE DBELL : 0x%x\n"
2521 "NUM DBELL FIRED : %d\n"
2522 "COMP RNG FULL : %d\n"
2523 "COMP RNG EMPT : %d\n"
2524 "COMP RNG USE HGH : %d\n"
2525 "COMP RNG USE LOW : %d\n"
2526 "BAM FIFO FULL : %d\n"
2527 "BAM FIFO EMPT : %d\n"
2528 "BAM FIFO USE HGH : %d\n"
2529 "BAM FIFO USE LOW : %d\n"
2530 "NUM DBELL : %d\n"
2531 "NUM UNEXP DBELL : %d\n"
2532 "NUM BAM INT HDL : 0x%x\n"
2533 "NUM BAM INT NON-RUN : 0x%x\n"
2534 "NUM QMB INT HDL : 0x%x",
2535 ipa_stat.tx_ch_stats.num_pkts_processed,
2536 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2537 ipa_stat.tx_ch_stats.num_db_fired,
2538 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2539 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2540 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2541 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2542 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2543 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2544 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2545 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2546 ipa_stat.tx_ch_stats.num_db,
2547 ipa_stat.tx_ch_stats.num_unexpected_db,
2548 ipa_stat.tx_ch_stats.num_bam_int_handled,
2549 ipa_stat.tx_ch_stats.
2550 num_bam_int_in_non_runnning_state,
2551 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2552
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302553 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002554 "==== IPA_UC IPA RX ====\n"
2555 "MAX OST PKT : %d\n"
2556 "NUM PKT PRCSD : %d\n"
2557 "RNG RP : 0x%x\n"
2558 "COMP RNG FULL : %d\n"
2559 "COMP RNG EMPT : %d\n"
2560 "COMP RNG USE HGH : %d\n"
2561 "COMP RNG USE LOW : %d\n"
2562 "BAM FIFO FULL : %d\n"
2563 "BAM FIFO EMPT : %d\n"
2564 "BAM FIFO USE HGH : %d\n"
2565 "BAM FIFO USE LOW : %d\n"
2566 "NUM DB : %d\n"
2567 "NUM UNEXP DB : %d\n"
2568 "NUM BAM INT HNDL : 0x%x\n",
2569 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2570 ipa_stat.rx_ch_stats.num_pkts_processed,
2571 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2572 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2573 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2574 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2575 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2576 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2577 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2578 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2579 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2580 ipa_stat.rx_ch_stats.num_db,
2581 ipa_stat.rx_ch_stats.num_unexpected_db,
2582 ipa_stat.rx_ch_stats.num_bam_int_handled);
2583 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2584 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2585 /* STATs from FW */
2586 uc_fw_stat = (struct ipa_uc_fw_stats *)
2587 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302588 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002589 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2590 uc_fw_stat->tx_pkts_completed,
2591 hdd_ipa->ipa_p_tx_packets);
2592 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2593 (uc_fw_stat->rx_num_ind_drop_no_space +
2594 uc_fw_stat->rx_num_ind_drop_no_buf +
2595 uc_fw_stat->rx_num_pkts_indicated),
2596 hdd_ipa->ipa_p_rx_packets);
2597
2598 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2599 hdd_ipa->ipa_p_rx_packets =
2600 (uc_fw_stat->rx_num_ind_drop_no_space +
2601 uc_fw_stat->rx_num_ind_drop_no_buf +
2602 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302603 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002604 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2605 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2606 hdd_ipa_uc_loaded_handler(hdd_ipa);
2607 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002608 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2609 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2610 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302612 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613}
2614
2615
2616/**
2617 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2618 * @adapter: device adapter instance
2619 * @offload_type: MCC or SCC
2620 * @enable: TX offload enable or disable
2621 *
2622 * Return: none
2623 */
2624static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002625 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002626{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002627 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002629 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002630 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002631
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002632 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002633 return;
2634
Yun Park8292dcb2016-10-07 16:46:06 -07002635 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002636 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002637
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002638 if (!iface_context) {
2639 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2640 "Interface context is NULL");
2641 return;
2642 }
2643
2644 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002645 /* IPA offload status is already set as desired */
2646 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002647 "%s: (offload_type=%d, vdev_id=%d, enable=%d)",
2648 "IPA offload status is already set",
2649 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002650 return;
2651 }
2652
Yun Park4540e862016-11-10 16:30:06 -08002653 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2654 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2655 "invalid session id: %d, offload_type=%d, enable=%d",
2656 adapter->sessionId, offload_type, enable);
2657 return;
2658 }
2659
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302660 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002661 sizeof(ipa_offload_enable_disable));
2662 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002663 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664 ipa_offload_enable_disable.enable = enable;
2665
Srinivas Girigowda97852372017-03-06 16:52:59 -08002666 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002667 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002668 ipa_offload_enable_disable.offload_type,
2669 ipa_offload_enable_disable.vdev_id,
2670 ipa_offload_enable_disable.enable);
2671
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302672 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002673 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2674 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302675 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002676 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
2677 __func__,
2678 ipa_offload_enable_disable.offload_type,
2679 ipa_offload_enable_disable.vdev_id,
2680 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002681 } else {
2682 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002683 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002684 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685 }
2686}
2687
2688/**
2689 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2690 * @work: uC OP work
2691 *
2692 * Return: None
2693 */
2694static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2695{
2696 struct op_msg_type *msg;
2697 struct uc_op_work_struct *uc_op_work = container_of(work,
2698 struct uc_op_work_struct, work);
2699 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2700
2701 cds_ssr_protect(__func__);
2702
2703 msg = uc_op_work->msg;
2704 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002705 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002706 "%s, posted msg %d", __func__, msg->op_code);
2707
2708 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2709
2710 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711}
2712
2713/**
2714 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2715 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2716 * @op_msg: operation message received from firmware
2717 * @hdd_ctx: Global HDD context
2718 *
2719 * Return: None
2720 */
2721static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2722{
2723 struct hdd_ipa_priv *hdd_ipa;
2724 struct op_msg_type *msg;
2725 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302726 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002727
2728 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302729 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002730 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731
2732 msg = (struct op_msg_type *)op_msg;
2733 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
2734
2735 if (unlikely(!hdd_ipa))
2736 goto end;
2737
2738 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302739 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 __func__, msg->op_code);
2741 goto end;
2742 }
2743
2744 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2745 if (uc_op_work->msg)
2746 /* When the same uC OPCODE is already pended, just return */
2747 goto end;
2748
2749 uc_op_work->msg = msg;
2750 schedule_work(&uc_op_work->work);
2751 return;
2752
2753end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302754 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755}
2756
2757/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002758 * hdd_ipa_init_uc_op_work - init ipa uc op work
2759 * @work: struct work_struct
2760 * @work_handler: work_handler
2761 *
2762 * Return: none
2763 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002764static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002765 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002766{
2767 INIT_WORK(work, work_handler);
2768}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002769
Yun Park637d6482016-10-05 10:51:33 -07002770#ifdef FEATURE_METERING
2771/**
2772 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2773 * IPA calls to get WLAN stats or set quota limit.
2774 * @priv: pointer to private data registered with IPA (we register a
2775 *» pointer to the global IPA context)
2776 * @evt: the IPA event which triggered the callback
2777 * @data: data associated with the event
2778 *
2779 * Return: None
2780 */
2781static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2782 void *data)
2783{
2784 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2785 hdd_adapter_t *adapter = NULL;
2786 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2787 struct ipa_set_wifi_quota *ipa_set_quota;
2788 int ret = 0;
2789
2790 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2791 return;
2792
2793 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2794
2795 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2796
2797 switch (evt) {
2798 case IPA_GET_WDI_SAP_STATS:
2799 /* fill-up ipa_get_wdi_sap_stats structure after getting
2800 ipa_uc_fw_stats from FW */
2801 wdi_sap_stats = data;
2802
2803 if (!adapter) {
2804 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2805 "IPA uC share stats failed - no adapter");
2806 wdi_sap_stats->stats_valid = 0;
2807 return;
2808 }
2809
2810 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
2811 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
2812 hdd_ipa_uc_sharing_stats_request(adapter,
2813 wdi_sap_stats->reset_stats);
2814 ret = wait_for_completion_timeout(
2815 &hdd_ipa->ipa_uc_sharing_stats_comp,
2816 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2817 if (!ret) {
2818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2819 "IPA uC share stats request timed out");
2820 wdi_sap_stats->stats_valid = 0;
2821 } else {
2822 wdi_sap_stats->stats_valid = 1;
2823
2824 wdi_sap_stats->ipv4_rx_packets =
2825 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2826 wdi_sap_stats->ipv4_rx_bytes =
2827 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2828 wdi_sap_stats->ipv6_rx_packets =
2829 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2830 wdi_sap_stats->ipv6_rx_bytes =
2831 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2832 wdi_sap_stats->ipv4_tx_packets =
2833 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2834 wdi_sap_stats->ipv4_tx_bytes =
2835 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2836 wdi_sap_stats->ipv6_tx_packets =
2837 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2838 wdi_sap_stats->ipv6_tx_bytes =
2839 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2840 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2841 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2842 "IPA_GET_WDI_SAP_STATS",
2843 wdi_sap_stats->stats_valid,
2844 wdi_sap_stats->ipv4_rx_packets,
2845 wdi_sap_stats->ipv4_rx_bytes,
2846 wdi_sap_stats->ipv6_rx_packets,
2847 wdi_sap_stats->ipv6_rx_bytes,
2848 wdi_sap_stats->ipv4_tx_packets,
2849 wdi_sap_stats->ipv4_tx_bytes,
2850 wdi_sap_stats->ipv6_tx_packets,
2851 wdi_sap_stats->ipv6_tx_bytes);
2852 }
2853 break;
2854 case IPA_SET_WIFI_QUOTA:
2855 /* get ipa_set_wifi_quota structure from IPA and pass to FW
2856 through quota_exceeded field in ipa_uc_fw_stats */
2857 ipa_set_quota = data;
2858
2859 if (!adapter) {
2860 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2861 "IPA uC set quota failed - no adapter");
2862 ipa_set_quota->set_valid = 0;
2863 return;
2864 }
2865
2866 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2867 ipa_set_quota->quota_bytes);
2868
2869 ret = wait_for_completion_timeout(
2870 &hdd_ipa->ipa_uc_set_quota_comp,
2871 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2872 if (!ret) {
2873 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2874 "IPA uC set quota request timed out");
2875 ipa_set_quota->set_valid = 0;
2876 } else {
2877 ipa_set_quota->quota_bytes =
2878 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2879 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2880 ipa_set_quota->set_valid =
2881 hdd_ipa->ipa_quota_rsp.success;
2882 }
2883
2884 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2885 ipa_set_quota->quota_bytes,
2886 ipa_set_quota->set_valid);
2887 break;
2888 }
2889}
2890
2891/**
2892 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2893 * IPA calls to get WLAN stats or set quota limit.
2894 * @priv: pointer to private data registered with IPA (we register a
2895 *» pointer to the global IPA context)
2896 * @evt: the IPA event which triggered the callback
2897 * @data: data associated with the event
2898 *
2899 * Return: None
2900 */
2901static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2902 void *data)
2903{
2904 cds_ssr_protect(__func__);
2905 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2906 cds_ssr_unprotect(__func__);
2907}
2908
2909static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt,
2910 struct ipa_wdi_in_params *pipe_in)
2911{
2912 pipe_in->wdi_notify = hdd_ipa_wdi_meter_notifier_cb;
2913
2914 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2915 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2916}
2917#else
2918static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt,
2919 struct ipa_wdi_in_params *pipe_in)
2920{
2921}
2922#endif
2923
Rajeev Kumar217f2172016-01-06 18:11:55 -08002924/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002925 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2926 * @hdd_ctx: Global HDD context
2927 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302928 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002929 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002930QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002931{
2932 struct ipa_wdi_in_params pipe_in;
2933 struct ipa_wdi_out_params pipe_out;
2934 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935 uint8_t i;
Leo Changfdb45c32016-10-28 11:09:23 -07002936 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002937 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
2938 int ret;
2939 QDF_STATUS stat = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002941 ENTER();
2942
Yun Parkbaa62862017-01-18 13:43:34 -08002943 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002944 if (!pdev || !soc) {
2945 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkbaa62862017-01-18 13:43:34 -08002946 stat = QDF_STATUS_E_FAILURE;
2947 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002948 }
Yun Parkbaa62862017-01-18 13:43:34 -08002949
2950 cdp_ipa_get_resource(soc, (void *)pdev, &ipa_ctxt->ipa_resource);
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002951 if ((ipa_ctxt->ipa_resource.ce_sr_base_paddr == 0) ||
2952 (ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr == 0) ||
2953 (ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr == 0) ||
2954 (ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr == 0)) {
2955 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2956 "IPA UC resource alloc fail");
2957 return QDF_STATUS_E_FAILURE;
2958 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002959 qdf_mem_zero(&ipa_ctxt->cons_pipe_in, sizeof(struct ipa_wdi_in_params));
2960 qdf_mem_zero(&ipa_ctxt->prod_pipe_in, sizeof(struct ipa_wdi_in_params));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302961 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
2962 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002963
Anurag Chouhanffb21542016-02-17 14:33:03 +05302964 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Arun Khandavallicc544b32017-01-30 19:52:16 +05302965
2966 if (!cds_is_driver_recovering()) {
2967 qdf_mutex_create(&ipa_ctxt->event_lock);
2968 qdf_mutex_create(&ipa_ctxt->ipa_lock);
2969 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002970
2971 /* TX PIPE */
2972 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2973 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
2974 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2975 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2976 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
2977 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2978 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
2979 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
2980 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
2981 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
2982 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2983 pipe_in.sys.notify = hdd_ipa_i2w_cb;
2984 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002985 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
2986 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002987 pipe_in.sys.keep_ipa_awake = true;
2988 }
2989
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002990 pipe_in.u.dl.comp_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002991 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002992 pipe_in.u.dl.comp_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002993 ipa_ctxt->ipa_resource.tx_comp_ring_size *
2994 sizeof(qdf_dma_addr_t);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002995 pipe_in.u.dl.ce_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002996 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002997 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
2998 pipe_in.u.dl.ce_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002999 ipa_ctxt->ipa_resource.ce_sr_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003000 pipe_in.u.dl.num_tx_buffers =
Yun Parkbaa62862017-01-18 13:43:34 -08003001 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003002
Yun Parkbaa62862017-01-18 13:43:34 -08003003 qdf_mem_copy(&ipa_ctxt->cons_pipe_in, &pipe_in,
3004 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003005 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->tx_comp_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08003006 IPA_CLIENT_WLAN1_CONS);
3007
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003008 if (true == ipa_ctxt->uc_loaded) {
3009 /* Connect WDI IPA PIPE */
Yun Parkbaa62862017-01-18 13:43:34 -08003010 ret = ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
3011 if (ret) {
3012 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3013 "ipa_connect_wdi_pipe falied for Tx: ret=%d",
3014 ret);
3015 stat = QDF_STATUS_E_FAILURE;
3016 goto fail_return;
3017 }
Yun Park637d6482016-10-05 10:51:33 -07003018
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003019 /* Micro Controller Doorbell register */
Srinivas Girigowda97852372017-03-06 16:52:59 -08003020 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003021 "CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
3022 (unsigned int)pipe_out.uc_door_bell_pa,
3023 ipa_ctxt->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003024 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Yun Parkbaa62862017-01-18 13:43:34 -08003025
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003026 /* WLAN TX PIPE Handle */
3027 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Srinivas Girigowda97852372017-03-06 16:52:59 -08003028 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003029 "TX: %s 0x%x, %s %d, %s 0x%x, %s 0x%x, %s %d, %s %d, %s 0x%x",
3030 "comp_ring_base_pa",
3031 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
3032 "comp_ring_size",
3033 pipe_in.u.dl.comp_ring_size,
3034 "ce_ring_base_pa",
3035 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
3036 "ce_door_bell_pa",
3037 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
3038 "ce_ring_size",
3039 pipe_in.u.dl.ce_ring_size,
3040 "num_tx_buffers",
3041 pipe_in.u.dl.num_tx_buffers,
3042 "tx_comp_doorbell_paddr",
3043 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003044 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003045
3046 /* RX PIPE */
3047 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3048 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
3049 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
3050 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
3051 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
3052 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
3053 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
3054 sizeof(struct sps_iovec);
3055 pipe_in.sys.notify = hdd_ipa_w2i_cb;
3056 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303057 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkbaa62862017-01-18 13:43:34 -08003058 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059 pipe_in.sys.keep_ipa_awake = true;
3060 }
3061
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003062 pipe_in.u.ul.rdy_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08003063 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003064 pipe_in.u.ul.rdy_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08003065 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003066 pipe_in.u.ul.rdy_ring_rp_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08003067 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003068 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Yun Parkbaa62862017-01-18 13:43:34 -08003069
Yun Park637d6482016-10-05 10:51:33 -07003070 hdd_ipa_init_metering(ipa_ctxt, &pipe_in);
3071
Yun Parkbaa62862017-01-18 13:43:34 -08003072 qdf_mem_copy(&ipa_ctxt->prod_pipe_in, &pipe_in,
3073 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003074 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->rx_ready_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08003075 IPA_CLIENT_WLAN1_PROD);
3076
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003077 if (true == ipa_ctxt->uc_loaded) {
Yun Parkbaa62862017-01-18 13:43:34 -08003078 ret = ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
3079 if (ret) {
3080 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3081 "ipa_connect_wdi_pipe falied for Rx: ret=%d",
3082 ret);
3083 stat = QDF_STATUS_E_FAILURE;
3084 goto fail_return;
3085
3086 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003087 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
3088 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Srinivas Girigowda97852372017-03-06 16:52:59 -08003089 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkbaa62862017-01-18 13:43:34 -08003090 "PROD DB pipe out 0x%x TX PIPE Handle 0x%x",
3091 (unsigned int)pipe_out.uc_door_bell_pa,
3092 ipa_ctxt->tx_pipe_handle);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003093 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003094 "RX: %s 0x%x, %s %d, %s 0x%x, %s 0x%x",
3095 "rdy_ring_base_pa",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003096 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
Yun Park637d6482016-10-05 10:51:33 -07003097 "rdy_ring_size",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003098 pipe_in.u.ul.rdy_ring_size,
Yun Park637d6482016-10-05 10:51:33 -07003099 "rdy_ring_rp_pa",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003100 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Yun Park637d6482016-10-05 10:51:33 -07003101 "rx_ready_doorbell_paddr",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003102 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
3103 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104
Yun Parkbaa62862017-01-18 13:43:34 -08003105 cdp_ipa_set_doorbell_paddr(soc, (void *)pdev,
3106 ipa_ctxt->tx_comp_doorbell_paddr,
3107 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108
Yun Parkbaa62862017-01-18 13:43:34 -08003109 cdp_ipa_register_op_cb(soc, (void *)pdev,
3110 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
3111
3112 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
3113 "ipa_uc_op_cb=0x%p, tx_comp_idx_paddr=0x%x, rx_rdy_idx_paddr=0x%x",
3114 pdev->ipa_uc_op_cb,
3115 (unsigned int)pdev->htt_pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr,
3116 (unsigned int)pdev->htt_pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117
3118 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08003119 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Yun Parkbaa62862017-01-18 13:43:34 -08003120 hdd_ipa_uc_fw_op_event_handler);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 ipa_ctxt->uc_op_work[i].msg = NULL;
3122 }
3123
Yun Parkbaa62862017-01-18 13:43:34 -08003124fail_return:
3125 EXIT();
3126 return stat;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127}
3128
Leo Change3e49442015-10-26 20:07:13 -07003129/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003130 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07003131 * @hdd_ctx: hdd main context
3132 *
3133 * Force shutdown IPA pipe
3134 * Independent of FW pipe status, IPA pipe shutdonw progress
3135 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3136 * independent from FW pipe status
3137 *
3138 * Return: NONE
3139 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003140static void __hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07003141{
3142 struct hdd_ipa_priv *hdd_ipa;
3143
3144 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
3145 return;
3146
3147 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
3148 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303149 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07003150 "IPA pipes are not down yet, force shutdown");
3151 hdd_ipa_uc_disable_pipes(hdd_ipa);
3152 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003153 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Leo Change3e49442015-10-26 20:07:13 -07003154 "IPA pipes are down, do nothing");
3155 }
Leo Change3e49442015-10-26 20:07:13 -07003156}
3157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003159 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
3160 * __hdd_ipa_uc_force_pipe_shutdown
3161 * @hdd_ctx: hdd main context
3162 *
3163 * Force shutdown IPA pipe
3164 * Independent of FW pipe status, IPA pipe shutdonw progress
3165 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3166 * independent from FW pipe status
3167 *
3168 * Return: NONE
3169 */
3170void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
3171{
3172 cds_ssr_protect(__func__);
3173 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
3174 cds_ssr_unprotect(__func__);
3175}
3176
3177/**
Govind Singh9c58eba2016-09-02 16:23:06 +05303178 * hdd_ipa_msg_free_fn() - Free an IPA message
3179 * @buff: pointer to the IPA message
3180 * @len: length of the IPA message
3181 * @type: type of IPA message
3182 *
3183 * Return: None
3184 */
3185static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3186{
Srinivas Girigowda97852372017-03-06 16:52:59 -08003187 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05303188 ghdd_ipa->stats.num_free_msg++;
3189 qdf_mem_free(buff);
3190}
3191
Govind Singh9c58eba2016-09-02 16:23:06 +05303192/**
jge62037862016-12-09 10:44:33 +08003193 * hdd_ipa_uc_send_evt() - send event to ipa
3194 * @hdd_ctx: pointer to hdd context
3195 * @type: event type
3196 * @mac_addr: pointer to mac address
3197 *
3198 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303199 *
3200 * Return: 0 - Success
3201 */
jge62037862016-12-09 10:44:33 +08003202static int hdd_ipa_uc_send_evt(hdd_adapter_t *adapter,
3203 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303204{
jge62037862016-12-09 10:44:33 +08003205 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303206 struct ipa_msg_meta meta;
3207 struct ipa_wlan_msg *msg;
3208 int ret = 0;
jge62037862016-12-09 10:44:33 +08003209
3210 meta.msg_len = sizeof(struct ipa_wlan_msg);
3211 msg = qdf_mem_malloc(meta.msg_len);
3212 if (msg == NULL) {
3213 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3214 "msg allocation failed");
3215 return -ENOMEM;
3216 }
3217
3218 meta.msg_type = type;
3219 strlcpy(msg->name, adapter->dev->name,
3220 IPA_RESOURCE_NAME_MAX);
3221 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003222 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003223 msg->name, meta.msg_type);
3224 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3225 if (ret) {
3226 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3227 "%s: Evt: %d fail:%d",
3228 msg->name, meta.msg_type, ret);
3229 qdf_mem_free(msg);
3230 return ret;
3231 }
3232
3233 hdd_ipa->stats.num_send_msg++;
3234
3235 return ret;
3236}
3237
3238/**
3239 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3240 * @hdd_ctx: pointer to hdd adapter
3241 *
3242 * Send disconnect client event to IPA driver during SSR
3243 *
3244 * Return: 0 - Success
3245 */
3246static int hdd_ipa_uc_disconnect_client(hdd_adapter_t *adapter)
3247{
3248 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3249 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303250 int i;
3251
3252 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3253 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3254 continue;
3255 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003256 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3257 hdd_ipa->sap_num_connected_sta) {
3258 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3259 adapter->aStaInfo[i].macAddrSTA.bytes);
3260 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303261 }
3262 }
3263
3264 return ret;
3265}
3266
3267/**
jge62037862016-12-09 10:44:33 +08003268 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3269 * @hdd_ctx: pointer to hdd adapter
3270 *
3271 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303272 *
3273 * Return: 0 - Success
3274 */
jge62037862016-12-09 10:44:33 +08003275
3276static int hdd_ipa_uc_disconnect_ap(hdd_adapter_t *adapter)
3277{
3278 int ret = 0;
3279
3280 if (adapter->ipa_context)
3281 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3282 adapter->dev->dev_addr);
3283
3284 return ret;
3285}
3286
jge62037862016-12-09 10:44:33 +08003287/**
3288 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3289 * @hdd_ctx: pointer to hdd adapter
3290 *
3291 * Send disconnect sta event to IPA driver during SSR
3292 *
3293 * Return: 0 - Success
3294 */
3295static int hdd_ipa_uc_disconnect_sta(hdd_adapter_t *adapter)
3296{
3297 hdd_station_ctx_t *pHddStaCtx;
3298 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3299 int ret = 0;
3300
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003301 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003302 hdd_ipa->sta_connected) {
3303 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3304 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003305 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003306 }
3307
3308 return ret;
3309}
jge62037862016-12-09 10:44:33 +08003310
3311/**
3312 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3313 * @hdd_ctx: pointer to hdd context
3314 *
3315 * Send disconnect event to IPA driver during SSR
3316 *
3317 * Return: 0 - Success
3318 */
3319static int hdd_ipa_uc_disconnect(hdd_context_t *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303320{
3321 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3322 QDF_STATUS status;
3323 hdd_adapter_t *adapter;
3324 int ret = 0;
3325
Govind Singh9c58eba2016-09-02 16:23:06 +05303326 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3327 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3328 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08003329 if (adapter->device_mode == QDF_SAP_MODE) {
3330 hdd_ipa_uc_disconnect_client(adapter);
3331 hdd_ipa_uc_disconnect_ap(adapter);
3332 } else if (adapter->device_mode == QDF_STA_MODE) {
3333 hdd_ipa_uc_disconnect_sta(adapter);
3334 }
3335
Govind Singh9c58eba2016-09-02 16:23:06 +05303336 status = hdd_get_next_adapter(
3337 hdd_ctx, adapter_node, &next);
3338 adapter_node = next;
3339 }
3340
3341 return ret;
3342}
3343
3344/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003345 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003346 *
3347 * Deinit basic IPA UC host side to be in sync reloaded FW during
3348 * SSR
3349 *
3350 * Return: 0 - Success
3351 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003352static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353{
3354 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3355 int idx;
3356 struct hdd_ipa_iface_context *iface_context;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303357 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358
Arun Khandavallicc544b32017-01-30 19:52:16 +05303359 if (!hdd_ipa)
3360 return 0;
3361
3362 hdd_ctx = hdd_ipa->hdd_ctx;
3363 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 return 0;
3365
jge62037862016-12-09 10:44:33 +08003366 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303367 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369 /* Clean up HDD IPA interfaces */
3370 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3371 (idx < HDD_IPA_MAX_IFACE); idx++) {
3372 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003373 if (iface_context->adapter && iface_context->adapter->magic ==
3374 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375 hdd_ipa_cleanup_iface(iface_context);
3376 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003377 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378 /* After SSR, wlan driver reloads FW again. But we need to protect
3379 * IPA submodule during SSR transient state. So deinit basic IPA
3380 * UC host side to be in sync with reloaded FW during SSR
3381 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08003382 if (!hdd_ipa->ipa_pipes_down)
3383 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303385 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3387 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3388 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3389 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303390 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003391
Srinivas Girigowda97852372017-03-06 16:52:59 -08003392 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303393 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
3394 __func__, hdd_ipa->tx_pipe_handle);
3395 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
3396
Srinivas Girigowda97852372017-03-06 16:52:59 -08003397 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303398 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
3399 __func__, hdd_ipa->rx_pipe_handle);
3400 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
3401
Guolei Bianca144d82016-11-10 11:07:42 +08003402 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3403 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3404
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 /* Full IPA driver cleanup not required since wlan driver is now
3406 * unloaded and reloaded after SSR.
3407 */
3408 return 0;
3409}
3410
3411/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003412 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3413 *
3414 * Deinit basic IPA UC host side to be in sync reloaded FW during
3415 * SSR
3416 *
3417 * Return: 0 - Success
3418 */
3419int hdd_ipa_uc_ssr_deinit(void)
3420{
3421 int ret;
3422
3423 cds_ssr_protect(__func__);
3424 ret = __hdd_ipa_uc_ssr_deinit();
3425 cds_ssr_unprotect(__func__);
3426
3427 return ret;
3428}
3429
3430/**
3431 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432 *
3433 * Init basic IPA UC host side to be in sync with reloaded FW after
3434 * SSR to resume IPA UC operations
3435 *
3436 * Return: 0 - Success
3437 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303438static int __hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440
Arun Khandavallicc544b32017-01-30 19:52:16 +05303441 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3442 int i;
3443 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303444
3445 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3446 return 0;
3447
Arun Khandavallicc544b32017-01-30 19:52:16 +05303448 /* Create the interface context */
3449 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3450 iface_context = &hdd_ipa->iface_context[i];
3451 iface_context->hdd_ipa = hdd_ipa;
3452 iface_context->cons_client =
3453 hdd_ipa_adapter_2_client[i].cons_client;
3454 iface_context->prod_client =
3455 hdd_ipa_adapter_2_client[i].prod_client;
3456 iface_context->iface_id = i;
3457 iface_context->adapter = NULL;
3458 }
3459 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3460 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3461 hdd_ipa->vdev_offload_enabled[i] = false;
3462 }
3463
3464 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3465 hdd_ipa->resource_loading = false;
3466 hdd_ipa->resource_unloading = false;
3467 hdd_ipa->sta_connected = 0;
3468 hdd_ipa->ipa_pipes_down = true;
3469 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303470 }
3471
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 return 0;
3473}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003474
3475/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003476 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3477 *
3478 * Init basic IPA UC host side to be in sync with reloaded FW after
3479 * SSR to resume IPA UC operations
3480 *
3481 * Return: 0 - Success
3482 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303483int hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003484{
3485 int ret;
3486
3487 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303488 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003489 cds_ssr_unprotect(__func__);
3490
3491 return ret;
3492}
3493
3494/**
3495 * __hdd_ipa_tx_packet_ipa() - send packet to IPA
Leo Chang3bc8fed2015-11-13 10:59:47 -08003496 * @hdd_ctx: Global HDD context
3497 * @skb: skb sent to IPA
3498 * @session_id: send packet instance session id
3499 *
3500 * Send TX packet which generated by system to IPA.
3501 * This routine only will be used for function verification
3502 *
3503 * Return: NULL packet sent to IPA properly
3504 * NULL invalid packet drop
3505 * skb packet not sent to IPA. legacy data path should handle
3506 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003507static struct sk_buff *__hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08003508 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07003509{
Leo Chang3bc8fed2015-11-13 10:59:47 -08003510 struct ipa_header *ipa_header;
3511 struct frag_header *frag_header;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003512 struct hdd_ipa_priv *hdd_ipa;
3513
3514 if (wlan_hdd_validate_context(hdd_ctx))
3515 return skb;
3516
3517 hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003518
3519 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3520 return skb;
3521
Leo Chang07b28f62016-05-11 12:29:22 -07003522 if (!hdd_ipa)
3523 return skb;
3524
3525 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
3526 return skb;
3527
Leo Changcc923e22016-06-16 15:29:03 -07003528 if (skb_headroom(skb) <
3529 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07003530 return skb;
3531
Leo Chang3bc8fed2015-11-13 10:59:47 -08003532 ipa_header = (struct ipa_header *) skb_push(skb,
3533 sizeof(struct ipa_header));
3534 if (!ipa_header) {
3535 /* No headroom, legacy */
3536 return skb;
3537 }
3538 memset(ipa_header, 0, sizeof(*ipa_header));
3539 ipa_header->vdev_id = 0;
3540
3541 frag_header = (struct frag_header *) skb_push(skb,
3542 sizeof(struct frag_header));
3543 if (!frag_header) {
3544 /* No headroom, drop */
3545 kfree_skb(skb);
3546 return NULL;
3547 }
3548 memset(frag_header, 0, sizeof(*frag_header));
3549 frag_header->length = skb->len - sizeof(struct frag_header)
3550 - sizeof(struct ipa_header);
3551
3552 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
3553 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07003554}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555
3556/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003557 * hdd_ipa_tx_packet_ipa() - SSR wrapper for __hdd_ipa_tx_packet_ipa
3558 * @hdd_ctx: Global HDD context
3559 * @skb: skb sent to IPA
3560 * @session_id: send packet instance session id
3561 *
3562 * Send TX packet which generated by system to IPA.
3563 * This routine only will be used for function verification
3564 *
3565 * Return: NULL packet sent to IPA properly
3566 * NULL invalid packet drop
3567 * skb packet not sent to IPA. legacy data path should handle
3568 */
3569struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
3570 struct sk_buff *skb, uint8_t session_id)
3571{
3572 struct sk_buff *ret;
3573
3574 cds_ssr_protect(__func__);
3575 ret = __hdd_ipa_tx_packet_ipa(hdd_ctx, skb, session_id);
3576 cds_ssr_unprotect(__func__);
3577
3578 return ret;
3579}
3580
3581/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3583 * @work: scheduled work
3584 *
3585 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3586 * not want to immediately release the wake lock since the system
3587 * would then potentially try to suspend when there is a healthy data
3588 * rate. Deferred work is scheduled and this function handles the
3589 * work. When this function is called, if the IPA resource is still
3590 * released then we release the wake lock.
3591 *
3592 * Return: None
3593 */
3594static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3595{
3596 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3597 struct hdd_ipa_priv,
3598 wake_lock_work);
3599
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303600 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601
3602 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3603 goto end;
3604
3605 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303606 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607 WIFI_POWER_EVENT_WAKELOCK_IPA);
3608
3609end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303610 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611}
3612
3613/**
3614 * hdd_ipa_rm_request() - Request resource from IPA
3615 * @hdd_ipa: Global HDD IPA context
3616 *
3617 * Return: 0 on success, negative errno on error
3618 */
3619static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3620{
3621 int ret = 0;
3622
3623 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3624 return 0;
3625
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303626 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003627
3628 switch (hdd_ipa->rm_state) {
3629 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303630 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631 return 0;
3632 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303633 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634 return -EINPROGRESS;
3635 case HDD_IPA_RM_RELEASED:
3636 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3637 break;
3638 }
3639
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303640 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641
3642 ret = ipa_rm_inactivity_timer_request_resource(
3643 IPA_RM_RESOURCE_WLAN_PROD);
3644
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303645 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 if (ret == 0) {
3647 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3648 hdd_ipa->stats.num_rm_grant_imm++;
3649 }
3650
3651 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3652 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303653 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654 WIFI_POWER_EVENT_WAKELOCK_IPA);
3655 hdd_ipa->wake_lock_released = false;
3656 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303657 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658
3659 return ret;
3660}
3661
3662/**
3663 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3664 * @hdd_ipa: Global HDD IPA context
3665 *
3666 * Return: 0 if resources released, negative errno otherwise
3667 */
3668static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3669{
3670 int ret = 0;
3671
3672 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3673 return 0;
3674
3675 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3676 return -EAGAIN;
3677
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303678 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679
Nirav Shahcbc6d722016-03-01 16:24:53 +05303680 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303681 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003682 return -EAGAIN;
3683 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303684 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303686 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687 switch (hdd_ipa->rm_state) {
3688 case HDD_IPA_RM_GRANTED:
3689 break;
3690 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303691 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 return -EINPROGRESS;
3693 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303694 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695 return 0;
3696 }
3697
3698 /* IPA driver returns immediately so set the state here to avoid any
3699 * race condition.
3700 */
3701 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3702 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303703 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003705 ret = ipa_rm_inactivity_timer_release_resource(
3706 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303708 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 if (unlikely(ret != 0)) {
3710 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3711 WARN_ON(1);
3712 }
3713
3714 /*
3715 * If wake_lock is released immediately, kernel would try to suspend
3716 * immediately as well, Just avoid ping-pong between suspend-resume
3717 * while there is healthy amount of data transfer going on by
3718 * releasing the wake_lock after some delay.
3719 */
3720 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3721 msecs_to_jiffies
3722 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3723
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303724 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003725
3726 return ret;
3727}
3728
3729/**
3730 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3731 * @user_data: user data registered with IPA
3732 * @event: the IPA resource manager event that occurred
3733 * @data: the data associated with the event
3734 *
3735 * Return: None
3736 */
3737static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3738 unsigned long data)
3739{
3740 struct hdd_ipa_priv *hdd_ipa = user_data;
3741
3742 if (unlikely(!hdd_ipa))
3743 return;
3744
3745 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3746 return;
3747
Srinivas Girigowda97852372017-03-06 16:52:59 -08003748 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003749
3750 switch (event) {
3751 case IPA_RM_RESOURCE_GRANTED:
3752 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3753 /* RM Notification comes with ISR context
3754 * it should be serialized into work queue to avoid
3755 * ISR sleep problem
3756 */
3757 hdd_ipa->uc_rm_work.event = event;
3758 schedule_work(&hdd_ipa->uc_rm_work.work);
3759 break;
3760 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303761 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303763 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003764 hdd_ipa->stats.num_rm_grant++;
3765 break;
3766
3767 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003768 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769 hdd_ipa->resource_unloading = false;
3770 break;
3771
3772 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303773 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 break;
3775 }
3776}
3777
3778/**
3779 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3780 *
3781 * Callback function registered with IPA that is called when IPA wants
3782 * to release the WLAN consumer resource
3783 *
3784 * Return: 0 if the request is granted, negative errno otherwise
3785 */
3786static int hdd_ipa_rm_cons_release(void)
3787{
3788 return 0;
3789}
3790
3791/**
3792 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3793 *
3794 * Callback function registered with IPA that is called when IPA wants
3795 * to access the WLAN consumer resource
3796 *
3797 * Return: 0 if the request is granted, negative errno otherwise
3798 */
3799static int hdd_ipa_rm_cons_request(void)
3800{
Yun Park4d8b60a2015-10-22 13:59:32 -07003801 int ret = 0;
3802
3803 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303804 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003805 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 __func__);
3807 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003808 ret = -EINPROGRESS;
3809 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303810 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003811 "%s: IPA resource unloading in progress",
3812 __func__);
3813 ghdd_ipa->pending_cons_req = true;
3814 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003816
3817 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818}
3819
3820/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003821 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822 * @hdd_ctx: Global HDD context
3823 * @tx_packets: Number of packets transmitted in the last sample period
3824 * @rx_packets: Number of packets received in the last sample period
3825 *
3826 * Return: 0 on success, negative errno on error
3827 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003828static int __hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 uint64_t rx_packets)
3830{
3831 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003832 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833 struct ipa_rm_perf_profile profile;
3834 int ret;
3835
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003836 if (wlan_hdd_validate_context(hdd_ctx))
3837 return 0;
3838
3839 hdd_ipa = hdd_ctx->hdd_ipa;
3840
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3842 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3843 return 0;
3844
3845 memset(&profile, 0, sizeof(profile));
3846
3847 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3848 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3849 else if (tx_packets >
3850 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3851 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3852 else
3853 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3854
3855 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3856 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3857 else if (rx_packets >
3858 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3859 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3860 else
3861 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3862
Yun Parkec845302016-12-15 09:22:57 -08003863 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864 "CONS perf curr: %d, next: %d",
3865 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003866 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 "PROD perf curr: %d, next: %d",
3868 hdd_ipa->curr_prod_bw, next_prod_bw);
3869
3870 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003871 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 hdd_ipa->curr_cons_bw, next_cons_bw);
3873 profile.max_supported_bandwidth_mbps = next_cons_bw;
3874 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
3875 &profile);
3876 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003877 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
3879 return ret;
3880 }
3881 hdd_ipa->curr_cons_bw = next_cons_bw;
3882 hdd_ipa->stats.num_cons_perf_req++;
3883 }
3884
3885 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003886 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003887 hdd_ipa->curr_prod_bw, next_prod_bw);
3888 profile.max_supported_bandwidth_mbps = next_prod_bw;
3889 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
3890 &profile);
3891 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003892 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003893 return ret;
3894 }
3895 hdd_ipa->curr_prod_bw = next_prod_bw;
3896 hdd_ipa->stats.num_prod_perf_req++;
3897 }
3898
3899 return 0;
3900}
3901
3902/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003903 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3904 * @hdd_ctx: Global HDD context
3905 * @tx_packets: Number of packets transmitted in the last sample period
3906 * @rx_packets: Number of packets received in the last sample period
3907 *
3908 * Return: 0 on success, negative errno on error
3909 */
3910int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
3911 uint64_t rx_packets)
3912{
3913 int ret;
3914
3915 cds_ssr_protect(__func__);
3916 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3917 cds_ssr_unprotect(__func__);
3918
3919 return ret;
3920}
3921
3922/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003923 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3924 * @work: struct work_struct
3925 * @work_handler: work_handler
3926 *
3927 * Return: none
3928 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003929static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3930 work_func_t work_handler)
3931{
3932 INIT_WORK(work, work_handler);
3933}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003934
3935/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 * hdd_ipa_setup_rm() - Setup IPA resource management
3937 * @hdd_ipa: Global HDD IPA context
3938 *
3939 * Return: 0 on success, negative errno on error
3940 */
3941static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3942{
3943 struct ipa_rm_create_params create_params = { 0 };
3944 int ret;
3945
3946 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3947 return 0;
3948
Rajeev Kumar217f2172016-01-06 18:11:55 -08003949 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3950 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951 memset(&create_params, 0, sizeof(create_params));
3952 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3953 create_params.reg_params.user_data = hdd_ipa;
3954 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3955 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3956
3957 ret = ipa_rm_create_resource(&create_params);
3958 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303959 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 "Create RM resource failed: %d", ret);
3961 goto setup_rm_fail;
3962 }
3963
3964 memset(&create_params, 0, sizeof(create_params));
3965 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3966 create_params.request_resource = hdd_ipa_rm_cons_request;
3967 create_params.release_resource = hdd_ipa_rm_cons_release;
3968 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3969
3970 ret = ipa_rm_create_resource(&create_params);
3971 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303972 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 "Create RM CONS resource failed: %d", ret);
3974 goto delete_prod;
3975 }
3976
3977 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3978 IPA_RM_RESOURCE_APPS_CONS);
3979
3980 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3981 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3982 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303983 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 ret);
3985 goto timer_init_failed;
3986 }
3987
3988 /* Set the lowest bandwidth to start with */
3989 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3990
3991 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303992 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 "Set perf level failed: %d", ret);
3994 goto set_perf_failed;
3995 }
3996
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303997 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3999 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304000 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
4002 hdd_ipa->wake_lock_released = true;
4003 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
4004
4005 return ret;
4006
4007set_perf_failed:
4008 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4009
4010timer_init_failed:
4011 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4012
4013delete_prod:
4014 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4015
4016setup_rm_fail:
4017 return ret;
4018}
4019
4020/**
4021 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
4022 * @hdd_ipa: Global HDD IPA context
4023 *
4024 * Destroys all resources associated with the IPA resource manager
4025 *
4026 * Return: None
4027 */
4028static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
4029{
4030 int ret;
4031
4032 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4033 return;
4034
4035 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304036 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037
4038#ifdef WLAN_OPEN_SOURCE
4039 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
4040#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304041 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042
4043 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4044
4045 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4046 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304047 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 "RM PROD resource delete failed %d", ret);
4049
4050 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4051 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304052 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053 "RM CONS resource delete failed %d", ret);
4054}
4055
4056/**
4057 * hdd_ipa_send_skb_to_network() - Send skb to kernel
4058 * @skb: network buffer
4059 * @adapter: network adapter
4060 *
4061 * Called when a network buffer is received which should not be routed
4062 * to the IPA module.
4063 *
4064 * Return: None
4065 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304066static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004067 hdd_adapter_t *adapter)
4068{
4069 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4070 unsigned int cpu_index;
4071
4072 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004073 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 adapter);
4075 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004076 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 return;
4078 }
4079
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004080 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004082 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 return;
4084 }
4085
4086 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
4087 skb->dev = adapter->dev;
4088 skb->protocol = eth_type_trans(skb, skb->dev);
4089 skb->ip_summed = CHECKSUM_NONE;
4090
4091 cpu_index = wlan_hdd_get_cpu();
4092
4093 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
4094 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
4095 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
4096 else
4097 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
4098
4099 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
4100 adapter->dev->last_rx = jiffies;
4101}
4102
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004103/**
Leo Chang69c39692016-10-12 20:11:12 -07004104 * hdd_ipa_forward() - handle packet forwarding to wlan tx
4105 * @hdd_ipa: pointer to hdd ipa context
4106 * @adapter: network adapter
4107 * @skb: data pointer
4108 *
4109 * if exception packet has set forward bit, copied new packet should be
4110 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
4111 * put into pm queue and tx procedure will be differed
4112 *
4113 * Return: None
4114 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07004115static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
4116 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07004117{
Leo Chang69c39692016-10-12 20:11:12 -07004118 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
4119
Leo Chang69c39692016-10-12 20:11:12 -07004120 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
4121 /* WLAN subsystem is in suspend, put int queue */
4122 if (hdd_ipa->suspended) {
4123 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4124 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4125 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004126 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
4127 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07004128 pm_tx_cb->exception = true;
4129 pm_tx_cb->adapter = adapter;
4130 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004131 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07004132 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4133 hdd_ipa->stats.num_tx_queued++;
4134 } else {
4135 /* Resume, put packet into WLAN TX */
4136 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004137 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07004138 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4139 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08004140 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07004141 } else {
Yun Parkb187d542016-11-14 18:10:04 -08004142 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07004143 hdd_ipa->ipa_tx_forward++;
4144 }
4145 }
4146}
4147
4148/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004149 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
4150 * @hdd_ipa: pointer to HDD IPA struct
4151 * @adapter: hdd adapter pointer
4152 * @desc: Firmware descriptor
4153 * @skb: Data buffer
4154 *
4155 * Return:
4156 * HDD_IPA_FORWARD_PKT_NONE
4157 * HDD_IPA_FORWARD_PKT_DISCARD
4158 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
4159 *
4160 */
4161
4162static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
4163 struct hdd_ipa_priv *hdd_ipa,
4164 hdd_adapter_t *adapter,
4165 uint8_t desc,
4166 qdf_nbuf_t skb)
4167{
4168 int ret = HDD_IPA_FORWARD_PKT_NONE;
4169
4170 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304171 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004172 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
4173 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304174 /* Drop the packet*/
4175 hdd_ipa->stats.num_tx_fwd_err++;
4176 kfree_skb(skb);
4177 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4178 return ret;
4179 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004180 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
4181 "Forward packet to Tx (fw_desc=%d)", desc);
4182 hdd_ipa->ipa_tx_forward++;
4183
4184 if ((desc & FW_RX_DESC_DISCARD_M)) {
4185 hdd_ipa_forward(hdd_ipa, adapter, skb);
4186 hdd_ipa->ipa_rx_internel_drop_count++;
4187 hdd_ipa->ipa_rx_discard++;
4188 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4189 } else {
4190 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004191
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004192 if (cloned_skb)
4193 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
4194 else
4195 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4196 "%s: tx skb alloc failed",
4197 __func__);
4198 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
4199 }
4200 }
4201
4202 return ret;
4203}
4204
4205/**
Yun Park637d6482016-10-05 10:51:33 -07004206 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004207 * @priv: pointer to private data registered with IPA (we register a
4208 * pointer to the global IPA context)
4209 * @evt: the IPA event which triggered the callback
4210 * @data: data associated with the event
4211 *
4212 * Return: None
4213 */
Yun Parkf8d6a122016-10-11 15:49:43 -07004214static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 unsigned long data)
4216{
4217 struct hdd_ipa_priv *hdd_ipa = NULL;
4218 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304219 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220 uint8_t iface_id;
4221 uint8_t session_id;
4222 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07004224 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225
4226 hdd_ipa = (struct hdd_ipa_priv *)priv;
4227
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08004228 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
4229 return;
4230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231 switch (evt) {
4232 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05304233 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07004234
4235 /*
4236 * When SSR is going on or driver is unloading,
4237 * just drop the packets.
4238 */
4239 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4240 if (0 != status) {
4241 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4242 "Invalid context: drop packet");
4243 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4244 kfree_skb(skb);
4245 return;
4246 }
4247
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4249 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004250 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004251 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4253 session_id, iface_id);
4254 } else {
4255 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4256 }
4257
4258 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304259 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 "IPA_RECEIVE: Invalid iface_id: %u",
4261 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004262 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004263 "w2i -- skb",
4264 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004265 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004266 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267 return;
4268 }
4269
4270 iface_context = &hdd_ipa->iface_context[iface_id];
4271 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004272 if (!adapter) {
4273 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4274 "IPA_RECEIVE: Adapter is NULL");
4275 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4276 kfree_skb(skb);
4277 return;
4278 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304280 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004281 "w2i -- skb",
4282 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4284 hdd_ipa->stats.num_rx_excep++;
4285 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4286 } else {
4287 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4288 }
4289
4290 iface_context->stats.num_rx_ipa_excep++;
4291
4292 /* Disable to forward Intra-BSS Rx packets when
4293 * ap_isolate=1 in hostapd.conf
4294 */
Yun Park046101c2016-09-02 15:32:14 -07004295 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 /*
4297 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4298 * all Rx packets to IPA uC, which need to be forwarded
4299 * to other interface.
4300 * And, IPA driver will send back to WLAN host driver
4301 * through exception pipe with fw_desc field set by FW.
4302 * Here we are checking fw_desc field for FORWARD bit
4303 * set, and forward to Tx. Then copy to kernel stack
4304 * only when DISCARD bit is not set.
4305 */
4306 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004307 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4308 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4309 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004310 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004312 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 "Intra-BSS FWD is disabled-skip forward to Tx");
4314 }
4315
4316 hdd_ipa_send_skb_to_network(skb, adapter);
4317 break;
4318
4319 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304320 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 "w2i cb wrong event: 0x%x", evt);
4322 return;
4323 }
4324}
4325
4326/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004327 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4328 * @priv: pointer to private data registered with IPA (we register a
4329 * pointer to the global IPA context)
4330 * @evt: the IPA event which triggered the callback
4331 * @data: data associated with the event
4332 *
4333 * Return: None
4334 */
4335static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4336 unsigned long data)
4337{
4338 cds_ssr_protect(__func__);
4339 __hdd_ipa_w2i_cb(priv, evt, data);
4340 cds_ssr_unprotect(__func__);
4341}
4342
4343/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004344 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4345 * @skb: packet buffer which was transmitted
4346 *
4347 * Return: None
4348 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304349void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350{
4351 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004352 struct ipa_rx_data *ipa_tx_desc;
4353 struct hdd_ipa_tx_desc *tx_desc;
4354 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355
Yun Park52b2b992016-09-22 15:49:51 -07004356 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%x", QDF_NBUF_CB_TX_IPA_PRIV(skb));
4357
4358 if (!qdf_nbuf_ipa_owned_get(skb)) {
4359 dev_kfree_skb_any(skb);
4360 return;
4361 }
4362
4363 /* Get Tx desc pointer from SKB CB */
4364 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4365 tx_desc = hdd_ipa->tx_desc_list + id;
4366 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4367
4368 /* Return Tx Desc to IPA */
4369 ipa_free_skb(ipa_tx_desc);
4370
4371 /* Return to free tx desc list */
4372 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4373 tx_desc->ipa_tx_desc_ptr = NULL;
4374 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4375 hdd_ipa->stats.num_tx_desc_q_cnt--;
4376 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377
4378 hdd_ipa->stats.num_tx_comp_cnt++;
4379
4380 atomic_dec(&hdd_ipa->tx_ref_cnt);
4381
4382 hdd_ipa_rm_try_release(hdd_ipa);
4383}
4384
4385/**
4386 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4387 * @iface_context: interface-specific IPA context
4388 * @ipa_tx_desc: packet data descriptor
4389 *
4390 * Return: None
4391 */
4392static void hdd_ipa_send_pkt_to_tl(
4393 struct hdd_ipa_iface_context *iface_context,
4394 struct ipa_rx_data *ipa_tx_desc)
4395{
4396 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304398 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004399 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304401 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 adapter = iface_context->adapter;
4403 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304404 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405 ipa_free_skb(ipa_tx_desc);
4406 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304407 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408 hdd_ipa_rm_try_release(hdd_ipa);
4409 return;
4410 }
4411
4412 /*
4413 * During CAC period, data packets shouldn't be sent over the air so
4414 * drop all the packets here
4415 */
4416 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4417 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304418 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419 iface_context->stats.num_tx_cac_drop++;
4420 hdd_ipa_rm_try_release(hdd_ipa);
4421 return;
4422 }
4423
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 ++adapter->stats.tx_packets;
4425
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304426 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427
4428 skb = ipa_tx_desc->skb;
4429
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304430 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004431
4432 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304433 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304435 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004436 ipa_tx_desc->dma_addr
4437 + HDD_IPA_WLAN_FRAG_HEADER
4438 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439 ipa_tx_desc->skb->len -=
4440 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4441 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304442 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
Yun Park52b2b992016-09-22 15:49:51 -07004444 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4445 /* get free Tx desc and assign ipa_tx_desc pointer */
4446 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4447 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4448 struct hdd_ipa_tx_desc, link);
4449 list_del(&tx_desc->link);
4450 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4451 hdd_ipa->stats.num_tx_desc_q_cnt++;
4452 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4453 /* Store Tx Desc index into SKB CB */
4454 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4455 } else {
4456 hdd_ipa->stats.num_tx_desc_error++;
4457 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4458 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4459 ipa_free_skb(ipa_tx_desc);
4460 hdd_ipa_rm_try_release(hdd_ipa);
4461 return;
4462 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463
4464 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4465
Leo Changfdb45c32016-10-28 11:09:23 -07004466 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004467 (struct cdp_vdev *)iface_context->tl_context,
4468 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304470 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004471 ipa_free_skb(ipa_tx_desc);
4472 iface_context->stats.num_tx_err++;
4473 hdd_ipa_rm_try_release(hdd_ipa);
4474 return;
4475 }
4476
4477 atomic_inc(&hdd_ipa->tx_ref_cnt);
4478
4479 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004480}
4481
4482/**
Leo Chang11545d62016-10-17 14:53:50 -07004483 * hdd_ipa_is_present() - get IPA hw status
4484 * @hdd_ctx: pointer to hdd context
4485 *
4486 * ipa_uc_reg_rdyCB is not directly designed to check
4487 * ipa hw status. This is an undocumented function which
4488 * has confirmed with IPA team.
4489 *
4490 * Return: true - ipa hw present
4491 * false - ipa hw not present
4492 */
4493bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
4494{
4495 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004496 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004497 return true;
4498 else
4499 return false;
4500}
4501
4502/**
Leo Chang69c39692016-10-12 20:11:12 -07004503 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504 * @work: pointer to the scheduled work
4505 *
4506 * Called during PM resume to send packets to TL which were queued
4507 * while host was in the process of suspending.
4508 *
4509 * Return: None
4510 */
Leo Chang69c39692016-10-12 20:11:12 -07004511static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512{
4513 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4514 struct hdd_ipa_priv,
4515 pm_work);
4516 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304517 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 uint32_t dequeued = 0;
4519
Leo Chang69c39692016-10-12 20:11:12 -07004520 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4521 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304522 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304523 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4524 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304525 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526
4527 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004528 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004529 if (pm_tx_cb->exception) {
4530 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4531 "FLUSH EXCEPTION");
4532 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
4533 } else {
4534 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004535 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004536 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304537 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004538 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304539 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004540 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4541 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542
4543 hdd_ipa->stats.num_tx_dequeued += dequeued;
4544 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4545 hdd_ipa->stats.num_max_pm_queue = dequeued;
4546}
4547
4548/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004549 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550 * @priv: pointer to private data registered with IPA (we register a
4551 * pointer to the interface-specific IPA context)
4552 * @evt: the IPA event which triggered the callback
4553 * @data: data associated with the event
4554 *
4555 * Return: None
4556 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004557static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558 unsigned long data)
4559{
4560 struct hdd_ipa_priv *hdd_ipa = NULL;
4561 struct ipa_rx_data *ipa_tx_desc;
4562 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304563 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304565 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004566
Mukul Sharma81661ae2015-10-30 20:26:02 +05304567 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004568 ipa_tx_desc = (struct ipa_rx_data *)data;
4569 hdd_ipa = iface_context->hdd_ipa;
4570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004572 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4573 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574 iface_context->stats.num_tx_drop++;
4575 return;
4576 }
4577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004578 /*
4579 * When SSR is going on or driver is unloading, just drop the packets.
4580 * During SSR, there is no use in queueing the packets as STA has to
4581 * connect back any way
4582 */
4583 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304584 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 ipa_free_skb(ipa_tx_desc);
4586 iface_context->stats.num_tx_drop++;
4587 return;
4588 }
4589
4590 skb = ipa_tx_desc->skb;
4591
Yun Parkb187d542016-11-14 18:10:04 -08004592 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4593 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004594
4595 /*
4596 * If PROD resource is not requested here then there may be cases where
4597 * IPA hardware may be clocked down because of not having proper
4598 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4599 * workaround to request PROD resource while data is going over CONS
4600 * pipe to prevent the IPA hardware clockdown.
4601 */
4602 hdd_ipa_rm_request(hdd_ipa);
4603
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304604 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004605 /*
4606 * If host is still suspended then queue the packets and these will be
4607 * drained later when resume completes. When packet is arrived here and
4608 * host is suspended, this means that there is already resume is in
4609 * progress.
4610 */
4611 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304612 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4614 pm_tx_cb->iface_context = iface_context;
4615 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304616 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004617 hdd_ipa->stats.num_tx_queued++;
4618
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304619 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004620 return;
4621 }
4622
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304623 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624
4625 /*
4626 * If we are here means, host is not suspended, wait for the work queue
4627 * to finish.
4628 */
4629#ifdef WLAN_OPEN_SOURCE
4630 flush_work(&hdd_ipa->pm_work);
4631#endif
4632
4633 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4634}
4635
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004636/*
4637 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4638 * @priv: pointer to private data registered with IPA (we register a
4639 * pointer to the interface-specific IPA context)
4640 * @evt: the IPA event which triggered the callback
4641 * @data: data associated with the event
4642 *
4643 * Return: None
4644 */
4645static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4646 unsigned long data)
4647{
4648 cds_ssr_protect(__func__);
4649 __hdd_ipa_i2w_cb(priv, evt, data);
4650 cds_ssr_unprotect(__func__);
4651}
4652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004654 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 * @hdd_ctx: Global HDD context
4656 *
4657 * Return: 0 on success, negativer errno on error
4658 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004659static int __hdd_ipa_suspend(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004661 struct hdd_ipa_priv *hdd_ipa;
4662
4663 if (wlan_hdd_validate_context(hdd_ctx))
4664 return 0;
4665
4666 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667
4668 if (!hdd_ipa_is_enabled(hdd_ctx))
4669 return 0;
4670
4671 /*
4672 * Check if IPA is ready for suspend, If we are here means, there is
4673 * high chance that suspend would go through but just to avoid any race
4674 * condition after suspend started, these checks are conducted before
4675 * allowing to suspend.
4676 */
4677 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4678 return -EAGAIN;
4679
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304680 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004681
4682 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304683 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004684 return -EAGAIN;
4685 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304686 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004687
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304688 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304690 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004691
4692 return 0;
4693}
4694
4695/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004696 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4697 * @hdd_ctx: Global HDD context
4698 *
4699 * Return: 0 on success, negativer errno on error
4700 */
4701int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
4702{
4703 int ret;
4704
4705 cds_ssr_protect(__func__);
4706 ret = __hdd_ipa_suspend(hdd_ctx);
4707 cds_ssr_unprotect(__func__);
4708
4709 return ret;
4710}
4711
4712/**
4713 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004714 * hdd_ctx: Global HDD context
4715 *
4716 * Return: 0 on success, negative errno on error
4717 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004718static int __hdd_ipa_resume(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004719{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004720 struct hdd_ipa_priv *hdd_ipa;
4721
4722 if (wlan_hdd_validate_context(hdd_ctx))
4723 return 0;
4724
4725 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726
4727 if (!hdd_ipa_is_enabled(hdd_ctx))
4728 return 0;
4729
4730 schedule_work(&hdd_ipa->pm_work);
4731
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304732 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004733 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304734 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735
4736 return 0;
4737}
4738
4739/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004740 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4741 * hdd_ctx: Global HDD context
4742 *
4743 * Return: 0 on success, negative errno on error
4744 */
4745int hdd_ipa_resume(hdd_context_t *hdd_ctx)
4746{
4747 int ret;
4748
4749 cds_ssr_protect(__func__);
4750 ret = __hdd_ipa_resume(hdd_ctx);
4751 cds_ssr_unprotect(__func__);
4752
4753 return ret;
4754}
4755
4756/**
Yun Park52b2b992016-09-22 15:49:51 -07004757 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4758 * @hdd_ipa: Global HDD IPA context
4759 *
4760 * Return: 0 on success, negative errno on error
4761 */
4762static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4763{
4764 int i;
4765 uint32_t max_desc_cnt;
4766 struct hdd_ipa_tx_desc *tmp_desc;
4767
4768 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4769
4770 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4771
4772 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc)*max_desc_cnt);
4773
4774 if (!tmp_desc) {
4775 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4776 "Free Tx descriptor allocation failed");
4777 return -ENOMEM;
4778 }
4779
4780 hdd_ipa->tx_desc_list = tmp_desc;
4781
4782 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4783 for (i = 0; i < max_desc_cnt; i++) {
4784 tmp_desc->id = i;
4785 tmp_desc->ipa_tx_desc_ptr = NULL;
4786 list_add_tail(&tmp_desc->link,
4787 &hdd_ipa->free_tx_desc_head);
4788 tmp_desc++;
4789 }
4790
4791 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4792 hdd_ipa->stats.num_tx_desc_error = 0;
4793
4794 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4795
4796 return 0;
4797}
4798
4799/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4801 * @hdd_ipa: Global HDD IPA context
4802 *
4803 * Return: 0 on success, negative errno on error
4804 */
4805static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4806{
4807 int i, ret = 0;
4808 struct ipa_sys_connect_params *ipa;
4809 uint32_t desc_fifo_sz;
4810
4811 /* The maximum number of descriptors that can be provided to a BAM at
4812 * once is one less than the total number of descriptors that the buffer
4813 * can contain.
4814 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4815 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4816 * be provided at once.
4817 * Because of above requirement, one extra descriptor will be added to
4818 * make sure hardware always has one descriptor.
4819 */
4820 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4821 + sizeof(struct sps_iovec);
4822
4823 /*setup TX pipes */
4824 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4825 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4826
4827 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4828 ipa->desc_fifo_sz = desc_fifo_sz;
4829 ipa->priv = &hdd_ipa->iface_context[i];
4830 ipa->notify = hdd_ipa_i2w_cb;
4831
4832 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4833 ipa->ipa_ep_cfg.hdr.hdr_len =
4834 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4835 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4836 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4837 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4838 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4839 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4840 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4841 } else {
4842 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4843 }
4844 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4845
4846 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4847 ipa->keep_ipa_awake = 1;
4848
4849 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4850 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004851 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4852 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 goto setup_sys_pipe_fail;
4854 }
4855 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4856 }
4857
4858 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4859 /*
4860 * Hard code it here, this can be extended if in case
4861 * PROD pipe is also per interface.
4862 * Right now there is no advantage of doing this.
4863 */
4864 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
4865
4866 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4867
4868 ipa->client = hdd_ipa->prod_client;
4869
4870 ipa->desc_fifo_sz = desc_fifo_sz;
4871 ipa->priv = hdd_ipa;
4872 ipa->notify = hdd_ipa_w2i_cb;
4873
4874 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4875 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4876 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4877 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4878
4879 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4880 ipa->keep_ipa_awake = 1;
4881
4882 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4883 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304884 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 "Failed for RX pipe: %d", ret);
4886 goto setup_sys_pipe_fail;
4887 }
4888 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4889 }
4890
Yun Park52b2b992016-09-22 15:49:51 -07004891 /* Allocate free Tx desc list */
4892 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4893 if (ret)
4894 goto setup_sys_pipe_fail;
4895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 return ret;
4897
4898setup_sys_pipe_fail:
4899
4900 while (--i >= 0) {
4901 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304902 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004903 sizeof(struct hdd_ipa_sys_pipe));
4904 }
4905
4906 return ret;
4907}
4908
4909/**
4910 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4911 * @hdd_ipa: Global HDD IPA context
4912 *
4913 * Return: None
4914 */
4915static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4916{
4917 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004918 uint32_t max_desc_cnt;
4919 struct hdd_ipa_tx_desc *tmp_desc;
4920 struct ipa_rx_data *ipa_tx_desc;
4921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004922 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4923 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
4924 ret =
4925 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4926 conn_hdl);
4927 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304928 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004929 ret);
4930
4931 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4932 }
4933 }
Yun Park52b2b992016-09-22 15:49:51 -07004934
4935 if (hdd_ipa->tx_desc_list) {
4936 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4937
4938 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4939 for (i = 0; i < max_desc_cnt; i++) {
4940 tmp_desc = hdd_ipa->tx_desc_list + i;
4941 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4942 if (ipa_tx_desc)
4943 ipa_free_skb(ipa_tx_desc);
4944 }
4945 tmp_desc = hdd_ipa->tx_desc_list;
4946 hdd_ipa->tx_desc_list = NULL;
4947 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4948 hdd_ipa->stats.num_tx_desc_error = 0;
4949 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4950 qdf_mem_free(tmp_desc);
4951 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004952}
4953
4954/**
4955 * hdd_ipa_register_interface() - register IPA interface
4956 * @hdd_ipa: Global IPA context
4957 * @iface_context: Per-interface IPA context
4958 *
4959 * Return: 0 on success, negative errno on error
4960 */
4961static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
4962 struct hdd_ipa_iface_context
4963 *iface_context)
4964{
4965 struct ipa_tx_intf tx_intf;
4966 struct ipa_rx_intf rx_intf;
4967 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
4968 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
4969 char *ifname = iface_context->adapter->dev->name;
4970
4971 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
4972 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
4973
4974 int num_prop = 1;
4975 int ret = 0;
4976
4977 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
4978 num_prop++;
4979
4980 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
4981 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304982 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304984 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 goto register_interface_fail;
4986 }
4987
4988 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
4989 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304990 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004991 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304992 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 goto register_interface_fail;
4994 }
4995
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304996 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
4997 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998
4999 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
5000 ifname, HDD_IPA_IPV4_NAME_EXT);
5001 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
5002 ifname, HDD_IPA_IPV6_NAME_EXT);
5003
5004 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
5005 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
5006 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5007 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
5008
5009 /*
5010 * Interface ID is 3rd byte in the CLD header. Add the meta data and
5011 * mask to identify the interface in IPA hardware
5012 */
5013 rx_prop[IPA_IP_v4].attrib.meta_data =
5014 htonl(iface_context->adapter->sessionId << 16);
5015 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
5016
5017 rx_intf.num_props++;
5018 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5019 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
5020 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
5021 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5022 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
5023 rx_prop[IPA_IP_v4].attrib.meta_data =
5024 htonl(iface_context->adapter->sessionId << 16);
5025 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
5026
5027 rx_intf.num_props++;
5028 }
5029
5030 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
5031 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5032 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
5033 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
5034 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
5035 IPA_RESOURCE_NAME_MAX);
5036 tx_intf.num_props++;
5037
5038 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5039 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
5040 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5041 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
5042 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
5043 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
5044 IPA_RESOURCE_NAME_MAX);
5045 tx_intf.num_props++;
5046 }
5047
5048 tx_intf.prop = tx_prop;
5049 rx_intf.prop = rx_prop;
5050
5051 /* Call the ipa api to register interface */
5052 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
5053
Yun Park52b2b992016-09-22 15:49:51 -07005054 /* Register IPA Tx desc free callback */
5055 qdf_nbuf_reg_free_cb(hdd_ipa_nbuf_cb);
5056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005057register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305058 qdf_mem_free(tx_prop);
5059 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060 return ret;
5061}
5062
5063/**
5064 * hdd_remove_ipa_header() - Remove a specific header from IPA
5065 * @name: Name of the header to be removed
5066 *
5067 * Return: None
5068 */
5069static void hdd_ipa_remove_header(char *name)
5070{
5071 struct ipa_ioc_get_hdr hdrlookup;
5072 int ret = 0, len;
5073 struct ipa_ioc_del_hdr *ipa_hdr;
5074
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305075 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
5077 ret = ipa_get_hdr(&hdrlookup);
5078 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005079 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005080 name, ret);
5081 return;
5082 }
5083
Srinivas Girigowda97852372017-03-06 16:52:59 -08005084 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005085 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305086 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305088 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 return;
5090 }
5091 ipa_hdr->num_hdls = 1;
5092 ipa_hdr->commit = 0;
5093 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
5094 ipa_hdr->hdl[0].status = -1;
5095 ret = ipa_del_hdr(ipa_hdr);
5096 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305097 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 ret);
5099
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305100 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101}
5102
5103/**
Yun Parkb187d542016-11-14 18:10:04 -08005104 * wlan_ipa_add_hdr() - Add IPA Tx header
5105 * @ipa_hdr: pointer to IPA header addition parameters
5106 *
5107 * Call IPA API to add IPA Tx header descriptor
5108 * and dump Tx header struct
5109 *
5110 * Return: 0 for success, non-zero for failure
5111 */
5112static int wlan_ipa_add_hdr(struct ipa_ioc_add_hdr *ipa_hdr)
5113{
5114 int ret;
5115
Srinivas Girigowda97852372017-03-06 16:52:59 -08005116 hdd_debug("==== IPA Tx Header ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08005117 "name: %s\n"
5118 "hdr_len: %d\n"
5119 "type: %d\n"
5120 "is_partial: %d\n"
5121 "hdr_hdl: 0x%x\n"
5122 "status: %d\n"
5123 "is_eth2_ofst_valid: %d\n"
5124 "eth2_ofst: %d\n",
5125 ipa_hdr->hdr[0].name,
5126 ipa_hdr->hdr[0].hdr_len,
5127 ipa_hdr->hdr[0].type,
5128 ipa_hdr->hdr[0].is_partial,
5129 ipa_hdr->hdr[0].hdr_hdl,
5130 ipa_hdr->hdr[0].status,
5131 ipa_hdr->hdr[0].is_eth2_ofst_valid,
5132 ipa_hdr->hdr[0].eth2_ofst);
5133
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08005134 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "hdr:",
Yun Parkb187d542016-11-14 18:10:04 -08005135 ipa_hdr->hdr[0].hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
5136
5137 ret = ipa_add_hdr(ipa_hdr);
5138 return ret;
5139}
5140
5141/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 * hdd_ipa_add_header_info() - Add IPA header for a given interface
5143 * @hdd_ipa: Global HDD IPA context
5144 * @iface_context: Interface-specific HDD IPA context
5145 * @mac_addr: Interface MAC address
5146 *
5147 * Return: 0 on success, negativer errno value on error
5148 */
5149static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
5150 struct hdd_ipa_iface_context *iface_context,
5151 uint8_t *mac_addr)
5152{
5153 hdd_adapter_t *adapter = iface_context->adapter;
5154 char *ifname;
5155 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
5156 int ret = -EINVAL;
5157 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
5158 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
5159
5160 ifname = adapter->dev->name;
5161
Srinivas Girigowda97852372017-03-06 16:52:59 -08005162 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163 ifname, mac_addr);
5164
5165 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305166 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 + sizeof(struct ipa_hdr_add));
5168 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305169 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 "%s: ipa_hdr allocation failed", ifname);
5171 ret = -ENOMEM;
5172 goto end;
5173 }
5174
5175 ipa_hdr->commit = 0;
5176 ipa_hdr->num_hdrs = 1;
5177
5178 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5179 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
5180 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
5181 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
5182 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305183 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005184 "ifname=%s, vdev_id=%d",
5185 ifname, uc_tx_hdr->ipa_hd.vdev_id);
5186 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5187 ifname, HDD_IPA_IPV4_NAME_EXT);
5188 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
5189 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
5190 ipa_hdr->hdr[0].is_partial = 1;
5191 ipa_hdr->hdr[0].hdr_hdl = 0;
5192 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
5193 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5194
Yun Parkb187d542016-11-14 18:10:04 -08005195 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196 } else {
5197 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
5198
5199 /* Set the Source MAC */
5200 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
5201 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
5202
5203 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5204 ifname, HDD_IPA_IPV4_NAME_EXT);
5205 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
5206 ipa_hdr->hdr[0].is_partial = 1;
5207 ipa_hdr->hdr[0].hdr_hdl = 0;
5208 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
5209 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5210
5211 /* Set the type to IPV4 in the header */
5212 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
5213
5214 ret = ipa_add_hdr(ipa_hdr);
5215 }
5216 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305217 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 ifname, ret);
5219 goto end;
5220 }
5221
Srinivas Girigowda97852372017-03-06 16:52:59 -08005222 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
5224
5225 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5226 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5227 ifname, HDD_IPA_IPV6_NAME_EXT);
5228
5229 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5230 uc_tx_hdr =
5231 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
5232 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08005233 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 } else {
5235 /* Set the type to IPV6 in the header */
5236 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
5237 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08005238 ret = ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 }
5240
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305242 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243 "%s: IPv6 add hdr failed: %d", ifname, ret);
5244 goto clean_ipv4_hdr;
5245 }
5246
Srinivas Girigowda97852372017-03-06 16:52:59 -08005247 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005248 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
5249 }
5250
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305251 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252
5253 return ret;
5254
5255clean_ipv4_hdr:
5256 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5257 ifname, HDD_IPA_IPV4_NAME_EXT);
5258 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
5259end:
5260 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305261 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262
5263 return ret;
5264}
5265
5266/**
5267 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
5268 * @adapter: Adapter upon which IPA was previously configured
5269 *
5270 * Return: None
5271 */
5272static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
5273{
5274 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5275 int ret;
5276 char name_ipa[IPA_RESOURCE_NAME_MAX];
5277
5278 /* Remove the headers */
5279 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
5280 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
5281 hdd_ipa_remove_header(name_ipa);
5282
5283 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5284 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
5285 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
5286 hdd_ipa_remove_header(name_ipa);
5287 }
5288 /* unregister the interface with IPA */
5289 ret = ipa_deregister_intf(adapter->dev->name);
5290 if (ret)
Srinivas Girigowda97852372017-03-06 16:52:59 -08005291 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 "%s: ipa_deregister_intf fail: %d",
5293 adapter->dev->name, ret);
5294}
5295
5296/**
5297 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
5298 * @iface_context: interface-specific IPA context
5299 *
5300 * Return: None
5301 */
5302static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
5303{
5304 if (iface_context == NULL)
5305 return;
5306
5307 hdd_ipa_clean_hdr(iface_context->adapter);
5308
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305309 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310 iface_context->adapter->ipa_context = NULL;
5311 iface_context->adapter = NULL;
5312 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305313 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 iface_context->ifa_address = 0;
5315 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305316 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05305318 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 }
5320 iface_context->hdd_ipa->num_iface--;
5321}
5322
5323/**
5324 * hdd_ipa_setup_iface() - Setup IPA on a given interface
5325 * @hdd_ipa: HDD IPA global context
5326 * @adapter: Interface upon which IPA is being setup
5327 * @sta_id: Station ID of the API instance
5328 *
5329 * Return: 0 on success, negative errno value on error
5330 */
5331static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
5332 hdd_adapter_t *adapter, uint8_t sta_id)
5333{
5334 struct hdd_ipa_iface_context *iface_context = NULL;
5335 void *tl_context = NULL;
5336 int i, ret = 0;
5337
5338 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
5339 * channel change indication. Since these indications are sent by lower
5340 * layer as SAP updates and IPA doesn't have to do anything for these
5341 * updates so ignoring!
5342 */
Krunal Sonibe766b02016-03-10 13:00:44 -08005343 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344 return 0;
5345
5346 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5347 if (hdd_ipa->iface_context[i].adapter == NULL) {
5348 iface_context = &(hdd_ipa->iface_context[i]);
5349 break;
5350 }
5351 }
5352
5353 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305354 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 "All the IPA interfaces are in use");
5356 ret = -ENOMEM;
5357 goto end;
5358 }
5359
5360 adapter->ipa_context = iface_context;
5361 iface_context->adapter = adapter;
5362 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005363 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07005364 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005365 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305366 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005367 "Not able to get TL context sta_id: %d", sta_id);
5368 ret = -EINVAL;
5369 goto end;
5370 }
5371
5372 iface_context->tl_context = tl_context;
5373
5374 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
5375 adapter->dev->dev_addr);
5376
5377 if (ret)
5378 goto end;
5379
5380 /* Configure the TX and RX pipes filter rules */
5381 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
5382 if (ret)
5383 goto cleanup_header;
5384
5385 hdd_ipa->num_iface++;
5386 return ret;
5387
5388cleanup_header:
5389
5390 hdd_ipa_clean_hdr(adapter);
5391end:
5392 if (iface_context)
5393 hdd_ipa_cleanup_iface(iface_context);
5394 return ret;
5395}
5396
Yun Parka27049a2016-10-11 12:30:49 -07005397#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005399 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400 * @mcc_mode: 0=MCC/1=SCC
5401 *
5402 * Return: 0 on success, negative errno value on error
5403 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005404static int __hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405{
5406 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305407 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408 hdd_adapter_t *pAdapter;
5409 struct ipa_msg_meta meta;
5410 struct ipa_wlan_msg *msg;
5411 int ret;
5412
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005413 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414 return -EINVAL;
5415
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005416 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
5417 return -EINVAL;
5418
5419 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005420 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005421 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305422 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08005424 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005425 pAdapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005426 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005427 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005428 hdd_deinit_tx_rx(pAdapter);
5429 }
5430 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005431 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 adapter_node = next;
5433 }
5434 }
5435
5436 /* Send SCC/MCC Switching event to IPA */
5437 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305438 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005439 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005440 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005441 return -ENOMEM;
5442 }
5443
5444 meta.msg_type = mcc_mode ?
5445 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08005446 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447
5448 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5449
5450 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005451 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005452 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305453 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005454 }
5455
5456 return ret;
5457}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005458
5459/**
5460 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
5461 * @mcc_mode: 0=MCC/1=SCC
5462 *
5463 * Return: 0 on success, negative errno value on error
5464 */
5465int hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
5466{
5467 int ret;
5468
5469 cds_ssr_protect(__func__);
5470 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
5471 cds_ssr_unprotect(__func__);
5472
5473 return ret;
5474}
Yun Parka27049a2016-10-11 12:30:49 -07005475#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005476
5477/**
5478 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
5479 * @event: IPA WLAN event to be converted to a string
5480 *
5481 * Return: ASCII string representing the IPA WLAN event
5482 */
5483static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
5484{
5485 switch (event) {
5486 case WLAN_CLIENT_CONNECT:
5487 return "WLAN_CLIENT_CONNECT";
5488 case WLAN_CLIENT_DISCONNECT:
5489 return "WLAN_CLIENT_DISCONNECT";
5490 case WLAN_CLIENT_POWER_SAVE_MODE:
5491 return "WLAN_CLIENT_POWER_SAVE_MODE";
5492 case WLAN_CLIENT_NORMAL_MODE:
5493 return "WLAN_CLIENT_NORMAL_MODE";
5494 case SW_ROUTING_ENABLE:
5495 return "SW_ROUTING_ENABLE";
5496 case SW_ROUTING_DISABLE:
5497 return "SW_ROUTING_DISABLE";
5498 case WLAN_AP_CONNECT:
5499 return "WLAN_AP_CONNECT";
5500 case WLAN_AP_DISCONNECT:
5501 return "WLAN_AP_DISCONNECT";
5502 case WLAN_STA_CONNECT:
5503 return "WLAN_STA_CONNECT";
5504 case WLAN_STA_DISCONNECT:
5505 return "WLAN_STA_DISCONNECT";
5506 case WLAN_CLIENT_CONNECT_EX:
5507 return "WLAN_CLIENT_CONNECT_EX";
5508
5509 case IPA_WLAN_EVENT_MAX:
5510 default:
5511 return "UNKNOWN";
5512 }
5513}
5514
5515/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07005516 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
5517 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
5518 *
5519 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
5520 */
5521static enum ipa_wlan_event
5522hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
5523{
5524 enum ipa_wlan_event ipa_event;
5525
5526 switch (hdd_ipa_event_type) {
5527 case HDD_IPA_CLIENT_CONNECT:
5528 ipa_event = WLAN_CLIENT_CONNECT;
5529 break;
5530 case HDD_IPA_CLIENT_DISCONNECT:
5531 ipa_event = WLAN_CLIENT_DISCONNECT;
5532 break;
5533 case HDD_IPA_AP_CONNECT:
5534 ipa_event = WLAN_AP_CONNECT;
5535 break;
5536 case HDD_IPA_AP_DISCONNECT:
5537 ipa_event = WLAN_AP_DISCONNECT;
5538 break;
5539 case HDD_IPA_STA_CONNECT:
5540 ipa_event = WLAN_STA_CONNECT;
5541 break;
5542 case HDD_IPA_STA_DISCONNECT:
5543 ipa_event = WLAN_STA_DISCONNECT;
5544 break;
5545 case HDD_IPA_CLIENT_CONNECT_EX:
5546 ipa_event = WLAN_CLIENT_CONNECT_EX;
5547 break;
5548 case HDD_IPA_WLAN_EVENT_MAX:
5549 default:
5550 ipa_event = IPA_WLAN_EVENT_MAX;
5551 break;
5552 }
5553 return ipa_event;
5554
5555}
5556
5557/**
5558 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 * @adapter: adapter upon which the event was received
5560 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005561 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562 * @mac_address: MAC address associated with the event
5563 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07005564 * This function is meant to be called from within wlan_hdd_ipa.c
5565 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005566 * Return: 0 on success, negative errno value on error
5567 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07005568static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005569 enum ipa_wlan_event type, uint8_t *mac_addr)
5570{
5571 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5572 struct ipa_msg_meta meta;
5573 struct ipa_wlan_msg *msg;
5574 struct ipa_wlan_msg_ex *msg_ex = NULL;
5575 int ret;
5576
Srinivas Girigowda97852372017-03-06 16:52:59 -08005577 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5579 mac_addr, sta_id);
5580
5581 if (type >= IPA_WLAN_EVENT_MAX)
5582 return -EINVAL;
5583
5584 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5585 return -EINVAL;
5586
5587 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305588 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589 return -EINVAL;
5590 }
5591
5592 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5593 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005594 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005595 return 0;
5596 }
5597
5598 /*
5599 * During IPA UC resource loading/unloading new events can be issued.
5600 * Store the events separately and handle them later.
5601 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005602 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5603 if (hdd_ipa->resource_loading) {
5604 unsigned int pending_event_count;
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005605 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005606
Yun Park64c405e2017-01-10 22:35:51 -08005607 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5608 "IPA resource load in progress");
Yun Park7c4f31b2016-11-30 10:09:21 -08005609
Yun Park64c405e2017-01-10 22:35:51 -08005610 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005611
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005612 pending_event_count =
5613 qdf_list_size(&hdd_ipa->pending_event);
5614 if (pending_event_count >=
5615 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005616 hdd_debug("Reached max pending event count");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005617 qdf_list_remove_front(&hdd_ipa->pending_event,
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005618 (qdf_list_node_t **)&pending_event);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005619 } else {
5620 pending_event =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005621 qdf_mem_malloc(sizeof(*pending_event));
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005622 }
5623
5624 if (!pending_event) {
Yun Park64c405e2017-01-10 22:35:51 -08005625 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park7c4f31b2016-11-30 10:09:21 -08005626 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5627 "Pending event memory alloc fail");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005628 return -ENOMEM;
5629 }
5630
5631 pending_event->adapter = adapter;
5632 pending_event->sta_id = sta_id;
5633 pending_event->type = type;
5634 qdf_mem_copy(pending_event->mac_addr,
5635 mac_addr,
5636 QDF_MAC_ADDR_SIZE);
5637 qdf_list_insert_back(&hdd_ipa->pending_event,
5638 &pending_event->node);
5639
Yun Park64c405e2017-01-10 22:35:51 -08005640 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005641 return 0;
5642 } else if (hdd_ipa->resource_unloading) {
Yun Park64c405e2017-01-10 22:35:51 -08005643 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5644 "IPA resource unload in progress");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005645 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005647 }
5648
5649 hdd_ipa->stats.event[type]++;
5650
Leo Chang3bc8fed2015-11-13 10:59:47 -08005651 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652 switch (type) {
5653 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005654 qdf_mutex_acquire(&hdd_ipa->event_lock);
5655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005656 /* STA already connected and without disconnect, connect again
5657 * This is Roaming scenario
5658 */
5659 if (hdd_ipa->sta_connected)
5660 hdd_ipa_cleanup_iface(adapter->ipa_context);
5661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5663 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305664 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005665 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005666 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005667
Yun Park8f289c82016-10-18 16:38:21 -07005668 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5669 (hdd_ipa->sap_num_connected_sta > 0) &&
5670 !hdd_ipa->sta_connected) {
5671 qdf_mutex_release(&hdd_ipa->event_lock);
5672 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005673 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005674 qdf_mutex_acquire(&hdd_ipa->event_lock);
5675 }
5676
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005677 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005679 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005682
5683 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684 break;
5685
5686 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005687 qdf_mutex_acquire(&hdd_ipa->event_lock);
5688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 /* For DFS channel we get two start_bss event (before and after
5690 * CAC). Also when ACS range includes both DFS and non DFS
5691 * channels, we could possibly change channel many times due to
5692 * RADAR detection and chosen channel may not be a DFS channels.
5693 * So dont return error here. Just discard the event.
5694 */
Yun Park8f289c82016-10-18 16:38:21 -07005695 if (adapter->ipa_context) {
5696 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005698 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005700 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5701 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005702 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005703 hdd_err("%s: Evt: %d, Interface setup failed",
5704 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005705 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005706 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707
Yun Park8f289c82016-10-18 16:38:21 -07005708 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5709 qdf_mutex_release(&hdd_ipa->event_lock);
5710 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005711 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005712 qdf_mutex_acquire(&hdd_ipa->event_lock);
5713 }
5714
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005715 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005717 (adapter->ipa_context))->iface_id;
5718
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305719 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005720 break;
5721
5722 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305723 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005724
5725 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005726 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005727 hdd_err("%s: Evt: %d, STA already disconnected",
5728 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005729 return -EINVAL;
5730 }
Yun Parka37592b2016-06-11 17:10:28 -07005731
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005732 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005733
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005735 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736 msg_ex->name);
5737 } else {
5738 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005739 if (!hdd_ipa->num_iface &&
5740 (HDD_IPA_UC_NUM_WDI_PIPE ==
5741 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005742 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743 }
5744
Yun Park74127cf2016-09-18 11:22:41 -07005745 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5746 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005747 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005749 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005750 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005751 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5752 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753 }
5754
Yun Park8f289c82016-10-18 16:38:21 -07005755 hdd_ipa_cleanup_iface(adapter->ipa_context);
5756
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305757 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758 break;
5759
5760 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005761 qdf_mutex_acquire(&hdd_ipa->event_lock);
5762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005764 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005765 hdd_err("%s: Evt: %d, SAP already disconnected",
5766 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005767 return -EINVAL;
5768 }
5769
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005770 if ((!hdd_ipa->num_iface) &&
5771 (HDD_IPA_UC_NUM_WDI_PIPE ==
5772 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005773 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005774 /*
5775 * We disable WDI pipes directly here since
5776 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5777 * processed when unloading WLAN driver is in
5778 * progress
5779 */
5780 hdd_ipa_uc_disable_pipes(hdd_ipa);
5781 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305782 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005783 "NO INTF left but still pipe clean up");
5784 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5785 }
5786 }
5787
5788 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005789 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005790 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005791 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005792 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005793 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5794 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795 }
Yun Parka37592b2016-06-11 17:10:28 -07005796
Yun Park8f289c82016-10-18 16:38:21 -07005797 hdd_ipa_cleanup_iface(adapter->ipa_context);
5798
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305799 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800 break;
5801
5802 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005803 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005804 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305806 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005807 return 0;
5808 }
5809
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305810 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005811 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5812 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005813 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305814 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005815 "%s: STA ID %d found, not valid",
5816 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005817 return 0;
5818 }
Yun Park312f71a2015-12-08 10:22:42 -08005819
5820 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005821 if (hdd_ipa->sap_num_connected_sta == 0 &&
5822 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005823 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005824 hdd_ipa->sta_connected) {
5825 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005826 hdd_ipa_uc_offload_enable_disable(
5827 hdd_get_adapter(hdd_ipa->hdd_ctx,
5828 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005829 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005830 qdf_mutex_acquire(&hdd_ipa->event_lock);
5831 }
Yun Parka37592b2016-06-11 17:10:28 -07005832
Yun Park312f71a2015-12-08 10:22:42 -08005833 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5834 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305835 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005836 "%s: handle 1st con ret %d",
5837 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005838
5839 if (hdd_ipa_uc_sta_is_enabled(
5840 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005841 hdd_ipa->sta_connected) {
5842 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005843 hdd_ipa_uc_offload_enable_disable(
5844 hdd_get_adapter(
5845 hdd_ipa->hdd_ctx,
5846 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005847 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005848 } else {
5849 qdf_mutex_release(&hdd_ipa->event_lock);
5850 }
Yun Parka37592b2016-06-11 17:10:28 -07005851
Yun Park312f71a2015-12-08 10:22:42 -08005852 return ret;
5853 }
5854 }
5855
5856 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005857
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305858 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005859
5860 meta.msg_type = type;
5861 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5862 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305863 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005864
5865 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305866 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005867 "msg_ex allocation failed");
5868 return -ENOMEM;
5869 }
5870 strlcpy(msg_ex->name, adapter->dev->name,
5871 IPA_RESOURCE_NAME_MAX);
5872 msg_ex->num_of_attribs = 1;
5873 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5874 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5875 msg_ex->attribs[0].offset =
5876 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5877 } else {
5878 msg_ex->attribs[0].offset =
5879 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5880 }
5881 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5882 IPA_MAC_ADDR_SIZE);
5883
5884 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5885
5886 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005887 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305888 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305889 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005890 return ret;
5891 }
5892 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005893 return ret;
5894
5895 case WLAN_CLIENT_DISCONNECT:
5896 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005897 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 "%s: IPA UC OFFLOAD NOT ENABLED",
5899 msg_ex->name);
5900 return 0;
5901 }
5902
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305903 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005905 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305906 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005907 "%s: STA ID %d NOT found, not valid",
5908 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005909 return 0;
5910 }
5911 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005912
Yun Park9b5030f2016-11-08 12:02:37 -08005913 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005914 if (!hdd_ipa->sap_num_connected_sta &&
5915 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005916 if ((false == hdd_ipa->resource_unloading)
5917 && (HDD_IPA_UC_NUM_WDI_PIPE ==
5918 hdd_ipa->activated_fw_pipe)) {
5919 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5920 }
5921
Yun Park8f289c82016-10-18 16:38:21 -07005922 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005923
5924 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5925 hdd_ipa->sta_connected)
5926 hdd_ipa_uc_offload_enable_disable(
5927 hdd_get_adapter(hdd_ipa->hdd_ctx,
5928 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005929 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005930 } else {
5931 qdf_mutex_release(&hdd_ipa->event_lock);
5932 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005933 break;
5934
5935 default:
5936 return 0;
5937 }
5938
5939 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305940 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005941 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305942 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943 return -ENOMEM;
5944 }
5945
5946 meta.msg_type = type;
5947 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5948 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5949
Srinivas Girigowda97852372017-03-06 16:52:59 -08005950 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005951 msg->name, meta.msg_type);
5952
5953 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5954
5955 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005956 hdd_err("%s: Evt: %d fail:%d",
5957 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305958 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005959 return ret;
5960 }
5961
5962 hdd_ipa->stats.num_send_msg++;
5963
5964end:
5965 return ret;
5966}
5967
5968/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005969 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005970 * @adapter: adapter upon which the event was received
5971 * @sta_id: station id for the event
5972 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5973 * @mac_address: MAC address associated with the event
5974 *
5975 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5976 *
5977 * Return: 0 on success, negative errno value on error
5978 */
5979int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
5980 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5981{
5982 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005983 int ret = 0;
5984
5985 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005986
Leo Changa202b522016-10-14 16:13:50 -07005987 /* Data path offload only support for STA and SAP mode */
5988 if ((QDF_STA_MODE == adapter->device_mode) ||
5989 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005990 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005991
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005992 cds_ssr_unprotect(__func__);
5993
5994 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005995}
5996
5997/**
5998 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5999 * @hdd_ipa: Global HDD IPA context
6000 *
6001 * Return: None
6002 */
6003static void
6004hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
6005{
6006 unsigned int pending_event_count;
6007 struct ipa_uc_pending_event *pending_event = NULL;
6008
6009 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08006010 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07006011 "%s, Pending Event Count %d", __func__, pending_event_count);
6012 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08006013 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07006014 "%s, No Pending Event", __func__);
6015 return;
6016 }
6017
6018 qdf_list_remove_front(&hdd_ipa->pending_event,
6019 (qdf_list_node_t **)&pending_event);
6020 while (pending_event != NULL) {
6021 __hdd_ipa_wlan_evt(pending_event->adapter,
6022 pending_event->type,
6023 pending_event->sta_id,
6024 pending_event->mac_addr);
6025 qdf_mem_free(pending_event);
6026 pending_event = NULL;
6027 qdf_list_remove_front(&hdd_ipa->pending_event,
6028 (qdf_list_node_t **)&pending_event);
6029 }
6030}
6031
6032/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006033 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
6034 * @state: IPA RM state value
6035 *
6036 * Return: ASCII string representing the IPA RM state
6037 */
6038static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
6039{
6040 switch (state) {
6041 case HDD_IPA_RM_RELEASED:
6042 return "RELEASED";
6043 case HDD_IPA_RM_GRANT_PENDING:
6044 return "GRANT_PENDING";
6045 case HDD_IPA_RM_GRANTED:
6046 return "GRANTED";
6047 }
6048
6049 return "UNKNOWN";
6050}
6051
6052/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006053 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006054 * @hdd_ctx: HDD global context
6055 *
6056 * Allocate hdd_ipa resources, ipa pipe resource and register
6057 * wlan interface with IPA module.
6058 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306059 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006060 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006061static QDF_STATUS __hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062{
6063 struct hdd_ipa_priv *hdd_ipa = NULL;
6064 int ret, i;
6065 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08006066 struct ol_txrx_pdev_t *pdev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006067
6068 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306069 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006070
Yun Parkbaa62862017-01-18 13:43:34 -08006071 ENTER();
6072
6073 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07006074 if (!pdev) {
6075 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
6076 goto fail_return;
6077 }
6078
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306079 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006080 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306081 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08006082 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006083 }
6084
6085 hdd_ctx->hdd_ipa = hdd_ipa;
6086 ghdd_ipa = hdd_ipa;
6087 hdd_ipa->hdd_ctx = hdd_ctx;
6088 hdd_ipa->num_iface = 0;
6089
6090 /* Create the interface context */
6091 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6092 iface_context = &hdd_ipa->iface_context[i];
6093 iface_context->hdd_ipa = hdd_ipa;
6094 iface_context->cons_client =
6095 hdd_ipa_adapter_2_client[i].cons_client;
6096 iface_context->prod_client =
6097 hdd_ipa_adapter_2_client[i].prod_client;
6098 iface_context->iface_id = i;
6099 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306100 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08006101 }
6102 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08006103 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
6104 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006105 }
6106
Leo Chang69c39692016-10-12 20:11:12 -07006107 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306108 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006109 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05306110 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006111
6112 ret = hdd_ipa_setup_rm(hdd_ipa);
6113 if (ret)
6114 goto fail_setup_rm;
6115
6116 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
6117 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306118 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006119 hdd_ipa->sap_num_connected_sta = 0;
6120 hdd_ipa->ipa_tx_packets_diff = 0;
6121 hdd_ipa->ipa_rx_packets_diff = 0;
6122 hdd_ipa->ipa_p_tx_packets = 0;
6123 hdd_ipa->ipa_p_rx_packets = 0;
6124 hdd_ipa->resource_loading = false;
6125 hdd_ipa->resource_unloading = false;
6126 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07006127 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08006128 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006129 /* Setup IPA sys_pipe for MCC */
6130 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
6131 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
6132 if (ret)
6133 goto fail_create_sys_pipe;
6134 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006135 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
6136 goto fail_create_sys_pipe;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006137 } else {
6138 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
6139 if (ret)
6140 goto fail_create_sys_pipe;
6141 }
6142
Yun Parkbaa62862017-01-18 13:43:34 -08006143 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306144 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006145
6146fail_create_sys_pipe:
6147 hdd_ipa_destroy_rm_resource(hdd_ipa);
6148fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306149 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306150 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08006151 hdd_ctx->hdd_ipa = NULL;
6152 ghdd_ipa = NULL;
6153fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08006154 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306155 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156}
6157
6158/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006159 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
6160 * @hdd_ctx: HDD global context
6161 *
6162 * Allocate hdd_ipa resources, ipa pipe resource and register
6163 * wlan interface with IPA module.
6164 *
6165 * Return: QDF_STATUS enumeration
6166 */
6167QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
6168{
6169 QDF_STATUS ret;
6170
6171 cds_ssr_protect(__func__);
6172 ret = __hdd_ipa_init(hdd_ctx);
6173 cds_ssr_unprotect(__func__);
6174
6175 return ret;
6176}
6177
Arun Khandavallicc544b32017-01-30 19:52:16 +05306178
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006179/**
Yun Parkf19e07d2015-11-20 11:34:27 -08006180 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
6181 * @hdd_ipa: pointer to HDD IPA struct
6182 *
6183 * Return: none
6184 */
Jeff Johnsond7720632016-10-05 16:04:32 -07006185static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08006186{
6187 struct ipa_uc_pending_event *pending_event = NULL;
6188
Anurag Chouhanffb21542016-02-17 14:33:03 +05306189 while (qdf_list_remove_front(&hdd_ipa->pending_event,
6190 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306191 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08006192 }
6193
Anurag Chouhanffb21542016-02-17 14:33:03 +05306194 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08006195}
6196
6197/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006198 * __hdd_ipa_cleanup - IPA cleanup function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199 * @hdd_ctx: HDD global context
6200 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306201 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006203static QDF_STATUS __hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204{
6205 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
6206 int i;
6207 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05306208 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
6210
6211 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306212 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213
6214 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
6215 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
6216 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6217 }
6218
6219 /* Teardown IPA sys_pipe for MCC */
6220 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
6221 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6222
6223 hdd_ipa_destroy_rm_resource(hdd_ipa);
6224
6225#ifdef WLAN_OPEN_SOURCE
6226 cancel_work_sync(&hdd_ipa->pm_work);
6227#endif
6228
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306229 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230
Nirav Shahcbc6d722016-03-01 16:24:53 +05306231 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
6232 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306233 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234
6235 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
6236 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
6237
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306238 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006239 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306240 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306242 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006243 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244
6245 /* destory the interface lock */
6246 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6247 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306248 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249 }
6250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08006252 if (ipa_uc_dereg_rdyCB())
6253 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
6254 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006256 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08006257 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Govind Singh0487bf22016-08-24 23:08:57 +05306258 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
6259 __func__, hdd_ipa->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006260 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Srinivas Girigowda97852372017-03-06 16:52:59 -08006261 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Govind Singh0487bf22016-08-24 23:08:57 +05306262 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
6263 __func__, hdd_ipa->rx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006264 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
6265 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306266 qdf_mutex_destroy(&hdd_ipa->event_lock);
6267 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08006268 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006269
6270#ifdef WLAN_OPEN_SOURCE
6271 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6272 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
6273 hdd_ipa->uc_op_work[i].msg = NULL;
6274 }
6275#endif
6276 }
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 */