blob: 0d323ba6776c7edc9b8ae46f86312cf5676608e4 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Rajeev Kumar3887f9b2018-01-10 11:24:01 -08002 * Copyright (c) 2013-2018 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 */
Yun Park6c86a662017-10-05 16:09:15 -070038#include <qdf_ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080042#include <linux/inetdevice.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include <wlan_hdd_softap_tx_rx.h>
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +053044#include <ol_txrx.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070045#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080046
47#include "cds_sched.h"
48
49#include "wma.h"
50#include "wma_api.h"
Prakash Dhavali87b38e32016-11-14 16:22:53 -080051#include "wal_rx_desc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080052
Dhanashri Atreb08959a2016-03-01 17:28:03 -080053#include "cdp_txrx_ipa.h"
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080054#include "wlan_policy_mgr_api.h"
55
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080056#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080057#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
Yun Parkb4f591d2017-03-29 15:51:01 -070058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059#define HDD_IPA_UC_NUM_WDI_PIPE 2
60#define HDD_IPA_UC_MAX_PENDING_EVENT 33
61
62#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
63#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
64#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
65#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
66
67#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
68#define HDD_IPA_MAX_IFACE 3
69#define HDD_IPA_MAX_SYSBAM_PIPE 4
Yun Parkb4f591d2017-03-29 15:51:01 -070070
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080071#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
72#define HDD_IPA_ENABLE_MASK BIT(0)
73#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
74#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
75#define HDD_IPA_RM_ENABLE_MASK BIT(3)
76#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
77#define HDD_IPA_UC_ENABLE_MASK BIT(5)
78#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
79#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
80
Yun Parkf19e07d2015-11-20 11:34:27 -080081#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
82
tfyu0380a972017-07-13 18:19:37 +080083#define IPA_WLAN_RX_SOFTIRQ_THRESH 16
84
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070085enum hdd_ipa_uc_op_code {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
87 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
88 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
89 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
90 HDD_IPA_UC_OPCODE_STATS = 4,
Yun Park637d6482016-10-05 10:51:33 -070091#ifdef FEATURE_METERING
92 HDD_IPA_UC_OPCODE_SHARING_STATS = 5,
93 HDD_IPA_UC_OPCODE_QUOTA_RSP = 6,
94 HDD_IPA_UC_OPCODE_QUOTA_IND = 7,
95#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -080096 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097 /* keep this last */
98 HDD_IPA_UC_OPCODE_MAX
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070099};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100
101/**
102 * enum - Reason codes for stat query
103 *
104 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
105 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
106 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800107 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800108 */
109enum {
110 HDD_IPA_UC_STAT_REASON_NONE,
111 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Park46255682017-10-09 15:56:34 -0700112 HDD_IPA_UC_STAT_REASON_BW_CAL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800113};
114
115/**
116 * enum hdd_ipa_rm_state - IPA resource manager state
117 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
118 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
119 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
120 */
121enum hdd_ipa_rm_state {
122 HDD_IPA_RM_RELEASED,
123 HDD_IPA_RM_GRANT_PENDING,
124 HDD_IPA_RM_GRANTED,
125};
126
127struct llc_snap_hdr {
128 uint8_t dsap;
129 uint8_t ssap;
130 uint8_t resv[4];
131 __be16 eth_type;
132} __packed;
133
Leo Chang3bc8fed2015-11-13 10:59:47 -0800134/**
135 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
136 * @eth: ether II header
137 * @llc_snap: LLC snap header
138 *
139 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800140struct hdd_ipa_tx_hdr {
141 struct ethhdr eth;
142 struct llc_snap_hdr llc_snap;
143} __packed;
144
Leo Chang3bc8fed2015-11-13 10:59:47 -0800145/**
146 * struct frag_header - fragment header type registered to IPA hardware
147 * @length: fragment length
148 * @reserved1: Reserved not used
149 * @reserved2: Reserved not used
150 *
151 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800152struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800153 uint16_t length;
154 uint32_t reserved1;
155 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156} __packed;
157
Leo Chang3bc8fed2015-11-13 10:59:47 -0800158/**
159 * struct ipa_header - ipa header type registered to IPA hardware
160 * @vdev_id: vdev id
161 * @reserved: Reserved not used
162 *
163 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164struct ipa_header {
165 uint32_t
166 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
167 reserved:24;
168} __packed;
169
Leo Chang3bc8fed2015-11-13 10:59:47 -0800170/**
171 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
172 * @frag_hd: fragment header
173 * @ipa_hd: ipa header
174 * @eth: ether II header
175 *
176 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800177struct hdd_ipa_uc_tx_hdr {
178 struct frag_header frag_hd;
179 struct ipa_header ipa_hd;
180 struct ethhdr eth;
181} __packed;
182
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800183/**
184 * struct hdd_ipa_cld_hdr - IPA CLD Header
185 * @reserved: reserved fields
186 * @iface_id: interface ID
187 * @sta_id: Station ID
188 *
189 * Packed 32-bit structure
190 * +----------+----------+--------------+--------+
191 * | Reserved | QCMAP ID | interface id | STA ID |
192 * +----------+----------+--------------+--------+
193 */
194struct hdd_ipa_cld_hdr {
195 uint8_t reserved[2];
196 uint8_t iface_id;
197 uint8_t sta_id;
198} __packed;
199
200struct hdd_ipa_rx_hdr {
201 struct hdd_ipa_cld_hdr cld_hdr;
202 struct ethhdr eth;
203} __packed;
204
205struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700206 bool exception;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700207 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208 struct hdd_ipa_iface_context *iface_context;
Yun Park6c86a662017-10-05 16:09:15 -0700209 qdf_ipa_rx_data_t *ipa_tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800210};
211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212struct hdd_ipa_sys_pipe {
213 uint32_t conn_hdl;
214 uint8_t conn_hdl_valid;
Yun Park6c86a662017-10-05 16:09:15 -0700215 qdf_ipa_sys_connect_params_t ipa_sys_params;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216};
217
218struct hdd_ipa_iface_stats {
219 uint64_t num_tx;
220 uint64_t num_tx_drop;
221 uint64_t num_tx_err;
222 uint64_t num_tx_cac_drop;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800223 uint64_t num_rx_ipa_excep;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224};
225
226struct hdd_ipa_priv;
227
228struct hdd_ipa_iface_context {
229 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700230 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231 void *tl_context;
232
Yun Park6c86a662017-10-05 16:09:15 -0700233 qdf_ipa_client_type_t cons_client;
234 qdf_ipa_client_type_t prod_client;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235
236 uint8_t iface_id; /* This iface ID */
237 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530238 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800239 uint32_t ifa_address;
240 struct hdd_ipa_iface_stats stats;
241};
242
243struct hdd_ipa_stats {
244 uint32_t event[IPA_WLAN_EVENT_MAX];
245 uint64_t num_send_msg;
246 uint64_t num_free_msg;
247
248 uint64_t num_rm_grant;
249 uint64_t num_rm_release;
250 uint64_t num_rm_grant_imm;
251 uint64_t num_cons_perf_req;
252 uint64_t num_prod_perf_req;
253
254 uint64_t num_rx_drop;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800255
Yun Park52b2b992016-09-22 15:49:51 -0700256 uint64_t num_tx_desc_q_cnt;
257 uint64_t num_tx_desc_error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258 uint64_t num_tx_comp_cnt;
259 uint64_t num_tx_queued;
260 uint64_t num_tx_dequeued;
261 uint64_t num_max_pm_queue;
262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800263 uint64_t num_rx_excep;
Yun Parkb187d542016-11-14 18:10:04 -0800264 uint64_t num_tx_fwd_ok;
265 uint64_t num_tx_fwd_err;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800266};
267
268struct ipa_uc_stas_map {
269 bool is_reserved;
270 uint8_t sta_id;
271};
272struct op_msg_type {
273 uint8_t msg_t;
274 uint8_t rsvd;
275 uint16_t op_code;
276 uint16_t len;
277 uint16_t rsvd_snd;
278};
279
280struct ipa_uc_fw_stats {
281 uint32_t tx_comp_ring_base;
282 uint32_t tx_comp_ring_size;
283 uint32_t tx_comp_ring_dbell_addr;
284 uint32_t tx_comp_ring_dbell_ind_val;
285 uint32_t tx_comp_ring_dbell_cached_val;
286 uint32_t tx_pkts_enqueued;
287 uint32_t tx_pkts_completed;
288 uint32_t tx_is_suspend;
289 uint32_t tx_reserved;
290 uint32_t rx_ind_ring_base;
291 uint32_t rx_ind_ring_size;
292 uint32_t rx_ind_ring_dbell_addr;
293 uint32_t rx_ind_ring_dbell_ind_val;
294 uint32_t rx_ind_ring_dbell_ind_cached_val;
295 uint32_t rx_ind_ring_rdidx_addr;
296 uint32_t rx_ind_ring_rd_idx_cached_val;
297 uint32_t rx_refill_idx;
298 uint32_t rx_num_pkts_indicated;
299 uint32_t rx_buf_refilled;
300 uint32_t rx_num_ind_drop_no_space;
301 uint32_t rx_num_ind_drop_no_buf;
302 uint32_t rx_is_suspend;
303 uint32_t rx_reserved;
304};
305
306struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530307 qdf_list_node_t node;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700308 struct hdd_adapter *adapter;
Yun Park6c86a662017-10-05 16:09:15 -0700309 qdf_ipa_wlan_event_t type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800310 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530311 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Yun Parka4bb37c2017-12-08 16:14:22 -0800312 bool is_loading;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800313};
314
315/**
316 * struct uc_rm_work_struct
317 * @work: uC RM work
318 * @event: IPA RM event
319 */
320struct uc_rm_work_struct {
321 struct work_struct work;
Yun Park6c86a662017-10-05 16:09:15 -0700322 qdf_ipa_rm_event_t event;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800323};
324
325/**
326 * struct uc_op_work_struct
327 * @work: uC OP work
328 * @msg: OP message
329 */
330struct uc_op_work_struct {
331 struct work_struct work;
332 struct op_msg_type *msg;
333};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334
335/**
336 * struct uc_rt_debug_info
337 * @time: system time
338 * @ipa_excep_count: IPA exception packet count
339 * @rx_drop_count: IPA Rx drop packet count
340 * @net_sent_count: IPA Rx packet sent to network stack count
341 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800342 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800343 * @tx_fwd_count: IPA Tx forward packet count
344 * @rx_destructor_call: IPA Rx packet destructor count
345 */
346struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530347 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800348 uint64_t ipa_excep_count;
349 uint64_t rx_drop_count;
350 uint64_t net_sent_count;
351 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800352 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800353 uint64_t tx_fwd_count;
354 uint64_t rx_destructor_call;
355};
356
Yun Park637d6482016-10-05 10:51:33 -0700357#ifdef FEATURE_METERING
358struct ipa_uc_sharing_stats {
359 uint64_t ipv4_rx_packets;
360 uint64_t ipv4_rx_bytes;
361 uint64_t ipv6_rx_packets;
362 uint64_t ipv6_rx_bytes;
363 uint64_t ipv4_tx_packets;
364 uint64_t ipv4_tx_bytes;
365 uint64_t ipv6_tx_packets;
366 uint64_t ipv6_tx_bytes;
367};
368
369struct ipa_uc_quota_rsp {
370 uint8_t success;
371 uint8_t reserved[3];
372 uint32_t quota_lo; /* quota limit low bytes */
373 uint32_t quota_hi; /* quota limit high bytes */
374};
375
376struct ipa_uc_quota_ind {
377 uint64_t quota_bytes; /* quota limit in bytes */
378};
379#endif
380
Yun Park52b2b992016-09-22 15:49:51 -0700381/**
382 * struct hdd_ipa_tx_desc
383 * @link: link to list head
384 * @priv: pointer to priv list entry
385 * @id: Tx desc idex
386 * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
387 */
388struct hdd_ipa_tx_desc {
389 struct list_head link;
390 void *priv;
391 uint32_t id;
Yun Park6c86a662017-10-05 16:09:15 -0700392 qdf_ipa_rx_data_t *ipa_tx_desc_ptr;
Yun Park52b2b992016-09-22 15:49:51 -0700393};
394
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395struct hdd_ipa_priv {
396 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
397 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
398 uint8_t num_iface;
399 enum hdd_ipa_rm_state rm_state;
400 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530401 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800402 * APIs as it is taken care gracefully. Without this, kernel would throw
403 * an warning if spin_lock_bh is used while IRQ is disabled
404 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530405 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800406 struct uc_rm_work_struct uc_rm_work;
407 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530408 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800409 struct delayed_work wake_lock_work;
410 bool wake_lock_released;
411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800412 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530413 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800414 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530415 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800416 bool suspended;
417
Yun Park52b2b992016-09-22 15:49:51 -0700418 qdf_spinlock_t q_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800420 struct list_head pend_desc_head;
Yun Park52b2b992016-09-22 15:49:51 -0700421 struct hdd_ipa_tx_desc *tx_desc_list;
422 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800423
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700424 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800425 struct hdd_ipa_stats stats;
426
427 struct notifier_block ipv4_notifier;
428 uint32_t curr_prod_bw;
429 uint32_t curr_cons_bw;
430
431 uint8_t activated_fw_pipe;
432 uint8_t sap_num_connected_sta;
433 uint8_t sta_connected;
434 uint32_t tx_pipe_handle;
435 uint32_t rx_pipe_handle;
436 bool resource_loading;
437 bool resource_unloading;
438 bool pending_cons_req;
439 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530440 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530441 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700442 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800443 uint32_t ipa_tx_packets_diff;
444 uint32_t ipa_rx_packets_diff;
445 uint32_t ipa_p_tx_packets;
446 uint32_t ipa_p_rx_packets;
447 uint32_t stat_req_reason;
448 uint64_t ipa_tx_forward;
449 uint64_t ipa_rx_discard;
450 uint64_t ipa_rx_net_send_count;
Yun Park46255682017-10-09 15:56:34 -0700451 uint64_t ipa_rx_internal_drop_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530453 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800454 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
455 unsigned int rt_buf_fill_index;
Yun Park6c86a662017-10-05 16:09:15 -0700456 qdf_ipa_wdi_in_params_t cons_pipe_in;
457 qdf_ipa_wdi_in_params_t prod_pipe_in;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800458 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800459 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530460 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530461 qdf_mutex_t rt_debug_lock;
462 qdf_mutex_t ipa_lock;
Yun Parkb4f591d2017-03-29 15:51:01 -0700463
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800464 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
465 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700466#ifdef FEATURE_METERING
467 struct ipa_uc_sharing_stats ipa_sharing_stats;
468 struct ipa_uc_quota_rsp ipa_quota_rsp;
469 struct ipa_uc_quota_ind ipa_quota_ind;
470 struct completion ipa_uc_sharing_stats_comp;
471 struct completion ipa_uc_set_quota_comp;
472#endif
Yun Park777d7242017-03-30 15:38:33 -0700473 struct completion ipa_resource_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800474};
475
Leo Changcc923e22016-06-16 15:29:03 -0700476#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
477#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
479#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
480#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
481#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
482#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700483#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
484 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800485
486#define HDD_IPA_GET_IFACE_ID(_data) \
487 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
488
489#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530490 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 "%s:%d: "fmt, __func__, __LINE__, ## args)
492
Govind Singhb6a89772016-08-12 11:23:35 +0530493#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
494 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
495 "%s:%d: "fmt, __func__, __LINE__, ## args)
496
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
498 do { \
Yun Parkec845302016-12-15 09:22:57 -0800499 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
500 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501 } while (0)
502
503#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
504 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
505
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
507
Yun Park0dad1002017-07-14 14:57:01 -0700508#define HDD_IPA_DBG_DUMP_RX_LEN 84
Yun Parkb187d542016-11-14 18:10:04 -0800509#define HDD_IPA_DBG_DUMP_TX_LEN 48
510
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511static struct hdd_ipa_adapter_2_client {
Yun Park6c86a662017-10-05 16:09:15 -0700512 qdf_ipa_client_type_t cons_client;
513 qdf_ipa_client_type_t prod_client;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
515 {
516 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
517 }, {
518 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
519 }, {
520 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
521 },
522};
523
Yun Park637d6482016-10-05 10:51:33 -0700524#ifdef FEATURE_METERING
525#define IPA_UC_SHARING_STATES_WAIT_TIME 500
526#define IPA_UC_SET_QUOTA_WAIT_TIME 500
527#endif
528
Yun Park777d7242017-03-30 15:38:33 -0700529#define IPA_RESOURCE_COMP_WAIT_TIME 100
530
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531static struct hdd_ipa_priv *ghdd_ipa;
532
533/* Local Function Prototypes */
Yun Park6c86a662017-10-05 16:09:15 -0700534static void hdd_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800535 unsigned long data);
Yun Park6c86a662017-10-05 16:09:15 -0700536static void hdd_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800537 unsigned long data);
Yun Parkb4f591d2017-03-29 15:51:01 -0700538#ifdef FEATURE_METERING
Yun Park6c86a662017-10-05 16:09:15 -0700539static void hdd_ipa_wdi_meter_notifier_cb(qdf_ipa_wdi_meter_evt_type_t evt,
Yun Parkb4f591d2017-03-29 15:51:01 -0700540 void *data);
541#else
542static void hdd_ipa_wdi_meter_notifier_cb(void);
543#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800544static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545
546static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Yun Parka4bb37c2017-12-08 16:14:22 -0800547static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa,
548 bool is_loading);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800550#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
551 defined(IPA_CLIENT_IS_MHI_CONS))
552/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800553 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
554 * @priv_ctxt: hdd ipa local context
555 *
556 * Will be called by IPA context.
557 * It's atomic context, then should be scheduled to kworker thread
558 *
559 * Return: None
560 */
561static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
562{
563 struct hdd_ipa_priv *hdd_ipa;
564 struct op_msg_type *msg;
565 struct uc_op_work_struct *uc_op_work;
566
567 if (priv_ctxt == NULL) {
568 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
569 return;
570 }
571
572 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
Yun Park6edb2172018-01-14 00:18:05 -0800573 hdd_ipa->uc_loaded = true;
574
575 uc_op_work = &hdd_ipa->uc_op_work[HDD_IPA_UC_OPCODE_UC_READY];
576
577 if (!list_empty(&uc_op_work->work.entry))
578 /* uc_op_work is not initialized yet */
579 return;
580
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800581 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
582 if (!msg) {
583 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
584 return;
585 }
586
587 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
588
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800589 /* When the same uC OPCODE is already pended, just return */
590 if (uc_op_work->msg)
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530591 goto done;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800592
593 uc_op_work->msg = msg;
594 schedule_work(&uc_op_work->work);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530595
jiadd91a6842017-08-01 14:46:02 +0800596 /* work handler will free the msg buffer */
597 return;
598
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530599done:
600 qdf_mem_free(msg);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800601}
602
603/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800604 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
605 * @ctrl: WDI control value
606 *
607 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
608 *
609 * Return: 0 on message send to ipa, -1 on failure
610 */
611static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
612{
Yun Park6c86a662017-10-05 16:09:15 -0700613 qdf_ipa_msg_meta_t meta;
614 qdf_ipa_wlan_msg_t *ipa_msg;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800615 int ret = 0;
616
617 /* WDI enable message to IPA */
Yun Park6c86a662017-10-05 16:09:15 -0700618 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*ipa_msg);
619 ipa_msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800620 if (ipa_msg == NULL) {
621 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
622 "msg allocation failed");
623 return -ENOMEM;
624 }
625
626 if (ctrl == true)
Yun Park6c86a662017-10-05 16:09:15 -0700627 QDF_IPA_MSG_META_MSG_TYPE(&meta) = WLAN_WDI_ENABLE;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800628 else
Yun Park6c86a662017-10-05 16:09:15 -0700629 QDF_IPA_MSG_META_MSG_TYPE(&meta) = WLAN_WDI_DISABLE;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800630
Srinivas Girigowda97852372017-03-06 16:52:59 -0800631 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park6c86a662017-10-05 16:09:15 -0700632 "ipa_send_msg(Evt:%d)", QDF_IPA_MSG_META_MSG_TYPE(&meta));
633 ret = qdf_ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800634 if (ret) {
635 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
636 "ipa_send_msg(Evt:%d)-fail=%d",
Yun Park6c86a662017-10-05 16:09:15 -0700637 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800638 qdf_mem_free(ipa_msg);
639 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800640 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800641}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800642
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800643/**
644 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
645 * @hdd_ipa: HDD IPA local context
646 *
647 * Register IPA UC ready callback function to IPA kernel driver
648 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
649 * open WDI pipe after WLAN driver loading finished
650 *
651 * Return: 0 Success
652 * -EPERM Registration fail
653 */
654static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
655{
Yun Park6c86a662017-10-05 16:09:15 -0700656 qdf_ipa_wdi_uc_ready_params_t uc_ready_param;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800657 int ret = 0;
658
659 hdd_ipa->uc_loaded = false;
Yun Park6c86a662017-10-05 16:09:15 -0700660 QDF_IPA_UC_READY_PARAMS_PRIV(&uc_ready_param) = (void *)hdd_ipa;
661 QDF_IPA_UC_READY_PARAMS_NOTIFY(&uc_ready_param) =
662 hdd_ipa_uc_loaded_uc_cb;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800663 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
664 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
665 "UC Ready CB register fail");
666 return -EPERM;
667 }
Yun Park6c86a662017-10-05 16:09:15 -0700668 if (false != QDF_IPA_UC_READY_PARAMS_IS_UC_READY(&uc_ready_param)) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700669 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800670 hdd_ipa->uc_loaded = true;
671 } else {
672 ret = hdd_ipa_uc_send_wdi_control_msg(false);
673 }
674
675 return ret;
676}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800677#else
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800678static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
679{
680 hdd_ipa->uc_loaded = true;
681 return 0;
682}
683
684static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
685{
686 return 0;
687}
688#endif
689
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800690/**
691 * hdd_ipa_is_enabled() - Is IPA enabled?
692 * @hdd_ctx: Global HDD context
693 *
694 * Return: true if IPA is enabled, false otherwise
695 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700696bool hdd_ipa_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800697{
698 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
699}
700
701/**
702 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
703 * @hdd_ctx: Global HDD context
704 *
705 * Return: true if IPA uC offload is enabled, false otherwise
706 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700707bool hdd_ipa_uc_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800708{
709 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
710}
711
712/**
713 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
714 * @hdd_ctx: Global HDD context
715 *
716 * Return: true if STA mode IPA uC offload is enabled, false otherwise
717 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700718static inline bool hdd_ipa_uc_sta_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800719{
720 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
721}
722
723/**
Guolei Bianca144d82016-11-10 11:07:42 +0800724 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
725 * @hdd_ipa: Global HDD IPA context
726 *
727 * Return: None
728 */
Guolei Bianca144d82016-11-10 11:07:42 +0800729static inline void hdd_ipa_uc_sta_reset_sta_connected(
730 struct hdd_ipa_priv *hdd_ipa)
731{
Yun Park637d6482016-10-05 10:51:33 -0700732 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800733 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700734 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800735}
Guolei Bianca144d82016-11-10 11:07:42 +0800736
737/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
739 * @hdd_ipa: Global HDD IPA context
740 *
741 * Return: true if pre-filter is enabled, otherwise false
742 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700743static inline bool hdd_ipa_is_pre_filter_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744{
745 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
746 HDD_IPA_PRE_FILTER_ENABLE_MASK);
747}
748
749/**
750 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
751 * @hdd_ipa: Global HDD IPA context
752 *
753 * Return: true if IPv6 is enabled, otherwise false
754 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700755static inline bool hdd_ipa_is_ipv6_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756{
757 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
758}
759
760/**
761 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
762 * @hdd_ipa: Global HDD IPA context
763 *
764 * Return: true if resource manager is enabled, otherwise false
765 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700766static inline bool hdd_ipa_is_rm_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767{
768 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
769}
770
771/**
772 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
773 * @hdd_ipa: Global HDD IPA context
774 *
775 * Return: true if resource manager is enabled, otherwise false
776 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700777static inline bool hdd_ipa_is_rt_debugging_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800778{
779 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
780}
781
782/**
783 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
784 * @hdd_ipa: Global HDD IPA context
785 *
786 * Return: true if clock scaling is enabled, otherwise false
787 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700788static inline bool hdd_ipa_is_clk_scaling_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789{
790 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
791 HDD_IPA_CLK_SCALING_ENABLE_MASK |
792 HDD_IPA_RM_ENABLE_MASK);
793}
794
795/**
796 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
797 * @ctext: pointer to hdd context.
798 *
799 * If rt debug enabled, periodically called, and fill debug buffer
800 *
801 * Return: none
802 */
803static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
804{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700805 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806 struct hdd_ipa_priv *hdd_ipa;
807 struct uc_rt_debug_info *dump_info = NULL;
808
809 if (wlan_hdd_validate_context(hdd_ctx))
810 return;
811
812 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700813 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 return;
815 }
816
817 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
818
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530819 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 dump_info = &hdd_ipa->rt_bug_buffer[
821 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
822
Deepthi Gowri6acee342016-10-28 15:00:38 +0530823 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
Yun Park46255682017-10-09 15:56:34 -0700825 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internal_drop_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800827 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800828 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
829 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
831 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530832 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833
Anurag Chouhan210db072016-02-22 18:42:15 +0530834 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
836}
837
838/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700839 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 * @hdd_ctx: pointer to hdd context.
841 *
842 * If rt debug enabled, dump debug buffer contents based on requirement
843 *
844 * Return: none
845 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700846static void __hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847{
848 struct hdd_ipa_priv *hdd_ipa;
849 unsigned int dump_count;
850 unsigned int dump_index;
851 struct uc_rt_debug_info *dump_info = NULL;
852
853 if (wlan_hdd_validate_context(hdd_ctx))
854 return;
855
856 hdd_ipa = hdd_ctx->hdd_ipa;
857 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700858 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 return;
860 }
861
Chris Guo1751acf2017-07-03 14:09:01 +0800862 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
863 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -0700864 "IPA RT debug is not enabled");
Chris Guo1751acf2017-07-03 14:09:01 +0800865 return;
866 }
867
Yun Park46255682017-10-09 15:56:34 -0700868 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Yun Park46255682017-10-09 15:56:34 -0700870 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Parkb187d542016-11-14 18:10:04 -0800871 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530873 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 for (dump_count = 0;
875 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
876 dump_count++) {
877 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
878 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
879 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Yun Park46255682017-10-09 15:56:34 -0700880 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530881 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882 dump_info->time, dump_info->ipa_excep_count,
883 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800884 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 dump_info->rx_destructor_call,
886 dump_info->rx_discard_count);
887 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530888 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Yun Park46255682017-10-09 15:56:34 -0700889 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
891}
892
893/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700894 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
895 * __hdd_ipa_uc_rt_debug_host_dump
896 * @hdd_ctx: pointer to hdd context.
897 *
898 * If rt debug enabled, dump debug buffer contents based on requirement
899 *
900 * Return: none
901 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700902void hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700903{
904 cds_ssr_protect(__func__);
905 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
906 cds_ssr_unprotect(__func__);
907}
908
909/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
911 * @ctext: pointer to hdd context.
912 *
913 * periodically called by timer expire
914 * will try to alloc dummy memory and detect out of memory condition
915 * if out of memory detected, dump wlan-ipa stats
916 *
917 * Return: none
918 */
919static void hdd_ipa_uc_rt_debug_handler(void *ctext)
920{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700921 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700922 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 void *dummy_ptr = NULL;
924
925 if (wlan_hdd_validate_context(hdd_ctx))
926 return;
927
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700928 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700931 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
932 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 return;
934 }
935
936 /* Allocate dummy buffer periodically and free immediately. this will
937 * proactively detect OOM and if allocation fails dump ipa stats
938 */
939 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
940 GFP_KERNEL | GFP_ATOMIC);
941 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800942 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
943 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700944 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
945 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 } else {
947 kfree(dummy_ptr);
948 }
949
Anurag Chouhan210db072016-02-22 18:42:15 +0530950 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951 HDD_IPA_UC_RT_DEBUG_PERIOD);
952}
953
954/**
Yun Parkb187d542016-11-14 18:10:04 -0800955 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 * @skb: packet pinter
957 *
958 * when free data packet, will be invoked by wlan client and will increase
959 * free counter
960 *
961 * Return: none
962 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700963static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964{
965 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700966 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 return;
968 }
969
970 ghdd_ipa->ipa_rx_destructor_count++;
971}
972
973/**
Yun Parkb187d542016-11-14 18:10:04 -0800974 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800975 * @hdd_ctx: hdd main context
976 *
977 * free all rt debugging resources
978 *
979 * Return: none
980 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700981static void hdd_ipa_uc_rt_debug_deinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982{
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700983 struct hdd_ipa_priv *hdd_ipa;
984
985 if (wlan_hdd_validate_context(hdd_ctx))
986 return;
987
988 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530990 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991
992 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700993 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
994 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995 return;
996 }
997
Anurag Chouhan210db072016-02-22 18:42:15 +0530998 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -0800999 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1000 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1001 }
1002 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1003
1004 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301005 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1006 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001007 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301008 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009}
1010
1011/**
Yun Parkb187d542016-11-14 18:10:04 -08001012 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013 * @hdd_ctx: hdd main context
1014 *
1015 * alloc and initialize all rt debugging resources
1016 *
1017 * Return: none
1018 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001019static void hdd_ipa_uc_rt_debug_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001020{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001021 struct hdd_ipa_priv *hdd_ipa;
1022
Chris Guo1751acf2017-07-03 14:09:01 +08001023 if (wlan_hdd_validate_context_in_loading(hdd_ctx))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001024 return;
1025
1026 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301028 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301030 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 sizeof(struct uc_rt_debug_info) *
1032 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1033 hdd_ipa->ipa_tx_forward = 0;
1034 hdd_ipa->ipa_rx_discard = 0;
1035 hdd_ipa->ipa_rx_net_send_count = 0;
Yun Park46255682017-10-09 15:56:34 -07001036 hdd_ipa->ipa_rx_internal_drop_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 hdd_ipa->ipa_rx_destructor_count = 0;
1038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 /* Reatime debug enable on feature enable */
1040 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001041 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1042 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043 return;
1044 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001045
1046 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1047 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1048 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1049 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1050
Anurag Chouhan210db072016-02-22 18:42:15 +05301051 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001052 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301053 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 HDD_IPA_UC_RT_DEBUG_PERIOD);
1055
1056}
1057
1058/**
Yun Parkb187d542016-11-14 18:10:04 -08001059 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1060 * @hdd_ipa: HDD IPA struct
1061 *
1062 * Dump entries in struct hdd_ipa
1063 *
1064 * Return: none
1065 */
1066static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1067{
1068 int i;
1069
1070 /* HDD IPA */
Yun Park46255682017-10-09 15:56:34 -07001071 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1072 "\n==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001073 "num_iface: %d\n"
1074 "rm_state: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001075 "rm_lock: %pK\n"
1076 "uc_rm_work: %pK\n"
1077 "uc_op_work: %pK\n"
1078 "wake_lock: %pK\n"
1079 "wake_lock_work: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001080 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001081 "tx_ref_cnt: %d\n"
1082 "pm_queue_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001083 "\thead: %pK\n"
1084 "\ttail: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001085 "\tqlen: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001086 "pm_work: %pK\n"
1087 "pm_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001088 "suspended: %d\n",
1089 hdd_ipa->num_iface,
1090 hdd_ipa->rm_state,
1091 &hdd_ipa->rm_lock,
1092 &hdd_ipa->uc_rm_work,
1093 &hdd_ipa->uc_op_work,
1094 &hdd_ipa->wake_lock,
1095 &hdd_ipa->wake_lock_work,
1096 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001097 hdd_ipa->tx_ref_cnt.counter,
1098 hdd_ipa->pm_queue_head.head,
1099 hdd_ipa->pm_queue_head.tail,
1100 hdd_ipa->pm_queue_head.qlen,
1101 &hdd_ipa->pm_work,
1102 &hdd_ipa->pm_lock,
1103 hdd_ipa->suspended);
Yun Park46255682017-10-09 15:56:34 -07001104
1105 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1106 "\nq_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001107 "pend_desc_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001108 "\tnext: %pK\n"
1109 "\tprev: %pK\n"
1110 "hdd_ctx: %pK\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001111 "stats: %pK\n"
1112 "ipv4_notifier: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001113 "curr_prod_bw: %d\n"
1114 "curr_cons_bw: %d\n"
1115 "activated_fw_pipe: %d\n"
1116 "sap_num_connected_sta: %d\n"
1117 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001118 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001119 hdd_ipa->pend_desc_head.next,
1120 hdd_ipa->pend_desc_head.prev,
1121 hdd_ipa->hdd_ctx,
Yun Parkb187d542016-11-14 18:10:04 -08001122 &hdd_ipa->stats,
1123 &hdd_ipa->ipv4_notifier,
1124 hdd_ipa->curr_prod_bw,
1125 hdd_ipa->curr_cons_bw,
1126 hdd_ipa->activated_fw_pipe,
1127 hdd_ipa->sap_num_connected_sta,
Yun Park46255682017-10-09 15:56:34 -07001128 (unsigned int)hdd_ipa->sta_connected);
1129
1130 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1131 "\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001132 "rx_pipe_handle: 0x%x\n"
1133 "resource_loading: %d\n"
1134 "resource_unloading: %d\n"
1135 "pending_cons_req: %d\n"
1136 "pending_event----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001137 "\tanchor.next: %pK\n"
1138 "\tanchor.prev: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001139 "\tcount: %d\n"
1140 "\tmax_size: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001141 "event_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001142 "ipa_tx_packets_diff: %d\n"
1143 "ipa_rx_packets_diff: %d\n"
1144 "ipa_p_tx_packets: %d\n"
1145 "ipa_p_rx_packets: %d\n"
1146 "stat_req_reason: %d\n",
1147 hdd_ipa->tx_pipe_handle,
1148 hdd_ipa->rx_pipe_handle,
1149 hdd_ipa->resource_loading,
1150 hdd_ipa->resource_unloading,
1151 hdd_ipa->pending_cons_req,
1152 hdd_ipa->pending_event.anchor.next,
1153 hdd_ipa->pending_event.anchor.prev,
1154 hdd_ipa->pending_event.count,
1155 hdd_ipa->pending_event.max_size,
1156 &hdd_ipa->event_lock,
1157 hdd_ipa->ipa_tx_packets_diff,
1158 hdd_ipa->ipa_rx_packets_diff,
1159 hdd_ipa->ipa_p_tx_packets,
1160 hdd_ipa->ipa_p_rx_packets,
1161 hdd_ipa->stat_req_reason);
1162
Yun Park46255682017-10-09 15:56:34 -07001163 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1164 "\ncons_pipe_in----\n"
1165 "\tsys: %pK\n"
1166 "\tdl.comp_ring_base_pa: 0x%x\n"
1167 "\tdl.comp_ring_size: %d\n"
1168 "\tdl.ce_ring_base_pa: 0x%x\n"
1169 "\tdl.ce_door_bell_pa: 0x%x\n"
1170 "\tdl.ce_ring_size: %d\n"
1171 "\tdl.num_tx_buffers: %d\n"
1172 "prod_pipe_in----\n"
1173 "\tsys: %pK\n"
1174 "\tul.rdy_ring_base_pa: 0x%x\n"
1175 "\tul.rdy_ring_size: %d\n"
1176 "\tul.rdy_ring_rp_pa: 0x%x\n"
1177 "uc_loaded: %d\n"
1178 "wdi_enabled: %d\n"
1179 "rt_debug_fill_timer: %pK\n"
1180 "rt_debug_lock: %pK\n"
1181 "ipa_lock: %pK\n",
1182 &hdd_ipa->cons_pipe_in.sys,
1183 (unsigned int)hdd_ipa->cons_pipe_in.u.dl.comp_ring_base_pa,
1184 hdd_ipa->cons_pipe_in.u.dl.comp_ring_size,
1185 (unsigned int)hdd_ipa->cons_pipe_in.u.dl.ce_ring_base_pa,
1186 (unsigned int)hdd_ipa->cons_pipe_in.u.dl.ce_door_bell_pa,
1187 hdd_ipa->cons_pipe_in.u.dl.ce_ring_size,
1188 hdd_ipa->cons_pipe_in.u.dl.num_tx_buffers,
1189 &hdd_ipa->prod_pipe_in.sys,
1190 (unsigned int)hdd_ipa->prod_pipe_in.u.ul.rdy_ring_base_pa,
1191 hdd_ipa->prod_pipe_in.u.ul.rdy_ring_size,
1192 (unsigned int)hdd_ipa->prod_pipe_in.u.ul.rdy_ring_rp_pa,
1193 hdd_ipa->uc_loaded,
1194 hdd_ipa->wdi_enabled,
1195 &hdd_ipa->rt_debug_fill_timer,
1196 &hdd_ipa->rt_debug_lock,
1197 &hdd_ipa->ipa_lock);
1198
1199 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1200 "\nvdev_to_iface----");
1201 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1202 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1203 "\n\t[%d]=%d", i, hdd_ipa->vdev_to_iface[i]);
1204 }
1205 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1206 "\nvdev_offload_enabled----");
1207 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1208 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1209 "\n\t[%d]=%d", i, hdd_ipa->vdev_offload_enabled[i]);
1210 }
1211 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1212 "\nassoc_stas_map ----");
Yun Parkb187d542016-11-14 18:10:04 -08001213 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Yun Park46255682017-10-09 15:56:34 -07001214 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1215 "\n\t[%d]: is_reserved=%d, sta_id=%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001216 hdd_ipa->assoc_stas_map[i].is_reserved,
1217 hdd_ipa->assoc_stas_map[i].sta_id);
1218 }
1219}
1220
1221/**
1222 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1223 * @hdd_ipa: HDD IPA struct
1224 *
1225 * Dump entire struct hdd_ipa_sys_pipe
1226 *
1227 * Return: none
1228 */
1229static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1230{
1231 int i;
1232
1233 /* IPA SYS Pipes */
Yun Park46255682017-10-09 15:56:34 -07001234 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1235 "\n==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001236
1237 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1238 struct hdd_ipa_sys_pipe *sys_pipe;
Yun Park6c86a662017-10-05 16:09:15 -07001239 qdf_ipa_sys_connect_params_t *ipa_sys_params;
Yun Parkb187d542016-11-14 18:10:04 -08001240
1241 sys_pipe = &hdd_ipa->sys_pipe[i];
1242 ipa_sys_params = &sys_pipe->ipa_sys_params;
1243
Yun Park46255682017-10-09 15:56:34 -07001244 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1245 "\nsys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001246 "\tconn_hdl: 0x%x\n"
1247 "\tconn_hdl_valid: %d\n"
1248 "\tnat_en: %d\n"
1249 "\thdr_len %d\n"
1250 "\thdr_additional_const_len: %d\n"
1251 "\thdr_ofst_pkt_size_valid: %d\n"
1252 "\thdr_ofst_pkt_size: %d\n"
1253 "\thdr_little_endian: %d\n"
1254 "\tmode: %d\n"
1255 "\tclient: %d\n"
1256 "\tdesc_fifo_sz: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001257 "\tpriv: %pK\n"
1258 "\tnotify: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001259 "\tskip_ep_cfg: %d\n"
1260 "\tkeep_ipa_awake: %d\n",
1261 i,
1262 sys_pipe->conn_hdl,
1263 sys_pipe->conn_hdl_valid,
Yun Park6c86a662017-10-05 16:09:15 -07001264 QDF_IPA_SYS_PARAMS_NAT_EN(ipa_sys_params),
1265 QDF_IPA_SYS_PARAMS_HDR_LEN(ipa_sys_params),
1266 QDF_IPA_SYS_PARAMS_HDR_ADDITIONAL_CONST_LEN(
1267 ipa_sys_params),
1268 QDF_IPA_SYS_PARAMS_HDR_OFST_PKT_SIZE_VALID(
1269 ipa_sys_params),
1270 QDF_IPA_SYS_PARAMS_HDR_OFST_PKT_SIZE(ipa_sys_params),
1271 QDF_IPA_SYS_PARAMS_HDR_LITTLE_ENDIAN(ipa_sys_params),
1272 QDF_IPA_SYS_PARAMS_MODE(ipa_sys_params),
1273 QDF_IPA_SYS_PARAMS_CLIENT(ipa_sys_params),
1274 QDF_IPA_SYS_PARAMS_DESC_FIFO_SZ(ipa_sys_params),
1275 QDF_IPA_SYS_PARAMS_PRIV(ipa_sys_params),
1276 QDF_IPA_SYS_PARAMS_NOTIFY(ipa_sys_params),
1277 QDF_IPA_SYS_PARAMS_SKIP_EP_CFG(ipa_sys_params),
1278 QDF_IPA_SYS_PARAMS_KEEP_IPA_AWAKE(ipa_sys_params));
Yun Parkb187d542016-11-14 18:10:04 -08001279 }
1280}
1281
1282/**
1283 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1284 * @hdd_ipa: HDD IPA struct
1285 *
1286 * Dump entire struct hdd_ipa_iface_context
1287 *
1288 * Return: none
1289 */
1290static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1291{
1292 int i;
1293
1294 /* IPA Interface Contexts */
Yun Park46255682017-10-09 15:56:34 -07001295 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1296 "\n==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001297
1298 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1299 struct hdd_ipa_iface_context *iface_context;
1300
1301 iface_context = &hdd_ipa->iface_context[i];
1302
Yun Park46255682017-10-09 15:56:34 -07001303 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1304 "\niface_context[%d]----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001305 "\thdd_ipa: %pK\n"
1306 "\tadapter: %pK\n"
1307 "\ttl_context: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001308 "\tcons_client: %d\n"
1309 "\tprod_client: %d\n"
1310 "\tiface_id: %d\n"
1311 "\tsta_id: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001312 "\tinterface_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001313 "\tifa_address: 0x%x\n",
1314 i,
1315 iface_context->hdd_ipa,
1316 iface_context->adapter,
1317 iface_context->tl_context,
1318 iface_context->cons_client,
1319 iface_context->prod_client,
1320 iface_context->iface_id,
1321 iface_context->sta_id,
1322 &iface_context->interface_lock,
1323 iface_context->ifa_address);
1324 }
1325}
1326
1327/**
1328 * hdd_ipa_dump_info() - dump HDD IPA struct
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001329 * @hdd_ctx: hdd main context
Yun Parkb187d542016-11-14 18:10:04 -08001330 *
1331 * Dump entire struct hdd_ipa
1332 *
1333 * Return: none
1334 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001335void hdd_ipa_dump_info(struct hdd_context *hdd_ctx)
Yun Parkb187d542016-11-14 18:10:04 -08001336{
1337 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1338
1339 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1340 hdd_ipa_dump_sys_pipe(hdd_ipa);
1341 hdd_ipa_dump_iface_context(hdd_ipa);
1342}
1343
1344/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001345 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1346 * enabled
1347 *
1348 * This routine is called to set TX flow info if IPA is enabled
1349 *
1350 * Return: None
1351 */
1352void hdd_ipa_set_tx_flow_info(void)
1353{
Jeff Johnson49d45e62017-08-29 14:30:42 -07001354 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07001355 struct hdd_station_ctx *sta_ctx;
Jeff Johnson87251032017-08-29 13:31:11 -07001356 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -07001357 struct hdd_hostapd_state *hostapd_state;
Dustin Brown4e565a42018-01-17 14:59:14 -08001358 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INIT;
1359 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INIT;
1360 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INIT;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001361 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1362 const char *p2pMode = "DEV";
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001363 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001364 cds_context_type *cds_ctx;
1365#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1366 uint8_t targetChannel = 0;
1367 uint8_t preAdapterChannel = 0;
1368 uint8_t channel24;
1369 uint8_t channel5;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001370 struct hdd_adapter *preAdapterContext = NULL;
1371 struct hdd_adapter *adapter2_4 = NULL;
1372 struct hdd_adapter *adapter5 = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001373 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1374#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1375 struct wlan_objmgr_psoc *psoc;
1376
1377 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1378 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001379 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001380 return;
1381 }
1382
1383 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1384 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001385 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001386 return;
1387 }
1388
1389 psoc = hdd_ctx->hdd_psoc;
Dustin Brown920397d2017-12-13 16:27:50 -08001390
1391 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001392 switch (adapter->device_mode) {
1393 case QDF_STA_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001394 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001395 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001396 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001397 staChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001398 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001399 qdf_copy_macaddr(&staBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001400 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001401#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1402 targetChannel = staChannel;
1403#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1404 }
1405 break;
1406 case QDF_P2P_CLIENT_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001407 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001408 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001409 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001410 p2pChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001411 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001412 qdf_copy_macaddr(&p2pBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001413 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001414 p2pMode = "CLI";
1415#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1416 targetChannel = p2pChannel;
1417#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1418 }
1419 break;
1420 case QDF_P2P_GO_MODE:
1421 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1422 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07001423 if (hostapd_state->bss_state == BSS_START
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001424 && hostapd_state->qdf_status ==
1425 QDF_STATUS_SUCCESS) {
Jeff Johnson01206862017-10-27 20:55:59 -07001426 p2pChannel = hdd_ap_ctx->operating_channel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001427 qdf_copy_macaddr(&p2pBssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07001428 &adapter->mac_addr);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001429#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1430 targetChannel = p2pChannel;
1431#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1432 }
1433 p2pMode = "GO";
1434 break;
1435 case QDF_SAP_MODE:
1436 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1437 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Jeff Johnson0f9f87b2017-10-28 09:21:06 -07001438 if (hostapd_state->bss_state == BSS_START
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001439 && hostapd_state->qdf_status ==
1440 QDF_STATUS_SUCCESS) {
Jeff Johnson01206862017-10-27 20:55:59 -07001441 apChannel = hdd_ap_ctx->operating_channel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001442 qdf_copy_macaddr(&apBssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07001443 &adapter->mac_addr);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001444#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1445 targetChannel = apChannel;
1446#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1447 }
1448 break;
1449 case QDF_IBSS_MODE:
1450 default:
1451 break;
1452 }
1453#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1454 if (targetChannel) {
1455 /*
1456 * This is first adapter detected as active
1457 * set as default for none concurrency case
1458 */
1459 if (!preAdapterChannel) {
1460 /* If IPA UC data path is enabled,
1461 * target should reserve extra tx descriptors
1462 * for IPA data path.
1463 * Then host data path should allow less TX
1464 * packet pumping in case IPA
1465 * data path enabled
1466 */
1467 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1468 (QDF_SAP_MODE == adapter->device_mode)) {
1469 adapter->tx_flow_low_watermark =
1470 hdd_ctx->config->TxFlowLowWaterMark +
1471 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1472 } else {
1473 adapter->tx_flow_low_watermark =
1474 hdd_ctx->config->
1475 TxFlowLowWaterMark;
1476 }
1477 adapter->tx_flow_high_watermark_offset =
1478 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1479 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001480 adapter->session_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001481 hdd_ctx->config->TxFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001482 hdd_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001483 adapter->device_mode,
1484 targetChannel,
1485 adapter->tx_flow_low_watermark,
1486 adapter->tx_flow_low_watermark +
1487 adapter->tx_flow_high_watermark_offset,
1488 hdd_ctx->config->TxFlowMaxQueueDepth);
1489 preAdapterChannel = targetChannel;
1490 preAdapterContext = adapter;
1491 } else {
1492 /*
1493 * SCC, disable TX flow control for both
1494 * SCC each adapter cannot reserve dedicated
1495 * channel resource, as a result, if any adapter
1496 * blocked OS Q by flow control,
1497 * blocked adapter will lost chance to recover
1498 */
1499 if (preAdapterChannel == targetChannel) {
1500 /* Current adapter */
1501 adapter->tx_flow_low_watermark = 0;
1502 adapter->
1503 tx_flow_high_watermark_offset = 0;
1504 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001505 adapter->session_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001506 hdd_ctx->config->
1507 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001508 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001509 hdd_device_mode_to_string(
1510 adapter->device_mode),
1511 adapter->device_mode,
1512 targetChannel,
1513 adapter->tx_flow_low_watermark,
1514 adapter->tx_flow_low_watermark +
1515 adapter->
1516 tx_flow_high_watermark_offset,
1517 hdd_ctx->config->
1518 TxHbwFlowMaxQueueDepth);
1519
1520 if (!preAdapterContext) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001521 hdd_err("SCC: Previous adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001522 continue;
1523 }
1524
1525 /* Previous adapter */
1526 preAdapterContext->
1527 tx_flow_low_watermark = 0;
1528 preAdapterContext->
1529 tx_flow_high_watermark_offset = 0;
1530 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001531 preAdapterContext->session_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001532 hdd_ctx->config->
1533 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001534 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001535 hdd_device_mode_to_string(
1536 preAdapterContext->device_mode
1537 ),
1538 preAdapterContext->device_mode,
1539 targetChannel,
1540 preAdapterContext->
1541 tx_flow_low_watermark,
1542 preAdapterContext->
1543 tx_flow_low_watermark +
1544 preAdapterContext->
1545 tx_flow_high_watermark_offset,
1546 hdd_ctx->config->
1547 TxHbwFlowMaxQueueDepth);
1548 }
1549 /*
1550 * MCC, each adapter will have dedicated
1551 * resource
1552 */
1553 else {
1554 /* current channel is 2.4 */
1555 if (targetChannel <=
1556 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1557 channel24 = targetChannel;
1558 channel5 = preAdapterChannel;
1559 adapter2_4 = adapter;
1560 adapter5 = preAdapterContext;
1561 } else {
1562 /* Current channel is 5 */
1563 channel24 = preAdapterChannel;
1564 channel5 = targetChannel;
1565 adapter2_4 = preAdapterContext;
1566 adapter5 = adapter;
1567 }
1568
1569 if (!adapter5) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001570 hdd_err("MCC: 5GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001571 continue;
1572 }
1573 adapter5->tx_flow_low_watermark =
1574 hdd_ctx->config->
1575 TxHbwFlowLowWaterMark;
1576 adapter5->
1577 tx_flow_high_watermark_offset =
1578 hdd_ctx->config->
1579 TxHbwFlowHighWaterMarkOffset;
1580 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001581 adapter5->session_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001582 hdd_ctx->config->
1583 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001584 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001585 hdd_device_mode_to_string(
1586 adapter5->device_mode),
1587 adapter5->device_mode,
1588 channel5,
1589 adapter5->tx_flow_low_watermark,
1590 adapter5->
1591 tx_flow_low_watermark +
1592 adapter5->
1593 tx_flow_high_watermark_offset,
1594 hdd_ctx->config->
1595 TxHbwFlowMaxQueueDepth);
1596
1597 if (!adapter2_4) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001598 hdd_err("MCC: 2.4GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001599 continue;
1600 }
1601 adapter2_4->tx_flow_low_watermark =
1602 hdd_ctx->config->
1603 TxLbwFlowLowWaterMark;
1604 adapter2_4->
1605 tx_flow_high_watermark_offset =
1606 hdd_ctx->config->
1607 TxLbwFlowHighWaterMarkOffset;
1608 cdp_fc_ll_set_tx_pause_q_depth(soc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07001609 adapter2_4->session_id,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001610 hdd_ctx->config->
1611 TxLbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001612 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001613 hdd_device_mode_to_string(
1614 adapter2_4->device_mode),
1615 adapter2_4->device_mode,
1616 channel24,
1617 adapter2_4->
1618 tx_flow_low_watermark,
1619 adapter2_4->
1620 tx_flow_low_watermark +
1621 adapter2_4->
1622 tx_flow_high_watermark_offset,
1623 hdd_ctx->config->
1624 TxLbwFlowMaxQueueDepth);
1625
1626 }
1627 }
1628 }
1629 targetChannel = 0;
1630#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001631 }
Dustin Brown920397d2017-12-13 16:27:50 -08001632
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001633 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1634}
1635
1636/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001637 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001639 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1640 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 *
1642 * Return: true if IPA is enabled, false otherwise
1643 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001644static void __hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001645 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1646{
1647 struct hdd_ipa_priv *hdd_ipa;
1648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 *ipa_tx_diff = 0;
1650 *ipa_rx_diff = 0;
1651
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001652 if (wlan_hdd_validate_context(hdd_ctx))
1653 return;
1654
1655 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1656
1657 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1658 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 return;
1660 }
1661
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301662 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1664 (false == hdd_ipa->resource_loading)) {
1665 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1666 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301668 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669}
1670
1671/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001672 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1673 * @hdd_ctx: Global HDD context
1674 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1675 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1676 *
1677 * Return: true if IPA is enabled, false otherwise
1678 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001679void hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001680 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1681{
1682 cds_ssr_protect(__func__);
1683 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1684 cds_ssr_unprotect(__func__);
1685}
1686
1687/**
1688 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 * @adapter: network adapter
1690 * @reason: STAT REQ Reason
1691 *
1692 * Return: None
1693 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07001694static void __hdd_ipa_uc_stat_request(struct hdd_adapter *adapter,
1695 uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001697 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698 struct hdd_ipa_priv *hdd_ipa;
1699
Yun Park637d6482016-10-05 10:51:33 -07001700 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702
Jeff Johnson399c6272017-08-30 10:51:00 -07001703 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001704
1705 if (wlan_hdd_validate_context(hdd_ctx))
1706 return;
1707
1708 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1709 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1710 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711 return;
1712 }
1713
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301714 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1716 (false == hdd_ipa->resource_loading)) {
1717 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001718 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001719 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07001720 adapter->session_id,
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001721 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001723 } else {
1724 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001726}
1727
1728/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001729 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1730 * @adapter: network adapter
1731 * @reason: STAT REQ Reason
1732 *
1733 * Return: None
1734 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001735void hdd_ipa_uc_stat_request(struct hdd_adapter *adapter, uint8_t reason)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001736{
1737 cds_ssr_protect(__func__);
1738 __hdd_ipa_uc_stat_request(adapter, reason);
1739 cds_ssr_unprotect(__func__);
1740}
1741
Yun Park637d6482016-10-05 10:51:33 -07001742#ifdef FEATURE_METERING
1743/**
1744 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1745 * @adapter: network adapter
1746 * @reset_stats: reset stat countis after response
1747 *
1748 * Return: None
1749 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001750void hdd_ipa_uc_sharing_stats_request(struct hdd_adapter *adapter,
Yun Park637d6482016-10-05 10:51:33 -07001751 uint8_t reset_stats)
1752{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001753 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001754 struct hdd_ipa_priv *hdd_ipa;
1755
1756 if (!adapter)
1757 return;
1758
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001759 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1760 hdd_ipa = hdd_ctx->hdd_ipa;
1761 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1762 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001763 return;
1764 }
1765
Yun Park637d6482016-10-05 10:51:33 -07001766 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001767 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001768 qdf_mutex_release(&hdd_ipa->ipa_lock);
1769 wma_cli_set_command(
Jeff Johnson1b780e42017-10-31 14:11:45 -07001770 (int)adapter->session_id,
Yun Park637d6482016-10-05 10:51:33 -07001771 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1772 reset_stats, VDEV_CMD);
1773 } else {
1774 qdf_mutex_release(&hdd_ipa->ipa_lock);
1775 }
1776}
1777
1778/**
1779 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1780 * @adapter: network adapter
1781 * @set_quota: when 1, FW starts quota monitoring
1782 * @quota_bytes: quota limit in bytes
1783 *
1784 * Return: None
1785 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001786void hdd_ipa_uc_set_quota(struct hdd_adapter *adapter, uint8_t set_quota,
Yun Park637d6482016-10-05 10:51:33 -07001787 uint64_t quota_bytes)
1788{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001789 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001790 struct hdd_ipa_priv *hdd_ipa;
1791
1792 if (!adapter)
1793 return;
1794
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001795 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1796 hdd_ipa = hdd_ctx->hdd_ipa;
1797 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1798 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001799 return;
1800 }
1801
1802 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1803 set_quota, quota_bytes);
1804
1805 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001806 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001807 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001808 wma_cli_set2_command(
Jeff Johnson1b780e42017-10-31 14:11:45 -07001809 (int)adapter->session_id,
Yun Park637d6482016-10-05 10:51:33 -07001810 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001811 (set_quota ? quota_bytes&0xffffffff : 0),
1812 (set_quota ? quota_bytes>>32 : 0),
1813 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001814 } else {
1815 qdf_mutex_release(&hdd_ipa->ipa_lock);
1816 }
1817}
1818#endif
1819
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001820/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1822 * @hdd_ipa: Global HDD IPA context
1823 * @sta_add: Should station be added
1824 * @sta_id: ID of the station being queried
1825 *
1826 * Return: true if the station was found
1827 */
1828static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1829 bool sta_add, uint8_t sta_id)
1830{
1831 bool sta_found = false;
1832 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1835 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1836 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1837 sta_found = true;
1838 break;
1839 }
1840 }
1841 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301842 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001843 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001844 return sta_found;
1845 }
1846 if (sta_add) {
1847 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1848 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1849 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1850 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1851 return sta_found;
1852 }
1853 }
1854 }
1855 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301856 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001857 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001858 return sta_found;
1859 }
1860 if (!sta_add) {
1861 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1862 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1863 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1864 hdd_ipa->assoc_stas_map[idx].is_reserved =
1865 false;
1866 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1867 return sta_found;
1868 }
1869 }
1870 }
1871 return sta_found;
1872}
1873
1874/**
1875 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1876 * @hdd_ipa: Global HDD IPA context
1877 *
1878 * Return: 0 on success, negative errno if error
1879 */
1880static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1881{
Yun Parkfec73dc2017-09-06 10:40:07 -07001882 int result = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07001883 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001884 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885
Yun Parke4239802018-01-09 11:01:40 -08001886 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Park199c2ed2017-10-02 11:24:22 -07001887
1888 if (!hdd_ipa->ipa_pipes_down) {
1889 /*
1890 * This shouldn't happen :
1891 * IPA WDI Pipes are already activated
1892 */
1893 WARN_ON(1);
1894 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
1895 "IPA WDI Pipes are already activated");
1896 goto end;
1897 }
Yun Parkfec73dc2017-09-06 10:40:07 -07001898
Yun Parkb4f591d2017-03-29 15:51:01 -07001899 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301901 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001902 "Enable PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001903 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001905
Yun Park777d7242017-03-30 15:38:33 -07001906 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Leo Change3e49442015-10-26 20:07:13 -07001907 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001908
1909 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1910
Yun Parkfec73dc2017-09-06 10:40:07 -07001911end:
Yun Parke4239802018-01-09 11:01:40 -08001912 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: ipa_pipes_down=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07001913 hdd_ipa->ipa_pipes_down);
Yun Park199c2ed2017-10-02 11:24:22 -07001914
Yun Parkfec73dc2017-09-06 10:40:07 -07001915 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916}
1917
1918/**
1919 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1920 * @hdd_ipa: Global HDD IPA context
1921 *
1922 * Return: 0 on success, negative errno if error
1923 */
1924static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1925{
Yun Parkb4f591d2017-03-29 15:51:01 -07001926 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1927 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkfec73dc2017-09-06 10:40:07 -07001928 int result = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929
Yun Parke4239802018-01-09 11:01:40 -08001930 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Park199c2ed2017-10-02 11:24:22 -07001931
1932 if (hdd_ipa->ipa_pipes_down) {
1933 /*
1934 * This shouldn't happen :
1935 * IPA WDI Pipes are already deactivated
1936 */
1937 WARN_ON(1);
1938 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
1939 "IPA WDI Pipes are already deactivated");
1940 goto end;
1941 }
Leo Change3e49442015-10-26 20:07:13 -07001942
Yun Parkb4f591d2017-03-29 15:51:01 -07001943 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001944
Yun Parkb4f591d2017-03-29 15:51:01 -07001945 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301947 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001948 "Disable WDI PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001949 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 }
1951
Yun Parkfec73dc2017-09-06 10:40:07 -07001952 hdd_ipa->ipa_pipes_down = true;
1953
1954end:
Yun Parke4239802018-01-09 11:01:40 -08001955 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: ipa_pipes_down=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07001956 hdd_ipa->ipa_pipes_down);
1957 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958}
1959
1960/**
1961 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1962 * @hdd_ipa: Global HDD IPA context
1963 *
1964 * Return: 0 on success, negative errno if error
1965 */
1966static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1967{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001968 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07001969
Yun Parke4239802018-01-09 11:01:40 -08001970 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07001971
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972 hdd_ipa->activated_fw_pipe = 0;
1973 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001974
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001975 /* If RM feature enabled
1976 * Request PROD Resource first
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07001977 * PROD resource may return sync or async manners
1978 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001979 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001980 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1981 /* RM PROD request sync return
1982 * enable pipe immediately
1983 */
1984 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301985 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001986 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001987 hdd_ipa->resource_loading = false;
1988 return -EBUSY;
1989 }
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301990 } else {
1991 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park199c2ed2017-10-02 11:24:22 -07001992 "IPA WDI Pipe activation deferred");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001993 }
1994 } else {
1995 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001996 * Just enabled all the PIPEs
1997 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301999 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002000 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002001 hdd_ipa->resource_loading = false;
2002 return -EBUSY;
2003 }
2004 hdd_ipa->resource_loading = false;
2005 }
Yun Park4cab6ee2015-10-27 11:43:40 -07002006
Yun Parke4239802018-01-09 11:01:40 -08002007 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002008 return 0;
2009}
2010
2011/**
2012 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
2013 * @hdd_ipa: Global HDD IPA context
2014 *
2015 * Return: None
2016 */
2017static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
2018{
Leo Changfdb45c32016-10-28 11:09:23 -07002019 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07002020 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002021
Yun Parke4239802018-01-09 11:01:40 -08002022 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07002023
Yun Parkb4f591d2017-03-29 15:51:01 -07002024 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08002025 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
2026 QDF_ASSERT(0);
2027 return;
2028 }
2029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030 hdd_ipa->resource_unloading = true;
Yun Park777d7242017-03-30 15:38:33 -07002031 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Yun Parkb4f591d2017-03-29 15:51:01 -07002032 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
2033 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
2034 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
2035 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Yun Parkfec73dc2017-09-06 10:40:07 -07002036
Yun Parke4239802018-01-09 11:01:40 -08002037 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: IPA WDI Pipes deactivated");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038}
2039
2040/**
2041 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2042 * @context: User context registered with TL (the IPA Global context is
2043 * registered
2044 * @rxpkt: Packet containing the notification
2045 * @staid: ID of the station associated with the packet
2046 *
2047 * Return: None
2048 */
2049static void
Yun Park6c86a662017-10-05 16:09:15 -07002050hdd_ipa_uc_rm_notify_handler(void *context, qdf_ipa_rm_event_t event)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051{
2052 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302053 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002054 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002055
2056 /*
2057 * When SSR is going on or driver is unloading, just return.
2058 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002059 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302060 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062
Yun Parkb4f591d2017-03-29 15:51:01 -07002063 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002064 return;
2065
Yun Park46255682017-10-09 15:56:34 -07002066 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "event code %d",
2067 event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068
2069 switch (event) {
2070 case IPA_RM_RESOURCE_GRANTED:
2071 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302072 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002073 if ((false == hdd_ipa->resource_unloading) &&
2074 (!hdd_ipa->activated_fw_pipe)) {
2075 hdd_ipa_uc_enable_pipes(hdd_ipa);
2076 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302077 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002078 break;
2079
2080 case IPA_RM_RESOURCE_RELEASED:
2081 /* Differed RM Released */
2082 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002083 break;
2084
2085 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302086 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07002087 "invalid event code %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002088 break;
2089 }
2090}
2091
2092/**
2093 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2094 * @hdd_ipa: Global HDD IPA context
2095 * @event: IPA resource manager event to be deferred
2096 *
2097 * This function is called when a resource manager event is received
2098 * from firmware in interrupt context. This function will defer the
2099 * handling to the OL RX thread
2100 *
2101 * Return: None
2102 */
2103static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2104{
Yun Park6c86a662017-10-05 16:09:15 -07002105 qdf_ipa_rm_event_t event;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002106 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2107 struct uc_rm_work_struct, work);
2108 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2109 struct hdd_ipa_priv, uc_rm_work);
2110
2111 cds_ssr_protect(__func__);
2112 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002113 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07002114 "posted event %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002115
2116 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2117 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002118}
2119
2120/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002121 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002122 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002123 *
2124 * Will handle IPA UC image loaded indication comes from IPA kernel
2125 *
2126 * Return: None
2127 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002128static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002129{
Yun Parkb4f591d2017-03-29 15:51:01 -07002130 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2131 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002132 struct hdd_context *hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07002133 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002134
Yun Park46255682017-10-09 15:56:34 -07002135 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC READY");
Yun Parkb4f591d2017-03-29 15:51:01 -07002136 if (true == hdd_ipa->uc_loaded) {
Yun Park46255682017-10-09 15:56:34 -07002137 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "UC already loaded");
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002138 return;
2139 }
2140
Yun Parkb4f591d2017-03-29 15:51:01 -07002141 hdd_ctx = hdd_ipa->hdd_ctx;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002142
Yun Parkb4f591d2017-03-29 15:51:01 -07002143 /* Connect pipe */
2144 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2145 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2146 hdd_ipa_wdi_meter_notifier_cb,
2147 hdd_ctx->config->IpaDescSize,
2148 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2149 &hdd_ipa->tx_pipe_handle,
2150 &hdd_ipa->rx_pipe_handle);
2151 if (status) {
2152 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2153 "Failure to setup IPA pipes (status=%d)",
2154 status);
2155 return;
2156 }
2157
2158 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002159
2160 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002161 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002162 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002163 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002164 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002165 }
2166}
2167
2168/**
Yun Park637d6482016-10-05 10:51:33 -07002169 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2170 * @hdd_ctx: Global HDD context
2171 * @op_msg: operation message received from firmware
2172 *
2173 * Return: QDF_STATUS enumeration
2174 */
2175#ifdef FEATURE_METERING
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002176static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002177 struct op_msg_type *op_msg)
2178{
2179 struct op_msg_type *msg = op_msg;
2180 struct ipa_uc_sharing_stats *uc_sharing_stats;
2181 struct ipa_uc_quota_rsp *uc_quota_rsp;
2182 struct ipa_uc_quota_ind *uc_quota_ind;
2183 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002184 struct hdd_adapter *adapter;
Yun Park637d6482016-10-05 10:51:33 -07002185
2186 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2187
2188 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2189 /* fill-up ipa_uc_sharing_stats structure from FW */
2190 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2191 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2192
2193 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2194 sizeof(struct ipa_uc_sharing_stats));
2195
2196 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2197
2198 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2199 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2200 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2201 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2202 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2203 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2204 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2205 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2206 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2207 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2208 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2209 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2210 /* received set quota response */
2211 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2212 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2213
2214 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2215 sizeof(struct ipa_uc_quota_rsp));
2216
2217 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2218 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2219 "%s: success=%d, quota_bytes=%llu",
2220 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2221 hdd_ipa->ipa_quota_rsp.success,
2222 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2223 hdd_ipa->ipa_quota_rsp.quota_lo);
2224 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2225 /* hit quota limit */
2226 uc_quota_ind = (struct ipa_uc_quota_ind *)
2227 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2228
2229 hdd_ipa->ipa_quota_ind.quota_bytes =
2230 uc_quota_ind->quota_bytes;
2231
2232 /* send quota exceeded indication to IPA */
2233 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2234 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2235 hdd_ipa->ipa_quota_ind.quota_bytes);
2236
2237 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2238 if (adapter)
2239 ipa_broadcast_wdi_quota_reach_ind(
2240 adapter->dev->ifindex,
2241 uc_quota_ind->quota_bytes);
2242 else
2243 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2244 "Failed quota_reach_ind: NULL adapter");
2245 } else {
2246 return QDF_STATUS_E_INVAL;
2247 }
2248
2249 return QDF_STATUS_SUCCESS;
2250}
2251#else
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002252static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002253 struct op_msg_type *op_msg)
2254{
2255 return QDF_STATUS_E_INVAL;
2256}
2257#endif
2258
Yun Park657c7d72017-06-07 15:44:59 -07002259#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
2260/* older versions had a typo */
2261#define num_bam_int_in_non_running_state num_bam_int_in_non_runnning_state
2262#endif
2263
Yun Park637d6482016-10-05 10:51:33 -07002264/**
Yun Park46255682017-10-09 15:56:34 -07002265 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
2266 * @event: IPA WLAN event to be converted to a string
2267 *
2268 * Return: ASCII string representing the IPA WLAN event
2269 */
Yun Park6c86a662017-10-05 16:09:15 -07002270static inline char *hdd_ipa_wlan_event_to_str(qdf_ipa_wlan_event_t event)
Yun Park46255682017-10-09 15:56:34 -07002271{
2272 switch (event) {
2273 CASE_RETURN_STRING(WLAN_CLIENT_CONNECT);
2274 CASE_RETURN_STRING(WLAN_CLIENT_DISCONNECT);
2275 CASE_RETURN_STRING(WLAN_CLIENT_POWER_SAVE_MODE);
2276 CASE_RETURN_STRING(WLAN_CLIENT_NORMAL_MODE);
2277 CASE_RETURN_STRING(SW_ROUTING_ENABLE);
2278 CASE_RETURN_STRING(SW_ROUTING_DISABLE);
2279 CASE_RETURN_STRING(WLAN_AP_CONNECT);
2280 CASE_RETURN_STRING(WLAN_AP_DISCONNECT);
2281 CASE_RETURN_STRING(WLAN_STA_CONNECT);
2282 CASE_RETURN_STRING(WLAN_STA_DISCONNECT);
2283 CASE_RETURN_STRING(WLAN_CLIENT_CONNECT_EX);
2284 default:
2285 return "UNKNOWN";
2286 }
2287}
2288
2289/**
2290 * hdd_ipa_print_session_info - Print IPA session info
2291 * @hdd_ipa: HDD IPA local context
2292 *
2293 * Return: None
2294 */
2295static void hdd_ipa_print_session_info(struct hdd_ipa_priv *hdd_ipa)
2296{
2297 uint8_t session_id;
2298 int device_mode;
2299 struct ipa_uc_pending_event *event = NULL, *next = NULL;
2300 struct hdd_ipa_iface_context *iface_context = NULL;
2301 int i;
2302
2303 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2304 "\n==== IPA SESSION INFO ====\n"
2305 "NUM IFACE: %d\n"
2306 "RM STATE: %d\n"
2307 "ACTIVATED FW PIPE: %d\n"
2308 "SAP NUM STAs: %d\n"
2309 "STA CONNECTED: %d\n"
2310 "CONCURRENT MODE: %s\n"
2311 "RSC LOADING: %d\n"
2312 "RSC UNLOADING: %d\n"
2313 "PENDING CONS REQ: %d\n"
2314 "IPA PIPES DOWN: %d\n"
2315 "IPA UC LOADED: %d\n"
2316 "IPA WDI ENABLED: %d\n"
2317 "NUM SEND MSG: %d\n"
2318 "NUM FREE MSG: %d\n",
2319 hdd_ipa->num_iface,
2320 hdd_ipa->rm_state,
2321 hdd_ipa->activated_fw_pipe,
2322 hdd_ipa->sap_num_connected_sta,
2323 hdd_ipa->sta_connected,
2324 (hdd_ipa->hdd_ctx->mcc_mode ? "MCC" : "SCC"),
2325 hdd_ipa->resource_loading,
2326 hdd_ipa->resource_unloading,
2327 hdd_ipa->pending_cons_req,
2328 hdd_ipa->ipa_pipes_down,
2329 hdd_ipa->uc_loaded,
2330 hdd_ipa->wdi_enabled,
2331 (unsigned int)hdd_ipa->stats.num_send_msg,
2332 (unsigned int)hdd_ipa->stats.num_free_msg);
2333
2334 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2335 iface_context = &hdd_ipa->iface_context[i];
2336 if (!iface_context || !iface_context->adapter)
2337 continue;
2338
Jeff Johnson1b780e42017-10-31 14:11:45 -07002339 session_id = iface_context->adapter->session_id;
Yun Park46255682017-10-09 15:56:34 -07002340 if (session_id >= CSR_ROAM_SESSION_MAX)
2341 continue;
2342
2343 device_mode = iface_context->adapter->device_mode;
2344 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2345 "\nIFACE[%d]: session:%d, sta_id:%d, mode:%s, offload:%d",
2346 i, session_id,
2347 iface_context->sta_id,
2348 hdd_device_mode_to_string(device_mode),
2349 hdd_ipa->vdev_offload_enabled[session_id]);
2350 }
2351
2352 for (i = 0; i < IPA_WLAN_EVENT_MAX; i++)
2353 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2354 "\nEVENT[%d]=%d",
2355 i, hdd_ipa->stats.event[i]);
2356
2357 i = 0;
2358 qdf_list_peek_front(&hdd_ipa->pending_event,
2359 (qdf_list_node_t **)&event);
2360 while (event != NULL) {
2361 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2362 "\nPENDING EVENT[%d]: DEV:%s, EVT:%s, sta_id:%d, MAC:%pM",
2363 i, event->adapter->dev->name,
2364 hdd_ipa_wlan_event_to_str(event->type),
2365 event->sta_id, event->mac_addr);
2366
2367 qdf_list_peek_next(&hdd_ipa->pending_event,
2368 (qdf_list_node_t *)event, (qdf_list_node_t **)&next);
2369 event = next;
2370 next = NULL;
2371 i++;
2372 }
2373}
2374
2375/**
2376 * hdd_ipa_print_txrx_stats - Print HDD IPA TX/RX stats
2377 * @hdd_ipa: HDD IPA local context
2378 *
2379 * Return: None
2380 */
2381static void hdd_ipa_print_txrx_stats(struct hdd_ipa_priv *hdd_ipa)
2382{
2383 int i;
2384 struct hdd_ipa_iface_context *iface_context = NULL;
2385
2386 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2387 "\n==== HDD IPA TX/RX STATS ====\n"
2388 "NUM RM GRANT: %llu\n"
2389 "NUM RM RELEASE: %llu\n"
2390 "NUM RM GRANT IMM: %llu\n"
2391 "NUM CONS PERF REQ: %llu\n"
2392 "NUM PROD PERF REQ: %llu\n"
2393 "NUM RX DROP: %llu\n"
2394 "NUM EXCP PKT: %llu\n"
2395 "NUM TX FWD OK: %llu\n"
2396 "NUM TX FWD ERR: %llu\n"
2397 "NUM TX DESC Q CNT: %llu\n"
2398 "NUM TX DESC ERROR: %llu\n"
2399 "NUM TX COMP CNT: %llu\n"
2400 "NUM TX QUEUED: %llu\n"
2401 "NUM TX DEQUEUED: %llu\n"
2402 "NUM MAX PM QUEUE: %llu\n"
2403 "TX REF CNT: %d\n"
2404 "SUSPENDED: %d\n"
2405 "PEND DESC HEAD: %pK\n"
2406 "TX DESC LIST: %pK\n"
2407 "FREE TX DESC HEAD: %pK\n",
2408 hdd_ipa->stats.num_rm_grant,
2409 hdd_ipa->stats.num_rm_release,
2410 hdd_ipa->stats.num_rm_grant_imm,
2411 hdd_ipa->stats.num_cons_perf_req,
2412 hdd_ipa->stats.num_prod_perf_req,
2413 hdd_ipa->stats.num_rx_drop,
2414 hdd_ipa->stats.num_rx_excep,
2415 hdd_ipa->stats.num_tx_fwd_ok,
2416 hdd_ipa->stats.num_tx_fwd_err,
2417 hdd_ipa->stats.num_tx_desc_q_cnt,
2418 hdd_ipa->stats.num_tx_desc_error,
2419 hdd_ipa->stats.num_tx_comp_cnt,
2420 hdd_ipa->stats.num_tx_queued,
2421 hdd_ipa->stats.num_tx_dequeued,
2422 hdd_ipa->stats.num_max_pm_queue,
2423 hdd_ipa->tx_ref_cnt.counter,
2424 hdd_ipa->suspended,
2425 &hdd_ipa->pend_desc_head,
2426 hdd_ipa->tx_desc_list,
2427 &hdd_ipa->free_tx_desc_head);
2428
2429 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2430 iface_context = &hdd_ipa->iface_context[i];
2431 if (!iface_context || !iface_context->adapter)
2432 continue;
2433
2434 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2435 "IFACE[%d]: TX:%llu, TX DROP:%llu, TX ERR:%llu, TX CAC DROP:%llu, RX IPA EXCEP:%llu",
2436 i,
2437 iface_context->stats.num_tx,
2438 iface_context->stats.num_tx_drop,
2439 iface_context->stats.num_tx_err,
2440 iface_context->stats.num_tx_cac_drop,
2441 iface_context->stats.num_rx_ipa_excep);
2442 }
2443}
2444
2445/**
2446 * hdd_ipa_print_fw_wdi_stats - Print WLAN FW WDI stats
2447 * @hdd_ipa: HDD IPA local context
2448 *
2449 * Return: None
2450 */
2451static void hdd_ipa_print_fw_wdi_stats(struct hdd_ipa_priv *hdd_ipa,
2452 struct ipa_uc_fw_stats *uc_fw_stat)
2453{
2454 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2455 "\n==== WLAN FW WDI TX STATS ====\n"
2456 "COMP RING BASE: 0x%x\n"
2457 "COMP RING SIZE: %d\n"
2458 "COMP RING DBELL : 0x%x\n"
2459 "COMP RING DBELL IND VAL : %d\n"
2460 "COMP RING DBELL CACHED VAL : %d\n"
2461 "PKTS ENQ : %d\n"
2462 "PKTS COMP : %d\n"
2463 "IS SUSPEND : %d\n",
2464 uc_fw_stat->tx_comp_ring_base,
2465 uc_fw_stat->tx_comp_ring_size,
2466 uc_fw_stat->tx_comp_ring_dbell_addr,
2467 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2468 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2469 uc_fw_stat->tx_pkts_enqueued,
2470 uc_fw_stat->tx_pkts_completed,
2471 uc_fw_stat->tx_is_suspend);
2472
2473 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2474 "\n==== WLAN FW WDI RX STATS ====\n"
2475 "IND RING BASE: 0x%x\n"
2476 "IND RING SIZE: %d\n"
2477 "IND RING DBELL : 0x%x\n"
2478 "IND RING DBELL IND VAL : %d\n"
2479 "IND RING DBELL CACHED VAL : %d\n"
2480 "RDY IND ADDR : 0x%x\n"
2481 "RDY IND CACHE VAL : %d\n"
2482 "RFIL IND : %d\n"
2483 "NUM PKT INDICAT : %d\n"
2484 "BUF REFIL : %d\n"
2485 "NUM DROP NO SPC : %d\n"
2486 "NUM DROP NO BUF : %d\n"
2487 "IS SUSPND : %d\n",
2488 uc_fw_stat->rx_ind_ring_base,
2489 uc_fw_stat->rx_ind_ring_size,
2490 uc_fw_stat->rx_ind_ring_dbell_addr,
2491 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2492 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2493 uc_fw_stat->rx_ind_ring_rdidx_addr,
2494 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2495 uc_fw_stat->rx_refill_idx,
2496 uc_fw_stat->rx_num_pkts_indicated,
2497 uc_fw_stat->rx_buf_refilled,
2498 uc_fw_stat->rx_num_ind_drop_no_space,
2499 uc_fw_stat->rx_num_ind_drop_no_buf,
2500 uc_fw_stat->rx_is_suspend);
2501}
2502
2503/**
2504 * hdd_ipa_print_ipa_wdi_stats - Print IPA WDI stats
2505 * @hdd_ipa: HDD IPA local context
2506 *
2507 * Return: None
2508 */
2509static void hdd_ipa_print_ipa_wdi_stats(struct hdd_ipa_priv *hdd_ipa)
2510{
2511 struct IpaHwStatsWDIInfoData_t ipa_stat;
2512
2513 ipa_get_wdi_stats(&ipa_stat);
2514
2515 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2516 "\n==== IPA WDI TX STATS ====\n"
2517 "NUM PROCD : %d\n"
2518 "CE DBELL : 0x%x\n"
2519 "NUM DBELL FIRED : %d\n"
2520 "COMP RNG FULL : %d\n"
2521 "COMP RNG EMPT : %d\n"
2522 "COMP RNG USE HGH : %d\n"
2523 "COMP RNG USE LOW : %d\n"
2524 "BAM FIFO FULL : %d\n"
2525 "BAM FIFO EMPT : %d\n"
2526 "BAM FIFO USE HGH : %d\n"
2527 "BAM FIFO USE LOW : %d\n"
2528 "NUM DBELL : %d\n"
2529 "NUM UNEXP DBELL : %d\n"
2530 "NUM BAM INT HDL : 0x%x\n"
2531 "NUM BAM INT NON-RUN : 0x%x\n"
2532 "NUM QMB INT HDL : 0x%x\n",
2533 ipa_stat.tx_ch_stats.num_pkts_processed,
2534 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2535 ipa_stat.tx_ch_stats.num_db_fired,
2536 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2537 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2538 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2539 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2540 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2541 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2542 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2543 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2544 ipa_stat.tx_ch_stats.num_db,
2545 ipa_stat.tx_ch_stats.num_unexpected_db,
2546 ipa_stat.tx_ch_stats.num_bam_int_handled,
2547 ipa_stat.tx_ch_stats.
2548#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
2549 num_bam_int_in_non_running_state,
2550#else
2551 num_bam_int_in_non_runnning_state,
2552#endif
2553 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2554
2555 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2556 "\n==== IPA WDI RX STATS ====\n"
2557 "MAX OST PKT : %d\n"
2558 "NUM PKT PRCSD : %d\n"
2559 "RNG RP : 0x%x\n"
2560 "IND RNG FULL : %d\n"
2561 "IND RNG EMPT : %d\n"
2562 "IND RNG USE HGH : %d\n"
2563 "IND RNG USE LOW : %d\n"
2564 "BAM FIFO FULL : %d\n"
2565 "BAM FIFO EMPT : %d\n"
2566 "BAM FIFO USE HGH : %d\n"
2567 "BAM FIFO USE LOW : %d\n"
2568 "NUM DB : %d\n"
2569 "NUM UNEXP DB : %d\n"
2570 "NUM BAM INT HNDL : 0x%x\n",
2571 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2572 ipa_stat.rx_ch_stats.num_pkts_processed,
2573 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2574 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2575 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2576 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2577 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2578 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2579 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2580 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2581 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2582 ipa_stat.rx_ch_stats.num_db,
2583 ipa_stat.rx_ch_stats.num_unexpected_db,
2584 ipa_stat.rx_ch_stats.num_bam_int_handled);
2585}
2586
2587/**
2588 * hdd_ipa_uc_info() - Print IPA uC resource and session information
2589 * @adapter: network adapter
2590 *
2591 * Return: None
2592 */
2593void hdd_ipa_uc_info(struct hdd_context *hdd_ctx)
2594{
2595 struct hdd_ipa_priv *hdd_ipa;
2596
2597 hdd_ipa = hdd_ctx->hdd_ipa;
2598
2599 if (!hdd_ipa) {
2600 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2601 "HDD IPA context is NULL");
2602 return;
2603 }
2604
2605 /* IPA session info */
2606 hdd_ipa_print_session_info(hdd_ipa);
2607}
2608
2609/**
2610 * hdd_ipa_uc_stat() - Print IPA uC stats
2611 * @adapter: network adapter
2612 *
2613 * Return: None
2614 */
2615void hdd_ipa_uc_stat(struct hdd_adapter *adapter)
2616{
2617 struct hdd_context *hdd_ctx;
2618 struct hdd_ipa_priv *hdd_ipa;
2619
2620 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2621 hdd_ipa = hdd_ctx->hdd_ipa;
2622
2623 if (!hdd_ipa) {
2624 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2625 "HDD IPA context is NULL");
2626 return;
2627 }
2628
2629 /* HDD IPA TX/RX stats */
2630 hdd_ipa_print_txrx_stats(hdd_ipa);
2631 /* IPA WDI stats */
2632 hdd_ipa_print_ipa_wdi_stats(hdd_ipa);
2633 /* WLAN FW WDI stats */
2634 hdd_ipa_uc_stat_request(adapter, HDD_IPA_UC_STAT_REASON_DEBUG);
2635}
2636
2637/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2639 * @op_msg: operation message received from firmware
2640 * @usr_ctxt: user context registered with TL (we register the HDD Global
2641 * context)
2642 *
2643 * Return: None
2644 */
2645static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2646{
2647 struct op_msg_type *msg = op_msg;
2648 struct ipa_uc_fw_stats *uc_fw_stat;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002649 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002650 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302651 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002652
2653 if (!op_msg || !usr_ctxt) {
Yun Park46255682017-10-09 15:56:34 -07002654 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "INVALID ARG");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655 return;
2656 }
2657
2658 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302659 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07002660 "INVALID OPCODE %d", msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002661 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002662 return;
2663 }
2664
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002665 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002666
2667 /*
2668 * When SSR is going on or driver is unloading, just return.
2669 */
2670 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302671 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302672 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002673 return;
2674 }
2675
2676 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2677
Govind Singhb6a89772016-08-12 11:23:35 +05302678 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002679 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002680
2681 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2682 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302683 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002684 hdd_ipa->activated_fw_pipe++;
2685 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2686 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002687 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002688 if (hdd_ipa->wdi_enabled == false) {
2689 hdd_ipa->wdi_enabled = true;
2690 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2691 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2692 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002693 }
Yun Parka4bb37c2017-12-08 16:14:22 -08002694 hdd_ipa_uc_proc_pending_event(hdd_ipa, true);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002695 if (hdd_ipa->pending_cons_req)
2696 ipa_rm_notify_completion(
2697 IPA_RM_RESOURCE_GRANTED,
2698 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002699 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302701 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002702 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002703 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302704 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705 hdd_ipa->activated_fw_pipe--;
2706 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002707 /*
2708 * Async return success from FW
2709 * Disable/suspend all the PIPEs
2710 */
Yun Parka4bb37c2017-12-08 16:14:22 -08002711 hdd_ipa->resource_unloading = false;
2712 complete(&hdd_ipa->ipa_resource_comp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002713 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002714 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2715 ipa_rm_release_resource(
2716 IPA_RM_RESOURCE_WLAN_PROD);
Yun Parka4bb37c2017-12-08 16:14:22 -08002717 hdd_ipa_uc_proc_pending_event(hdd_ipa, false);
Yun Park5b635012015-12-02 15:05:01 -08002718 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002719 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302720 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002721 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002723 uc_fw_stat = (struct ipa_uc_fw_stats *)
Yun Park46255682017-10-09 15:56:34 -07002724 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725
Yun Park46255682017-10-09 15:56:34 -07002726 /* WLAN FW WDI stats */
2727 hdd_ipa_print_fw_wdi_stats(hdd_ipa, uc_fw_stat);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2729 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2730 /* STATs from FW */
2731 uc_fw_stat = (struct ipa_uc_fw_stats *)
2732 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302733 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002734 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2735 uc_fw_stat->tx_pkts_completed,
2736 hdd_ipa->ipa_p_tx_packets);
2737 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2738 (uc_fw_stat->rx_num_ind_drop_no_space +
2739 uc_fw_stat->rx_num_ind_drop_no_buf +
2740 uc_fw_stat->rx_num_pkts_indicated),
2741 hdd_ipa->ipa_p_rx_packets);
2742
2743 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2744 hdd_ipa->ipa_p_rx_packets =
2745 (uc_fw_stat->rx_num_ind_drop_no_space +
2746 uc_fw_stat->rx_num_ind_drop_no_buf +
2747 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302748 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002749 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2750 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2751 hdd_ipa_uc_loaded_handler(hdd_ipa);
2752 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002753 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2754 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2755 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756 }
Yun Park8957d802017-01-25 12:27:29 -08002757
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302758 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002759}
2760
2761
2762/**
2763 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2764 * @adapter: device adapter instance
2765 * @offload_type: MCC or SCC
2766 * @enable: TX offload enable or disable
2767 *
2768 * Return: none
2769 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002770static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002771 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002772{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002773 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002775 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002776 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002777
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002778 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779 return;
2780
Yun Park8292dcb2016-10-07 16:46:06 -07002781 iface_context = adapter->ipa_context;
Jeff Johnson1b780e42017-10-31 14:11:45 -07002782 session_id = adapter->session_id;
Yun Park8292dcb2016-10-07 16:46:06 -07002783
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002784 if (!iface_context) {
2785 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2786 "Interface context is NULL");
2787 return;
2788 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002789 if (session_id >= CSR_ROAM_SESSION_MAX) {
2790 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2791 "invalid session id: %d", session_id);
2792 return;
2793 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002794 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park199c2ed2017-10-02 11:24:22 -07002795 /*
2796 * This shouldn't happen :
2797 * IPA offload status is already set as desired
2798 */
2799 WARN_ON(1);
2800 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
Yun Parkb4f591d2017-03-29 15:51:01 -07002801 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002802 "IPA offload status is already set",
2803 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002804 return;
2805 }
2806
Jeff Johnson1b780e42017-10-31 14:11:45 -07002807 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Yun Park4540e862016-11-10 16:30:06 -08002808 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2809 "invalid session id: %d, offload_type=%d, enable=%d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002810 adapter->session_id, offload_type, enable);
Yun Park4540e862016-11-10 16:30:06 -08002811 return;
2812 }
2813
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302814 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002815 sizeof(ipa_offload_enable_disable));
2816 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002817 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002818 ipa_offload_enable_disable.enable = enable;
2819
Yun Park199c2ed2017-10-02 11:24:22 -07002820 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07002821 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002822 ipa_offload_enable_disable.offload_type,
2823 ipa_offload_enable_disable.vdev_id,
2824 ipa_offload_enable_disable.enable);
2825
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302826 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07002828 adapter->session_id, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302829 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07002830 "Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
2831 ipa_offload_enable_disable.offload_type,
2832 ipa_offload_enable_disable.vdev_id,
2833 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002834 } else {
2835 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002836 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002837 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002838 }
2839}
2840
2841/**
2842 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2843 * @work: uC OP work
2844 *
2845 * Return: None
2846 */
2847static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2848{
2849 struct op_msg_type *msg;
2850 struct uc_op_work_struct *uc_op_work = container_of(work,
2851 struct uc_op_work_struct, work);
2852 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2853
2854 cds_ssr_protect(__func__);
2855
2856 msg = uc_op_work->msg;
2857 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002858 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07002859 "posted msg %d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860
2861 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2862
2863 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864}
2865
2866/**
2867 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2868 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2869 * @op_msg: operation message received from firmware
2870 * @hdd_ctx: Global HDD context
2871 *
2872 * Return: None
2873 */
2874static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2875{
2876 struct hdd_ipa_priv *hdd_ipa;
2877 struct op_msg_type *msg;
2878 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302879 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002880
2881 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302882 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002883 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884
2885 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002886 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002887
2888 if (unlikely(!hdd_ipa))
2889 goto end;
2890
2891 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002892 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2893 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894 goto end;
2895 }
2896
2897 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2898 if (uc_op_work->msg)
2899 /* When the same uC OPCODE is already pended, just return */
2900 goto end;
2901
2902 uc_op_work->msg = msg;
2903 schedule_work(&uc_op_work->work);
2904 return;
2905
2906end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302907 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908}
2909
2910/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002911 * hdd_ipa_init_uc_op_work - init ipa uc op work
2912 * @work: struct work_struct
2913 * @work_handler: work_handler
2914 *
2915 * Return: none
2916 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002917static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002918 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002919{
2920 INIT_WORK(work, work_handler);
2921}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002922
Yun Park637d6482016-10-05 10:51:33 -07002923#ifdef FEATURE_METERING
2924/**
2925 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2926 * IPA calls to get WLAN stats or set quota limit.
2927 * @priv: pointer to private data registered with IPA (we register a
2928 *» pointer to the global IPA context)
2929 * @evt: the IPA event which triggered the callback
2930 * @data: data associated with the event
2931 *
2932 * Return: None
2933 */
Yun Park6c86a662017-10-05 16:09:15 -07002934static void __hdd_ipa_wdi_meter_notifier_cb(qdf_ipa_wdi_meter_evt_type_t evt,
Yun Park637d6482016-10-05 10:51:33 -07002935 void *data)
2936{
2937 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002938 struct hdd_adapter *adapter = NULL;
Yun Park6c86a662017-10-05 16:09:15 -07002939 qdf_ipa_get_wdi_sap_stats_t *wdi_sap_stats;
2940 qdf_ipa_set_wifi_quota_t *ipa_set_quota;
Yun Park637d6482016-10-05 10:51:33 -07002941 int ret = 0;
2942
2943 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2944 return;
2945
2946 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2947
2948 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2949
2950 switch (evt) {
2951 case IPA_GET_WDI_SAP_STATS:
2952 /* fill-up ipa_get_wdi_sap_stats structure after getting
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002953 * ipa_uc_fw_stats from FW
2954 */
Yun Park637d6482016-10-05 10:51:33 -07002955 wdi_sap_stats = data;
2956
2957 if (!adapter) {
2958 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2959 "IPA uC share stats failed - no adapter");
Yun Park6c86a662017-10-05 16:09:15 -07002960 QDF_IPA_GET_WDI_SAP_STATS_STATS_VALID(wdi_sap_stats) =
2961 0;
Yun Park637d6482016-10-05 10:51:33 -07002962 return;
2963 }
2964
2965 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002966 hdd_ipa_uc_sharing_stats_request(adapter,
Yun Park6c86a662017-10-05 16:09:15 -07002967 QDF_IPA_GET_WDI_SAP_STATS_RESET_STATS(wdi_sap_stats));
Yun Park637d6482016-10-05 10:51:33 -07002968 ret = wait_for_completion_timeout(
2969 &hdd_ipa->ipa_uc_sharing_stats_comp,
2970 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2971 if (!ret) {
2972 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2973 "IPA uC share stats request timed out");
Yun Park6c86a662017-10-05 16:09:15 -07002974 QDF_IPA_GET_WDI_SAP_STATS_STATS_VALID(wdi_sap_stats)
2975 = 0;
Yun Park637d6482016-10-05 10:51:33 -07002976 } else {
Yun Park6c86a662017-10-05 16:09:15 -07002977 QDF_IPA_GET_WDI_SAP_STATS_STATS_VALID(wdi_sap_stats)
2978 = 1;
Yun Park637d6482016-10-05 10:51:33 -07002979
Yun Park6c86a662017-10-05 16:09:15 -07002980 QDF_IPA_GET_WDI_SAP_STATS_IPV4_RX_PACKETS(wdi_sap_stats)
2981 = hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2982 QDF_IPA_GET_WDI_SAP_STATS_IPV4_RX_BYTES(wdi_sap_stats)
2983 = hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2984 QDF_IPA_GET_WDI_SAP_STATS_IPV6_RX_PACKETS(wdi_sap_stats)
2985 = hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2986 QDF_IPA_GET_WDI_SAP_STATS_IPV6_RX_BYTES(wdi_sap_stats)
2987 = hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2988 QDF_IPA_GET_WDI_SAP_STATS_IPV4_TX_PACKETS(wdi_sap_stats)
2989 = hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2990 QDF_IPA_GET_WDI_SAP_STATS_IPV4_TX_BYTES(wdi_sap_stats)
2991 = hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2992 QDF_IPA_GET_WDI_SAP_STATS_IPV6_TX_PACKETS(wdi_sap_stats)
2993 = hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2994 QDF_IPA_GET_WDI_SAP_STATS_IPV6_TX_BYTES(wdi_sap_stats)
2995 = hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
Yun Park637d6482016-10-05 10:51:33 -07002996 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2997 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2998 "IPA_GET_WDI_SAP_STATS",
Yun Park6c86a662017-10-05 16:09:15 -07002999 QDF_IPA_GET_WDI_SAP_STATS_STATS_VALID(
3000 wdi_sap_stats),
3001 QDF_IPA_GET_WDI_SAP_STATS_IPV4_RX_PACKETS(
3002 wdi_sap_stats),
3003 QDF_IPA_GET_WDI_SAP_STATS_IPV4_RX_BYTES(
3004 wdi_sap_stats),
3005 QDF_IPA_GET_WDI_SAP_STATS_IPV6_RX_PACKETS(
3006 wdi_sap_stats),
3007 QDF_IPA_GET_WDI_SAP_STATS_IPV6_RX_BYTES(
3008 wdi_sap_stats),
3009 QDF_IPA_GET_WDI_SAP_STATS_IPV4_TX_PACKETS(
3010 wdi_sap_stats),
3011 QDF_IPA_GET_WDI_SAP_STATS_IPV4_TX_BYTES(
3012 wdi_sap_stats),
3013 QDF_IPA_GET_WDI_SAP_STATS_IPV6_TX_PACKETS(
3014 wdi_sap_stats),
3015 QDF_IPA_GET_WDI_SAP_STATS_IPV6_TX_BYTES(
3016 wdi_sap_stats));
Yun Park637d6482016-10-05 10:51:33 -07003017 }
3018 break;
3019 case IPA_SET_WIFI_QUOTA:
3020 /* get ipa_set_wifi_quota structure from IPA and pass to FW
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07003021 * through quota_exceeded field in ipa_uc_fw_stats
3022 */
Yun Park637d6482016-10-05 10:51:33 -07003023 ipa_set_quota = data;
3024
3025 if (!adapter) {
3026 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3027 "IPA uC set quota failed - no adapter");
3028 ipa_set_quota->set_valid = 0;
3029 return;
3030 }
3031
Yun Park777d7242017-03-30 15:38:33 -07003032 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07003033 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
3034 ipa_set_quota->quota_bytes);
3035
3036 ret = wait_for_completion_timeout(
3037 &hdd_ipa->ipa_uc_set_quota_comp,
3038 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
3039 if (!ret) {
3040 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3041 "IPA uC set quota request timed out");
Yun Park6c86a662017-10-05 16:09:15 -07003042 QDF_IPA_SET_WIFI_QUOTA_SET_VALID(ipa_set_quota) = 0;
Yun Park637d6482016-10-05 10:51:33 -07003043 } else {
Yun Park6c86a662017-10-05 16:09:15 -07003044 QDF_IPA_SET_WIFI_QUOTA_BYTES(ipa_set_quota) =
Yun Park637d6482016-10-05 10:51:33 -07003045 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
3046 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
Yun Park6c86a662017-10-05 16:09:15 -07003047 QDF_IPA_SET_WIFI_QUOTA_SET_VALID(ipa_set_quota) =
Yun Park637d6482016-10-05 10:51:33 -07003048 hdd_ipa->ipa_quota_rsp.success;
3049 }
3050
3051 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
3052 ipa_set_quota->quota_bytes,
3053 ipa_set_quota->set_valid);
3054 break;
3055 }
3056}
3057
3058/**
3059 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
3060 * IPA calls to get WLAN stats or set quota limit.
3061 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07003062 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07003063 * @evt: the IPA event which triggered the callback
3064 * @data: data associated with the event
3065 *
3066 * Return: None
3067 */
Yun Park6c86a662017-10-05 16:09:15 -07003068static void hdd_ipa_wdi_meter_notifier_cb(qdf_ipa_wdi_meter_evt_type_t evt,
Yun Park637d6482016-10-05 10:51:33 -07003069 void *data)
3070{
3071 cds_ssr_protect(__func__);
3072 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
3073 cds_ssr_unprotect(__func__);
3074}
3075
Yun Parkb4f591d2017-03-29 15:51:01 -07003076static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07003077{
Yun Park637d6482016-10-05 10:51:33 -07003078 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
3079 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
3080}
3081#else
Yun Parkb4f591d2017-03-29 15:51:01 -07003082static void hdd_ipa_wdi_meter_notifier_cb(void)
3083{
3084}
3085
3086static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07003087{
3088}
3089#endif
3090
Rajeev Kumar217f2172016-01-06 18:11:55 -08003091/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003092 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
3093 * @hdd_ctx: Global HDD context
3094 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003095 * This function is called to update IPA pipe configuration with resources
3096 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
3097 * (cds_enable)
3098 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303099 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003101QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102{
Yun Parkb4f591d2017-03-29 15:51:01 -07003103 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07003104 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08003105 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07003106 uint8_t i;
3107 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003109 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3110 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003111
Rajeev Kumar3887f9b2018-01-10 11:24:01 -08003112 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003113
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003114 /* Do only IPA Pipe specific configuration here. All one time
3115 * initialization wrt IPA UC shall in hdd_ipa_init and those need
3116 * to be reinit at SSR shall in be SSR deinit / reinit functions.
3117 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003118 if (!pdev || !soc) {
3119 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07003120 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08003121 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003122 }
Yun Parka4bb37c2017-12-08 16:14:22 -08003123
3124 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3125 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3126 hdd_ipa->vdev_offload_enabled[i] = false;
3127 }
3128
Yun Parkb4f591d2017-03-29 15:51:01 -07003129 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003130 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
3131 "IPA UC resource alloc fail");
Yun Park199c2ed2017-10-02 11:24:22 -07003132 status = QDF_STATUS_E_FAILURE;
3133 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003134 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003135
Yun Parkb4f591d2017-03-29 15:51:01 -07003136 if (true == hdd_ipa->uc_loaded) {
3137 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
3138 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
3139 hdd_ipa_wdi_meter_notifier_cb,
3140 hdd_ctx->config->IpaDescSize,
3141 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
3142 &hdd_ipa->tx_pipe_handle,
3143 &hdd_ipa->rx_pipe_handle);
3144 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08003145 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07003146 "Failure to setup IPA pipes (status=%d)",
3147 status);
Yun Park199c2ed2017-10-02 11:24:22 -07003148 status = QDF_STATUS_E_FAILURE;
3149 goto fail_return;
Yun Parkbaa62862017-01-18 13:43:34 -08003150 }
Yun Park637d6482016-10-05 10:51:33 -07003151
Yun Parkb4f591d2017-03-29 15:51:01 -07003152 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
3153 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003154 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155
Yun Parkb4f591d2017-03-29 15:51:01 -07003156 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08003157 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
3158
Yun Parkb4f591d2017-03-29 15:51:01 -07003159 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
3160 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
Yun Parka4bb37c2017-12-08 16:14:22 -08003161 hdd_ipa_uc_fw_op_event_handler);
Yun Parkb4f591d2017-03-29 15:51:01 -07003162 hdd_ipa->uc_op_work[i].msg = NULL;
3163 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164
Yun Parkbaa62862017-01-18 13:43:34 -08003165fail_return:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -08003166 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: status=%d", status);
Yun Parkb4f591d2017-03-29 15:51:01 -07003167 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168}
3169
Leo Change3e49442015-10-26 20:07:13 -07003170/**
Yun Parkd8fb1a82017-10-13 16:48:20 -07003171 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
3172 * @hdd_ipa: pointer to HDD IPA struct
3173 *
3174 * Return: none
3175 */
3176static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
3177{
3178 struct ipa_uc_pending_event *pending_event = NULL;
3179
3180 while (qdf_list_remove_front(&hdd_ipa->pending_event,
3181 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
3182 qdf_mem_free(pending_event);
3183}
3184
3185/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303186 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
3187 * @hdd_ctx: Global HDD context
3188 *
3189 * Return: 0 on success, negativer errno on error
3190 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003191int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303192{
3193 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Yun Park6edb2172018-01-14 00:18:05 -08003194 int i, ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07003195 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303196
Yun Parke4239802018-01-09 11:01:40 -08003197 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003198
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303199 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3200 return ret;
3201
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05303202 if (!hdd_ipa->ipa_pipes_down)
3203 hdd_ipa_uc_disable_pipes(hdd_ipa);
3204
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303205 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07003206 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
3207 hdd_ipa->tx_pipe_handle,
3208 hdd_ipa->rx_pipe_handle);
3209 if (status) {
3210 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3211 "Failure to cleanup IPA pipes (status=%d)",
3212 status);
Yun Park6edb2172018-01-14 00:18:05 -08003213 ret = -EFAULT;
Yun Parkb4f591d2017-03-29 15:51:01 -07003214 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303215 }
3216
Yun Parka4bb37c2017-12-08 16:14:22 -08003217 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07003218 hdd_ipa_cleanup_pending_event(hdd_ipa);
Yun Parka4bb37c2017-12-08 16:14:22 -08003219 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07003220
Yun Park6edb2172018-01-14 00:18:05 -08003221 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
3222 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
3223 qdf_mem_free(hdd_ipa->uc_op_work[i].msg);
3224 hdd_ipa->uc_op_work[i].msg = NULL;
3225 }
3226
Yun Parke4239802018-01-09 11:01:40 -08003227 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: ret=%d", ret);
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303228 return ret;
3229}
3230
3231/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003232 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07003233 * @hdd_ctx: hdd main context
3234 *
3235 * Force shutdown IPA pipe
3236 * Independent of FW pipe status, IPA pipe shutdonw progress
3237 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3238 * independent from FW pipe status
3239 *
3240 * Return: NONE
3241 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003242static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07003243{
3244 struct hdd_ipa_priv *hdd_ipa;
3245
Yun Parke4239802018-01-09 11:01:40 -08003246 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003247
Leo Change3e49442015-10-26 20:07:13 -07003248 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
3249 return;
3250
3251 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
3252 if (false == hdd_ipa->ipa_pipes_down) {
Yun Park46255682017-10-09 15:56:34 -07003253 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Parkb4f591d2017-03-29 15:51:01 -07003254 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07003255 hdd_ipa_uc_disable_pipes(hdd_ipa);
3256 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003257 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07003258 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07003259 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003260
Yun Parke4239802018-01-09 11:01:40 -08003261 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit");
Leo Change3e49442015-10-26 20:07:13 -07003262}
3263
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003265 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
3266 * __hdd_ipa_uc_force_pipe_shutdown
3267 * @hdd_ctx: hdd main context
3268 *
3269 * Force shutdown IPA pipe
3270 * Independent of FW pipe status, IPA pipe shutdonw progress
3271 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3272 * independent from FW pipe status
3273 *
3274 * Return: NONE
3275 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003276void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003277{
3278 cds_ssr_protect(__func__);
3279 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
3280 cds_ssr_unprotect(__func__);
3281}
3282
3283/**
Govind Singh9c58eba2016-09-02 16:23:06 +05303284 * hdd_ipa_msg_free_fn() - Free an IPA message
3285 * @buff: pointer to the IPA message
3286 * @len: length of the IPA message
3287 * @type: type of IPA message
3288 *
3289 * Return: None
3290 */
3291static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3292{
Srinivas Girigowda97852372017-03-06 16:52:59 -08003293 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05303294 ghdd_ipa->stats.num_free_msg++;
3295 qdf_mem_free(buff);
3296}
3297
Govind Singh9c58eba2016-09-02 16:23:06 +05303298/**
jge62037862016-12-09 10:44:33 +08003299 * hdd_ipa_uc_send_evt() - send event to ipa
3300 * @hdd_ctx: pointer to hdd context
3301 * @type: event type
3302 * @mac_addr: pointer to mac address
3303 *
3304 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303305 *
3306 * Return: 0 - Success
3307 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003308static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
Yun Park6c86a662017-10-05 16:09:15 -07003309 qdf_ipa_wlan_event_t type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303310{
jge62037862016-12-09 10:44:33 +08003311 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park6c86a662017-10-05 16:09:15 -07003312 qdf_ipa_msg_meta_t meta;
3313 qdf_ipa_wlan_msg_t *msg;
Govind Singh9c58eba2016-09-02 16:23:06 +05303314 int ret = 0;
jge62037862016-12-09 10:44:33 +08003315
Yun Park6c86a662017-10-05 16:09:15 -07003316 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t);
3317 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
jge62037862016-12-09 10:44:33 +08003318 if (msg == NULL) {
3319 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3320 "msg allocation failed");
3321 return -ENOMEM;
3322 }
3323
Yun Park6c86a662017-10-05 16:09:15 -07003324 QDF_IPA_MSG_META_MSG_TYPE(&meta) = type;
3325 strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), adapter->dev->name,
jge62037862016-12-09 10:44:33 +08003326 IPA_RESOURCE_NAME_MAX);
Yun Park6c86a662017-10-05 16:09:15 -07003327 memcpy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, ETH_ALEN);
Yun Park199c2ed2017-10-02 11:24:22 -07003328 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Yun Park6c86a662017-10-05 16:09:15 -07003329 QDF_IPA_WLAN_MSG_NAME(msg), QDF_IPA_MSG_META_MSG_TYPE(&meta));
3330 ret = qdf_ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
jge62037862016-12-09 10:44:33 +08003331 if (ret) {
3332 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3333 "%s: Evt: %d fail:%d",
Yun Park6c86a662017-10-05 16:09:15 -07003334 QDF_IPA_WLAN_MSG_NAME(msg),
3335 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
jge62037862016-12-09 10:44:33 +08003336 qdf_mem_free(msg);
3337 return ret;
3338 }
3339
3340 hdd_ipa->stats.num_send_msg++;
3341
3342 return ret;
3343}
3344
3345/**
3346 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3347 * @hdd_ctx: pointer to hdd adapter
3348 *
3349 * Send disconnect client event to IPA driver during SSR
3350 *
3351 * Return: 0 - Success
3352 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003353static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003354{
3355 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3356 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303357 int i;
3358
Yun Parke4239802018-01-09 11:01:40 -08003359 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Govind Singh9c58eba2016-09-02 16:23:06 +05303360 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003361 if (qdf_is_macaddr_broadcast(&adapter->sta_info[i].sta_mac))
Govind Singh9c58eba2016-09-02 16:23:06 +05303362 continue;
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003363 if ((adapter->sta_info[i].in_use) &&
3364 (!adapter->sta_info[i].is_deauth_in_progress) &&
jge62037862016-12-09 10:44:33 +08003365 hdd_ipa->sap_num_connected_sta) {
3366 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003367 adapter->sta_info[i].sta_mac.bytes);
jge62037862016-12-09 10:44:33 +08003368 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303369 }
3370 }
Yun Parke4239802018-01-09 11:01:40 -08003371 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: sap_num_connected_sta=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07003372 hdd_ipa->sap_num_connected_sta);
Govind Singh9c58eba2016-09-02 16:23:06 +05303373
3374 return ret;
3375}
3376
3377/**
jge62037862016-12-09 10:44:33 +08003378 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3379 * @hdd_ctx: pointer to hdd adapter
3380 *
3381 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303382 *
3383 * Return: 0 - Success
3384 */
jge62037862016-12-09 10:44:33 +08003385
Jeff Johnson49d45e62017-08-29 14:30:42 -07003386static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003387{
3388 int ret = 0;
3389
Yun Parke4239802018-01-09 11:01:40 -08003390 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003391 if (adapter->ipa_context) {
jge62037862016-12-09 10:44:33 +08003392 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3393 adapter->dev->dev_addr);
Yun Parkfec73dc2017-09-06 10:40:07 -07003394 }
Yun Parke4239802018-01-09 11:01:40 -08003395 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit");
jge62037862016-12-09 10:44:33 +08003396
3397 return ret;
3398}
3399
jge62037862016-12-09 10:44:33 +08003400/**
3401 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3402 * @hdd_ctx: pointer to hdd adapter
3403 *
3404 * Send disconnect sta event to IPA driver during SSR
3405 *
3406 * Return: 0 - Success
3407 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003408static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003409{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003410 struct hdd_station_ctx *sta_ctx;
jge62037862016-12-09 10:44:33 +08003411 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3412 int ret = 0;
3413
Yun Parke4239802018-01-09 11:01:40 -08003414 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003415 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003416 hdd_ipa->sta_connected) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07003417 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
jge62037862016-12-09 10:44:33 +08003418 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Jeff Johnsond377dce2017-10-04 10:32:42 -07003419 sta_ctx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003420 }
Yun Parke4239802018-01-09 11:01:40 -08003421 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit");
jge62037862016-12-09 10:44:33 +08003422
3423 return ret;
3424}
jge62037862016-12-09 10:44:33 +08003425
3426/**
3427 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3428 * @hdd_ctx: pointer to hdd context
3429 *
3430 * Send disconnect event to IPA driver during SSR
3431 *
3432 * Return: 0 - Success
3433 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003434static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303435{
Jeff Johnson49d45e62017-08-29 14:30:42 -07003436 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303437 int ret = 0;
3438
Dustin Brown920397d2017-12-13 16:27:50 -08003439 hdd_for_each_adapter(hdd_ctx, adapter) {
jge62037862016-12-09 10:44:33 +08003440 if (adapter->device_mode == QDF_SAP_MODE) {
3441 hdd_ipa_uc_disconnect_client(adapter);
3442 hdd_ipa_uc_disconnect_ap(adapter);
3443 } else if (adapter->device_mode == QDF_STA_MODE) {
3444 hdd_ipa_uc_disconnect_sta(adapter);
3445 }
Govind Singh9c58eba2016-09-02 16:23:06 +05303446 }
3447
3448 return ret;
3449}
3450
3451/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003452 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 *
3454 * Deinit basic IPA UC host side to be in sync reloaded FW during
3455 * SSR
3456 *
3457 * Return: 0 - Success
3458 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003459static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460{
3461 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3462 int idx;
3463 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003464 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465
Yun Parke4239802018-01-09 11:01:40 -08003466 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003467
Arun Khandavallicc544b32017-01-30 19:52:16 +05303468 if (!hdd_ipa)
3469 return 0;
3470
3471 hdd_ctx = hdd_ipa->hdd_ctx;
3472 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 return 0;
3474
jge62037862016-12-09 10:44:33 +08003475 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303476 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003477
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 /* Clean up HDD IPA interfaces */
3479 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3480 (idx < HDD_IPA_MAX_IFACE); idx++) {
3481 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003482 if (iface_context->adapter && iface_context->adapter->magic ==
3483 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 hdd_ipa_cleanup_iface(iface_context);
3485 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003486 hdd_ipa->num_iface = 0;
Yun Parka4bb37c2017-12-08 16:14:22 -08003487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 /* After SSR, wlan driver reloads FW again. But we need to protect
3489 * IPA submodule during SSR transient state. So deinit basic IPA
3490 * UC host side to be in sync with reloaded FW during SSR
3491 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303493 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3495 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3496 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3497 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303498 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499
Guolei Bianca144d82016-11-10 11:07:42 +08003500 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3501 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3502
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003503 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3504 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3505 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3506 hdd_ipa->uc_op_work[idx].msg = NULL;
3507 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003508
Yun Parke4239802018-01-09 11:01:40 -08003509 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510 return 0;
3511}
3512
3513/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003514 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3515 *
3516 * Deinit basic IPA UC host side to be in sync reloaded FW during
3517 * SSR
3518 *
3519 * Return: 0 - Success
3520 */
3521int hdd_ipa_uc_ssr_deinit(void)
3522{
3523 int ret;
3524
3525 cds_ssr_protect(__func__);
3526 ret = __hdd_ipa_uc_ssr_deinit();
3527 cds_ssr_unprotect(__func__);
3528
3529 return ret;
3530}
3531
3532/**
3533 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534 *
3535 * Init basic IPA UC host side to be in sync with reloaded FW after
3536 * SSR to resume IPA UC operations
3537 *
3538 * Return: 0 - Success
3539 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003540static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542
Arun Khandavallicc544b32017-01-30 19:52:16 +05303543 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3544 int i;
3545 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303546
Yun Parke4239802018-01-09 11:01:40 -08003547 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003548
Arun Khandavallicc544b32017-01-30 19:52:16 +05303549 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3550 return 0;
3551
Arun Khandavallicc544b32017-01-30 19:52:16 +05303552 /* Create the interface context */
3553 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3554 iface_context = &hdd_ipa->iface_context[i];
3555 iface_context->hdd_ipa = hdd_ipa;
3556 iface_context->cons_client =
3557 hdd_ipa_adapter_2_client[i].cons_client;
3558 iface_context->prod_client =
3559 hdd_ipa_adapter_2_client[i].prod_client;
3560 iface_context->iface_id = i;
3561 iface_context->adapter = NULL;
3562 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05303563
3564 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3565 hdd_ipa->resource_loading = false;
3566 hdd_ipa->resource_unloading = false;
3567 hdd_ipa->sta_connected = 0;
3568 hdd_ipa->ipa_pipes_down = true;
3569 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303570 }
3571
Yun Parke4239802018-01-09 11:01:40 -08003572 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573 return 0;
3574}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003575
3576/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003577 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3578 *
3579 * Init basic IPA UC host side to be in sync with reloaded FW after
3580 * SSR to resume IPA UC operations
3581 *
3582 * Return: 0 - Success
3583 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003584int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003585{
3586 int ret;
3587
3588 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303589 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003590 cds_ssr_unprotect(__func__);
3591
3592 return ret;
3593}
3594
3595/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3597 * @work: scheduled work
3598 *
3599 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3600 * not want to immediately release the wake lock since the system
3601 * would then potentially try to suspend when there is a healthy data
3602 * rate. Deferred work is scheduled and this function handles the
3603 * work. When this function is called, if the IPA resource is still
3604 * released then we release the wake lock.
3605 *
3606 * Return: None
3607 */
3608static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3609{
3610 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3611 struct hdd_ipa_priv,
3612 wake_lock_work);
3613
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303614 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003615
3616 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3617 goto end;
3618
3619 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303620 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 WIFI_POWER_EVENT_WAKELOCK_IPA);
3622
3623end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303624 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625}
3626
3627/**
3628 * hdd_ipa_rm_request() - Request resource from IPA
3629 * @hdd_ipa: Global HDD IPA context
3630 *
3631 * Return: 0 on success, negative errno on error
3632 */
3633static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3634{
3635 int ret = 0;
3636
3637 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3638 return 0;
3639
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303640 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641
3642 switch (hdd_ipa->rm_state) {
3643 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303644 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 return 0;
3646 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303647 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648 return -EINPROGRESS;
3649 case HDD_IPA_RM_RELEASED:
3650 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3651 break;
3652 }
3653
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303654 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655
Yun Park6c86a662017-10-05 16:09:15 -07003656 ret = qdf_ipa_rm_inactivity_timer_request_resource(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 IPA_RM_RESOURCE_WLAN_PROD);
3658
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303659 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 if (ret == 0) {
3661 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3662 hdd_ipa->stats.num_rm_grant_imm++;
3663 }
3664
3665 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3666 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303667 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 WIFI_POWER_EVENT_WAKELOCK_IPA);
3669 hdd_ipa->wake_lock_released = false;
3670 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303671 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003672
3673 return ret;
3674}
3675
3676/**
3677 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3678 * @hdd_ipa: Global HDD IPA context
3679 *
3680 * Return: 0 if resources released, negative errno otherwise
3681 */
3682static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3683{
3684 int ret = 0;
3685
3686 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3687 return 0;
3688
3689 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3690 return -EAGAIN;
3691
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303692 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003693
Nirav Shahcbc6d722016-03-01 16:24:53 +05303694 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303695 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003696 return -EAGAIN;
3697 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303698 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003699
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303700 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701 switch (hdd_ipa->rm_state) {
3702 case HDD_IPA_RM_GRANTED:
3703 break;
3704 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303705 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706 return -EINPROGRESS;
3707 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303708 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 return 0;
3710 }
3711
3712 /* IPA driver returns immediately so set the state here to avoid any
3713 * race condition.
3714 */
3715 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3716 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303717 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003718
Yun Park6c86a662017-10-05 16:09:15 -07003719 ret = qdf_ipa_rm_inactivity_timer_release_resource(
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003720 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303722 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 if (unlikely(ret != 0)) {
3724 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3725 WARN_ON(1);
Yun Park199c2ed2017-10-02 11:24:22 -07003726 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
3727 "ipa_rm_inactivity_timer_release_resource returnied fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728 }
3729
3730 /*
3731 * If wake_lock is released immediately, kernel would try to suspend
3732 * immediately as well, Just avoid ping-pong between suspend-resume
3733 * while there is healthy amount of data transfer going on by
3734 * releasing the wake_lock after some delay.
3735 */
3736 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3737 msecs_to_jiffies
3738 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3739
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303740 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003741
3742 return ret;
3743}
3744
3745/**
3746 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3747 * @user_data: user data registered with IPA
3748 * @event: the IPA resource manager event that occurred
3749 * @data: the data associated with the event
3750 *
3751 * Return: None
3752 */
Yun Park6c86a662017-10-05 16:09:15 -07003753static void hdd_ipa_rm_notify(void *user_data, qdf_ipa_rm_event_t event,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003754 unsigned long data)
3755{
3756 struct hdd_ipa_priv *hdd_ipa = user_data;
3757
3758 if (unlikely(!hdd_ipa))
3759 return;
3760
3761 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3762 return;
3763
Srinivas Girigowda97852372017-03-06 16:52:59 -08003764 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765
3766 switch (event) {
3767 case IPA_RM_RESOURCE_GRANTED:
3768 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3769 /* RM Notification comes with ISR context
3770 * it should be serialized into work queue to avoid
3771 * ISR sleep problem
3772 */
3773 hdd_ipa->uc_rm_work.event = event;
3774 schedule_work(&hdd_ipa->uc_rm_work.work);
3775 break;
3776 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303777 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303779 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780 hdd_ipa->stats.num_rm_grant++;
3781 break;
3782
3783 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003784 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 hdd_ipa->resource_unloading = false;
3786 break;
3787
3788 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303789 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003790 break;
3791 }
3792}
3793
3794/**
3795 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3796 *
3797 * Callback function registered with IPA that is called when IPA wants
3798 * to release the WLAN consumer resource
3799 *
3800 * Return: 0 if the request is granted, negative errno otherwise
3801 */
3802static int hdd_ipa_rm_cons_release(void)
3803{
3804 return 0;
3805}
3806
3807/**
3808 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3809 *
3810 * Callback function registered with IPA that is called when IPA wants
3811 * to access the WLAN consumer resource
3812 *
3813 * Return: 0 if the request is granted, negative errno otherwise
3814 */
3815static int hdd_ipa_rm_cons_request(void)
3816{
Yun Park4d8b60a2015-10-22 13:59:32 -07003817 int ret = 0;
3818
3819 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303820 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003821 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003823 ret = -EINPROGRESS;
3824 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303825 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003826 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003827 ghdd_ipa->pending_cons_req = true;
3828 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003830
3831 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832}
3833
3834/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003835 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003836 * @hdd_ctx: Global HDD context
3837 * @tx_packets: Number of packets transmitted in the last sample period
3838 * @rx_packets: Number of packets received in the last sample period
3839 *
3840 * Return: 0 on success, negative errno on error
3841 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07003842static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx,
3843 uint64_t tx_packets,
3844 uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845{
3846 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003847 struct hdd_ipa_priv *hdd_ipa;
Yun Park6c86a662017-10-05 16:09:15 -07003848 qdf_ipa_rm_perf_profile_t profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003849 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850 int ret;
3851
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003852 if (wlan_hdd_validate_context(hdd_ctx))
3853 return 0;
3854
3855 hdd_ipa = hdd_ctx->hdd_ipa;
3856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3858 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3859 return 0;
3860
3861 memset(&profile, 0, sizeof(profile));
3862
3863 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3864 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3865 else if (tx_packets >
3866 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3867 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3868 else
3869 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3870
3871 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3872 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3873 else if (rx_packets >
3874 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3875 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3876 else
3877 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3878
Yun Parkec845302016-12-15 09:22:57 -08003879 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880 "CONS perf curr: %d, next: %d",
3881 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003882 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883 "PROD perf curr: %d, next: %d",
3884 hdd_ipa->curr_prod_bw, next_prod_bw);
3885
3886 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003887 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003888 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003889 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3890 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003892 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003893
3894 return ret;
3895 }
3896 hdd_ipa->curr_cons_bw = next_cons_bw;
3897 hdd_ipa->stats.num_cons_perf_req++;
3898 }
3899
3900 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003901 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003903 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3904 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003905 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003906 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 return ret;
3908 }
3909 hdd_ipa->curr_prod_bw = next_prod_bw;
3910 hdd_ipa->stats.num_prod_perf_req++;
3911 }
3912
3913 return 0;
3914}
3915
3916/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003917 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3918 * @hdd_ctx: Global HDD context
3919 * @tx_packets: Number of packets transmitted in the last sample period
3920 * @rx_packets: Number of packets received in the last sample period
3921 *
3922 * Return: 0 on success, negative errno on error
3923 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003924int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003925 uint64_t rx_packets)
3926{
3927 int ret;
3928
3929 cds_ssr_protect(__func__);
3930 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3931 cds_ssr_unprotect(__func__);
3932
3933 return ret;
3934}
3935
3936/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003937 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3938 * @work: struct work_struct
3939 * @work_handler: work_handler
3940 *
3941 * Return: none
3942 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003943static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3944 work_func_t work_handler)
3945{
3946 INIT_WORK(work, work_handler);
3947}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003948
3949/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 * hdd_ipa_setup_rm() - Setup IPA resource management
3951 * @hdd_ipa: Global HDD IPA context
3952 *
3953 * Return: 0 on success, negative errno on error
3954 */
3955static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3956{
Yun Park6c86a662017-10-05 16:09:15 -07003957 qdf_ipa_rm_create_params_t create_params = { 0 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 int ret;
3959
3960 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3961 return 0;
3962
Rajeev Kumar217f2172016-01-06 18:11:55 -08003963 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3964 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003965 memset(&create_params, 0, sizeof(create_params));
Yun Park6c86a662017-10-05 16:09:15 -07003966 QDF_IPA_RM_CREATE_PARAMS_NAME(&create_params) =
3967 IPA_RM_RESOURCE_WLAN_PROD;
3968 QDF_IPA_RM_CREATE_PARAMS_USER_DATA(&create_params) =
3969 hdd_ipa;
3970 QDF_IPA_RM_CREATE_PARAMS_NOTIFY_CB(&create_params) =
3971 hdd_ipa_rm_notify;
3972 QDF_IPA_RM_CREATE_PARAMS_FLOOR_VOLTAGE(&create_params) =
3973 IPA_VOLTAGE_SVS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974
Yun Park6c86a662017-10-05 16:09:15 -07003975 ret = qdf_ipa_rm_create_resource(&create_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303977 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 "Create RM resource failed: %d", ret);
3979 goto setup_rm_fail;
3980 }
3981
3982 memset(&create_params, 0, sizeof(create_params));
Yun Park6c86a662017-10-05 16:09:15 -07003983 QDF_IPA_RM_CREATE_PARAMS_NAME(&create_params) =
3984 IPA_RM_RESOURCE_WLAN_CONS;
3985 QDF_IPA_RM_CREATE_PARAMS_REQUEST_RESOURCE(&create_params) =
3986 hdd_ipa_rm_cons_request;
3987 QDF_IPA_RM_CREATE_PARAMS_RELEASE_RESOURCE(&create_params) =
3988 hdd_ipa_rm_cons_release;
3989 QDF_IPA_RM_CREATE_PARAMS_FLOOR_VOLTAGE(&create_params) =
3990 IPA_VOLTAGE_SVS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991
Yun Park6c86a662017-10-05 16:09:15 -07003992 ret = qdf_ipa_rm_create_resource(&create_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303994 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995 "Create RM CONS resource failed: %d", ret);
3996 goto delete_prod;
3997 }
3998
3999 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
4000 IPA_RM_RESOURCE_APPS_CONS);
4001
Yun Park6c86a662017-10-05 16:09:15 -07004002 ret = qdf_ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
4003 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304005 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 ret);
4007 goto timer_init_failed;
4008 }
4009
4010 /* Set the lowest bandwidth to start with */
4011 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
4012
4013 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304014 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015 "Set perf level failed: %d", ret);
4016 goto set_perf_failed;
4017 }
4018
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304019 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
4021 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304022 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
4024 hdd_ipa->wake_lock_released = true;
4025 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
4026
4027 return ret;
4028
4029set_perf_failed:
4030 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4031
4032timer_init_failed:
4033 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4034
4035delete_prod:
4036 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4037
4038setup_rm_fail:
4039 return ret;
4040}
4041
4042/**
4043 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
4044 * @hdd_ipa: Global HDD IPA context
4045 *
4046 * Destroys all resources associated with the IPA resource manager
4047 *
4048 * Return: None
4049 */
4050static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
4051{
4052 int ret;
4053
4054 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4055 return;
4056
4057 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304058 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304061 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062
4063 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4064
Yun Park6c86a662017-10-05 16:09:15 -07004065 ret = qdf_ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304067 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 "RM PROD resource delete failed %d", ret);
4069
Yun Park6c86a662017-10-05 16:09:15 -07004070 ret = qdf_ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304072 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 "RM CONS resource delete failed %d", ret);
4074}
4075
tfyu0380a972017-07-13 18:19:37 +08004076#ifdef QCA_CONFIG_SMP
4077static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
4078{
4079 return netif_rx_ni(skb);
4080}
4081#else
4082static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
4083{
4084 struct iphdr *ip_h;
4085 static atomic_t softirq_mitigation_cntr =
4086 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
4087 int result;
4088
4089 ip_h = (struct iphdr *)(skb->data);
4090 if ((skb->protocol == htons(ETH_P_IP)) &&
4091 (ip_h->protocol == IPPROTO_ICMP)) {
4092 result = netif_rx_ni(skb);
4093 } else {
4094 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
4095 * to avoid excessive softirq's.
4096 */
4097 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
4098 result = netif_rx_ni(skb);
4099 atomic_set(&softirq_mitigation_cntr,
4100 IPA_WLAN_RX_SOFTIRQ_THRESH);
4101 } else {
4102 result = netif_rx(skb);
4103 }
4104 }
4105
4106 return result;
4107}
4108#endif
4109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110/**
4111 * hdd_ipa_send_skb_to_network() - Send skb to kernel
4112 * @skb: network buffer
4113 * @adapter: network adapter
4114 *
4115 * Called when a network buffer is received which should not be routed
4116 * to the IPA module.
4117 *
4118 * Return: None
4119 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304120static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004121 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004122{
tfyu0380a972017-07-13 18:19:37 +08004123 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4125 unsigned int cpu_index;
4126
4127 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07004128 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 adapter);
Yun Park46255682017-10-09 15:56:34 -07004130 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004131 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132 return;
4133 }
4134
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004135 if (cds_is_driver_unloading()) {
Yun Park46255682017-10-09 15:56:34 -07004136 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004137 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138 return;
4139 }
4140
4141 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
4142 skb->dev = adapter->dev;
4143 skb->protocol = eth_type_trans(skb, skb->dev);
4144 skb->ip_summed = CHECKSUM_NONE;
4145
4146 cpu_index = wlan_hdd_get_cpu();
4147
Jeff Johnson6ced42c2017-10-20 12:48:11 -07004148 ++adapter->hdd_stats.tx_rx_stats.rx_packets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08004149 result = hdd_ipa_aggregated_rx_ind(skb);
4150 if (result == NET_RX_SUCCESS)
Jeff Johnson6ced42c2017-10-20 12:48:11 -07004151 ++adapter->hdd_stats.tx_rx_stats.rx_delivered[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 else
Jeff Johnson6ced42c2017-10-20 12:48:11 -07004153 ++adapter->hdd_stats.tx_rx_stats.rx_refused[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154
Yun Park46255682017-10-09 15:56:34 -07004155 hdd_ipa->ipa_rx_net_send_count++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004156}
4157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158/**
Leo Chang69c39692016-10-12 20:11:12 -07004159 * hdd_ipa_forward() - handle packet forwarding to wlan tx
4160 * @hdd_ipa: pointer to hdd ipa context
4161 * @adapter: network adapter
4162 * @skb: data pointer
4163 *
4164 * if exception packet has set forward bit, copied new packet should be
4165 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
4166 * put into pm queue and tx procedure will be differed
4167 *
4168 * Return: None
4169 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07004170static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004171 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07004172{
Leo Chang69c39692016-10-12 20:11:12 -07004173 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
4174
Leo Chang69c39692016-10-12 20:11:12 -07004175 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Yun Park01deb2c2017-06-14 15:21:44 -07004176
4177 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
4178 qdf_nbuf_ipa_owned_set(skb);
4179
Yun Park46255682017-10-09 15:56:34 -07004180 /* WLAN subsystem is in suspend, put in queue */
Leo Chang69c39692016-10-12 20:11:12 -07004181 if (hdd_ipa->suspended) {
4182 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Yun Park46255682017-10-09 15:56:34 -07004183 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4184 "Tx in suspend, put in queue");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004185 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
4186 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07004187 pm_tx_cb->exception = true;
4188 pm_tx_cb->adapter = adapter;
4189 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004190 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07004191 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4192 hdd_ipa->stats.num_tx_queued++;
4193 } else {
4194 /* Resume, put packet into WLAN TX */
4195 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004196 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07004197 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07004198 "packet Tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08004199 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07004200 } else {
Yun Parkb187d542016-11-14 18:10:04 -08004201 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07004202 }
4203 }
4204}
4205
4206/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004207 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
4208 * @hdd_ipa: pointer to HDD IPA struct
4209 * @adapter: hdd adapter pointer
4210 * @desc: Firmware descriptor
4211 * @skb: Data buffer
4212 *
4213 * Return:
4214 * HDD_IPA_FORWARD_PKT_NONE
4215 * HDD_IPA_FORWARD_PKT_DISCARD
4216 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
4217 *
4218 */
4219
4220static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
4221 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004222 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004223 uint8_t desc,
4224 qdf_nbuf_t skb)
4225{
4226 int ret = HDD_IPA_FORWARD_PKT_NONE;
Yun Park0dad1002017-07-14 14:57:01 -07004227 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
4228 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004229
4230 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304231 if (!ol_txrx_fwd_desc_thresh_check(
Yun Park0dad1002017-07-14 14:57:01 -07004232 (struct ol_txrx_vdev_t *)cdp_get_vdev_from_vdev_id(soc,
4233 (struct cdp_pdev *)pdev,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004234 adapter->session_id))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304235 /* Drop the packet*/
4236 hdd_ipa->stats.num_tx_fwd_err++;
4237 kfree_skb(skb);
4238 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4239 return ret;
4240 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004241 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
4242 "Forward packet to Tx (fw_desc=%d)", desc);
4243 hdd_ipa->ipa_tx_forward++;
4244
4245 if ((desc & FW_RX_DESC_DISCARD_M)) {
4246 hdd_ipa_forward(hdd_ipa, adapter, skb);
Yun Park46255682017-10-09 15:56:34 -07004247 hdd_ipa->ipa_rx_internal_drop_count++;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004248 hdd_ipa->ipa_rx_discard++;
4249 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4250 } else {
4251 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004252
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004253 if (cloned_skb)
4254 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
4255 else
4256 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07004257 "tx skb alloc failed");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004258 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
4259 }
4260 }
4261
4262 return ret;
4263}
4264
4265/**
Yun Park637d6482016-10-05 10:51:33 -07004266 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267 * @priv: pointer to private data registered with IPA (we register a
4268 * pointer to the global IPA context)
4269 * @evt: the IPA event which triggered the callback
4270 * @data: data associated with the event
4271 *
4272 * Return: None
4273 */
Yun Park6c86a662017-10-05 16:09:15 -07004274static void __hdd_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
4275 unsigned long data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276{
4277 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004278 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304279 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 uint8_t iface_id;
4281 uint8_t session_id;
4282 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07004284 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285
4286 hdd_ipa = (struct hdd_ipa_priv *)priv;
4287
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08004288 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
4289 return;
4290
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 switch (evt) {
4292 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05304293 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07004294
4295 /*
4296 * When SSR is going on or driver is unloading,
4297 * just drop the packets.
4298 */
4299 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4300 if (0 != status) {
4301 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4302 "Invalid context: drop packet");
Yun Park46255682017-10-09 15:56:34 -07004303 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004304 kfree_skb(skb);
4305 return;
4306 }
4307
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4309 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004310 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004311 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4313 session_id, iface_id);
4314 } else {
4315 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4316 }
4317
4318 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304319 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 "IPA_RECEIVE: Invalid iface_id: %u",
4321 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004322 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004323 "w2i -- skb",
4324 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Yun Park46255682017-10-09 15:56:34 -07004325 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004326 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 return;
4328 }
4329
4330 iface_context = &hdd_ipa->iface_context[iface_id];
4331 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004332 if (!adapter) {
4333 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4334 "IPA_RECEIVE: Adapter is NULL");
Yun Park46255682017-10-09 15:56:34 -07004335 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Park16a78262017-02-01 12:15:03 -08004336 kfree_skb(skb);
4337 return;
4338 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304340 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004341 "w2i -- skb",
4342 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4344 hdd_ipa->stats.num_rx_excep++;
4345 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4346 } else {
4347 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4348 }
4349
4350 iface_context->stats.num_rx_ipa_excep++;
4351
4352 /* Disable to forward Intra-BSS Rx packets when
4353 * ap_isolate=1 in hostapd.conf
4354 */
Jeff Johnsonb9424862017-10-30 08:49:35 -07004355 if (!adapter->session.ap.disable_intrabss_fwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356 /*
4357 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4358 * all Rx packets to IPA uC, which need to be forwarded
4359 * to other interface.
4360 * And, IPA driver will send back to WLAN host driver
4361 * through exception pipe with fw_desc field set by FW.
4362 * Here we are checking fw_desc field for FORWARD bit
4363 * set, and forward to Tx. Then copy to kernel stack
4364 * only when DISCARD bit is not set.
4365 */
4366 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004367 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4368 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4369 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004370 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004371 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004372 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373 "Intra-BSS FWD is disabled-skip forward to Tx");
4374 }
4375
4376 hdd_ipa_send_skb_to_network(skb, adapter);
4377 break;
4378
4379 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304380 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 "w2i cb wrong event: 0x%x", evt);
4382 return;
4383 }
4384}
4385
4386/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004387 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4388 * @priv: pointer to private data registered with IPA (we register a
4389 * pointer to the global IPA context)
4390 * @evt: the IPA event which triggered the callback
4391 * @data: data associated with the event
4392 *
4393 * Return: None
4394 */
Yun Park6c86a662017-10-05 16:09:15 -07004395static void hdd_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
Yun Parkf8d6a122016-10-11 15:49:43 -07004396 unsigned long data)
4397{
4398 cds_ssr_protect(__func__);
4399 __hdd_ipa_w2i_cb(priv, evt, data);
4400 cds_ssr_unprotect(__func__);
4401}
4402
4403/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4405 * @skb: packet buffer which was transmitted
4406 *
4407 * Return: None
4408 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304409void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410{
4411 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park6c86a662017-10-05 16:09:15 -07004412 qdf_ipa_rx_data_t *ipa_tx_desc;
Yun Park52b2b992016-09-22 15:49:51 -07004413 struct hdd_ipa_tx_desc *tx_desc;
4414 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415
Yun Park52b2b992016-09-22 15:49:51 -07004416 if (!qdf_nbuf_ipa_owned_get(skb)) {
4417 dev_kfree_skb_any(skb);
4418 return;
4419 }
4420
4421 /* Get Tx desc pointer from SKB CB */
4422 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4423 tx_desc = hdd_ipa->tx_desc_list + id;
4424 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4425
4426 /* Return Tx Desc to IPA */
4427 ipa_free_skb(ipa_tx_desc);
4428
4429 /* Return to free tx desc list */
4430 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4431 tx_desc->ipa_tx_desc_ptr = NULL;
4432 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4433 hdd_ipa->stats.num_tx_desc_q_cnt--;
4434 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004435
4436 hdd_ipa->stats.num_tx_comp_cnt++;
4437
4438 atomic_dec(&hdd_ipa->tx_ref_cnt);
4439
4440 hdd_ipa_rm_try_release(hdd_ipa);
4441}
4442
4443/**
4444 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4445 * @iface_context: interface-specific IPA context
4446 * @ipa_tx_desc: packet data descriptor
4447 *
4448 * Return: None
4449 */
4450static void hdd_ipa_send_pkt_to_tl(
4451 struct hdd_ipa_iface_context *iface_context,
Yun Park6c86a662017-10-05 16:09:15 -07004452 qdf_ipa_rx_data_t *ipa_tx_desc)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453{
4454 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004455 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304456 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004457 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304459 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460 adapter = iface_context->adapter;
4461 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304462 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463 ipa_free_skb(ipa_tx_desc);
4464 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304465 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 hdd_ipa_rm_try_release(hdd_ipa);
4467 return;
4468 }
4469
4470 /*
4471 * During CAC period, data packets shouldn't be sent over the air so
4472 * drop all the packets here
4473 */
hqu70708ab2017-10-10 17:52:01 +08004474 if (QDF_SAP_MODE == adapter->device_mode ||
4475 QDF_P2P_GO_MODE == adapter->device_mode) {
4476 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4477 ipa_free_skb(ipa_tx_desc);
4478 qdf_spin_unlock_bh(&iface_context->interface_lock);
4479 iface_context->stats.num_tx_cac_drop++;
4480 hdd_ipa_rm_try_release(hdd_ipa);
4481 return;
4482 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483 }
4484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004485 ++adapter->stats.tx_packets;
4486
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304487 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488
Yun Park6c86a662017-10-05 16:09:15 -07004489 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304491 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004492
4493 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304494 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304496 qdf_nbuf_mapped_paddr_set(skb,
Yun Park6c86a662017-10-05 16:09:15 -07004497 QDF_IPA_RX_DATA_DMA_ADDR(ipa_tx_desc)
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004498 + HDD_IPA_WLAN_FRAG_HEADER
4499 + HDD_IPA_WLAN_IPA_HEADER);
Yun Park6c86a662017-10-05 16:09:15 -07004500 QDF_IPA_RX_DATA_SKB_LEN(ipa_tx_desc) -=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004501 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4502 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304503 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504
Yun Park52b2b992016-09-22 15:49:51 -07004505 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4506 /* get free Tx desc and assign ipa_tx_desc pointer */
4507 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4508 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4509 struct hdd_ipa_tx_desc, link);
4510 list_del(&tx_desc->link);
4511 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4512 hdd_ipa->stats.num_tx_desc_q_cnt++;
4513 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4514 /* Store Tx Desc index into SKB CB */
4515 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4516 } else {
4517 hdd_ipa->stats.num_tx_desc_error++;
4518 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Yun Park52b2b992016-09-22 15:49:51 -07004519 ipa_free_skb(ipa_tx_desc);
4520 hdd_ipa_rm_try_release(hdd_ipa);
4521 return;
4522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523
Yun Park6c86a662017-10-05 16:09:15 -07004524 adapter->stats.tx_bytes += QDF_IPA_RX_DATA_SKB_LEN(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525
Leo Changfdb45c32016-10-28 11:09:23 -07004526 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Yun Park6c86a662017-10-05 16:09:15 -07004527 (struct cdp_vdev *)iface_context->tl_context,
4528 QDF_IPA_RX_DATA_SKB(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004529 if (skb) {
jiad05c1e812017-08-01 16:48:52 +08004530 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004531 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 return;
4533 }
4534
4535 atomic_inc(&hdd_ipa->tx_ref_cnt);
4536
4537 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004538}
4539
4540/**
Leo Chang11545d62016-10-17 14:53:50 -07004541 * hdd_ipa_is_present() - get IPA hw status
4542 * @hdd_ctx: pointer to hdd context
4543 *
4544 * ipa_uc_reg_rdyCB is not directly designed to check
4545 * ipa hw status. This is an undocumented function which
4546 * has confirmed with IPA team.
4547 *
4548 * Return: true - ipa hw present
4549 * false - ipa hw not present
4550 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004551bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004552{
jiad4ab698b2018-02-02 13:43:09 +08004553 /*
4554 * Check if ipa hw is enabled
4555 * TODO: Add support for WDI unified API
4556 */
4557 if (ipa_uc_reg_rdyCB(NULL) != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004558 return true;
4559 else
4560 return false;
4561}
4562
4563/**
Leo Chang69c39692016-10-12 20:11:12 -07004564 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565 * @work: pointer to the scheduled work
4566 *
4567 * Called during PM resume to send packets to TL which were queued
4568 * while host was in the process of suspending.
4569 *
4570 * Return: None
4571 */
Leo Chang69c39692016-10-12 20:11:12 -07004572static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573{
4574 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4575 struct hdd_ipa_priv,
4576 pm_work);
4577 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304578 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579 uint32_t dequeued = 0;
4580
Leo Chang69c39692016-10-12 20:11:12 -07004581 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4582 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304583 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304584 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4585 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304586 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004587
4588 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004590 if (pm_tx_cb->exception) {
Yun Park46255682017-10-09 15:56:34 -07004591 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4592 "Flush Exception");
Govind Singh1dab23b2017-08-12 13:31:00 +05304593 if (pm_tx_cb->adapter->dev)
4594 hdd_softap_hard_start_xmit(skb,
4595 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304596 else
4597 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004598 } else {
4599 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004600 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004601 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304602 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304604 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004605 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4606 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004607
4608 hdd_ipa->stats.num_tx_dequeued += dequeued;
4609 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4610 hdd_ipa->stats.num_max_pm_queue = dequeued;
4611}
4612
4613/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004614 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004615 * @priv: pointer to private data registered with IPA (we register a
4616 * pointer to the interface-specific IPA context)
4617 * @evt: the IPA event which triggered the callback
4618 * @data: data associated with the event
4619 *
4620 * Return: None
4621 */
Yun Park6c86a662017-10-05 16:09:15 -07004622static void __hdd_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
4623 unsigned long data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624{
4625 struct hdd_ipa_priv *hdd_ipa = NULL;
Yun Park6c86a662017-10-05 16:09:15 -07004626 qdf_ipa_rx_data_t *ipa_tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304628 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304630 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631
Mukul Sharma81661ae2015-10-30 20:26:02 +05304632 iface_context = (struct hdd_ipa_iface_context *)priv;
Yun Park6c86a662017-10-05 16:09:15 -07004633 ipa_tx_desc = (qdf_ipa_rx_data_t *)data;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004634 hdd_ipa = iface_context->hdd_ipa;
4635
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004636 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004637 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4638 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004639 iface_context->stats.num_tx_drop++;
4640 return;
4641 }
4642
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643 /*
4644 * When SSR is going on or driver is unloading, just drop the packets.
4645 * During SSR, there is no use in queueing the packets as STA has to
4646 * connect back any way
4647 */
4648 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304649 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004650 ipa_free_skb(ipa_tx_desc);
4651 iface_context->stats.num_tx_drop++;
4652 return;
4653 }
4654
Yun Park6c86a662017-10-05 16:09:15 -07004655 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004656
Yun Parkb187d542016-11-14 18:10:04 -08004657 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4658 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004659
4660 /*
4661 * If PROD resource is not requested here then there may be cases where
4662 * IPA hardware may be clocked down because of not having proper
4663 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4664 * workaround to request PROD resource while data is going over CONS
4665 * pipe to prevent the IPA hardware clockdown.
4666 */
4667 hdd_ipa_rm_request(hdd_ipa);
4668
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304669 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670 /*
4671 * If host is still suspended then queue the packets and these will be
4672 * drained later when resume completes. When packet is arrived here and
4673 * host is suspended, this means that there is already resume is in
4674 * progress.
4675 */
4676 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304677 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004678 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4679 pm_tx_cb->iface_context = iface_context;
4680 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304681 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 hdd_ipa->stats.num_tx_queued++;
4683
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304684 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004685 return;
4686 }
4687
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304688 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689
4690 /*
4691 * If we are here means, host is not suspended, wait for the work queue
4692 * to finish.
4693 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004694 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004695
4696 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4697}
4698
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004699/*
4700 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4701 * @priv: pointer to private data registered with IPA (we register a
4702 * pointer to the interface-specific IPA context)
4703 * @evt: the IPA event which triggered the callback
4704 * @data: data associated with the event
4705 *
4706 * Return: None
4707 */
Yun Park6c86a662017-10-05 16:09:15 -07004708static void hdd_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004709 unsigned long data)
4710{
4711 cds_ssr_protect(__func__);
4712 __hdd_ipa_i2w_cb(priv, evt, data);
4713 cds_ssr_unprotect(__func__);
4714}
4715
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004716/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004717 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718 * @hdd_ctx: Global HDD context
4719 *
4720 * Return: 0 on success, negativer errno on error
4721 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004722static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004723{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004724 struct hdd_ipa_priv *hdd_ipa;
4725
4726 if (wlan_hdd_validate_context(hdd_ctx))
4727 return 0;
4728
4729 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004730
4731 if (!hdd_ipa_is_enabled(hdd_ctx))
4732 return 0;
4733
4734 /*
4735 * Check if IPA is ready for suspend, If we are here means, there is
4736 * high chance that suspend would go through but just to avoid any race
4737 * condition after suspend started, these checks are conducted before
4738 * allowing to suspend.
4739 */
4740 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4741 return -EAGAIN;
4742
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304743 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744
4745 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304746 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004747 return -EAGAIN;
4748 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304749 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304751 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004752 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304753 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754
4755 return 0;
4756}
4757
4758/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004759 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4760 * @hdd_ctx: Global HDD context
4761 *
4762 * Return: 0 on success, negativer errno on error
4763 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004764int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004765{
4766 int ret;
4767
4768 cds_ssr_protect(__func__);
4769 ret = __hdd_ipa_suspend(hdd_ctx);
4770 cds_ssr_unprotect(__func__);
4771
4772 return ret;
4773}
4774
4775/**
4776 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777 * hdd_ctx: Global HDD context
4778 *
4779 * Return: 0 on success, negative errno on error
4780 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004781static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004782{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004783 struct hdd_ipa_priv *hdd_ipa;
4784
4785 if (wlan_hdd_validate_context(hdd_ctx))
4786 return 0;
4787
4788 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004789
4790 if (!hdd_ipa_is_enabled(hdd_ctx))
4791 return 0;
4792
4793 schedule_work(&hdd_ipa->pm_work);
4794
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304795 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304797 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798
4799 return 0;
4800}
4801
4802/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004803 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4804 * hdd_ctx: Global HDD context
4805 *
4806 * Return: 0 on success, negative errno on error
4807 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004808int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004809{
4810 int ret;
4811
4812 cds_ssr_protect(__func__);
4813 ret = __hdd_ipa_resume(hdd_ctx);
4814 cds_ssr_unprotect(__func__);
4815
4816 return ret;
4817}
4818
4819/**
Yun Park52b2b992016-09-22 15:49:51 -07004820 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4821 * @hdd_ipa: Global HDD IPA context
4822 *
4823 * Return: 0 on success, negative errno on error
4824 */
4825static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4826{
4827 int i;
4828 uint32_t max_desc_cnt;
4829 struct hdd_ipa_tx_desc *tmp_desc;
4830
Yun Parkd9c528e2017-08-30 16:34:57 -07004831 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
Yun Park52b2b992016-09-22 15:49:51 -07004832
4833 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4834
jiad14fe4fb2017-08-08 13:33:14 +08004835 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
Yun Parkd9c528e2017-08-30 16:34:57 -07004836 max_desc_cnt);
Yun Park52b2b992016-09-22 15:49:51 -07004837
4838 if (!tmp_desc) {
4839 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkd9c528e2017-08-30 16:34:57 -07004840 "Free Tx descriptor allocation failed");
Yun Park52b2b992016-09-22 15:49:51 -07004841 return -ENOMEM;
4842 }
4843
4844 hdd_ipa->tx_desc_list = tmp_desc;
4845
4846 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004847 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004848 tmp_desc->id = i;
4849 tmp_desc->ipa_tx_desc_ptr = NULL;
4850 list_add_tail(&tmp_desc->link,
4851 &hdd_ipa->free_tx_desc_head);
4852 tmp_desc++;
4853 }
4854
4855 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4856 hdd_ipa->stats.num_tx_desc_error = 0;
4857
4858 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4859
4860 return 0;
4861}
4862
Yun Park9281cb72017-11-30 11:14:30 -08004863#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Yun Park52b2b992016-09-22 15:49:51 -07004864/**
Yun Park9281cb72017-11-30 11:14:30 -08004865 * hdd_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004866 * @hdd_ipa: Global HDD IPA context
Yun Park9281cb72017-11-30 11:14:30 -08004867 * @desc_fifo_sz: Number of descriptors
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 *
4869 * Return: 0 on success, negative errno on error
4870 */
Yun Park9281cb72017-11-30 11:14:30 -08004871static int hdd_ipa_setup_tx_sys_pipe(struct hdd_ipa_priv *hdd_ipa,
4872 int32_t desc_fifo_sz)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873{
4874 int i, ret = 0;
Yun Park6c86a662017-10-05 16:09:15 -07004875 qdf_ipa_sys_connect_params_t *ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876
4877 /*setup TX pipes */
4878 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4879 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4880
4881 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4882 ipa->desc_fifo_sz = desc_fifo_sz;
4883 ipa->priv = &hdd_ipa->iface_context[i];
4884 ipa->notify = hdd_ipa_i2w_cb;
4885
4886 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4887 ipa->ipa_ep_cfg.hdr.hdr_len =
4888 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4889 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4890 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4891 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4892 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4893 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4894 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4895 } else {
4896 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4897 }
4898 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4899
4900 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4901 ipa->keep_ipa_awake = 1;
4902
Yun Park6c86a662017-10-05 16:09:15 -07004903 ret = qdf_ipa_setup_sys_pipe(ipa,
4904 &hdd_ipa->sys_pipe[i].conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004906 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4907 "Failed for pipe %d ret: %d", i, ret);
Yun Park9281cb72017-11-30 11:14:30 -08004908 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909 }
4910 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4911 }
4912
Yun Park9281cb72017-11-30 11:14:30 -08004913 return ret;
4914}
4915#else
4916/**
4917 * hdd_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes
4918 * @hdd_ipa: Global HDD IPA context
4919 * @desc_fifo_sz: Number of descriptors
4920 *
4921 * Return: 0 on success, negative errno on error
4922 */
4923static int hdd_ipa_setup_tx_sys_pipe(struct hdd_ipa_priv *hdd_ipa,
4924 int32_t desc_fifo_sz)
4925{
4926 /*
4927 * The Tx system pipes are not needed for MCC when TX_FLOW_CONTROL_V2
4928 * is enabled, where per vdev descriptors are supported in firmware.
4929 */
4930 return 0;
4931}
4932#endif
4933
4934/**
4935 * hdd_ipa_setup_rx_sys_pipe() - Setup IPA Rx system pipes
4936 * @hdd_ipa: Global HDD IPA context
4937 * @desc_fifo_sz: Number of descriptors
4938 *
4939 * Return: 0 on success, negative errno on error
4940 */
4941static int hdd_ipa_setup_rx_sys_pipe(struct hdd_ipa_priv *hdd_ipa,
4942 int32_t desc_fifo_sz)
4943{
4944 int ret = 0;
4945 qdf_ipa_sys_connect_params_t *ipa;
4946
4947 /*
4948 * Hard code it here, this can be extended if in case
4949 * PROD pipe is also per interface.
4950 * Right now there is no advantage of doing this.
4951 */
4952 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4953
4954 ipa->client = IPA_CLIENT_WLAN1_PROD;
4955
4956 ipa->desc_fifo_sz = desc_fifo_sz;
4957 ipa->priv = hdd_ipa;
4958 ipa->notify = hdd_ipa_w2i_cb;
4959
4960 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4961 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4962 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4963 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4964
4965 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4966 ipa->keep_ipa_awake = 1;
4967
4968 ret = qdf_ipa_setup_sys_pipe(ipa,
4969 &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl);
4970 if (ret) {
4971 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4972 "Failed for RX pipe: %d", ret);
4973 return ret;
4974 }
4975 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4976
4977 return ret;
4978}
4979
4980/**
4981 * hdd_ipa_setup_sys_pipe() - Setup all IPA system pipes
4982 * @hdd_ipa: Global HDD IPA context
4983 *
4984 * Return: 0 on success, negative errno on error
4985 */
4986static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4987{
4988 int i = HDD_IPA_MAX_IFACE, ret = 0;
4989 uint32_t desc_fifo_sz;
4990
4991 /* The maximum number of descriptors that can be provided to a BAM at
4992 * once is one less than the total number of descriptors that the buffer
4993 * can contain.
4994 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4995 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4996 * be provided at once.
4997 * Because of above requirement, one extra descriptor will be added to
4998 * make sure hardware always has one descriptor.
4999 */
5000 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
Yuanyuan Liu23a8eec2017-12-15 16:01:12 -08005001 + SPS_DESC_SIZE;
Yun Park9281cb72017-11-30 11:14:30 -08005002
5003 ret = hdd_ipa_setup_tx_sys_pipe(hdd_ipa, desc_fifo_sz);
5004 if (ret) {
5005 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5006 "Failed for TX pipe: %d", ret);
5007 goto setup_sys_pipe_fail;
5008 }
5009
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005010 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park9281cb72017-11-30 11:14:30 -08005011 ret = hdd_ipa_setup_rx_sys_pipe(hdd_ipa, desc_fifo_sz);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005012 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305013 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park9281cb72017-11-30 11:14:30 -08005014 "Failed for RX pipe: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015 goto setup_sys_pipe_fail;
5016 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005017 }
5018
Yun Parkd9c528e2017-08-30 16:34:57 -07005019 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07005020 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
5021 if (ret)
5022 goto setup_sys_pipe_fail;
5023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005024 return ret;
5025
5026setup_sys_pipe_fail:
5027
Yun Park9281cb72017-11-30 11:14:30 -08005028 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
5029 if (hdd_ipa->sys_pipe[i].conn_hdl_valid)
5030 qdf_ipa_teardown_sys_pipe(
5031 hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305032 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033 sizeof(struct hdd_ipa_sys_pipe));
5034 }
5035
5036 return ret;
5037}
5038
5039/**
5040 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
5041 * @hdd_ipa: Global HDD IPA context
5042 *
5043 * Return: None
5044 */
5045static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
5046{
5047 int ret = 0, i;
Yun Parkd9c528e2017-08-30 16:34:57 -07005048 uint32_t max_desc_cnt;
Yun Park52b2b992016-09-22 15:49:51 -07005049 struct hdd_ipa_tx_desc *tmp_desc;
Yun Park6c86a662017-10-05 16:09:15 -07005050 qdf_ipa_rx_data_t *ipa_tx_desc;
Yun Park52b2b992016-09-22 15:49:51 -07005051
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005052 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
5053 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Park9281cb72017-11-30 11:14:30 -08005054 ret = qdf_ipa_teardown_sys_pipe(
5055 hdd_ipa->sys_pipe[i].conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305057 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005058 ret);
5059
5060 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
5061 }
5062 }
Yun Park52b2b992016-09-22 15:49:51 -07005063
5064 if (hdd_ipa->tx_desc_list) {
Yun Parkd9c528e2017-08-30 16:34:57 -07005065 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
5066
Yun Park52b2b992016-09-22 15:49:51 -07005067 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07005068 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07005069 tmp_desc = hdd_ipa->tx_desc_list + i;
5070 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
5071 if (ipa_tx_desc)
5072 ipa_free_skb(ipa_tx_desc);
5073 }
5074 tmp_desc = hdd_ipa->tx_desc_list;
5075 hdd_ipa->tx_desc_list = NULL;
5076 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
5077 hdd_ipa->stats.num_tx_desc_error = 0;
5078 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
5079 qdf_mem_free(tmp_desc);
5080 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081}
5082
5083/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
5085 * @iface_context: interface-specific IPA context
5086 *
5087 * Return: None
5088 */
5089static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
5090{
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005091 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07005092
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 if (iface_context == NULL)
5094 return;
Orhan K AKYILDIZ3332be32017-05-31 15:36:31 -07005095 if (iface_context->adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
5096 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
5097 "%s: bad adapter(%pK).magic(%d)!",
5098 __func__, iface_context->adapter,
5099 iface_context->adapter->magic);
5100 return;
5101 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005102
Yun Parkb4f591d2017-03-29 15:51:01 -07005103 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
5104 iface_context->adapter->dev->name,
5105 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305107 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005108 iface_context->adapter->ipa_context = NULL;
5109 iface_context->adapter = NULL;
5110 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305111 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005112 iface_context->ifa_address = 0;
5113 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305114 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05305116 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117 }
5118 iface_context->hdd_ipa->num_iface--;
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005119 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: num_iface=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005120 iface_context->hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005121}
5122
5123/**
5124 * hdd_ipa_setup_iface() - Setup IPA on a given interface
5125 * @hdd_ipa: HDD IPA global context
5126 * @adapter: Interface upon which IPA is being setup
5127 * @sta_id: Station ID of the API instance
5128 *
5129 * Return: 0 on success, negative errno value on error
5130 */
5131static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07005132 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133{
5134 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park0dad1002017-07-14 14:57:01 -07005135 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
5136 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 void *tl_context = NULL;
5138 int i, ret = 0;
5139
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005140 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07005141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
5143 * channel change indication. Since these indications are sent by lower
5144 * layer as SAP updates and IPA doesn't have to do anything for these
5145 * updates so ignoring!
5146 */
Krunal Sonibe766b02016-03-10 13:00:44 -08005147 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005148 return 0;
5149
5150 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5151 if (hdd_ipa->iface_context[i].adapter == NULL) {
5152 iface_context = &(hdd_ipa->iface_context[i]);
5153 break;
5154 }
5155 }
5156
5157 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305158 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 "All the IPA interfaces are in use");
5160 ret = -ENOMEM;
5161 goto end;
5162 }
5163
5164 adapter->ipa_context = iface_context;
5165 iface_context->adapter = adapter;
5166 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005167 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Yun Park0dad1002017-07-14 14:57:01 -07005168 soc, (struct cdp_pdev *)pdev, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005169 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305170 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171 "Not able to get TL context sta_id: %d", sta_id);
5172 ret = -EINVAL;
5173 goto end;
5174 }
5175
5176 iface_context->tl_context = tl_context;
5177
Yun Parkb4f591d2017-03-29 15:51:01 -07005178 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
5179 adapter->dev->name, adapter->dev->dev_addr,
5180 iface_context->prod_client,
5181 iface_context->cons_client,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005182 adapter->session_id,
Yun Parkb4f591d2017-03-29 15:51:01 -07005183 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005184 if (ret)
5185 goto end;
5186
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187 hdd_ipa->num_iface++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005188
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005189 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: num_iface=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005190 hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 return ret;
5192
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193end:
5194 if (iface_context)
5195 hdd_ipa_cleanup_iface(iface_context);
5196 return ret;
5197}
5198
Yun Parka27049a2016-10-11 12:30:49 -07005199#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005201 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Jeff Johnson4929cd92017-10-06 19:21:57 -07005202 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 * @mcc_mode: 0=MCC/1=SCC
5204 *
5205 * Return: 0 on success, negative errno value on error
5206 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07005207static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx,
5208 bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209{
Jeff Johnson089d0432017-10-02 13:27:21 -07005210 struct hdd_adapter *adapter;
Yun Park6c86a662017-10-05 16:09:15 -07005211 qdf_ipa_msg_meta_t meta;
5212 qdf_ipa_wlan_msg_t *msg;
5213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214 int ret;
5215
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005216 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 return -EINVAL;
5218
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005219 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
5220 return -EINVAL;
5221
5222 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 /* Flush TxRx queue for each adapter before switch to SCC */
Dustin Brown920397d2017-12-13 16:27:50 -08005224 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson089d0432017-10-02 13:27:21 -07005225 if (adapter->device_mode == QDF_STA_MODE ||
5226 adapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005227 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnson089d0432017-10-02 13:27:21 -07005228 adapter->device_mode);
5229 hdd_deinit_tx_rx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 }
5232 }
5233
5234 /* Send SCC/MCC Switching event to IPA */
Yun Park6c86a662017-10-05 16:09:15 -07005235 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*msg);
5236 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005238 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 return -ENOMEM;
5240 }
5241
Yun Park6c86a662017-10-05 16:09:15 -07005242 QDF_IPA_MSG_META_MSG_TYPE(&meta) = mcc_mode ?
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Yun Park6c86a662017-10-05 16:09:15 -07005244 hdd_debug("ipa_send_msg(Evt:%d)", QDF_IPA_MSG_META_MSG_TYPE(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245
Yun Park6c86a662017-10-05 16:09:15 -07005246 ret = qdf_ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005247
5248 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005249 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Yun Park6c86a662017-10-05 16:09:15 -07005250 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305251 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252 }
5253
5254 return ret;
5255}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005256
5257/**
5258 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
5259 * @mcc_mode: 0=MCC/1=SCC
5260 *
5261 * Return: 0 on success, negative errno value on error
5262 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005263int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005264{
5265 int ret;
5266
5267 cds_ssr_protect(__func__);
5268 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
5269 cds_ssr_unprotect(__func__);
5270
5271 return ret;
5272}
Yun Parka27049a2016-10-11 12:30:49 -07005273#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005274
5275/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07005276 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
5277 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
5278 *
Yun Park6c86a662017-10-05 16:09:15 -07005279 * Return: qdf_ipa_wlan_event representing the hdd_ipa_wlan_event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005280 */
Yun Park6c86a662017-10-05 16:09:15 -07005281static qdf_ipa_wlan_event_t
Mohit Khannafa99aea2016-05-12 21:43:13 -07005282hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
5283{
Yun Park6c86a662017-10-05 16:09:15 -07005284 qdf_ipa_wlan_event_t ipa_event;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005285
5286 switch (hdd_ipa_event_type) {
5287 case HDD_IPA_CLIENT_CONNECT:
5288 ipa_event = WLAN_CLIENT_CONNECT;
5289 break;
5290 case HDD_IPA_CLIENT_DISCONNECT:
5291 ipa_event = WLAN_CLIENT_DISCONNECT;
5292 break;
5293 case HDD_IPA_AP_CONNECT:
5294 ipa_event = WLAN_AP_CONNECT;
5295 break;
5296 case HDD_IPA_AP_DISCONNECT:
5297 ipa_event = WLAN_AP_DISCONNECT;
5298 break;
5299 case HDD_IPA_STA_CONNECT:
5300 ipa_event = WLAN_STA_CONNECT;
5301 break;
5302 case HDD_IPA_STA_DISCONNECT:
5303 ipa_event = WLAN_STA_DISCONNECT;
5304 break;
5305 case HDD_IPA_CLIENT_CONNECT_EX:
5306 ipa_event = WLAN_CLIENT_CONNECT_EX;
5307 break;
5308 case HDD_IPA_WLAN_EVENT_MAX:
5309 default:
5310 ipa_event = IPA_WLAN_EVENT_MAX;
5311 break;
5312 }
5313 return ipa_event;
5314
5315}
5316
5317/**
5318 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 * @adapter: adapter upon which the event was received
5320 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005321 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322 * @mac_address: MAC address associated with the event
5323 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07005324 * This function is meant to be called from within wlan_hdd_ipa.c
5325 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005326 * Return: 0 on success, negative errno value on error
5327 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005328static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Yun Park6c86a662017-10-05 16:09:15 -07005329 qdf_ipa_wlan_event_t type, uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005330{
5331 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park6c86a662017-10-05 16:09:15 -07005332 qdf_ipa_msg_meta_t meta;
5333 qdf_ipa_wlan_msg_t *msg;
5334 qdf_ipa_wlan_msg_ex_t *msg_ex = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 int ret;
5336
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005337 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: EVT: %s, MAC: %pM, sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005338 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5339 mac_addr, sta_id);
5340
5341 if (type >= IPA_WLAN_EVENT_MAX)
5342 return -EINVAL;
5343
5344 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5345 return -EINVAL;
5346
5347 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305348 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349 return -EINVAL;
5350 }
5351
5352 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5353 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005354 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 return 0;
5356 }
5357
5358 /*
5359 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 */
Yun Park777d7242017-03-30 15:38:33 -07005361 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5362 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
5363 unsigned int pending_event_count;
5364 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005365
Yun Park46255682017-10-09 15:56:34 -07005366 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park777d7242017-03-30 15:38:33 -07005367 "%s:IPA resource %s inprogress",
5368 hdd_ipa_wlan_event_to_str(type),
5369 hdd_ipa->resource_loading ?
5370 "load" : "unload");
5371
5372 /* Wait until completion of the long/unloading */
5373 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
5374 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
5375 if (!ret) {
5376 /*
5377 * If timed out, store the events separately and
5378 * handle them later.
5379 */
Yun Park46255682017-10-09 15:56:34 -07005380 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park777d7242017-03-30 15:38:33 -07005381 "IPA resource %s timed out",
5382 hdd_ipa->resource_loading ?
5383 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08005384
Yun Parka4bb37c2017-12-08 16:14:22 -08005385 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005386
Yun Parka4bb37c2017-12-08 16:14:22 -08005387 pending_event_count =
5388 qdf_list_size(&hdd_ipa->pending_event);
5389 if (pending_event_count >=
5390 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5391 hdd_debug("Reached max pending event count");
5392 qdf_list_remove_front(
5393 &hdd_ipa->pending_event,
5394 (qdf_list_node_t **)&pending_event);
5395 } else {
5396 pending_event =
5397 (struct ipa_uc_pending_event *)
5398 qdf_mem_malloc(sizeof(
Yun Park777d7242017-03-30 15:38:33 -07005399 struct ipa_uc_pending_event));
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005400 }
Yun Parka4bb37c2017-12-08 16:14:22 -08005401
5402 if (!pending_event) {
5403 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5404 "Pending event memory alloc fail");
5405 qdf_mutex_release(&hdd_ipa->ipa_lock);
5406 return -ENOMEM;
5407 }
5408
5409 pending_event->adapter = adapter;
5410 pending_event->sta_id = sta_id;
5411 pending_event->type = type;
5412 pending_event->is_loading =
5413 hdd_ipa->resource_loading;
5414 qdf_mem_copy(pending_event->mac_addr,
5415 mac_addr, QDF_MAC_ADDR_SIZE);
5416 qdf_list_insert_back(&hdd_ipa->pending_event,
5417 &pending_event->node);
5418
5419 qdf_mutex_release(&hdd_ipa->ipa_lock);
5420
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005421 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422 }
Yun Park46255682017-10-09 15:56:34 -07005423 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Jeff Johnson4929cd92017-10-06 19:21:57 -07005424 "IPA resource %s completed",
5425 hdd_ipa->resource_loading ?
5426 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427 }
5428
5429 hdd_ipa->stats.event[type]++;
5430
Yun Park6c86a662017-10-05 16:09:15 -07005431 QDF_IPA_MSG_META_MSG_TYPE(&meta) = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 switch (type) {
5433 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005434 qdf_mutex_acquire(&hdd_ipa->event_lock);
5435
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005436 /* STA already connected and without disconnect, connect again
5437 * This is Roaming scenario
5438 */
5439 if (hdd_ipa->sta_connected)
5440 hdd_ipa_cleanup_iface(adapter->ipa_context);
5441
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005442 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5443 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305444 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005445 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005446 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447
Yun Park8f289c82016-10-18 16:38:21 -07005448 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5449 (hdd_ipa->sap_num_connected_sta > 0) &&
5450 !hdd_ipa->sta_connected) {
5451 qdf_mutex_release(&hdd_ipa->event_lock);
5452 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005453 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005454 qdf_mutex_acquire(&hdd_ipa->event_lock);
5455 }
5456
Jeff Johnson1b780e42017-10-31 14:11:45 -07005457 hdd_ipa->vdev_to_iface[adapter->session_id] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005458 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005459 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005461 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005462
5463 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005464
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005465 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "sta_connected=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005466 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005467 break;
5468
5469 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005470 qdf_mutex_acquire(&hdd_ipa->event_lock);
5471
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005472 /* For DFS channel we get two start_bss event (before and after
5473 * CAC). Also when ACS range includes both DFS and non DFS
5474 * channels, we could possibly change channel many times due to
5475 * RADAR detection and chosen channel may not be a DFS channels.
5476 * So dont return error here. Just discard the event.
5477 */
Yun Park8f289c82016-10-18 16:38:21 -07005478 if (adapter->ipa_context) {
5479 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005481 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5484 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005485 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005486 hdd_err("%s: Evt: %d, Interface setup failed",
Yun Park6c86a662017-10-05 16:09:15 -07005487 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005488 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005489 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490
Yun Park8f289c82016-10-18 16:38:21 -07005491 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5492 qdf_mutex_release(&hdd_ipa->event_lock);
5493 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005494 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005495 qdf_mutex_acquire(&hdd_ipa->event_lock);
5496 }
5497
Jeff Johnson1b780e42017-10-31 14:11:45 -07005498 hdd_ipa->vdev_to_iface[adapter->session_id] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005499 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005500 (adapter->ipa_context))->iface_id;
5501
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305502 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005503 break;
5504
5505 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305506 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005507
5508 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005509 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005510 hdd_err("%s: Evt: %d, STA already disconnected",
Yun Park6c86a662017-10-05 16:09:15 -07005511 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005512 return -EINVAL;
5513 }
Yun Parka37592b2016-06-11 17:10:28 -07005514
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005515 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005516
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005517 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005518 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005519 msg_ex->name);
5520 } else {
5521 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Park3b7152b2017-08-25 08:33:37 -07005522 if ((1 == hdd_ipa->num_iface) &&
Yun Parka37592b2016-06-11 17:10:28 -07005523 (HDD_IPA_UC_NUM_WDI_PIPE ==
Yun Park3b7152b2017-08-25 08:33:37 -07005524 hdd_ipa->activated_fw_pipe) &&
5525 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005526 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005527 }
5528
Yun Park74127cf2016-09-18 11:22:41 -07005529 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5530 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005531 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005532 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005533 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005534 qdf_mutex_acquire(&hdd_ipa->event_lock);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005535 hdd_ipa->vdev_to_iface[adapter->session_id] =
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005536 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537 }
5538
Yun Park8f289c82016-10-18 16:38:21 -07005539 hdd_ipa_cleanup_iface(adapter->ipa_context);
5540
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305541 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005542
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -08005543 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "sta_connected=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005544 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005545 break;
5546
5547 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005548 qdf_mutex_acquire(&hdd_ipa->event_lock);
5549
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005550 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005551 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005552 hdd_err("%s: Evt: %d, SAP already disconnected",
Yun Park6c86a662017-10-05 16:09:15 -07005553 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554 return -EINVAL;
5555 }
5556
Yun Park3b7152b2017-08-25 08:33:37 -07005557 if ((1 == hdd_ipa->num_iface) &&
5558 (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
5559 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005560 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561 /*
5562 * We disable WDI pipes directly here since
5563 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5564 * processed when unloading WLAN driver is in
5565 * progress
5566 */
5567 hdd_ipa_uc_disable_pipes(hdd_ipa);
5568 } else {
Yun Park199c2ed2017-10-02 11:24:22 -07005569 /*
5570 * This shouldn't happen :
5571 * No interface left but WDI pipes are still
5572 * active - force close WDI pipes
5573 */
5574 WARN_ON(1);
5575 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
5576 "No interface left but WDI pipes are still active - force close WDI pipes");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5578 }
5579 }
5580
5581 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005582 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005583 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005584 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005585 qdf_mutex_acquire(&hdd_ipa->event_lock);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005586 hdd_ipa->vdev_to_iface[adapter->session_id] =
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005587 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588 }
Yun Parka37592b2016-06-11 17:10:28 -07005589
Yun Park8f289c82016-10-18 16:38:21 -07005590 hdd_ipa_cleanup_iface(adapter->ipa_context);
5591
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305592 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593 break;
5594
5595 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005596 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005597 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305599 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005600 return 0;
5601 }
5602
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305603 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005604 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5605 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005606 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305607 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005608 "%s: STA ID %d found, not valid",
5609 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005610 return 0;
5611 }
Yun Park312f71a2015-12-08 10:22:42 -08005612
5613 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005614 if (hdd_ipa->sap_num_connected_sta == 0 &&
5615 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005616 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005617 hdd_ipa->sta_connected) {
5618 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005619 hdd_ipa_uc_offload_enable_disable(
5620 hdd_get_adapter(hdd_ipa->hdd_ctx,
5621 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005622 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005623 qdf_mutex_acquire(&hdd_ipa->event_lock);
5624 }
Yun Parka37592b2016-06-11 17:10:28 -07005625
Yun Park312f71a2015-12-08 10:22:42 -08005626 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5627 if (ret) {
Yun Park46255682017-10-09 15:56:34 -07005628 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park312f71a2015-12-08 10:22:42 -08005629 "%s: handle 1st con ret %d",
5630 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005631
5632 if (hdd_ipa_uc_sta_is_enabled(
5633 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005634 hdd_ipa->sta_connected) {
5635 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005636 hdd_ipa_uc_offload_enable_disable(
5637 hdd_get_adapter(
5638 hdd_ipa->hdd_ctx,
5639 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005640 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005641 } else {
5642 qdf_mutex_release(&hdd_ipa->event_lock);
5643 }
Yun Parka37592b2016-06-11 17:10:28 -07005644
Yun Park312f71a2015-12-08 10:22:42 -08005645 return ret;
5646 }
5647 }
5648
5649 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005650
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305651 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652
Yun Park6c86a662017-10-05 16:09:15 -07005653 QDF_IPA_MSG_META_MSG_TYPE(&meta) = type;
5654 QDF_IPA_MSG_META_MSG_LEN(&meta) =
5655 (sizeof(qdf_ipa_wlan_msg_ex_t) +
5656 sizeof(qdf_ipa_wlan_hdr_attrib_val_t));
5657 msg_ex = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005658
5659 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305660 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661 "msg_ex allocation failed");
5662 return -ENOMEM;
5663 }
5664 strlcpy(msg_ex->name, adapter->dev->name,
5665 IPA_RESOURCE_NAME_MAX);
5666 msg_ex->num_of_attribs = 1;
5667 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5668 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5669 msg_ex->attribs[0].offset =
5670 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5671 } else {
5672 msg_ex->attribs[0].offset =
5673 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5674 }
5675 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5676 IPA_MAC_ADDR_SIZE);
5677
5678 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5679
5680 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005681 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305682 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305683 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684 return ret;
5685 }
5686 hdd_ipa->stats.num_send_msg++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005687
Yun Park199c2ed2017-10-02 11:24:22 -07005688 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "sap_num_connected_sta=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005689 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005690 return ret;
5691
5692 case WLAN_CLIENT_DISCONNECT:
5693 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005694 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005695 "%s: IPA UC OFFLOAD NOT ENABLED",
5696 msg_ex->name);
5697 return 0;
5698 }
5699
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305700 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Park73ea8bb2017-08-25 07:27:39 -07005701 if (!hdd_ipa->sap_num_connected_sta) {
5702 qdf_mutex_release(&hdd_ipa->event_lock);
5703 hdd_err("%s: Evt: %d, Client already disconnected",
Yun Park6c86a662017-10-05 16:09:15 -07005704 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
Yun Park73ea8bb2017-08-25 07:27:39 -07005705 return 0;
5706 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005708 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305709 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005710 "%s: STA ID %d NOT found, not valid",
5711 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005712 return 0;
5713 }
5714 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005715
Yun Park9b5030f2016-11-08 12:02:37 -08005716 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005717 if (!hdd_ipa->sap_num_connected_sta &&
5718 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005719 if ((false == hdd_ipa->resource_unloading)
5720 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305721 hdd_ipa->activated_fw_pipe) &&
5722 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005723 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5724 }
5725
Yun Park9b5030f2016-11-08 12:02:37 -08005726 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005727 hdd_ipa->sta_connected) {
5728 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005729 hdd_ipa_uc_offload_enable_disable(
5730 hdd_get_adapter(hdd_ipa->hdd_ctx,
5731 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005732 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005733 } else {
5734 qdf_mutex_release(&hdd_ipa->event_lock);
5735 }
Yun Park8f289c82016-10-18 16:38:21 -07005736 } else {
5737 qdf_mutex_release(&hdd_ipa->event_lock);
5738 }
Yun Parkfec73dc2017-09-06 10:40:07 -07005739
Yun Park199c2ed2017-10-02 11:24:22 -07005740 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "sap_num_connected_sta=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005741 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005742 break;
5743
5744 default:
5745 return 0;
5746 }
5747
Yun Park6c86a662017-10-05 16:09:15 -07005748 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t);
5749 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305751 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752 return -ENOMEM;
5753 }
5754
Yun Park6c86a662017-10-05 16:09:15 -07005755 QDF_IPA_MSG_META_MSG_TYPE(&meta) = type;
5756 strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), adapter->dev->name,
5757 IPA_RESOURCE_NAME_MAX);
5758 memcpy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005759
Srinivas Girigowda97852372017-03-06 16:52:59 -08005760 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Yun Park6c86a662017-10-05 16:09:15 -07005761 QDF_IPA_WLAN_MSG_NAME(msg),
5762 QDF_IPA_MSG_META_MSG_TYPE(&meta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763
5764 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5765
5766 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005767 hdd_err("%s: Evt: %d fail:%d",
Yun Park6c86a662017-10-05 16:09:15 -07005768 QDF_IPA_WLAN_MSG_NAME(msg),
5769 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305770 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005771 return ret;
5772 }
5773
5774 hdd_ipa->stats.num_send_msg++;
5775
5776end:
5777 return ret;
5778}
5779
5780/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005781 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005782 * @adapter: adapter upon which the event was received
5783 * @sta_id: station id for the event
5784 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5785 * @mac_address: MAC address associated with the event
5786 *
5787 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5788 *
5789 * Return: 0 on success, negative errno value on error
5790 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005791int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005792 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5793{
Yun Park6c86a662017-10-05 16:09:15 -07005794 qdf_ipa_wlan_event_t type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005795 int ret = 0;
5796
5797 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005798
Leo Changa202b522016-10-14 16:13:50 -07005799 /* Data path offload only support for STA and SAP mode */
5800 if ((QDF_STA_MODE == adapter->device_mode) ||
5801 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005802 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005803
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005804 cds_ssr_unprotect(__func__);
5805
5806 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005807}
5808
5809/**
5810 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5811 * @hdd_ipa: Global HDD IPA context
Yun Parka4bb37c2017-12-08 16:14:22 -08005812 * @is_loading: Indicate if invoked during loading
Mohit Khannafa99aea2016-05-12 21:43:13 -07005813 *
5814 * Return: None
5815 */
5816static void
Yun Parka4bb37c2017-12-08 16:14:22 -08005817hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa, bool is_loading)
Mohit Khannafa99aea2016-05-12 21:43:13 -07005818{
5819 unsigned int pending_event_count;
5820 struct ipa_uc_pending_event *pending_event = NULL;
5821
5822 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005823 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07005824 "Pending Event Count %d", pending_event_count);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005825 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005826 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07005827 "No Pending Event");
Mohit Khannafa99aea2016-05-12 21:43:13 -07005828 return;
5829 }
5830
5831 qdf_list_remove_front(&hdd_ipa->pending_event,
5832 (qdf_list_node_t **)&pending_event);
5833 while (pending_event != NULL) {
Yun Parka4bb37c2017-12-08 16:14:22 -08005834 if (pending_event->is_loading == is_loading)
5835 __hdd_ipa_wlan_evt(pending_event->adapter,
5836 pending_event->sta_id,
5837 pending_event->type,
5838 pending_event->mac_addr);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005839 qdf_mem_free(pending_event);
5840 pending_event = NULL;
5841 qdf_list_remove_front(&hdd_ipa->pending_event,
5842 (qdf_list_node_t **)&pending_event);
5843 }
5844}
5845
5846/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005847 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5848 * @state: IPA RM state value
5849 *
5850 * Return: ASCII string representing the IPA RM state
5851 */
5852static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5853{
5854 switch (state) {
5855 case HDD_IPA_RM_RELEASED:
5856 return "RELEASED";
5857 case HDD_IPA_RM_GRANT_PENDING:
5858 return "GRANT_PENDING";
5859 case HDD_IPA_RM_GRANTED:
5860 return "GRANTED";
5861 }
5862
5863 return "UNKNOWN";
5864}
5865
5866/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005867 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005868 * @hdd_ctx: HDD global context
5869 *
5870 * Allocate hdd_ipa resources, ipa pipe resource and register
5871 * wlan interface with IPA module.
5872 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305873 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005874 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005875static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005876{
5877 struct hdd_ipa_priv *hdd_ipa = NULL;
5878 int ret, i;
5879 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005880 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park6c86a662017-10-05 16:09:15 -07005881 qdf_ipa_rm_perf_profile_t profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005882
5883 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305884 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005885
Rajeev Kumar3887f9b2018-01-10 11:24:01 -08005886 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "enter");
Yun Park199c2ed2017-10-02 11:24:22 -07005887
Yun Parkbaa62862017-01-18 13:43:34 -08005888 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005889 if (!pdev) {
5890 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5891 goto fail_return;
5892 }
5893
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305894 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005895 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305896 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005897 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 }
5899
5900 hdd_ctx->hdd_ipa = hdd_ipa;
5901 ghdd_ipa = hdd_ipa;
5902 hdd_ipa->hdd_ctx = hdd_ctx;
5903 hdd_ipa->num_iface = 0;
5904
5905 /* Create the interface context */
5906 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5907 iface_context = &hdd_ipa->iface_context[i];
5908 iface_context->hdd_ipa = hdd_ipa;
5909 iface_context->cons_client =
5910 hdd_ipa_adapter_2_client[i].cons_client;
5911 iface_context->prod_client =
5912 hdd_ipa_adapter_2_client[i].prod_client;
5913 iface_context->iface_id = i;
5914 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305915 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005916 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917
Leo Chang69c39692016-10-12 20:11:12 -07005918 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305919 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005920 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305921 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005922 qdf_list_create(&hdd_ipa->pending_event, 1000);
5923 qdf_mutex_create(&hdd_ipa->event_lock);
5924 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005925
5926 ret = hdd_ipa_setup_rm(hdd_ipa);
5927 if (ret)
5928 goto fail_setup_rm;
5929
Yun Park9281cb72017-11-30 11:14:30 -08005930 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++)
5931 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
5932 sizeof(struct hdd_ipa_sys_pipe));
5933
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5935 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305936 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005937 hdd_ipa->sap_num_connected_sta = 0;
5938 hdd_ipa->ipa_tx_packets_diff = 0;
5939 hdd_ipa->ipa_rx_packets_diff = 0;
5940 hdd_ipa->ipa_p_tx_packets = 0;
5941 hdd_ipa->ipa_p_rx_packets = 0;
5942 hdd_ipa->resource_loading = false;
5943 hdd_ipa->resource_unloading = false;
5944 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005945 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005946 hdd_ipa->wdi_enabled = false;
Yun Park9281cb72017-11-30 11:14:30 -08005947 /* Setup IPA system pipes */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005948 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5949 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5950 if (ret)
5951 goto fail_create_sys_pipe;
5952 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005953 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5954 goto fail_create_sys_pipe;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005955 } else {
5956 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5957 if (ret)
5958 goto fail_create_sys_pipe;
5959 }
5960
Yun Park66f24c42017-03-20 10:39:47 -07005961 /* When IPA clock scaling is disabled, initialze maximum clock */
5962 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5963 profile.max_supported_bandwidth_mbps = 800;
5964 hdd_debug("IPA clock scaling is disabled.");
5965 hdd_debug("Set initial CONS/PROD perf: %d",
5966 profile.max_supported_bandwidth_mbps);
5967 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5968 &profile);
5969 if (ret) {
5970 hdd_err("RM CONS set perf profile failed: %d", ret);
5971 goto fail_create_sys_pipe;
5972 }
5973
5974 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5975 &profile);
5976 if (ret) {
5977 hdd_err("RM PROD set perf profile failed: %d", ret);
5978 goto fail_create_sys_pipe;
5979 }
5980 }
5981
Yun Park777d7242017-03-30 15:38:33 -07005982 init_completion(&hdd_ipa->ipa_resource_comp);
5983
Yun Parke4239802018-01-09 11:01:40 -08005984 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: success");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305985 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005986
5987fail_create_sys_pipe:
5988 hdd_ipa_destroy_rm_resource(hdd_ipa);
5989fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305990 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305991 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005992 hdd_ctx->hdd_ipa = NULL;
5993 ghdd_ipa = NULL;
5994fail_return:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -08005995 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "exit: fail");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305996 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005997}
5998
5999/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006000 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
6001 * @hdd_ctx: HDD global context
6002 *
6003 * Allocate hdd_ipa resources, ipa pipe resource and register
6004 * wlan interface with IPA module.
6005 *
6006 * Return: QDF_STATUS enumeration
6007 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07006008QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006009{
6010 QDF_STATUS ret;
6011
6012 cds_ssr_protect(__func__);
6013 ret = __hdd_ipa_init(hdd_ctx);
6014 cds_ssr_unprotect(__func__);
6015
6016 return ret;
6017}
6018
Arun Khandavallicc544b32017-01-30 19:52:16 +05306019
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006020/**
Govind Singh1dab23b2017-08-12 13:31:00 +05306021 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022 * @hdd_ctx: HDD global context
6023 *
Govind Singh1dab23b2017-08-12 13:31:00 +05306024 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025 */
Govind Singh1dab23b2017-08-12 13:31:00 +05306026static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006027{
6028 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05306029 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006030 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
6031
6032 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05306033 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006034
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006035 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006036
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306037 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006038
Nirav Shahcbc6d722016-03-01 16:24:53 +05306039 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
6040 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306041 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006042
6043 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07006044 if (pm_tx_cb->ipa_tx_desc)
6045 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006046
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306047 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006048 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306049 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05306050}
6051
6052/**
6053 * __hdd_ipa_cleanup - IPA cleanup function
6054 * @hdd_ctx: HDD global context
6055 *
6056 * Return: QDF_STATUS enumeration
6057 */
6058static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
6059{
6060 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
6061 int i;
6062 struct hdd_ipa_iface_context *iface_context = NULL;
6063
6064 if (!hdd_ipa_is_enabled(hdd_ctx))
6065 return QDF_STATUS_SUCCESS;
6066
6067 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
6068 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
6069 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6070 }
6071
6072 /* Teardown IPA sys_pipe for MCC */
6073 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
6074 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6075
6076 hdd_ipa_destroy_rm_resource(hdd_ipa);
6077
6078 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006079
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306080 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006081 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006082
6083 /* destory the interface lock */
6084 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6085 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306086 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006087 }
6088
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006089 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08006090 if (ipa_uc_dereg_rdyCB())
6091 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
6092 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006093 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306094 qdf_mutex_destroy(&hdd_ipa->event_lock);
6095 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07006096 qdf_list_destroy(&hdd_ipa->pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6099 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
Yun Park6edb2172018-01-14 00:18:05 -08006100 qdf_mem_free(hdd_ipa->uc_op_work[i].msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006101 hdd_ipa->uc_op_work[i].msg = NULL;
6102 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006103 }
6104
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306105 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106 hdd_ctx->hdd_ipa = NULL;
6107
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306108 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006110
6111/**
Govind Singh1dab23b2017-08-12 13:31:00 +05306112 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
6113 * @hdd_ctx: HDD global context
6114 *
6115 * Return: None
6116 */
6117void hdd_ipa_flush(struct hdd_context *hdd_ctx)
6118{
6119 cds_ssr_protect(__func__);
6120 __hdd_ipa_flush(hdd_ctx);
6121 cds_ssr_unprotect(__func__);
6122}
6123
6124/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006125 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
6126 * @hdd_ctx: HDD global context
6127 *
6128 * Return: QDF_STATUS enumeration
6129 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07006130QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006131{
6132 QDF_STATUS ret;
6133
6134 cds_ssr_protect(__func__);
6135 ret = __hdd_ipa_cleanup(hdd_ctx);
6136 cds_ssr_unprotect(__func__);
6137
6138 return ret;
6139}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006140#endif /* IPA_OFFLOAD */