blob: 15a97c7c3e2e94024627d37ec62db4a398fc00ef [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
Mohit Khannafa99aea2016-05-12 21:43:13 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070051#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080052
53#include "cds_sched.h"
54
55#include "wma.h"
56#include "wma_api.h"
Prakash Dhavali87b38e32016-11-14 16:22:53 -080057#include "wal_rx_desc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080058
Dhanashri Atreb08959a2016-03-01 17:28:03 -080059#include "cdp_txrx_ipa.h"
60
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061#define HDD_IPA_DESC_BUFFER_RATIO 4
62#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
63#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
64
65#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
67/* WDI TX and RX PIPE */
68#define HDD_IPA_UC_NUM_WDI_PIPE 2
69#define HDD_IPA_UC_MAX_PENDING_EVENT 33
70
71#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
72#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
73#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
74#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
75
76#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
77#define HDD_IPA_MAX_IFACE 3
78#define HDD_IPA_MAX_SYSBAM_PIPE 4
79#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
80#define HDD_IPA_ENABLE_MASK BIT(0)
81#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
82#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
83#define HDD_IPA_RM_ENABLE_MASK BIT(3)
84#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
85#define HDD_IPA_UC_ENABLE_MASK BIT(5)
86#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
87#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
88
Yun Parkf19e07d2015-11-20 11:34:27 -080089#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
90
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091typedef enum {
92 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
93 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
94 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
95 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
96 HDD_IPA_UC_OPCODE_STATS = 4,
97 /* keep this last */
98 HDD_IPA_UC_OPCODE_MAX
99} hdd_ipa_uc_op_code;
100
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
107 */
108enum {
109 HDD_IPA_UC_STAT_REASON_NONE,
110 HDD_IPA_UC_STAT_REASON_DEBUG,
111 HDD_IPA_UC_STAT_REASON_BW_CAL
112};
113
114/**
115 * enum hdd_ipa_rm_state - IPA resource manager state
116 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
117 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
118 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
119 */
120enum hdd_ipa_rm_state {
121 HDD_IPA_RM_RELEASED,
122 HDD_IPA_RM_GRANT_PENDING,
123 HDD_IPA_RM_GRANTED,
124};
125
126struct llc_snap_hdr {
127 uint8_t dsap;
128 uint8_t ssap;
129 uint8_t resv[4];
130 __be16 eth_type;
131} __packed;
132
Leo Chang3bc8fed2015-11-13 10:59:47 -0800133/**
134 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
135 * @eth: ether II header
136 * @llc_snap: LLC snap header
137 *
138 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139struct hdd_ipa_tx_hdr {
140 struct ethhdr eth;
141 struct llc_snap_hdr llc_snap;
142} __packed;
143
Leo Chang3bc8fed2015-11-13 10:59:47 -0800144/**
145 * struct frag_header - fragment header type registered to IPA hardware
146 * @length: fragment length
147 * @reserved1: Reserved not used
148 * @reserved2: Reserved not used
149 *
150 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800152 uint16_t length;
153 uint32_t reserved1;
154 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155} __packed;
156
Leo Chang3bc8fed2015-11-13 10:59:47 -0800157/**
158 * struct ipa_header - ipa header type registered to IPA hardware
159 * @vdev_id: vdev id
160 * @reserved: Reserved not used
161 *
162 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800163struct ipa_header {
164 uint32_t
165 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
166 reserved:24;
167} __packed;
168
Leo Chang3bc8fed2015-11-13 10:59:47 -0800169/**
170 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
171 * @frag_hd: fragment header
172 * @ipa_hd: ipa header
173 * @eth: ether II header
174 *
175 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176struct hdd_ipa_uc_tx_hdr {
177 struct frag_header frag_hd;
178 struct ipa_header ipa_hd;
179 struct ethhdr eth;
180} __packed;
181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182/**
183 * struct hdd_ipa_cld_hdr - IPA CLD Header
184 * @reserved: reserved fields
185 * @iface_id: interface ID
186 * @sta_id: Station ID
187 *
188 * Packed 32-bit structure
189 * +----------+----------+--------------+--------+
190 * | Reserved | QCMAP ID | interface id | STA ID |
191 * +----------+----------+--------------+--------+
192 */
193struct hdd_ipa_cld_hdr {
194 uint8_t reserved[2];
195 uint8_t iface_id;
196 uint8_t sta_id;
197} __packed;
198
199struct hdd_ipa_rx_hdr {
200 struct hdd_ipa_cld_hdr cld_hdr;
201 struct ethhdr eth;
202} __packed;
203
204struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700205 bool exception;
206 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207 struct hdd_ipa_iface_context *iface_context;
208 struct ipa_rx_data *ipa_tx_desc;
209};
210
211struct hdd_ipa_uc_rx_hdr {
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_sys_pipe {
216 uint32_t conn_hdl;
217 uint8_t conn_hdl_valid;
218 struct ipa_sys_connect_params ipa_sys_params;
219};
220
221struct hdd_ipa_iface_stats {
222 uint64_t num_tx;
223 uint64_t num_tx_drop;
224 uint64_t num_tx_err;
225 uint64_t num_tx_cac_drop;
226 uint64_t num_rx_prefilter;
227 uint64_t num_rx_ipa_excep;
228 uint64_t num_rx_recv;
229 uint64_t num_rx_recv_mul;
230 uint64_t num_rx_send_desc_err;
231 uint64_t max_rx_mul;
232};
233
234struct hdd_ipa_priv;
235
236struct hdd_ipa_iface_context {
237 struct hdd_ipa_priv *hdd_ipa;
238 hdd_adapter_t *adapter;
239 void *tl_context;
240
241 enum ipa_client_type cons_client;
242 enum ipa_client_type prod_client;
243
244 uint8_t iface_id; /* This iface ID */
245 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530246 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 uint32_t ifa_address;
248 struct hdd_ipa_iface_stats stats;
249};
250
251struct hdd_ipa_stats {
252 uint32_t event[IPA_WLAN_EVENT_MAX];
253 uint64_t num_send_msg;
254 uint64_t num_free_msg;
255
256 uint64_t num_rm_grant;
257 uint64_t num_rm_release;
258 uint64_t num_rm_grant_imm;
259 uint64_t num_cons_perf_req;
260 uint64_t num_prod_perf_req;
261
262 uint64_t num_rx_drop;
263 uint64_t num_rx_ipa_tx_dp;
264 uint64_t num_rx_ipa_splice;
265 uint64_t num_rx_ipa_loop;
266 uint64_t num_rx_ipa_tx_dp_err;
267 uint64_t num_rx_ipa_write_done;
268 uint64_t num_max_ipa_tx_mul;
269 uint64_t num_rx_ipa_hw_maxed_out;
270 uint64_t max_pend_q_cnt;
271
272 uint64_t num_tx_comp_cnt;
273 uint64_t num_tx_queued;
274 uint64_t num_tx_dequeued;
275 uint64_t num_max_pm_queue;
276
277 uint64_t num_freeq_empty;
278 uint64_t num_pri_freeq_empty;
279 uint64_t num_rx_excep;
280 uint64_t num_tx_bcmc;
281 uint64_t num_tx_bcmc_err;
282};
283
284struct ipa_uc_stas_map {
285 bool is_reserved;
286 uint8_t sta_id;
287};
288struct op_msg_type {
289 uint8_t msg_t;
290 uint8_t rsvd;
291 uint16_t op_code;
292 uint16_t len;
293 uint16_t rsvd_snd;
294};
295
296struct ipa_uc_fw_stats {
297 uint32_t tx_comp_ring_base;
298 uint32_t tx_comp_ring_size;
299 uint32_t tx_comp_ring_dbell_addr;
300 uint32_t tx_comp_ring_dbell_ind_val;
301 uint32_t tx_comp_ring_dbell_cached_val;
302 uint32_t tx_pkts_enqueued;
303 uint32_t tx_pkts_completed;
304 uint32_t tx_is_suspend;
305 uint32_t tx_reserved;
306 uint32_t rx_ind_ring_base;
307 uint32_t rx_ind_ring_size;
308 uint32_t rx_ind_ring_dbell_addr;
309 uint32_t rx_ind_ring_dbell_ind_val;
310 uint32_t rx_ind_ring_dbell_ind_cached_val;
311 uint32_t rx_ind_ring_rdidx_addr;
312 uint32_t rx_ind_ring_rd_idx_cached_val;
313 uint32_t rx_refill_idx;
314 uint32_t rx_num_pkts_indicated;
315 uint32_t rx_buf_refilled;
316 uint32_t rx_num_ind_drop_no_space;
317 uint32_t rx_num_ind_drop_no_buf;
318 uint32_t rx_is_suspend;
319 uint32_t rx_reserved;
320};
321
322struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530323 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324 hdd_adapter_t *adapter;
325 enum ipa_wlan_event type;
326 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530327 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328};
329
330/**
331 * struct uc_rm_work_struct
332 * @work: uC RM work
333 * @event: IPA RM event
334 */
335struct uc_rm_work_struct {
336 struct work_struct work;
337 enum ipa_rm_event event;
338};
339
340/**
341 * struct uc_op_work_struct
342 * @work: uC OP work
343 * @msg: OP message
344 */
345struct uc_op_work_struct {
346 struct work_struct work;
347 struct op_msg_type *msg;
348};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800349
350/**
351 * struct uc_rt_debug_info
352 * @time: system time
353 * @ipa_excep_count: IPA exception packet count
354 * @rx_drop_count: IPA Rx drop packet count
355 * @net_sent_count: IPA Rx packet sent to network stack count
356 * @rx_discard_count: IPA Rx discard packet count
357 * @rx_mcbc_count: IPA Rx BCMC packet count
358 * @tx_mcbc_count: IPA Tx BCMC packet countt
359 * @tx_fwd_count: IPA Tx forward packet count
360 * @rx_destructor_call: IPA Rx packet destructor count
361 */
362struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530363 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 uint64_t ipa_excep_count;
365 uint64_t rx_drop_count;
366 uint64_t net_sent_count;
367 uint64_t rx_discard_count;
368 uint64_t rx_mcbc_count;
369 uint64_t tx_mcbc_count;
370 uint64_t tx_fwd_count;
371 uint64_t rx_destructor_call;
372};
373
374struct hdd_ipa_priv {
375 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
376 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
377 uint8_t num_iface;
378 enum hdd_ipa_rm_state rm_state;
379 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530380 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800381 * APIs as it is taken care gracefully. Without this, kernel would throw
382 * an warning if spin_lock_bh is used while IRQ is disabled
383 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530384 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800385 struct uc_rm_work_struct uc_rm_work;
386 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530387 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800388 struct delayed_work wake_lock_work;
389 bool wake_lock_released;
390
391 enum ipa_client_type prod_client;
392
393 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530394 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530396 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800397 bool suspended;
398
399 uint32_t pending_hw_desc_cnt;
400 uint32_t hw_desc_cnt;
401 spinlock_t q_lock;
402 uint32_t freeq_cnt;
403 struct list_head free_desc_head;
404
405 uint32_t pend_q_cnt;
406 struct list_head pend_desc_head;
407
408 hdd_context_t *hdd_ctx;
409
410 struct dentry *debugfs_dir;
411 struct hdd_ipa_stats stats;
412
413 struct notifier_block ipv4_notifier;
414 uint32_t curr_prod_bw;
415 uint32_t curr_cons_bw;
416
417 uint8_t activated_fw_pipe;
418 uint8_t sap_num_connected_sta;
419 uint8_t sta_connected;
420 uint32_t tx_pipe_handle;
421 uint32_t rx_pipe_handle;
422 bool resource_loading;
423 bool resource_unloading;
424 bool pending_cons_req;
425 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530426 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530427 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700428 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800429 uint32_t ipa_tx_packets_diff;
430 uint32_t ipa_rx_packets_diff;
431 uint32_t ipa_p_tx_packets;
432 uint32_t ipa_p_rx_packets;
433 uint32_t stat_req_reason;
434 uint64_t ipa_tx_forward;
435 uint64_t ipa_rx_discard;
436 uint64_t ipa_rx_net_send_count;
437 uint64_t ipa_rx_internel_drop_count;
438 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530439 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800440 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
441 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530442 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530443 qdf_mutex_t rt_debug_lock;
444 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800445 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800446 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530447 qdf_dma_addr_t tx_comp_doorbell_paddr;
448 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800449
450 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
451 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452};
453
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800454/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800455 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800456 * They will be implemented fully by another update.
457 * The stubs will let the compile go ahead, and functionality
458 * is broken.
459 * This should be OK and IPA is not enabled yet
460 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700461static void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800462{
463 void *vaddr;
464 uint32_t ipa_priv = priv;
465
466 vaddr = &ipa_priv; /* just to use the var */
467 vaddr = NULL;
468 return vaddr;
469}
470
Jeff Johnsond7720632016-10-05 16:04:32 -0700471static uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800472{
473 uint32_t ipa_priv = 0;
474
475 BUG_ON(ptr == NULL);
476 return ipa_priv;
477}
Leo Changcc923e22016-06-16 15:29:03 -0700478
479#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
480#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800481#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
482#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
483#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
484#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
485#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
486#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700487#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
488 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489
490#define HDD_IPA_GET_IFACE_ID(_data) \
491 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
492
493#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530494 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800495 "%s:%d: "fmt, __func__, __LINE__, ## args)
496
Govind Singhb6a89772016-08-12 11:23:35 +0530497#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
498 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
499 "%s:%d: "fmt, __func__, __LINE__, ## args)
500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
502 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530503 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
504 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800505 } while (0)
506
507#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
508 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
509
510#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
511 do { \
512 hdd_ipa->ipa_rx_internel_drop_count++; \
513 } while (0)
514#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
515 do { \
516 hdd_ipa->ipa_rx_net_send_count++; \
517 } while (0)
518#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
519
Leo Chang07b28f62016-05-11 12:29:22 -0700520#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800521#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
522do { \
523 pipe_in.u.ul.rdy_ring_rp_va = \
524 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
525 pipe_in.u.ul.rdy_comp_ring_base_pa = \
526 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
527 pipe_in.u.ul.rdy_comp_ring_size = \
528 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
529 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
530 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
531 pipe_in.u.ul.rdy_comp_ring_wp_va = \
532 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800533} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700534
535#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800536#else
537/* Do nothing */
538#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700539#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700540#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800542static struct hdd_ipa_adapter_2_client {
543 enum ipa_client_type cons_client;
544 enum ipa_client_type prod_client;
545} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
546 {
547 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
548 }, {
549 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
550 }, {
551 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
552 },
553};
554
555/* For Tx pipes, use Ethernet-II Header format */
556struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
557 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800558 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559 0x00000000,
560 0x00000000
561 },
562 {
563 0x00000000
564 },
565 {
566 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
567 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
568 0x0008
569 }
570};
571
572/* For Tx pipes, use 802.3 Header format */
573static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
574 {
575 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
576 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
577 0x00 /* length can be zero */
578 },
579 {
580 /* LLC SNAP header 8 bytes */
581 0xaa, 0xaa,
582 {0x03, 0x00, 0x00, 0x00},
583 0x0008 /* type value(2 bytes) ,filled by wlan */
584 /* 0x0800 - IPV4, 0x86dd - IPV6 */
585 }
586};
587
588static const char *op_string[] = {
589 "TX_SUSPEND",
590 "TX_RESUME",
591 "RX_SUSPEND",
592 "RX_RESUME",
593 "STATS",
594};
595
596static struct hdd_ipa_priv *ghdd_ipa;
597
598/* Local Function Prototypes */
599static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
600 unsigned long data);
601static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
602 unsigned long data);
603
604static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700605static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606
607/**
608 * hdd_ipa_is_enabled() - Is IPA enabled?
609 * @hdd_ctx: Global HDD context
610 *
611 * Return: true if IPA is enabled, false otherwise
612 */
613bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
614{
615 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
616}
617
618/**
619 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
620 * @hdd_ctx: Global HDD context
621 *
622 * Return: true if IPA uC offload is enabled, false otherwise
623 */
624bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
625{
626 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
627}
628
629/**
630 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
631 * @hdd_ctx: Global HDD context
632 *
633 * Return: true if STA mode IPA uC offload is enabled, false otherwise
634 */
635static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
636{
637 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
638}
639
640/**
Guolei Bianca144d82016-11-10 11:07:42 +0800641 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
642 * @hdd_ipa: Global HDD IPA context
643 *
644 * Return: None
645 */
646#ifdef IPA_UC_STA_OFFLOAD
647static inline void hdd_ipa_uc_sta_reset_sta_connected(
648 struct hdd_ipa_priv *hdd_ipa)
649{
650 vos_lock_acquire(&hdd_ipa->event_lock);
651 hdd_ipa->sta_connected = 0;
652 vos_lock_release(&hdd_ipa->event_lock);
653}
654#else
655static inline void hdd_ipa_uc_sta_reset_sta_connected(
656 struct hdd_ipa_priv *hdd_ipa)
657{
658}
659#endif
660
661/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800662 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
663 * @hdd_ipa: Global HDD IPA context
664 *
665 * Return: true if pre-filter is enabled, otherwise false
666 */
667static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
668{
669 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
670 HDD_IPA_PRE_FILTER_ENABLE_MASK);
671}
672
673/**
674 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
675 * @hdd_ipa: Global HDD IPA context
676 *
677 * Return: true if IPv6 is enabled, otherwise false
678 */
679static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
680{
681 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
682}
683
684/**
685 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
686 * @hdd_ipa: Global HDD IPA context
687 *
688 * Return: true if resource manager is enabled, otherwise false
689 */
690static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
691{
692 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
693}
694
695/**
696 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
697 * @hdd_ipa: Global HDD IPA context
698 *
699 * Return: true if resource manager is enabled, otherwise false
700 */
701static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
702{
703 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
704}
705
706/**
707 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
708 * @hdd_ipa: Global HDD IPA context
709 *
710 * Return: true if clock scaling is enabled, otherwise false
711 */
712static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
713{
714 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
715 HDD_IPA_CLK_SCALING_ENABLE_MASK |
716 HDD_IPA_RM_ENABLE_MASK);
717}
718
719/**
720 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
721 * @ctext: pointer to hdd context.
722 *
723 * If rt debug enabled, periodically called, and fill debug buffer
724 *
725 * Return: none
726 */
727static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
728{
729 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
730 struct hdd_ipa_priv *hdd_ipa;
731 struct uc_rt_debug_info *dump_info = NULL;
732
733 if (wlan_hdd_validate_context(hdd_ctx))
734 return;
735
736 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530737 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 "%s: IPA UC is not enabled", __func__);
739 return;
740 }
741
742 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
743
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530744 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 dump_info = &hdd_ipa->rt_bug_buffer[
746 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
747
Deepthi Gowri6acee342016-10-28 15:00:38 +0530748 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
750 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
751 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
752 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
753 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
754 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
755 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
756 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530757 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
Anurag Chouhan210db072016-02-22 18:42:15 +0530759 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
761}
762
763/**
764 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
765 * @hdd_ctx: pointer to hdd context.
766 *
767 * If rt debug enabled, dump debug buffer contents based on requirement
768 *
769 * Return: none
770 */
771void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
772{
773 struct hdd_ipa_priv *hdd_ipa;
774 unsigned int dump_count;
775 unsigned int dump_index;
776 struct uc_rt_debug_info *dump_info = NULL;
777
778 if (wlan_hdd_validate_context(hdd_ctx))
779 return;
780
781 hdd_ipa = hdd_ctx->hdd_ipa;
782 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530783 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 "%s: IPA UC is not enabled", __func__);
785 return;
786 }
787
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530788 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530790 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
792
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530793 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794 for (dump_count = 0;
795 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
796 dump_count++) {
797 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
798 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
799 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530800 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530801 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802 dump_info->time, dump_info->ipa_excep_count,
803 dump_info->rx_drop_count, dump_info->net_sent_count,
804 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
805 dump_info->rx_destructor_call,
806 dump_info->rx_discard_count);
807 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530808 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530809 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
811}
812
813/**
814 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
815 * @ctext: pointer to hdd context.
816 *
817 * periodically called by timer expire
818 * will try to alloc dummy memory and detect out of memory condition
819 * if out of memory detected, dump wlan-ipa stats
820 *
821 * Return: none
822 */
823static void hdd_ipa_uc_rt_debug_handler(void *ctext)
824{
825 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
826 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
827 void *dummy_ptr = NULL;
828
829 if (wlan_hdd_validate_context(hdd_ctx))
830 return;
831
832 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530833 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834 "%s: IPA RT debug is not enabled", __func__);
835 return;
836 }
837
838 /* Allocate dummy buffer periodically and free immediately. this will
839 * proactively detect OOM and if allocation fails dump ipa stats
840 */
841 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
842 GFP_KERNEL | GFP_ATOMIC);
843 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530844 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 "%s: Dummy alloc fail", __func__);
846 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
847 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800848 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800849 } else {
850 kfree(dummy_ptr);
851 }
852
Anurag Chouhan210db072016-02-22 18:42:15 +0530853 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 HDD_IPA_UC_RT_DEBUG_PERIOD);
855}
856
857/**
858 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
859 * @skb: packet pinter
860 *
861 * when free data packet, will be invoked by wlan client and will increase
862 * free counter
863 *
864 * Return: none
865 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700866static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867{
868 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530869 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 "%s: invalid hdd context", __func__);
871 return;
872 }
873
874 ghdd_ipa->ipa_rx_destructor_count++;
875}
876
877/**
878 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
879 * @hdd_ctx: hdd main context
880 *
881 * free all rt debugging resources
882 *
883 * Return: none
884 */
885static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
886{
887 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
888
Anurag Chouhan210db072016-02-22 18:42:15 +0530889 if (QDF_TIMER_STATE_STOPPED !=
890 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
891 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530893 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530894 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895
896 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530897 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898 "%s: IPA RT debug is not enabled", __func__);
899 return;
900 }
901
Anurag Chouhan210db072016-02-22 18:42:15 +0530902 if (QDF_TIMER_STATE_STOPPED !=
903 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
904 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530906 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907}
908
909/**
910 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
911 * @hdd_ctx: hdd main context
912 *
913 * alloc and initialize all rt debugging resources
914 *
915 * Return: none
916 */
917static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
918{
919 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
920
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530921 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800922 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530923 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 sizeof(struct uc_rt_debug_info) *
925 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
926 hdd_ipa->ipa_tx_forward = 0;
927 hdd_ipa->ipa_rx_discard = 0;
928 hdd_ipa->ipa_rx_net_send_count = 0;
929 hdd_ipa->ipa_rx_internel_drop_count = 0;
930 hdd_ipa->ipa_rx_destructor_count = 0;
931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800932 /* Reatime debug enable on feature enable */
933 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530934 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935 "%s: IPA RT debug is not enabled", __func__);
936 return;
937 }
Yun Parkdfc1da52016-11-15 14:50:11 -0800938
939 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
940 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
941 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
942 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
943
Anurag Chouhan210db072016-02-22 18:42:15 +0530944 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530946 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947 HDD_IPA_UC_RT_DEBUG_PERIOD);
948
949}
950
951/**
952 * hdd_ipa_uc_stat_query() - Query the IPA stats
953 * @hdd_ctx: Global HDD context
954 * @ipa_tx_diff: tx packet count diff from previous
955 * tx packet count
956 * @ipa_rx_diff: rx packet count diff from previous
957 * rx packet count
958 *
959 * Return: true if IPA is enabled, false otherwise
960 */
961void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
962 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
963{
964 struct hdd_ipa_priv *hdd_ipa;
965
966 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
967 *ipa_tx_diff = 0;
968 *ipa_rx_diff = 0;
969
970 if (!hdd_ipa_is_enabled(pHddCtx) ||
971 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
972 return;
973 }
974
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530975 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
977 (false == hdd_ipa->resource_loading)) {
978 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
979 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkf8d6a122016-10-11 15:49:43 -0700980 HDD_IPA_LOG(LOGOFF, "STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 *ipa_tx_diff, *ipa_rx_diff);
982 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530983 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 return;
985}
986
987/**
988 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
989 * @adapter: network adapter
990 * @reason: STAT REQ Reason
991 *
992 * Return: None
993 */
994void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
995{
996 hdd_context_t *pHddCtx;
997 struct hdd_ipa_priv *hdd_ipa;
998
999 if (!adapter) {
1000 return;
1001 }
1002
1003 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
1004 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
1005 if (!hdd_ipa_is_enabled(pHddCtx) ||
1006 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1007 return;
1008 }
1009
Yun Park8f289c82016-10-18 16:38:21 -07001010 HDD_IPA_LOG(LOGOFF, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301011 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1013 (false == hdd_ipa->resource_loading)) {
1014 hdd_ipa->stat_req_reason = reason;
1015 wma_cli_set_command(
1016 (int)adapter->sessionId,
1017 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
1018 0, VDEV_CMD);
1019 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301020 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021}
1022
1023/**
1024 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1025 * @hdd_ipa: Global HDD IPA context
1026 * @sta_add: Should station be added
1027 * @sta_id: ID of the station being queried
1028 *
1029 * Return: true if the station was found
1030 */
1031static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1032 bool sta_add, uint8_t sta_id)
1033{
1034 bool sta_found = false;
1035 uint8_t idx;
1036 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1037 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1038 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1039 sta_found = true;
1040 break;
1041 }
1042 }
1043 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301044 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045 "%s: STA ID %d already exist, cannot add",
1046 __func__, sta_id);
1047 return sta_found;
1048 }
1049 if (sta_add) {
1050 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1051 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1052 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1053 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1054 return sta_found;
1055 }
1056 }
1057 }
1058 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301059 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 "%s: STA ID %d does not exist, cannot delete",
1061 __func__, sta_id);
1062 return sta_found;
1063 }
1064 if (!sta_add) {
1065 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1066 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1067 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1068 hdd_ipa->assoc_stas_map[idx].is_reserved =
1069 false;
1070 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1071 return sta_found;
1072 }
1073 }
1074 }
1075 return sta_found;
1076}
1077
1078/**
1079 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1080 * @hdd_ipa: Global HDD IPA context
1081 *
1082 * Return: 0 on success, negative errno if error
1083 */
1084static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1085{
1086 int result;
1087 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001088 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001089
1090 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301091 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001092 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1093 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1095 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301096 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 "%s: Enable TX PIPE fail, code %d",
1098 __func__, result);
1099 return result;
1100 }
1101 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1102 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301103 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104 "%s: Resume TX PIPE fail, code %d",
1105 __func__, result);
1106 return result;
1107 }
Leo Changfdb45c32016-10-28 11:09:23 -07001108 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, true, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109
1110 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301111 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001112 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1113 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1115 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301116 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 "%s: Enable RX PIPE fail, code %d",
1118 __func__, result);
1119 return result;
1120 }
1121 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1122 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301123 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 "%s: Resume RX PIPE fail, code %d",
1125 __func__, result);
1126 return result;
1127 }
Leo Changfdb45c32016-10-28 11:09:23 -07001128 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001129 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001130 return 0;
1131}
1132
1133/**
1134 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1135 * @hdd_ipa: Global HDD IPA context
1136 *
1137 * Return: 0 on success, negative errno if error
1138 */
1139static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1140{
1141 int result;
1142
Leo Change3e49442015-10-26 20:07:13 -07001143 hdd_ipa->ipa_pipes_down = true;
1144
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301145 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1147 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301148 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001149 "%s: Suspend RX PIPE fail, code %d",
1150 __func__, result);
1151 return result;
1152 }
1153 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1154 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301155 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001156 "%s: Disable RX PIPE fail, code %d",
1157 __func__, result);
1158 return result;
1159 }
1160
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301161 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001162 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1163 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301164 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001165 "%s: Suspend TX PIPE fail, code %d",
1166 __func__, result);
1167 return result;
1168 }
1169 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1170 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301171 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 "%s: Disable TX PIPE fail, code %d",
1173 __func__, result);
1174 return result;
1175 }
1176
1177 return 0;
1178}
1179
1180/**
1181 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1182 * @hdd_ipa: Global HDD IPA context
1183 *
1184 * Return: 0 on success, negative errno if error
1185 */
1186static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1187{
1188 hdd_ipa->activated_fw_pipe = 0;
1189 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001191 /* If RM feature enabled
1192 * Request PROD Resource first
1193 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001194 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1195 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1196 /* RM PROD request sync return
1197 * enable pipe immediately
1198 */
1199 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301200 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001201 "%s: IPA WDI Pipe activation failed",
1202 __func__);
1203 hdd_ipa->resource_loading = false;
1204 return -EBUSY;
1205 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 }
1207 } else {
1208 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001209 * Just enabled all the PIPEs
1210 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001211 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301212 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001213 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 __func__);
1215 hdd_ipa->resource_loading = false;
1216 return -EBUSY;
1217 }
1218 hdd_ipa->resource_loading = false;
1219 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001220
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301221 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001222 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223 return 0;
1224}
1225
1226/**
1227 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1228 * @hdd_ipa: Global HDD IPA context
1229 *
1230 * Return: None
1231 */
1232static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1233{
1234 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001235 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236
1237 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301238 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Leo Changfdb45c32016-10-28 11:09:23 -07001239 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301240 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Leo Changfdb45c32016-10-28 11:09:23 -07001241 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242}
1243
1244/**
1245 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1246 * @context: User context registered with TL (the IPA Global context is
1247 * registered
1248 * @rxpkt: Packet containing the notification
1249 * @staid: ID of the station associated with the packet
1250 *
1251 * Return: None
1252 */
1253static void
1254hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1255{
1256 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301257 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258
1259 /*
1260 * When SSR is going on or driver is unloading, just return.
1261 */
1262 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301263 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265
1266 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1267 return;
1268
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301269 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001270 __func__, event);
1271
1272 switch (event) {
1273 case IPA_RM_RESOURCE_GRANTED:
1274 /* Differed RM Granted */
1275 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301276 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277 if ((false == hdd_ipa->resource_unloading) &&
1278 (!hdd_ipa->activated_fw_pipe)) {
1279 hdd_ipa_uc_enable_pipes(hdd_ipa);
1280 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301281 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001282 break;
1283
1284 case IPA_RM_RESOURCE_RELEASED:
1285 /* Differed RM Released */
1286 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001287 break;
1288
1289 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301290 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 "%s, invalid event code %d", __func__, event);
1292 break;
1293 }
1294}
1295
1296/**
1297 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1298 * @hdd_ipa: Global HDD IPA context
1299 * @event: IPA resource manager event to be deferred
1300 *
1301 * This function is called when a resource manager event is received
1302 * from firmware in interrupt context. This function will defer the
1303 * handling to the OL RX thread
1304 *
1305 * Return: None
1306 */
1307static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1308{
1309 enum ipa_rm_event event;
1310 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1311 struct uc_rm_work_struct, work);
1312 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1313 struct hdd_ipa_priv, uc_rm_work);
1314
1315 cds_ssr_protect(__func__);
1316 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301317 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001318 "%s, posted event %d", __func__, event);
1319
1320 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1321 cds_ssr_unprotect(__func__);
1322
1323 return;
1324}
1325
1326/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001327 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1328 * @op_msg: operation message received from firmware
1329 * @usr_ctxt: user context registered with TL (we register the HDD Global
1330 * context)
1331 *
1332 * Return: None
1333 */
1334static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1335{
1336 struct op_msg_type *msg = op_msg;
1337 struct ipa_uc_fw_stats *uc_fw_stat;
1338 struct IpaHwStatsWDIInfoData_t ipa_stat;
1339 struct hdd_ipa_priv *hdd_ipa;
1340 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301341 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342
1343 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301344 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345 return;
1346 }
1347
1348 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301349 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1351 return;
1352 }
1353
1354 hdd_ctx = (hdd_context_t *) usr_ctxt;
1355
1356 /*
1357 * When SSR is going on or driver is unloading, just return.
1358 */
1359 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301360 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301361 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 return;
1363 }
1364
1365 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1366
Govind Singhb6a89772016-08-12 11:23:35 +05301367 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1369
1370 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1371 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301372 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 hdd_ipa->activated_fw_pipe++;
1374 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1375 hdd_ipa->resource_loading = false;
1376 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001377 if (hdd_ipa->pending_cons_req)
1378 ipa_rm_notify_completion(
1379 IPA_RM_RESOURCE_GRANTED,
1380 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001381 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301383 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001384 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301386 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 hdd_ipa->activated_fw_pipe--;
1388 if (!hdd_ipa->activated_fw_pipe) {
1389 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001390 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1391 ipa_rm_release_resource(
1392 IPA_RM_RESOURCE_WLAN_PROD);
1393 /* Sync return success from IPA
1394 * Enable/resume all the PIPEs */
1395 hdd_ipa->resource_unloading = false;
1396 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1397 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301399 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001400 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001402 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301404 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001406 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 "CE RING SIZE: %d\n"
1408 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001409 (unsigned long long)res->ce_sr_base_paddr,
1410 res->ce_sr_ring_size,
1411 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301412 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001414 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 "COMP RING SIZE: %d\n"
1416 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001417 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001418 (unsigned long long)res->tx_comp_ring_base_paddr,
1419 res->tx_comp_ring_size,
1420 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001421 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301422 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001423 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001424 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001425 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001426 "IND RING DBELL : 0x%llx\n"
1427 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 "NUM EXCP PKT : %llu\n"
1429 "NUM TX BCMC : %llu\n"
1430 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001431 (unsigned long long)res->rx_rdy_ring_base_paddr,
1432 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001433 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001434 (unsigned long long)hdd_ipa->ipa_resource.
1435 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 hdd_ipa->stats.num_rx_excep,
1437 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001438 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301439 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1441 "SAP NUM STAs: %d\n"
1442 "STA CONNECTED: %d\n"
1443 "TX PIPE HDL: %d\n"
1444 "RX PIPE HDL : %d\n"
1445 "RSC LOADING : %d\n"
1446 "RSC UNLOADING : %d\n"
1447 "PNDNG CNS RQT : %d",
1448 hdd_ipa->sap_num_connected_sta,
1449 hdd_ipa->sta_connected,
1450 hdd_ipa->tx_pipe_handle,
1451 hdd_ipa->rx_pipe_handle,
1452 (unsigned int)hdd_ipa->resource_loading,
1453 (unsigned int)hdd_ipa->resource_unloading,
1454 (unsigned int)hdd_ipa->pending_cons_req);
1455
1456 /* STATs from FW */
1457 uc_fw_stat = (struct ipa_uc_fw_stats *)
1458 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301459 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 "==== IPA_UC WLAN_FW TX ====\n"
1461 "COMP RING BASE: 0x%x\n"
1462 "COMP RING SIZE: %d\n"
1463 "COMP RING DBELL : 0x%x\n"
1464 "COMP RING DBELL IND VAL : %d\n"
1465 "COMP RING DBELL CACHED VAL : %d\n"
1466 "COMP RING DBELL CACHED VAL : %d\n"
1467 "PKTS ENQ : %d\n"
1468 "PKTS COMP : %d\n"
1469 "IS SUSPEND : %d\n"
1470 "RSVD : 0x%x",
1471 uc_fw_stat->tx_comp_ring_base,
1472 uc_fw_stat->tx_comp_ring_size,
1473 uc_fw_stat->tx_comp_ring_dbell_addr,
1474 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1475 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1476 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1477 uc_fw_stat->tx_pkts_enqueued,
1478 uc_fw_stat->tx_pkts_completed,
1479 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301480 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481 "==== IPA_UC WLAN_FW RX ====\n"
1482 "IND RING BASE: 0x%x\n"
1483 "IND RING SIZE: %d\n"
1484 "IND RING DBELL : 0x%x\n"
1485 "IND RING DBELL IND VAL : %d\n"
1486 "IND RING DBELL CACHED VAL : %d\n"
1487 "RDY IND ADDR : 0x%x\n"
1488 "RDY IND CACHE VAL : %d\n"
1489 "RFIL IND : %d\n"
1490 "NUM PKT INDICAT : %d\n"
1491 "BUF REFIL : %d\n"
1492 "NUM DROP NO SPC : %d\n"
1493 "NUM DROP NO BUF : %d\n"
1494 "IS SUSPND : %d\n"
1495 "RSVD : 0x%x\n",
1496 uc_fw_stat->rx_ind_ring_base,
1497 uc_fw_stat->rx_ind_ring_size,
1498 uc_fw_stat->rx_ind_ring_dbell_addr,
1499 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1500 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1501 uc_fw_stat->rx_ind_ring_rdidx_addr,
1502 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1503 uc_fw_stat->rx_refill_idx,
1504 uc_fw_stat->rx_num_pkts_indicated,
1505 uc_fw_stat->rx_buf_refilled,
1506 uc_fw_stat->rx_num_ind_drop_no_space,
1507 uc_fw_stat->rx_num_ind_drop_no_buf,
1508 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1509 /* STATs from IPA */
1510 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301511 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512 "==== IPA_UC IPA TX ====\n"
1513 "NUM PROCD : %d\n"
1514 "CE DBELL : 0x%x\n"
1515 "NUM DBELL FIRED : %d\n"
1516 "COMP RNG FULL : %d\n"
1517 "COMP RNG EMPT : %d\n"
1518 "COMP RNG USE HGH : %d\n"
1519 "COMP RNG USE LOW : %d\n"
1520 "BAM FIFO FULL : %d\n"
1521 "BAM FIFO EMPT : %d\n"
1522 "BAM FIFO USE HGH : %d\n"
1523 "BAM FIFO USE LOW : %d\n"
1524 "NUM DBELL : %d\n"
1525 "NUM UNEXP DBELL : %d\n"
1526 "NUM BAM INT HDL : 0x%x\n"
1527 "NUM BAM INT NON-RUN : 0x%x\n"
1528 "NUM QMB INT HDL : 0x%x",
1529 ipa_stat.tx_ch_stats.num_pkts_processed,
1530 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1531 ipa_stat.tx_ch_stats.num_db_fired,
1532 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1533 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1534 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1535 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1536 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1537 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1538 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1539 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1540 ipa_stat.tx_ch_stats.num_db,
1541 ipa_stat.tx_ch_stats.num_unexpected_db,
1542 ipa_stat.tx_ch_stats.num_bam_int_handled,
1543 ipa_stat.tx_ch_stats.
1544 num_bam_int_in_non_runnning_state,
1545 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1546
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301547 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548 "==== IPA_UC IPA RX ====\n"
1549 "MAX OST PKT : %d\n"
1550 "NUM PKT PRCSD : %d\n"
1551 "RNG RP : 0x%x\n"
1552 "COMP RNG FULL : %d\n"
1553 "COMP RNG EMPT : %d\n"
1554 "COMP RNG USE HGH : %d\n"
1555 "COMP RNG USE LOW : %d\n"
1556 "BAM FIFO FULL : %d\n"
1557 "BAM FIFO EMPT : %d\n"
1558 "BAM FIFO USE HGH : %d\n"
1559 "BAM FIFO USE LOW : %d\n"
1560 "NUM DB : %d\n"
1561 "NUM UNEXP DB : %d\n"
1562 "NUM BAM INT HNDL : 0x%x\n",
1563 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1564 ipa_stat.rx_ch_stats.num_pkts_processed,
1565 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1566 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1567 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1568 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1569 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1570 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1571 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1572 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1573 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1574 ipa_stat.rx_ch_stats.num_db,
1575 ipa_stat.rx_ch_stats.num_unexpected_db,
1576 ipa_stat.rx_ch_stats.num_bam_int_handled);
1577 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1578 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1579 /* STATs from FW */
1580 uc_fw_stat = (struct ipa_uc_fw_stats *)
1581 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301582 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001583 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1584 uc_fw_stat->tx_pkts_completed,
1585 hdd_ipa->ipa_p_tx_packets);
1586 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1587 (uc_fw_stat->rx_num_ind_drop_no_space +
1588 uc_fw_stat->rx_num_ind_drop_no_buf +
1589 uc_fw_stat->rx_num_pkts_indicated),
1590 hdd_ipa->ipa_p_rx_packets);
1591
1592 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1593 hdd_ipa->ipa_p_rx_packets =
1594 (uc_fw_stat->rx_num_ind_drop_no_space +
1595 uc_fw_stat->rx_num_ind_drop_no_buf +
1596 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301597 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 } else {
Yun Park8292dcb2016-10-07 16:46:06 -07001599 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
1600 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001601 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301602 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603}
1604
1605
1606/**
1607 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1608 * @adapter: device adapter instance
1609 * @offload_type: MCC or SCC
1610 * @enable: TX offload enable or disable
1611 *
1612 * Return: none
1613 */
1614static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001615 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001617 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07001619 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001620 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001622 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 return;
1624
Yun Park8292dcb2016-10-07 16:46:06 -07001625 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001626 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07001627
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001628 if (!iface_context) {
1629 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1630 "Interface context is NULL");
1631 return;
1632 }
1633
1634 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07001635 /* IPA offload status is already set as desired */
1636 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001637 "%s: (offload_type=%d, vdev_id=%d, enable=%d)",
1638 "IPA offload status is already set",
1639 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001640 return;
1641 }
1642
Yun Park4540e862016-11-10 16:30:06 -08001643 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
1644 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1645 "invalid session id: %d, offload_type=%d, enable=%d",
1646 adapter->sessionId, offload_type, enable);
1647 return;
1648 }
1649
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301650 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 sizeof(ipa_offload_enable_disable));
1652 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001653 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654 ipa_offload_enable_disable.enable = enable;
1655
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301656 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001657 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 ipa_offload_enable_disable.offload_type,
1659 ipa_offload_enable_disable.vdev_id,
1660 ipa_offload_enable_disable.enable);
1661
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301662 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1664 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301665 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001666 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
1667 __func__,
1668 ipa_offload_enable_disable.offload_type,
1669 ipa_offload_enable_disable.vdev_id,
1670 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001671 } else {
1672 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08001673 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07001674 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001675 }
1676}
1677
1678/**
1679 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1680 * @work: uC OP work
1681 *
1682 * Return: None
1683 */
1684static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1685{
1686 struct op_msg_type *msg;
1687 struct uc_op_work_struct *uc_op_work = container_of(work,
1688 struct uc_op_work_struct, work);
1689 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1690
1691 cds_ssr_protect(__func__);
1692
1693 msg = uc_op_work->msg;
1694 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301695 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696 "%s, posted msg %d", __func__, msg->op_code);
1697
1698 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1699
1700 cds_ssr_unprotect(__func__);
1701
1702 return;
1703}
1704
1705/**
1706 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1707 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1708 * @op_msg: operation message received from firmware
1709 * @hdd_ctx: Global HDD context
1710 *
1711 * Return: None
1712 */
1713static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1714{
1715 struct hdd_ipa_priv *hdd_ipa;
1716 struct op_msg_type *msg;
1717 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301718 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719
1720 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301721 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723
1724 msg = (struct op_msg_type *)op_msg;
1725 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1726
1727 if (unlikely(!hdd_ipa))
1728 goto end;
1729
1730 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301731 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 __func__, msg->op_code);
1733 goto end;
1734 }
1735
1736 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1737 if (uc_op_work->msg)
1738 /* When the same uC OPCODE is already pended, just return */
1739 goto end;
1740
1741 uc_op_work->msg = msg;
1742 schedule_work(&uc_op_work->work);
1743 return;
1744
1745end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301746 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747}
1748
1749/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001750 * hdd_ipa_init_uc_op_work - init ipa uc op work
1751 * @work: struct work_struct
1752 * @work_handler: work_handler
1753 *
1754 * Return: none
1755 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001756static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1757 work_func_t work_handler)
1758{
1759 INIT_WORK(work, work_handler);
1760}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001761
1762
1763/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001764 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1765 * @hdd_ctx: Global HDD context
1766 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301767 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301769static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770{
1771 struct ipa_wdi_in_params pipe_in;
1772 struct ipa_wdi_out_params pipe_out;
1773 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1774 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1775 uint8_t i;
Leo Changfdb45c32016-10-28 11:09:23 -07001776 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001777
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301778 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1779 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780
Anurag Chouhanffb21542016-02-17 14:33:03 +05301781 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301782 qdf_mutex_create(&ipa_ctxt->event_lock);
1783 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784
1785 /* TX PIPE */
1786 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1787 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1788 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1789 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1790 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1791 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1792 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1793 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1794 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1795 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1796 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1797 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1798 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301799 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001800 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1801 pipe_in.sys.keep_ipa_awake = true;
1802 }
1803
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001804 pipe_in.u.dl.comp_ring_base_pa =
1805 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001806 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001807 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1808 sizeof(qdf_dma_addr_t);
1809 pipe_in.u.dl.ce_ring_base_pa =
1810 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1811 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1812 pipe_in.u.dl.ce_ring_size =
1813 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1814 pipe_in.u.dl.num_tx_buffers =
1815 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001816
1817 /* Connect WDI IPA PIPE */
1818 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1819 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301820 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1821 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1822 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1823 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001824 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 /* WLAN TX PIPE Handle */
1826 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301827 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1829 " CERZ %d, NB %d, CDBPAD 0x%x",
1830 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1831 pipe_in.u.dl.comp_ring_size,
1832 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1833 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1834 pipe_in.u.dl.ce_ring_size,
1835 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001836 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001837
1838 /* RX PIPE */
1839 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1840 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1841 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1842 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1843 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1844 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1845 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1846 sizeof(struct sps_iovec);
1847 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1848 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301849 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1851 pipe_in.sys.keep_ipa_awake = true;
1852 }
1853
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001854 pipe_in.u.ul.rdy_ring_base_pa =
1855 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1856 pipe_in.u.ul.rdy_ring_size =
1857 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1858 pipe_in.u.ul.rdy_ring_rp_pa =
1859 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001860 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001862 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301864 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001865 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1866 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1867 pipe_in.u.ul.rdy_ring_size,
1868 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001869 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870
Leo Changfdb45c32016-10-28 11:09:23 -07001871 cdp_ipa_set_doorbell_paddr(soc, cds_ctx->pdev_txrx_ctx,
1872 ipa_ctxt->tx_comp_doorbell_paddr,
1873 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874
Leo Changfdb45c32016-10-28 11:09:23 -07001875 cdp_ipa_register_op_cb(soc, cds_ctx->pdev_txrx_ctx,
1876 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877
1878 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001879 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880 hdd_ipa_uc_fw_op_event_handler);
1881 ipa_ctxt->uc_op_work[i].msg = NULL;
1882 }
1883
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301884 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885}
1886
Leo Change3e49442015-10-26 20:07:13 -07001887/**
1888 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1889 * @hdd_ctx: hdd main context
1890 *
1891 * Force shutdown IPA pipe
1892 * Independent of FW pipe status, IPA pipe shutdonw progress
1893 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1894 * independent from FW pipe status
1895 *
1896 * Return: NONE
1897 */
1898void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1899{
1900 struct hdd_ipa_priv *hdd_ipa;
1901
1902 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1903 return;
1904
1905 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1906 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301907 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001908 "IPA pipes are not down yet, force shutdown");
1909 hdd_ipa_uc_disable_pipes(hdd_ipa);
1910 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301911 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001912 "IPA pipes are down, do nothing");
1913 }
1914
1915 return;
1916}
1917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918/**
Govind Singh9c58eba2016-09-02 16:23:06 +05301919 * hdd_ipa_msg_free_fn() - Free an IPA message
1920 * @buff: pointer to the IPA message
1921 * @len: length of the IPA message
1922 * @type: type of IPA message
1923 *
1924 * Return: None
1925 */
1926static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
1927{
1928 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "msg type:%d, len:%d", type, len);
1929 ghdd_ipa->stats.num_free_msg++;
1930 qdf_mem_free(buff);
1931}
1932
1933
1934/**
1935 * hdd_ipa_send_disconnect() - ipa send disconnect clients
1936 * adapter: pointer to hdd adapter
1937 * Send disconnect evnt to IPA driver during SSR
1938 *
1939 * Return: 0 - Success
1940 */
1941static int hdd_ipa_send_disconnect(hdd_adapter_t *adapter)
1942{
1943 struct ipa_msg_meta meta;
1944 struct ipa_wlan_msg *msg;
1945 int ret = 0;
1946 int i;
1947
1948 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
1949 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
1950 continue;
1951 if ((adapter->aStaInfo[i].isUsed) &&
1952 (!adapter->aStaInfo[i].isDeauthInProgress)) {
1953 meta.msg_len = sizeof(struct ipa_wlan_msg);
1954 msg = qdf_mem_malloc(meta.msg_len);
1955 if (msg == NULL) {
1956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1957 "msg allocation failed");
1958 return -ENOMEM;
1959 }
1960 meta.msg_type = WLAN_CLIENT_DISCONNECT;
1961 strlcpy(msg->name, adapter->dev->name,
1962 IPA_RESOURCE_NAME_MAX);
1963 memcpy(msg->mac_addr, adapter->aStaInfo[i].macAddrSTA.bytes,
1964 ETH_ALEN);
1965 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
1966 msg->name, meta.msg_type);
1967 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
1968 if (ret) {
1969 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1970 "%s: Evt: %d fail:%d",
1971 msg->name, meta.msg_type, ret);
1972 qdf_mem_free(msg);
1973 return ret;
1974 }
1975 }
1976 }
1977
1978 return ret;
1979}
1980
1981/**
1982 * hdd_ipa_uc_disconnect_client() - disconnect ipa sap clients
1983 * hdd_ctx: pointer to hdd context
1984 * Send disconnect evnt to IPA driver during SSR
1985 *
1986 * Return: 0 - Success
1987 */
1988static int hdd_ipa_uc_disconnect_client(hdd_context_t *hdd_ctx)
1989{
1990 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
1991 QDF_STATUS status;
1992 hdd_adapter_t *adapter;
1993 int ret = 0;
1994
1995
1996 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1997 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
1998 adapter = adapter_node->pAdapter;
1999 if (adapter->device_mode == QDF_SAP_MODE)
2000 hdd_ipa_send_disconnect(adapter);
2001 status = hdd_get_next_adapter(
2002 hdd_ctx, adapter_node, &next);
2003 adapter_node = next;
2004 }
2005
2006 return ret;
2007}
2008
2009/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002010 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
2011 *
2012 * Deinit basic IPA UC host side to be in sync reloaded FW during
2013 * SSR
2014 *
2015 * Return: 0 - Success
2016 */
2017int hdd_ipa_uc_ssr_deinit(void)
2018{
2019 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2020 int idx;
2021 struct hdd_ipa_iface_context *iface_context;
2022
Leo Chang3bc8fed2015-11-13 10:59:47 -08002023 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 return 0;
2025
Govind Singh9c58eba2016-09-02 16:23:06 +05302026 /* send disconnect to ipa driver for connected clients */
2027 hdd_ipa_uc_disconnect_client(hdd_ipa->hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 /* Clean up HDD IPA interfaces */
2029 for (idx = 0; (hdd_ipa->num_iface > 0) &&
2030 (idx < HDD_IPA_MAX_IFACE); idx++) {
2031 iface_context = &hdd_ipa->iface_context[idx];
2032 if (iface_context && iface_context->adapter)
2033 hdd_ipa_cleanup_iface(iface_context);
2034 }
2035
2036 /* After SSR, wlan driver reloads FW again. But we need to protect
2037 * IPA submodule during SSR transient state. So deinit basic IPA
2038 * UC host side to be in sync with reloaded FW during SSR
2039 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08002040 if (!hdd_ipa->ipa_pipes_down)
2041 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302043 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
2045 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
2046 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
2047 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302048 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002049
Guolei Bianca144d82016-11-10 11:07:42 +08002050 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
2051 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
2052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002053 /* Full IPA driver cleanup not required since wlan driver is now
2054 * unloaded and reloaded after SSR.
2055 */
2056 return 0;
2057}
2058
2059/**
2060 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
2061 *
2062 * Init basic IPA UC host side to be in sync with reloaded FW after
2063 * SSR to resume IPA UC operations
2064 *
2065 * Return: 0 - Success
2066 */
2067int hdd_ipa_uc_ssr_reinit(void)
2068{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002069
2070 /* After SSR is complete, IPA UC can resume operation. But now wlan
2071 * driver will be unloaded and reloaded, which takes care of IPA cleanup
2072 * and initialization. This is a placeholder func if IPA has to resume
2073 * operations without driver reload.
2074 */
2075 return 0;
2076}
Leo Chang3bc8fed2015-11-13 10:59:47 -08002077
2078/**
2079 * hdd_ipa_tx_packet_ipa() - send packet to IPA
2080 * @hdd_ctx: Global HDD context
2081 * @skb: skb sent to IPA
2082 * @session_id: send packet instance session id
2083 *
2084 * Send TX packet which generated by system to IPA.
2085 * This routine only will be used for function verification
2086 *
2087 * Return: NULL packet sent to IPA properly
2088 * NULL invalid packet drop
2089 * skb packet not sent to IPA. legacy data path should handle
2090 */
2091struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
2092 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07002093{
Leo Chang3bc8fed2015-11-13 10:59:47 -08002094 struct ipa_header *ipa_header;
2095 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07002096 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002097
2098 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2099 return skb;
2100
Leo Chang07b28f62016-05-11 12:29:22 -07002101 if (!hdd_ipa)
2102 return skb;
2103
2104 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
2105 return skb;
2106
Leo Changcc923e22016-06-16 15:29:03 -07002107 if (skb_headroom(skb) <
2108 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07002109 return skb;
2110
Leo Chang3bc8fed2015-11-13 10:59:47 -08002111 ipa_header = (struct ipa_header *) skb_push(skb,
2112 sizeof(struct ipa_header));
2113 if (!ipa_header) {
2114 /* No headroom, legacy */
2115 return skb;
2116 }
2117 memset(ipa_header, 0, sizeof(*ipa_header));
2118 ipa_header->vdev_id = 0;
2119
2120 frag_header = (struct frag_header *) skb_push(skb,
2121 sizeof(struct frag_header));
2122 if (!frag_header) {
2123 /* No headroom, drop */
2124 kfree_skb(skb);
2125 return NULL;
2126 }
2127 memset(frag_header, 0, sizeof(*frag_header));
2128 frag_header->length = skb->len - sizeof(struct frag_header)
2129 - sizeof(struct ipa_header);
2130
2131 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2132 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002133}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134
2135/**
2136 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2137 * @work: scheduled work
2138 *
2139 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2140 * not want to immediately release the wake lock since the system
2141 * would then potentially try to suspend when there is a healthy data
2142 * rate. Deferred work is scheduled and this function handles the
2143 * work. When this function is called, if the IPA resource is still
2144 * released then we release the wake lock.
2145 *
2146 * Return: None
2147 */
2148static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2149{
2150 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2151 struct hdd_ipa_priv,
2152 wake_lock_work);
2153
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302154 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002155
2156 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2157 goto end;
2158
2159 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302160 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002161 WIFI_POWER_EVENT_WAKELOCK_IPA);
2162
2163end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302164 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002165}
2166
2167/**
2168 * hdd_ipa_rm_request() - Request resource from IPA
2169 * @hdd_ipa: Global HDD IPA context
2170 *
2171 * Return: 0 on success, negative errno on error
2172 */
2173static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2174{
2175 int ret = 0;
2176
2177 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2178 return 0;
2179
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302180 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002181
2182 switch (hdd_ipa->rm_state) {
2183 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302184 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002185 return 0;
2186 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302187 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188 return -EINPROGRESS;
2189 case HDD_IPA_RM_RELEASED:
2190 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2191 break;
2192 }
2193
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302194 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002195
2196 ret = ipa_rm_inactivity_timer_request_resource(
2197 IPA_RM_RESOURCE_WLAN_PROD);
2198
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302199 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002200 if (ret == 0) {
2201 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2202 hdd_ipa->stats.num_rm_grant_imm++;
2203 }
2204
2205 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2206 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302207 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002208 WIFI_POWER_EVENT_WAKELOCK_IPA);
2209 hdd_ipa->wake_lock_released = false;
2210 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302211 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002212
2213 return ret;
2214}
2215
2216/**
2217 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2218 * @hdd_ipa: Global HDD IPA context
2219 *
2220 * Return: 0 if resources released, negative errno otherwise
2221 */
2222static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2223{
2224 int ret = 0;
2225
2226 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2227 return 0;
2228
2229 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2230 return -EAGAIN;
2231
2232 spin_lock_bh(&hdd_ipa->q_lock);
2233 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2234 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2235 spin_unlock_bh(&hdd_ipa->q_lock);
2236 return -EAGAIN;
2237 }
2238 spin_unlock_bh(&hdd_ipa->q_lock);
2239
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302240 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241
Nirav Shahcbc6d722016-03-01 16:24:53 +05302242 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302243 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002244 return -EAGAIN;
2245 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302246 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002247
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302248 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002249 switch (hdd_ipa->rm_state) {
2250 case HDD_IPA_RM_GRANTED:
2251 break;
2252 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302253 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002254 return -EINPROGRESS;
2255 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302256 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002257 return 0;
2258 }
2259
2260 /* IPA driver returns immediately so set the state here to avoid any
2261 * race condition.
2262 */
2263 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2264 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302265 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002266
2267 ret =
2268 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2269
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302270 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002271 if (unlikely(ret != 0)) {
2272 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2273 WARN_ON(1);
2274 }
2275
2276 /*
2277 * If wake_lock is released immediately, kernel would try to suspend
2278 * immediately as well, Just avoid ping-pong between suspend-resume
2279 * while there is healthy amount of data transfer going on by
2280 * releasing the wake_lock after some delay.
2281 */
2282 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2283 msecs_to_jiffies
2284 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2285
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302286 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002287
2288 return ret;
2289}
2290
2291/**
2292 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2293 * @user_data: user data registered with IPA
2294 * @event: the IPA resource manager event that occurred
2295 * @data: the data associated with the event
2296 *
2297 * Return: None
2298 */
2299static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2300 unsigned long data)
2301{
2302 struct hdd_ipa_priv *hdd_ipa = user_data;
2303
2304 if (unlikely(!hdd_ipa))
2305 return;
2306
2307 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2308 return;
2309
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302310 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002311
2312 switch (event) {
2313 case IPA_RM_RESOURCE_GRANTED:
2314 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2315 /* RM Notification comes with ISR context
2316 * it should be serialized into work queue to avoid
2317 * ISR sleep problem
2318 */
2319 hdd_ipa->uc_rm_work.event = event;
2320 schedule_work(&hdd_ipa->uc_rm_work.work);
2321 break;
2322 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302323 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002324 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302325 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002326 hdd_ipa->stats.num_rm_grant++;
2327 break;
2328
2329 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302330 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002331 hdd_ipa->resource_unloading = false;
2332 break;
2333
2334 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302335 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002336 break;
2337 }
2338}
2339
2340/**
2341 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2342 *
2343 * Callback function registered with IPA that is called when IPA wants
2344 * to release the WLAN consumer resource
2345 *
2346 * Return: 0 if the request is granted, negative errno otherwise
2347 */
2348static int hdd_ipa_rm_cons_release(void)
2349{
2350 return 0;
2351}
2352
2353/**
2354 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2355 *
2356 * Callback function registered with IPA that is called when IPA wants
2357 * to access the WLAN consumer resource
2358 *
2359 * Return: 0 if the request is granted, negative errno otherwise
2360 */
2361static int hdd_ipa_rm_cons_request(void)
2362{
Yun Park4d8b60a2015-10-22 13:59:32 -07002363 int ret = 0;
2364
2365 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302366 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002367 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 __func__);
2369 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002370 ret = -EINPROGRESS;
2371 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302372 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002373 "%s: IPA resource unloading in progress",
2374 __func__);
2375 ghdd_ipa->pending_cons_req = true;
2376 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002377 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002378
2379 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002380}
2381
2382/**
2383 * hdd_ipa_set_perf_level() - Set IPA performance level
2384 * @hdd_ctx: Global HDD context
2385 * @tx_packets: Number of packets transmitted in the last sample period
2386 * @rx_packets: Number of packets received in the last sample period
2387 *
2388 * Return: 0 on success, negative errno on error
2389 */
2390int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2391 uint64_t rx_packets)
2392{
2393 uint32_t next_cons_bw, next_prod_bw;
2394 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2395 struct ipa_rm_perf_profile profile;
2396 int ret;
2397
2398 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2399 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2400 return 0;
2401
2402 memset(&profile, 0, sizeof(profile));
2403
2404 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2405 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2406 else if (tx_packets >
2407 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2408 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2409 else
2410 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2411
2412 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2413 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2414 else if (rx_packets >
2415 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2416 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2417 else
2418 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2419
Yun Park8f289c82016-10-18 16:38:21 -07002420 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002421 "CONS perf curr: %d, next: %d",
2422 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Park8f289c82016-10-18 16:38:21 -07002423 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002424 "PROD perf curr: %d, next: %d",
2425 hdd_ipa->curr_prod_bw, next_prod_bw);
2426
2427 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302428 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 "Requesting CONS perf curr: %d, next: %d",
2430 hdd_ipa->curr_cons_bw, next_cons_bw);
2431 profile.max_supported_bandwidth_mbps = next_cons_bw;
2432 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2433 &profile);
2434 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302435 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436 "RM CONS set perf profile failed: %d", ret);
2437
2438 return ret;
2439 }
2440 hdd_ipa->curr_cons_bw = next_cons_bw;
2441 hdd_ipa->stats.num_cons_perf_req++;
2442 }
2443
2444 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302445 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002446 "Requesting PROD perf curr: %d, next: %d",
2447 hdd_ipa->curr_prod_bw, next_prod_bw);
2448 profile.max_supported_bandwidth_mbps = next_prod_bw;
2449 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2450 &profile);
2451 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302452 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002453 "RM PROD set perf profile failed: %d", ret);
2454 return ret;
2455 }
2456 hdd_ipa->curr_prod_bw = next_prod_bw;
2457 hdd_ipa->stats.num_prod_perf_req++;
2458 }
2459
2460 return 0;
2461}
2462
2463/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002464 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2465 * @work: struct work_struct
2466 * @work_handler: work_handler
2467 *
2468 * Return: none
2469 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002470static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2471 work_func_t work_handler)
2472{
2473 INIT_WORK(work, work_handler);
2474}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002475
2476/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002477 * hdd_ipa_setup_rm() - Setup IPA resource management
2478 * @hdd_ipa: Global HDD IPA context
2479 *
2480 * Return: 0 on success, negative errno on error
2481 */
2482static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2483{
2484 struct ipa_rm_create_params create_params = { 0 };
2485 int ret;
2486
2487 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2488 return 0;
2489
Rajeev Kumar217f2172016-01-06 18:11:55 -08002490 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2491 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002492 memset(&create_params, 0, sizeof(create_params));
2493 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2494 create_params.reg_params.user_data = hdd_ipa;
2495 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2496 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2497
2498 ret = ipa_rm_create_resource(&create_params);
2499 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302500 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002501 "Create RM resource failed: %d", ret);
2502 goto setup_rm_fail;
2503 }
2504
2505 memset(&create_params, 0, sizeof(create_params));
2506 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2507 create_params.request_resource = hdd_ipa_rm_cons_request;
2508 create_params.release_resource = hdd_ipa_rm_cons_release;
2509 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2510
2511 ret = ipa_rm_create_resource(&create_params);
2512 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302513 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002514 "Create RM CONS resource failed: %d", ret);
2515 goto delete_prod;
2516 }
2517
2518 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2519 IPA_RM_RESOURCE_APPS_CONS);
2520
2521 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2522 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2523 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302524 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002525 ret);
2526 goto timer_init_failed;
2527 }
2528
2529 /* Set the lowest bandwidth to start with */
2530 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2531
2532 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302533 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002534 "Set perf level failed: %d", ret);
2535 goto set_perf_failed;
2536 }
2537
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302538 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002539 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2540 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302541 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002542 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2543 hdd_ipa->wake_lock_released = true;
2544 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2545
2546 return ret;
2547
2548set_perf_failed:
2549 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2550
2551timer_init_failed:
2552 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2553
2554delete_prod:
2555 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2556
2557setup_rm_fail:
2558 return ret;
2559}
2560
2561/**
2562 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2563 * @hdd_ipa: Global HDD IPA context
2564 *
2565 * Destroys all resources associated with the IPA resource manager
2566 *
2567 * Return: None
2568 */
2569static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2570{
2571 int ret;
2572
2573 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2574 return;
2575
2576 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302577 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578
2579#ifdef WLAN_OPEN_SOURCE
2580 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2581#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302582 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583
2584 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2585
2586 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2587 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302588 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002589 "RM PROD resource delete failed %d", ret);
2590
2591 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2592 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302593 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594 "RM CONS resource delete failed %d", ret);
2595}
2596
2597/**
2598 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2599 * @skb: network buffer
2600 * @adapter: network adapter
2601 *
2602 * Called when a network buffer is received which should not be routed
2603 * to the IPA module.
2604 *
2605 * Return: None
2606 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302607static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002608 hdd_adapter_t *adapter)
2609{
2610 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2611 unsigned int cpu_index;
2612
2613 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302614 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 adapter);
2616 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002617 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002618 return;
2619 }
2620
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002621 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002622 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002623 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624 return;
2625 }
2626
2627 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2628 skb->dev = adapter->dev;
2629 skb->protocol = eth_type_trans(skb, skb->dev);
2630 skb->ip_summed = CHECKSUM_NONE;
2631
2632 cpu_index = wlan_hdd_get_cpu();
2633
2634 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2635 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2636 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2637 else
2638 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2639
2640 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2641 adapter->dev->last_rx = jiffies;
2642}
2643
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002644/**
Leo Chang69c39692016-10-12 20:11:12 -07002645 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2646 * @hdd_ipa: pointer to hdd ipa context
2647 * @adapter: network adapter
2648 * @skb: data pointer
2649 *
2650 * if exception packet has set forward bit, copied new packet should be
2651 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2652 * put into pm queue and tx procedure will be differed
2653 *
2654 * Return: None
2655 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002656static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2657 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002658{
Leo Chang69c39692016-10-12 20:11:12 -07002659 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2660
Leo Chang69c39692016-10-12 20:11:12 -07002661 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2662 /* WLAN subsystem is in suspend, put int queue */
2663 if (hdd_ipa->suspended) {
2664 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2665 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2666 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002667 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
2668 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07002669 pm_tx_cb->exception = true;
2670 pm_tx_cb->adapter = adapter;
2671 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002672 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07002673 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2674 hdd_ipa->stats.num_tx_queued++;
2675 } else {
2676 /* Resume, put packet into WLAN TX */
2677 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002678 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07002679 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2680 "packet tx fail");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002681 hdd_ipa->stats.num_tx_bcmc_err++;
Leo Chang69c39692016-10-12 20:11:12 -07002682 } else {
2683 hdd_ipa->stats.num_tx_bcmc++;
2684 hdd_ipa->ipa_tx_forward++;
2685 }
2686 }
2687}
2688
2689/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002690 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
2691 * @hdd_ipa: pointer to HDD IPA struct
2692 * @adapter: hdd adapter pointer
2693 * @desc: Firmware descriptor
2694 * @skb: Data buffer
2695 *
2696 * Return:
2697 * HDD_IPA_FORWARD_PKT_NONE
2698 * HDD_IPA_FORWARD_PKT_DISCARD
2699 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
2700 *
2701 */
2702
2703static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
2704 struct hdd_ipa_priv *hdd_ipa,
2705 hdd_adapter_t *adapter,
2706 uint8_t desc,
2707 qdf_nbuf_t skb)
2708{
2709 int ret = HDD_IPA_FORWARD_PKT_NONE;
2710
2711 if ((desc & FW_RX_DESC_FORWARD_M)) {
2712 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
2713 "Forward packet to Tx (fw_desc=%d)", desc);
2714 hdd_ipa->ipa_tx_forward++;
2715
2716 if ((desc & FW_RX_DESC_DISCARD_M)) {
2717 hdd_ipa_forward(hdd_ipa, adapter, skb);
2718 hdd_ipa->ipa_rx_internel_drop_count++;
2719 hdd_ipa->ipa_rx_discard++;
2720 ret = HDD_IPA_FORWARD_PKT_DISCARD;
2721 } else {
2722 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
2723 if (cloned_skb)
2724 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
2725 else
2726 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2727 "%s: tx skb alloc failed",
2728 __func__);
2729 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
2730 }
2731 }
2732
2733 return ret;
2734}
2735
2736/**
Leo Chang69c39692016-10-12 20:11:12 -07002737 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738 * @priv: pointer to private data registered with IPA (we register a
2739 * pointer to the global IPA context)
2740 * @evt: the IPA event which triggered the callback
2741 * @data: data associated with the event
2742 *
2743 * Return: None
2744 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002745static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746 unsigned long data)
2747{
2748 struct hdd_ipa_priv *hdd_ipa = NULL;
2749 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302750 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751 uint8_t iface_id;
2752 uint8_t session_id;
2753 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002754 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002755 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756
2757 hdd_ipa = (struct hdd_ipa_priv *)priv;
2758
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08002759 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2760 return;
2761
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002762 switch (evt) {
2763 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302764 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002765
2766 /*
2767 * When SSR is going on or driver is unloading,
2768 * just drop the packets.
2769 */
2770 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2771 if (0 != status) {
2772 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2773 "Invalid context: drop packet");
2774 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2775 kfree_skb(skb);
2776 return;
2777 }
2778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2780 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002781 iface_id = hdd_ipa->vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302782 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002783 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2784 session_id, iface_id);
2785 } else {
2786 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2787 }
2788
2789 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302790 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791 "IPA_RECEIVE: Invalid iface_id: %u",
2792 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302793 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002794 "w2i -- skb", skb->data, 8);
2795 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002796 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797 return;
2798 }
2799
2800 iface_context = &hdd_ipa->iface_context[iface_id];
2801 adapter = iface_context->adapter;
2802
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302803 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002804 "w2i -- skb", skb->data, 8);
2805 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2806 hdd_ipa->stats.num_rx_excep++;
2807 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2808 } else {
2809 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2810 }
2811
2812 iface_context->stats.num_rx_ipa_excep++;
2813
2814 /* Disable to forward Intra-BSS Rx packets when
2815 * ap_isolate=1 in hostapd.conf
2816 */
Yun Park046101c2016-09-02 15:32:14 -07002817 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002818 /*
2819 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2820 * all Rx packets to IPA uC, which need to be forwarded
2821 * to other interface.
2822 * And, IPA driver will send back to WLAN host driver
2823 * through exception pipe with fw_desc field set by FW.
2824 * Here we are checking fw_desc field for FORWARD bit
2825 * set, and forward to Tx. Then copy to kernel stack
2826 * only when DISCARD bit is not set.
2827 */
2828 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002829 if (HDD_IPA_FORWARD_PKT_DISCARD ==
2830 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
2831 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002832 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302834 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002835 "Intra-BSS FWD is disabled-skip forward to Tx");
2836 }
2837
2838 hdd_ipa_send_skb_to_network(skb, adapter);
2839 break;
2840
2841 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302842 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843 "w2i cb wrong event: 0x%x", evt);
2844 return;
2845 }
2846}
2847
2848/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002849 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2850 * @priv: pointer to private data registered with IPA (we register a
2851 * pointer to the global IPA context)
2852 * @evt: the IPA event which triggered the callback
2853 * @data: data associated with the event
2854 *
2855 * Return: None
2856 */
2857static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2858 unsigned long data)
2859{
2860 cds_ssr_protect(__func__);
2861 __hdd_ipa_w2i_cb(priv, evt, data);
2862 cds_ssr_unprotect(__func__);
2863}
2864
2865/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002866 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2867 * @skb: packet buffer which was transmitted
2868 *
2869 * Return: None
2870 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302871void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002872{
2873 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2874
Govind Singhb6a89772016-08-12 11:23:35 +05302875 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302876 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002877 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302878 ipa_free_skb((struct ipa_rx_data *)
2879 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002880
2881 hdd_ipa->stats.num_tx_comp_cnt++;
2882
2883 atomic_dec(&hdd_ipa->tx_ref_cnt);
2884
2885 hdd_ipa_rm_try_release(hdd_ipa);
2886}
2887
2888/**
2889 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2890 * @iface_context: interface-specific IPA context
2891 * @ipa_tx_desc: packet data descriptor
2892 *
2893 * Return: None
2894 */
2895static void hdd_ipa_send_pkt_to_tl(
2896 struct hdd_ipa_iface_context *iface_context,
2897 struct ipa_rx_data *ipa_tx_desc)
2898{
2899 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002900 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302901 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302903 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904 adapter = iface_context->adapter;
2905 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302906 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907 ipa_free_skb(ipa_tx_desc);
2908 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302909 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002910 hdd_ipa_rm_try_release(hdd_ipa);
2911 return;
2912 }
2913
2914 /*
2915 * During CAC period, data packets shouldn't be sent over the air so
2916 * drop all the packets here
2917 */
2918 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2919 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302920 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 iface_context->stats.num_tx_cac_drop++;
2922 hdd_ipa_rm_try_release(hdd_ipa);
2923 return;
2924 }
2925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 ++adapter->stats.tx_packets;
2927
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302928 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002929
2930 skb = ipa_tx_desc->skb;
2931
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302932 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302933 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002934 /* FIXME: This is broken. No such field in cb any more:
2935 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302937 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002938 ipa_tx_desc->dma_addr
2939 + HDD_IPA_WLAN_FRAG_HEADER
2940 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941 ipa_tx_desc->skb->len -=
2942 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2943 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302944 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002946 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302947 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002948
2949 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2950
Leo Changfdb45c32016-10-28 11:09:23 -07002951 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
2952 iface_context->tl_context, ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302954 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955 ipa_free_skb(ipa_tx_desc);
2956 iface_context->stats.num_tx_err++;
2957 hdd_ipa_rm_try_release(hdd_ipa);
2958 return;
2959 }
2960
2961 atomic_inc(&hdd_ipa->tx_ref_cnt);
2962
2963 iface_context->stats.num_tx++;
2964
2965}
2966
2967/**
Leo Chang11545d62016-10-17 14:53:50 -07002968 * hdd_ipa_is_present() - get IPA hw status
2969 * @hdd_ctx: pointer to hdd context
2970 *
2971 * ipa_uc_reg_rdyCB is not directly designed to check
2972 * ipa hw status. This is an undocumented function which
2973 * has confirmed with IPA team.
2974 *
2975 * Return: true - ipa hw present
2976 * false - ipa hw not present
2977 */
2978bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2979{
2980 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002981 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002982 return true;
2983 else
2984 return false;
2985}
2986
2987/**
Leo Chang69c39692016-10-12 20:11:12 -07002988 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002989 * @work: pointer to the scheduled work
2990 *
2991 * Called during PM resume to send packets to TL which were queued
2992 * while host was in the process of suspending.
2993 *
2994 * Return: None
2995 */
Leo Chang69c39692016-10-12 20:11:12 -07002996static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002997{
2998 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2999 struct hdd_ipa_priv,
3000 pm_work);
3001 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303002 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003003 uint32_t dequeued = 0;
3004
Leo Chang69c39692016-10-12 20:11:12 -07003005 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
3006 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303007 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05303008 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
3009 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303010 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011
3012 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07003014 if (pm_tx_cb->exception) {
3015 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3016 "FLUSH EXCEPTION");
3017 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
3018 } else {
3019 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07003021 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303022 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003023 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303024 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07003025 qdf_wake_lock_release(&hdd_ipa->wake_lock,
3026 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027
3028 hdd_ipa->stats.num_tx_dequeued += dequeued;
3029 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
3030 hdd_ipa->stats.num_max_pm_queue = dequeued;
3031}
3032
3033/**
3034 * hdd_ipa_i2w_cb() - IPA to WLAN callback
3035 * @priv: pointer to private data registered with IPA (we register a
3036 * pointer to the interface-specific IPA context)
3037 * @evt: the IPA event which triggered the callback
3038 * @data: data associated with the event
3039 *
3040 * Return: None
3041 */
3042static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
3043 unsigned long data)
3044{
3045 struct hdd_ipa_priv *hdd_ipa = NULL;
3046 struct ipa_rx_data *ipa_tx_desc;
3047 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303048 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003049 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303050 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003051
Mukul Sharma81661ae2015-10-30 20:26:02 +05303052 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003053 ipa_tx_desc = (struct ipa_rx_data *)data;
3054 hdd_ipa = iface_context->hdd_ipa;
3055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003056 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003057 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
3058 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003059 iface_context->stats.num_tx_drop++;
3060 return;
3061 }
3062
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063 /*
3064 * When SSR is going on or driver is unloading, just drop the packets.
3065 * During SSR, there is no use in queueing the packets as STA has to
3066 * connect back any way
3067 */
3068 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303069 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070 ipa_free_skb(ipa_tx_desc);
3071 iface_context->stats.num_tx_drop++;
3072 return;
3073 }
3074
3075 skb = ipa_tx_desc->skb;
3076
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303077 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003078
3079 /*
3080 * If PROD resource is not requested here then there may be cases where
3081 * IPA hardware may be clocked down because of not having proper
3082 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
3083 * workaround to request PROD resource while data is going over CONS
3084 * pipe to prevent the IPA hardware clockdown.
3085 */
3086 hdd_ipa_rm_request(hdd_ipa);
3087
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303088 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 /*
3090 * If host is still suspended then queue the packets and these will be
3091 * drained later when resume completes. When packet is arrived here and
3092 * host is suspended, this means that there is already resume is in
3093 * progress.
3094 */
3095 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303096 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
3098 pm_tx_cb->iface_context = iface_context;
3099 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303100 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101 hdd_ipa->stats.num_tx_queued++;
3102
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303103 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104 return;
3105 }
3106
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303107 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108
3109 /*
3110 * If we are here means, host is not suspended, wait for the work queue
3111 * to finish.
3112 */
3113#ifdef WLAN_OPEN_SOURCE
3114 flush_work(&hdd_ipa->pm_work);
3115#endif
3116
3117 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
3118}
3119
3120/**
3121 * hdd_ipa_suspend() - Suspend IPA
3122 * @hdd_ctx: Global HDD context
3123 *
3124 * Return: 0 on success, negativer errno on error
3125 */
3126int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
3127{
3128 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3129
3130 if (!hdd_ipa_is_enabled(hdd_ctx))
3131 return 0;
3132
3133 /*
3134 * Check if IPA is ready for suspend, If we are here means, there is
3135 * high chance that suspend would go through but just to avoid any race
3136 * condition after suspend started, these checks are conducted before
3137 * allowing to suspend.
3138 */
3139 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3140 return -EAGAIN;
3141
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303142 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143
3144 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303145 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146 return -EAGAIN;
3147 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303148 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303150 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303152 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153
3154 return 0;
3155}
3156
3157/**
3158 * hdd_ipa_resume() - Resume IPA following suspend
3159 * hdd_ctx: Global HDD context
3160 *
3161 * Return: 0 on success, negative errno on error
3162 */
3163int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3164{
3165 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3166
3167 if (!hdd_ipa_is_enabled(hdd_ctx))
3168 return 0;
3169
3170 schedule_work(&hdd_ipa->pm_work);
3171
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303172 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303174 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175
3176 return 0;
3177}
3178
3179/**
3180 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3181 * @hdd_ipa: Global HDD IPA context
3182 *
3183 * Return: 0 on success, negative errno on error
3184 */
3185static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3186{
3187 int i, ret = 0;
3188 struct ipa_sys_connect_params *ipa;
3189 uint32_t desc_fifo_sz;
3190
3191 /* The maximum number of descriptors that can be provided to a BAM at
3192 * once is one less than the total number of descriptors that the buffer
3193 * can contain.
3194 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3195 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3196 * be provided at once.
3197 * Because of above requirement, one extra descriptor will be added to
3198 * make sure hardware always has one descriptor.
3199 */
3200 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3201 + sizeof(struct sps_iovec);
3202
3203 /*setup TX pipes */
3204 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3205 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3206
3207 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3208 ipa->desc_fifo_sz = desc_fifo_sz;
3209 ipa->priv = &hdd_ipa->iface_context[i];
3210 ipa->notify = hdd_ipa_i2w_cb;
3211
3212 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3213 ipa->ipa_ep_cfg.hdr.hdr_len =
3214 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3215 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3216 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3217 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3218 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3219 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3220 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3221 } else {
3222 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3223 }
3224 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3225
3226 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3227 ipa->keep_ipa_awake = 1;
3228
3229 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3230 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303231 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003232 " ret: %d", i, ret);
3233 goto setup_sys_pipe_fail;
3234 }
3235 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3236 }
3237
3238 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3239 /*
3240 * Hard code it here, this can be extended if in case
3241 * PROD pipe is also per interface.
3242 * Right now there is no advantage of doing this.
3243 */
3244 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3245
3246 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3247
3248 ipa->client = hdd_ipa->prod_client;
3249
3250 ipa->desc_fifo_sz = desc_fifo_sz;
3251 ipa->priv = hdd_ipa;
3252 ipa->notify = hdd_ipa_w2i_cb;
3253
3254 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3255 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3256 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3257 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3258
3259 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3260 ipa->keep_ipa_awake = 1;
3261
3262 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3263 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303264 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265 "Failed for RX pipe: %d", ret);
3266 goto setup_sys_pipe_fail;
3267 }
3268 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3269 }
3270
3271 return ret;
3272
3273setup_sys_pipe_fail:
3274
3275 while (--i >= 0) {
3276 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303277 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278 sizeof(struct hdd_ipa_sys_pipe));
3279 }
3280
3281 return ret;
3282}
3283
3284/**
3285 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3286 * @hdd_ipa: Global HDD IPA context
3287 *
3288 * Return: None
3289 */
3290static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3291{
3292 int ret = 0, i;
3293 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3294 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3295 ret =
3296 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3297 conn_hdl);
3298 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303299 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300 ret);
3301
3302 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3303 }
3304 }
3305}
3306
3307/**
3308 * hdd_ipa_register_interface() - register IPA interface
3309 * @hdd_ipa: Global IPA context
3310 * @iface_context: Per-interface IPA context
3311 *
3312 * Return: 0 on success, negative errno on error
3313 */
3314static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3315 struct hdd_ipa_iface_context
3316 *iface_context)
3317{
3318 struct ipa_tx_intf tx_intf;
3319 struct ipa_rx_intf rx_intf;
3320 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3321 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3322 char *ifname = iface_context->adapter->dev->name;
3323
3324 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3325 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3326
3327 int num_prop = 1;
3328 int ret = 0;
3329
3330 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3331 num_prop++;
3332
3333 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3334 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303335 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303337 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338 goto register_interface_fail;
3339 }
3340
3341 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3342 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303343 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303345 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003346 goto register_interface_fail;
3347 }
3348
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303349 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3350 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351
3352 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3353 ifname, HDD_IPA_IPV4_NAME_EXT);
3354 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3355 ifname, HDD_IPA_IPV6_NAME_EXT);
3356
3357 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3358 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3359 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3360 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3361
3362 /*
3363 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3364 * mask to identify the interface in IPA hardware
3365 */
3366 rx_prop[IPA_IP_v4].attrib.meta_data =
3367 htonl(iface_context->adapter->sessionId << 16);
3368 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3369
3370 rx_intf.num_props++;
3371 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3372 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3373 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3374 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3375 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3376 rx_prop[IPA_IP_v4].attrib.meta_data =
3377 htonl(iface_context->adapter->sessionId << 16);
3378 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3379
3380 rx_intf.num_props++;
3381 }
3382
3383 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3384 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3385 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3386 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3387 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3388 IPA_RESOURCE_NAME_MAX);
3389 tx_intf.num_props++;
3390
3391 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3392 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3393 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3394 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3395 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3396 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3397 IPA_RESOURCE_NAME_MAX);
3398 tx_intf.num_props++;
3399 }
3400
3401 tx_intf.prop = tx_prop;
3402 rx_intf.prop = rx_prop;
3403
3404 /* Call the ipa api to register interface */
3405 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3406
3407register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303408 qdf_mem_free(tx_prop);
3409 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 return ret;
3411}
3412
3413/**
3414 * hdd_remove_ipa_header() - Remove a specific header from IPA
3415 * @name: Name of the header to be removed
3416 *
3417 * Return: None
3418 */
3419static void hdd_ipa_remove_header(char *name)
3420{
3421 struct ipa_ioc_get_hdr hdrlookup;
3422 int ret = 0, len;
3423 struct ipa_ioc_del_hdr *ipa_hdr;
3424
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303425 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3427 ret = ipa_get_hdr(&hdrlookup);
3428 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303429 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 name, ret);
3431 return;
3432 }
3433
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303434 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303436 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303438 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 return;
3440 }
3441 ipa_hdr->num_hdls = 1;
3442 ipa_hdr->commit = 0;
3443 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3444 ipa_hdr->hdl[0].status = -1;
3445 ret = ipa_del_hdr(ipa_hdr);
3446 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303447 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448 ret);
3449
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303450 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003451}
3452
3453/**
3454 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3455 * @hdd_ipa: Global HDD IPA context
3456 * @iface_context: Interface-specific HDD IPA context
3457 * @mac_addr: Interface MAC address
3458 *
3459 * Return: 0 on success, negativer errno value on error
3460 */
3461static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3462 struct hdd_ipa_iface_context *iface_context,
3463 uint8_t *mac_addr)
3464{
3465 hdd_adapter_t *adapter = iface_context->adapter;
3466 char *ifname;
3467 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3468 int ret = -EINVAL;
3469 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3470 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3471
3472 ifname = adapter->dev->name;
3473
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303474 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 ifname, mac_addr);
3476
3477 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303478 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 + sizeof(struct ipa_hdr_add));
3480 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303481 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003482 "%s: ipa_hdr allocation failed", ifname);
3483 ret = -ENOMEM;
3484 goto end;
3485 }
3486
3487 ipa_hdr->commit = 0;
3488 ipa_hdr->num_hdrs = 1;
3489
3490 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3491 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3492 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3493 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3494 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303495 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496 "ifname=%s, vdev_id=%d",
3497 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3498 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3499 ifname, HDD_IPA_IPV4_NAME_EXT);
3500 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3501 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3502 ipa_hdr->hdr[0].is_partial = 1;
3503 ipa_hdr->hdr[0].hdr_hdl = 0;
3504 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3505 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3506
3507 ret = ipa_add_hdr(ipa_hdr);
3508 } else {
3509 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3510
3511 /* Set the Source MAC */
3512 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3513 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3514
3515 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3516 ifname, HDD_IPA_IPV4_NAME_EXT);
3517 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3518 ipa_hdr->hdr[0].is_partial = 1;
3519 ipa_hdr->hdr[0].hdr_hdl = 0;
3520 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3521 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3522
3523 /* Set the type to IPV4 in the header */
3524 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3525
3526 ret = ipa_add_hdr(ipa_hdr);
3527 }
3528 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303529 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 ifname, ret);
3531 goto end;
3532 }
3533
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303534 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3536
3537 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3538 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3539 ifname, HDD_IPA_IPV6_NAME_EXT);
3540
3541 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3542 uc_tx_hdr =
3543 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3544 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3545 } else {
3546 /* Set the type to IPV6 in the header */
3547 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3548 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3549 }
3550
3551 ret = ipa_add_hdr(ipa_hdr);
3552 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303553 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554 "%s: IPv6 add hdr failed: %d", ifname, ret);
3555 goto clean_ipv4_hdr;
3556 }
3557
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303558 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3560 }
3561
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303562 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003563
3564 return ret;
3565
3566clean_ipv4_hdr:
3567 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3568 ifname, HDD_IPA_IPV4_NAME_EXT);
3569 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3570end:
3571 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303572 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573
3574 return ret;
3575}
3576
3577/**
3578 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3579 * @adapter: Adapter upon which IPA was previously configured
3580 *
3581 * Return: None
3582 */
3583static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3584{
3585 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3586 int ret;
3587 char name_ipa[IPA_RESOURCE_NAME_MAX];
3588
3589 /* Remove the headers */
3590 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3591 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3592 hdd_ipa_remove_header(name_ipa);
3593
3594 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3595 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3596 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3597 hdd_ipa_remove_header(name_ipa);
3598 }
3599 /* unregister the interface with IPA */
3600 ret = ipa_deregister_intf(adapter->dev->name);
3601 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303602 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 "%s: ipa_deregister_intf fail: %d",
3604 adapter->dev->name, ret);
3605}
3606
3607/**
3608 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3609 * @iface_context: interface-specific IPA context
3610 *
3611 * Return: None
3612 */
3613static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3614{
3615 if (iface_context == NULL)
3616 return;
3617
3618 hdd_ipa_clean_hdr(iface_context->adapter);
3619
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303620 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 iface_context->adapter->ipa_context = NULL;
3622 iface_context->adapter = NULL;
3623 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303624 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 iface_context->ifa_address = 0;
3626 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303627 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303629 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630 }
3631 iface_context->hdd_ipa->num_iface--;
3632}
3633
3634/**
3635 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3636 * @hdd_ipa: HDD IPA global context
3637 * @adapter: Interface upon which IPA is being setup
3638 * @sta_id: Station ID of the API instance
3639 *
3640 * Return: 0 on success, negative errno value on error
3641 */
3642static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3643 hdd_adapter_t *adapter, uint8_t sta_id)
3644{
3645 struct hdd_ipa_iface_context *iface_context = NULL;
3646 void *tl_context = NULL;
3647 int i, ret = 0;
3648
3649 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3650 * channel change indication. Since these indications are sent by lower
3651 * layer as SAP updates and IPA doesn't have to do anything for these
3652 * updates so ignoring!
3653 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003654 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 return 0;
3656
3657 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3658 if (hdd_ipa->iface_context[i].adapter == NULL) {
3659 iface_context = &(hdd_ipa->iface_context[i]);
3660 break;
3661 }
3662 }
3663
3664 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303665 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003666 "All the IPA interfaces are in use");
3667 ret = -ENOMEM;
3668 goto end;
3669 }
3670
3671 adapter->ipa_context = iface_context;
3672 iface_context->adapter = adapter;
3673 iface_context->sta_id = sta_id;
Leo Changfdb45c32016-10-28 11:09:23 -07003674 tl_context = cdp_peer_get_vdev_by_sta_id(
3675 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303677 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678 "Not able to get TL context sta_id: %d", sta_id);
3679 ret = -EINVAL;
3680 goto end;
3681 }
3682
3683 iface_context->tl_context = tl_context;
3684
3685 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3686 adapter->dev->dev_addr);
3687
3688 if (ret)
3689 goto end;
3690
3691 /* Configure the TX and RX pipes filter rules */
3692 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3693 if (ret)
3694 goto cleanup_header;
3695
3696 hdd_ipa->num_iface++;
3697 return ret;
3698
3699cleanup_header:
3700
3701 hdd_ipa_clean_hdr(adapter);
3702end:
3703 if (iface_context)
3704 hdd_ipa_cleanup_iface(iface_context);
3705 return ret;
3706}
3707
Yun Parka27049a2016-10-11 12:30:49 -07003708#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709/**
3710 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3711 * @mcc_mode: 0=MCC/1=SCC
3712 *
3713 * Return: 0 on success, negative errno value on error
3714 */
3715int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3716{
3717 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303718 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003719 hdd_adapter_t *pAdapter;
3720 struct ipa_msg_meta meta;
3721 struct ipa_wlan_msg *msg;
3722 int ret;
3723
3724 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3725 return -EINVAL;
3726
3727 if (!pHddCtx->mcc_mode) {
3728 /* Flush TxRx queue for each adapter before switch to SCC */
3729 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303730 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003731 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003732 if (pAdapter->device_mode == QDF_STA_MODE ||
3733 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303734 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003735 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3736 pAdapter->device_mode);
3737 hdd_deinit_tx_rx(pAdapter);
3738 }
3739 status = hdd_get_next_adapter(
3740 pHddCtx, adapter_node, &next);
3741 adapter_node = next;
3742 }
3743 }
3744
3745 /* Send SCC/MCC Switching event to IPA */
3746 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303747 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003748 if (msg == NULL) {
3749 hddLog(LOGE, "msg allocation failed");
3750 return -ENOMEM;
3751 }
3752
3753 meta.msg_type = mcc_mode ?
3754 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3755 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3756
3757 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3758
3759 if (ret) {
3760 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3761 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303762 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003763 }
3764
3765 return ret;
3766}
Yun Parka27049a2016-10-11 12:30:49 -07003767#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003768
3769/**
3770 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3771 * @event: IPA WLAN event to be converted to a string
3772 *
3773 * Return: ASCII string representing the IPA WLAN event
3774 */
3775static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3776{
3777 switch (event) {
3778 case WLAN_CLIENT_CONNECT:
3779 return "WLAN_CLIENT_CONNECT";
3780 case WLAN_CLIENT_DISCONNECT:
3781 return "WLAN_CLIENT_DISCONNECT";
3782 case WLAN_CLIENT_POWER_SAVE_MODE:
3783 return "WLAN_CLIENT_POWER_SAVE_MODE";
3784 case WLAN_CLIENT_NORMAL_MODE:
3785 return "WLAN_CLIENT_NORMAL_MODE";
3786 case SW_ROUTING_ENABLE:
3787 return "SW_ROUTING_ENABLE";
3788 case SW_ROUTING_DISABLE:
3789 return "SW_ROUTING_DISABLE";
3790 case WLAN_AP_CONNECT:
3791 return "WLAN_AP_CONNECT";
3792 case WLAN_AP_DISCONNECT:
3793 return "WLAN_AP_DISCONNECT";
3794 case WLAN_STA_CONNECT:
3795 return "WLAN_STA_CONNECT";
3796 case WLAN_STA_DISCONNECT:
3797 return "WLAN_STA_DISCONNECT";
3798 case WLAN_CLIENT_CONNECT_EX:
3799 return "WLAN_CLIENT_CONNECT_EX";
3800
3801 case IPA_WLAN_EVENT_MAX:
3802 default:
3803 return "UNKNOWN";
3804 }
3805}
3806
3807/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003808 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3809 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3810 *
3811 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3812 */
3813static enum ipa_wlan_event
3814hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3815{
3816 enum ipa_wlan_event ipa_event;
3817
3818 switch (hdd_ipa_event_type) {
3819 case HDD_IPA_CLIENT_CONNECT:
3820 ipa_event = WLAN_CLIENT_CONNECT;
3821 break;
3822 case HDD_IPA_CLIENT_DISCONNECT:
3823 ipa_event = WLAN_CLIENT_DISCONNECT;
3824 break;
3825 case HDD_IPA_AP_CONNECT:
3826 ipa_event = WLAN_AP_CONNECT;
3827 break;
3828 case HDD_IPA_AP_DISCONNECT:
3829 ipa_event = WLAN_AP_DISCONNECT;
3830 break;
3831 case HDD_IPA_STA_CONNECT:
3832 ipa_event = WLAN_STA_CONNECT;
3833 break;
3834 case HDD_IPA_STA_DISCONNECT:
3835 ipa_event = WLAN_STA_DISCONNECT;
3836 break;
3837 case HDD_IPA_CLIENT_CONNECT_EX:
3838 ipa_event = WLAN_CLIENT_CONNECT_EX;
3839 break;
3840 case HDD_IPA_WLAN_EVENT_MAX:
3841 default:
3842 ipa_event = IPA_WLAN_EVENT_MAX;
3843 break;
3844 }
3845 return ipa_event;
3846
3847}
3848
3849/**
3850 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851 * @adapter: adapter upon which the event was received
3852 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003853 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 * @mac_address: MAC address associated with the event
3855 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003856 * This function is meant to be called from within wlan_hdd_ipa.c
3857 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 * Return: 0 on success, negative errno value on error
3859 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003860static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861 enum ipa_wlan_event type, uint8_t *mac_addr)
3862{
3863 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3864 struct ipa_msg_meta meta;
3865 struct ipa_wlan_msg *msg;
3866 struct ipa_wlan_msg_ex *msg_ex = NULL;
3867 int ret;
3868
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303869 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3871 mac_addr, sta_id);
3872
3873 if (type >= IPA_WLAN_EVENT_MAX)
3874 return -EINVAL;
3875
3876 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3877 return -EINVAL;
3878
3879 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303880 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881 return -EINVAL;
3882 }
3883
3884 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3885 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003886 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003887 return 0;
3888 }
3889
3890 /*
3891 * During IPA UC resource loading/unloading new events can be issued.
3892 * Store the events separately and handle them later.
3893 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07003894 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3895 if (hdd_ipa->resource_loading) {
3896 unsigned int pending_event_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07003898 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08003899
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07003900 hdd_err("IPA resource %s inprogress",
3901 hdd_ipa->resource_loading ? "load":"unload");
Yun Parkf19e07d2015-11-20 11:34:27 -08003902
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07003903 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003904
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07003905 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
3906 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3907 hdd_notice("Reached max pending event count");
3908 qdf_list_remove_front(&hdd_ipa->pending_event,
3909 (qdf_list_node_t **)&pending_event);
3910 } else {
3911 pending_event =
3912 (struct ipa_uc_pending_event *)qdf_mem_malloc(
3913 sizeof(struct ipa_uc_pending_event));
3914 }
3915
3916 if (!pending_event) {
3917 hdd_err("Pending event memory alloc fail");
3918 qdf_mutex_release(&hdd_ipa->event_lock);
3919 return -ENOMEM;
3920 }
3921
3922 pending_event->adapter = adapter;
3923 pending_event->sta_id = sta_id;
3924 pending_event->type = type;
3925 qdf_mem_copy(pending_event->mac_addr,
3926 mac_addr,
3927 QDF_MAC_ADDR_SIZE);
3928 qdf_list_insert_back(&hdd_ipa->pending_event,
3929 &pending_event->node);
3930
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303931 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07003932 return 0;
3933 } else if (hdd_ipa->resource_unloading) {
3934 hdd_err("%s: IPA resource unload inprogress", __func__);
3935 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 }
3938
3939 hdd_ipa->stats.event[type]++;
3940
Leo Chang3bc8fed2015-11-13 10:59:47 -08003941 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 switch (type) {
3943 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003944 qdf_mutex_acquire(&hdd_ipa->event_lock);
3945
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 /* STA already connected and without disconnect, connect again
3947 * This is Roaming scenario
3948 */
3949 if (hdd_ipa->sta_connected)
3950 hdd_ipa_cleanup_iface(adapter->ipa_context);
3951
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3953 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303954 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003955 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003956 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957
Yun Park8f289c82016-10-18 16:38:21 -07003958 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3959 (hdd_ipa->sap_num_connected_sta > 0) &&
3960 !hdd_ipa->sta_connected) {
3961 qdf_mutex_release(&hdd_ipa->event_lock);
3962 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003963 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07003964 qdf_mutex_acquire(&hdd_ipa->event_lock);
3965 }
3966
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003967 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003969 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003972
3973 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003974 break;
3975
3976 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003977 qdf_mutex_acquire(&hdd_ipa->event_lock);
3978
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 /* For DFS channel we get two start_bss event (before and after
3980 * CAC). Also when ACS range includes both DFS and non DFS
3981 * channels, we could possibly change channel many times due to
3982 * RADAR detection and chosen channel may not be a DFS channels.
3983 * So dont return error here. Just discard the event.
3984 */
Yun Park8f289c82016-10-18 16:38:21 -07003985 if (adapter->ipa_context) {
3986 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003988 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3991 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303992 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 "%s: Evt: %d, Interface setup failed",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05303994 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303995 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003997 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998
Yun Park8f289c82016-10-18 16:38:21 -07003999 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4000 qdf_mutex_release(&hdd_ipa->event_lock);
4001 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004002 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07004003 qdf_mutex_acquire(&hdd_ipa->event_lock);
4004 }
4005
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004006 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004007 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07004008 (adapter->ipa_context))->iface_id;
4009
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304010 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011 break;
4012
4013 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304014 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015
4016 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304017 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 "%s: Evt: %d, STA already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304019 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304020 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 return -EINVAL;
4022 }
Yun Parka37592b2016-06-11 17:10:28 -07004023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07004025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304027 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 "%s: IPA UC OFFLOAD NOT ENABLED",
4029 msg_ex->name);
4030 } else {
4031 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07004032 if (!hdd_ipa->num_iface &&
4033 (HDD_IPA_UC_NUM_WDI_PIPE ==
4034 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 }
4037
Yun Park74127cf2016-09-18 11:22:41 -07004038 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4039 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07004040 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004042 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004043 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004044 hdd_ipa->vdev_to_iface[adapter->sessionId] =
4045 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004046 }
4047
Yun Park8f289c82016-10-18 16:38:21 -07004048 hdd_ipa_cleanup_iface(adapter->ipa_context);
4049
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304050 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051 break;
4052
4053 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07004054 qdf_mutex_acquire(&hdd_ipa->event_lock);
4055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304057 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058 "%s: Evt: %d, SAP already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304059 adapter->dev->name, type);
Yun Park8f289c82016-10-18 16:38:21 -07004060 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 return -EINVAL;
4062 }
4063
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 if ((!hdd_ipa->num_iface) &&
4065 (HDD_IPA_UC_NUM_WDI_PIPE ==
4066 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004067 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 /*
4069 * We disable WDI pipes directly here since
4070 * IPA_OPCODE_TX/RX_SUSPEND message will not be
4071 * processed when unloading WLAN driver is in
4072 * progress
4073 */
4074 hdd_ipa_uc_disable_pipes(hdd_ipa);
4075 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304076 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 "NO INTF left but still pipe clean up");
4078 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4079 }
4080 }
4081
4082 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07004083 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004084 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004085 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004086 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004087 hdd_ipa->vdev_to_iface[adapter->sessionId] =
4088 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089 }
Yun Parka37592b2016-06-11 17:10:28 -07004090
Yun Park8f289c82016-10-18 16:38:21 -07004091 hdd_ipa_cleanup_iface(adapter->ipa_context);
4092
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304093 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094 break;
4095
4096 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304098 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004099 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304100 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004101 return 0;
4102 }
4103
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304104 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
4106 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07004107 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304108 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 "%s: STA ID %d found, not valid",
4110 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111 return 0;
4112 }
Yun Park312f71a2015-12-08 10:22:42 -08004113
4114 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07004115 if (0 == hdd_ipa->sap_num_connected_sta) {
4116 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004117 hdd_ipa->sta_connected) {
4118 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004119 hdd_ipa_uc_offload_enable_disable(
4120 hdd_get_adapter(hdd_ipa->hdd_ctx,
4121 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004122 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07004123 qdf_mutex_acquire(&hdd_ipa->event_lock);
4124 }
Yun Parka37592b2016-06-11 17:10:28 -07004125
Yun Park312f71a2015-12-08 10:22:42 -08004126 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
4127 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304128 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08004129 "%s: handle 1st con ret %d",
4130 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07004131
4132 if (hdd_ipa_uc_sta_is_enabled(
4133 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004134 hdd_ipa->sta_connected) {
4135 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004136 hdd_ipa_uc_offload_enable_disable(
4137 hdd_get_adapter(
4138 hdd_ipa->hdd_ctx,
4139 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004140 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004141 } else {
4142 qdf_mutex_release(&hdd_ipa->event_lock);
4143 }
Yun Parka37592b2016-06-11 17:10:28 -07004144
Yun Park312f71a2015-12-08 10:22:42 -08004145 return ret;
4146 }
4147 }
4148
4149 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08004150
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304151 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152
4153 meta.msg_type = type;
4154 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
4155 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304156 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157
4158 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304159 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160 "msg_ex allocation failed");
4161 return -ENOMEM;
4162 }
4163 strlcpy(msg_ex->name, adapter->dev->name,
4164 IPA_RESOURCE_NAME_MAX);
4165 msg_ex->num_of_attribs = 1;
4166 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4167 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4168 msg_ex->attribs[0].offset =
4169 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4170 } else {
4171 msg_ex->attribs[0].offset =
4172 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4173 }
4174 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4175 IPA_MAC_ADDR_SIZE);
4176
4177 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4178
4179 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304180 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304181 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304182 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004183 return ret;
4184 }
4185 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 return ret;
4187
4188 case WLAN_CLIENT_DISCONNECT:
4189 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304190 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004191 "%s: IPA UC OFFLOAD NOT ENABLED",
4192 msg_ex->name);
4193 return 0;
4194 }
4195
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304196 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304198 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004199 "%s: STA ID %d NOT found, not valid",
4200 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304201 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202 return 0;
4203 }
4204 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07004205
Yun Park9b5030f2016-11-08 12:02:37 -08004206 /* Disable IPA UC TX PIPE when last STA disconnected */
4207 if (!hdd_ipa->sap_num_connected_sta) {
4208 if ((false == hdd_ipa->resource_unloading)
4209 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4210 hdd_ipa->activated_fw_pipe)) {
4211 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4212 }
4213
Yun Park8f289c82016-10-18 16:38:21 -07004214 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004215
4216 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4217 hdd_ipa->sta_connected)
4218 hdd_ipa_uc_offload_enable_disable(
4219 hdd_get_adapter(hdd_ipa->hdd_ctx,
4220 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004221 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004222 } else {
4223 qdf_mutex_release(&hdd_ipa->event_lock);
4224 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225 break;
4226
4227 default:
4228 return 0;
4229 }
4230
4231 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304232 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304234 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 return -ENOMEM;
4236 }
4237
4238 meta.msg_type = type;
4239 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4240 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4241
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304242 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 msg->name, meta.msg_type);
4244
4245 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4246
4247 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304248 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304250 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251 return ret;
4252 }
4253
4254 hdd_ipa->stats.num_send_msg++;
4255
4256end:
4257 return ret;
4258}
4259
4260/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004261 * hdd_ipa_wlan_evt() - IPA event handler
4262 * @adapter: adapter upon which the event was received
4263 * @sta_id: station id for the event
4264 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4265 * @mac_address: MAC address associated with the event
4266 *
4267 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4268 *
4269 * Return: 0 on success, negative errno value on error
4270 */
4271int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4272 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4273{
4274 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4275
Leo Changa202b522016-10-14 16:13:50 -07004276 /* Data path offload only support for STA and SAP mode */
4277 if ((QDF_STA_MODE == adapter->device_mode) ||
4278 (QDF_SAP_MODE == adapter->device_mode))
4279 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4280
4281 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004282}
4283
4284/**
4285 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4286 * @hdd_ipa: Global HDD IPA context
4287 *
4288 * Return: None
4289 */
4290static void
4291hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4292{
4293 unsigned int pending_event_count;
4294 struct ipa_uc_pending_event *pending_event = NULL;
4295
4296 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4297 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4298 "%s, Pending Event Count %d", __func__, pending_event_count);
4299 if (!pending_event_count) {
4300 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4301 "%s, No Pending Event", __func__);
4302 return;
4303 }
4304
4305 qdf_list_remove_front(&hdd_ipa->pending_event,
4306 (qdf_list_node_t **)&pending_event);
4307 while (pending_event != NULL) {
4308 __hdd_ipa_wlan_evt(pending_event->adapter,
4309 pending_event->type,
4310 pending_event->sta_id,
4311 pending_event->mac_addr);
4312 qdf_mem_free(pending_event);
4313 pending_event = NULL;
4314 qdf_list_remove_front(&hdd_ipa->pending_event,
4315 (qdf_list_node_t **)&pending_event);
4316 }
4317}
4318
4319/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4321 * @state: IPA RM state value
4322 *
4323 * Return: ASCII string representing the IPA RM state
4324 */
4325static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4326{
4327 switch (state) {
4328 case HDD_IPA_RM_RELEASED:
4329 return "RELEASED";
4330 case HDD_IPA_RM_GRANT_PENDING:
4331 return "GRANT_PENDING";
4332 case HDD_IPA_RM_GRANTED:
4333 return "GRANTED";
4334 }
4335
4336 return "UNKNOWN";
4337}
4338
4339/**
4340 * hdd_ipa_init() - IPA initialization function
4341 * @hdd_ctx: HDD global context
4342 *
4343 * Allocate hdd_ipa resources, ipa pipe resource and register
4344 * wlan interface with IPA module.
4345 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304346 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304348QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349{
4350 struct hdd_ipa_priv *hdd_ipa = NULL;
4351 int ret, i;
4352 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004353 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354
4355 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304356 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357
Yun Park7f171ab2016-07-29 15:44:22 -07004358 if (!pdev) {
4359 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4360 goto fail_return;
4361 }
4362
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304363 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304365 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004366 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 }
4368
4369 hdd_ctx->hdd_ipa = hdd_ipa;
4370 ghdd_ipa = hdd_ipa;
4371 hdd_ipa->hdd_ctx = hdd_ctx;
4372 hdd_ipa->num_iface = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07004373 cdp_ipa_get_resource(cds_get_context(QDF_MODULE_ID_SOC),
4374 cds_get_context(QDF_MODULE_ID_TXRX),
4375 &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004376 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4377 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4378 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4379 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304380 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004381 "IPA UC resource alloc fail");
4382 goto fail_get_resource;
4383 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384
4385 /* Create the interface context */
4386 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4387 iface_context = &hdd_ipa->iface_context[i];
4388 iface_context->hdd_ipa = hdd_ipa;
4389 iface_context->cons_client =
4390 hdd_ipa_adapter_2_client[i].cons_client;
4391 iface_context->prod_client =
4392 hdd_ipa_adapter_2_client[i].prod_client;
4393 iface_context->iface_id = i;
4394 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304395 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004396 }
4397 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004398 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
4399 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 }
4401
Leo Chang69c39692016-10-12 20:11:12 -07004402 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304403 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304404 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004405
4406 ret = hdd_ipa_setup_rm(hdd_ipa);
4407 if (ret)
4408 goto fail_setup_rm;
4409
4410 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4411 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304412 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413 hdd_ipa->sap_num_connected_sta = 0;
4414 hdd_ipa->ipa_tx_packets_diff = 0;
4415 hdd_ipa->ipa_rx_packets_diff = 0;
4416 hdd_ipa->ipa_p_tx_packets = 0;
4417 hdd_ipa->ipa_p_rx_packets = 0;
4418 hdd_ipa->resource_loading = false;
4419 hdd_ipa->resource_unloading = false;
4420 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004421 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 /* Setup IPA sys_pipe for MCC */
4423 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4424 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4425 if (ret)
4426 goto fail_create_sys_pipe;
4427 }
4428 hdd_ipa_uc_ol_init(hdd_ctx);
4429 } else {
4430 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4431 if (ret)
4432 goto fail_create_sys_pipe;
4433 }
4434
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304435 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436
4437fail_create_sys_pipe:
4438 hdd_ipa_destroy_rm_resource(hdd_ipa);
4439fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304440 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004441fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304442 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004443 hdd_ctx->hdd_ipa = NULL;
4444 ghdd_ipa = NULL;
4445fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304446 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004447}
4448
4449/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004450 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4451 * @hdd_ipa: pointer to HDD IPA struct
4452 *
4453 * Return: none
4454 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004455static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004456{
4457 struct ipa_uc_pending_event *pending_event = NULL;
4458
Anurag Chouhanffb21542016-02-17 14:33:03 +05304459 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4460 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304461 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004462 }
4463
Anurag Chouhanffb21542016-02-17 14:33:03 +05304464 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004465}
4466
4467/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468 * hdd_ipa_cleanup - IPA cleanup function
4469 * @hdd_ctx: HDD global context
4470 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304471 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004472 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304473QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474{
4475 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4476 int i;
4477 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304478 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4480
4481 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304482 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483
4484 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4485 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4486 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4487 }
4488
4489 /* Teardown IPA sys_pipe for MCC */
4490 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4491 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4492
4493 hdd_ipa_destroy_rm_resource(hdd_ipa);
4494
4495#ifdef WLAN_OPEN_SOURCE
4496 cancel_work_sync(&hdd_ipa->pm_work);
4497#endif
4498
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304499 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500
Nirav Shahcbc6d722016-03-01 16:24:53 +05304501 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4502 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304503 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504
4505 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4506 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4507
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304508 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004509 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304510 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304512 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513
4514 /* destory the interface lock */
4515 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4516 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304517 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 }
4519
4520 /* This should never hit but still make sure that there are no pending
4521 * descriptor in IPA hardware
4522 */
4523 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304524 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525 "IPA Pending write done: %d Waiting!",
4526 hdd_ipa->pending_hw_desc_cnt);
4527
4528 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4529 usleep_range(100, 100);
4530 }
4531
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304532 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004533 "IPA Pending write done: desc: %d %s(%d)!",
4534 hdd_ipa->pending_hw_desc_cnt,
4535 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4536 : "leak", i);
4537 }
4538 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4539 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304540 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304541 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4542 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004543 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304544 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304545 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4546 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304548 qdf_mutex_destroy(&hdd_ipa->event_lock);
4549 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004550 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004551
4552#ifdef WLAN_OPEN_SOURCE
4553 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4554 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4555 hdd_ipa->uc_op_work[i].msg = NULL;
4556 }
4557#endif
4558 }
4559
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304560 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561 hdd_ctx->hdd_ipa = NULL;
4562
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304563 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564}
4565#endif /* IPA_OFFLOAD */