blob: bf6dea3c003f73c73d65532ed93c86d9ef4d3f78 [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
2759 switch (evt) {
2760 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302761 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002762
2763 /*
2764 * When SSR is going on or driver is unloading,
2765 * just drop the packets.
2766 */
2767 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2768 if (0 != status) {
2769 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2770 "Invalid context: drop packet");
2771 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2772 kfree_skb(skb);
2773 return;
2774 }
2775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2777 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002778 iface_id = hdd_ipa->vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302779 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002780 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2781 session_id, iface_id);
2782 } else {
2783 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2784 }
2785
2786 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302787 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 "IPA_RECEIVE: Invalid iface_id: %u",
2789 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302790 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791 "w2i -- skb", skb->data, 8);
2792 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002793 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002794 return;
2795 }
2796
2797 iface_context = &hdd_ipa->iface_context[iface_id];
2798 adapter = iface_context->adapter;
2799
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302800 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801 "w2i -- skb", skb->data, 8);
2802 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2803 hdd_ipa->stats.num_rx_excep++;
2804 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2805 } else {
2806 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2807 }
2808
2809 iface_context->stats.num_rx_ipa_excep++;
2810
2811 /* Disable to forward Intra-BSS Rx packets when
2812 * ap_isolate=1 in hostapd.conf
2813 */
Yun Park046101c2016-09-02 15:32:14 -07002814 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002815 /*
2816 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2817 * all Rx packets to IPA uC, which need to be forwarded
2818 * to other interface.
2819 * And, IPA driver will send back to WLAN host driver
2820 * through exception pipe with fw_desc field set by FW.
2821 * Here we are checking fw_desc field for FORWARD bit
2822 * set, and forward to Tx. Then copy to kernel stack
2823 * only when DISCARD bit is not set.
2824 */
2825 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08002826 if (HDD_IPA_FORWARD_PKT_DISCARD ==
2827 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
2828 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002829 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302831 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 "Intra-BSS FWD is disabled-skip forward to Tx");
2833 }
2834
2835 hdd_ipa_send_skb_to_network(skb, adapter);
2836 break;
2837
2838 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302839 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002840 "w2i cb wrong event: 0x%x", evt);
2841 return;
2842 }
2843}
2844
2845/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002846 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2847 * @priv: pointer to private data registered with IPA (we register a
2848 * pointer to the global IPA context)
2849 * @evt: the IPA event which triggered the callback
2850 * @data: data associated with the event
2851 *
2852 * Return: None
2853 */
2854static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2855 unsigned long data)
2856{
2857 cds_ssr_protect(__func__);
2858 __hdd_ipa_w2i_cb(priv, evt, data);
2859 cds_ssr_unprotect(__func__);
2860}
2861
2862/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2864 * @skb: packet buffer which was transmitted
2865 *
2866 * Return: None
2867 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302868void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869{
2870 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2871
Govind Singhb6a89772016-08-12 11:23:35 +05302872 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302873 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002874 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302875 ipa_free_skb((struct ipa_rx_data *)
2876 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002877
2878 hdd_ipa->stats.num_tx_comp_cnt++;
2879
2880 atomic_dec(&hdd_ipa->tx_ref_cnt);
2881
2882 hdd_ipa_rm_try_release(hdd_ipa);
2883}
2884
2885/**
2886 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2887 * @iface_context: interface-specific IPA context
2888 * @ipa_tx_desc: packet data descriptor
2889 *
2890 * Return: None
2891 */
2892static void hdd_ipa_send_pkt_to_tl(
2893 struct hdd_ipa_iface_context *iface_context,
2894 struct ipa_rx_data *ipa_tx_desc)
2895{
2896 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002897 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302898 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302900 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901 adapter = iface_context->adapter;
2902 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302903 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904 ipa_free_skb(ipa_tx_desc);
2905 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302906 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907 hdd_ipa_rm_try_release(hdd_ipa);
2908 return;
2909 }
2910
2911 /*
2912 * During CAC period, data packets shouldn't be sent over the air so
2913 * drop all the packets here
2914 */
2915 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2916 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302917 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002918 iface_context->stats.num_tx_cac_drop++;
2919 hdd_ipa_rm_try_release(hdd_ipa);
2920 return;
2921 }
2922
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002923 ++adapter->stats.tx_packets;
2924
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302925 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926
2927 skb = ipa_tx_desc->skb;
2928
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302929 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302930 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002931 /* FIXME: This is broken. No such field in cb any more:
2932 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002933 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302934 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002935 ipa_tx_desc->dma_addr
2936 + HDD_IPA_WLAN_FRAG_HEADER
2937 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 ipa_tx_desc->skb->len -=
2939 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2940 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302941 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002943 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302944 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945
2946 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2947
Leo Changfdb45c32016-10-28 11:09:23 -07002948 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
2949 iface_context->tl_context, ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002950 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302951 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002952 ipa_free_skb(ipa_tx_desc);
2953 iface_context->stats.num_tx_err++;
2954 hdd_ipa_rm_try_release(hdd_ipa);
2955 return;
2956 }
2957
2958 atomic_inc(&hdd_ipa->tx_ref_cnt);
2959
2960 iface_context->stats.num_tx++;
2961
2962}
2963
2964/**
Leo Chang11545d62016-10-17 14:53:50 -07002965 * hdd_ipa_is_present() - get IPA hw status
2966 * @hdd_ctx: pointer to hdd context
2967 *
2968 * ipa_uc_reg_rdyCB is not directly designed to check
2969 * ipa hw status. This is an undocumented function which
2970 * has confirmed with IPA team.
2971 *
2972 * Return: true - ipa hw present
2973 * false - ipa hw not present
2974 */
2975bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2976{
2977 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002978 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002979 return true;
2980 else
2981 return false;
2982}
2983
2984/**
Leo Chang69c39692016-10-12 20:11:12 -07002985 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986 * @work: pointer to the scheduled work
2987 *
2988 * Called during PM resume to send packets to TL which were queued
2989 * while host was in the process of suspending.
2990 *
2991 * Return: None
2992 */
Leo Chang69c39692016-10-12 20:11:12 -07002993static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994{
2995 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2996 struct hdd_ipa_priv,
2997 pm_work);
2998 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302999 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003000 uint32_t dequeued = 0;
3001
Leo Chang69c39692016-10-12 20:11:12 -07003002 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
3003 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303004 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05303005 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
3006 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303007 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008
3009 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003010 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07003011 if (pm_tx_cb->exception) {
3012 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3013 "FLUSH EXCEPTION");
3014 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
3015 } else {
3016 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07003018 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303019 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303021 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07003022 qdf_wake_lock_release(&hdd_ipa->wake_lock,
3023 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003024
3025 hdd_ipa->stats.num_tx_dequeued += dequeued;
3026 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
3027 hdd_ipa->stats.num_max_pm_queue = dequeued;
3028}
3029
3030/**
3031 * hdd_ipa_i2w_cb() - IPA to WLAN callback
3032 * @priv: pointer to private data registered with IPA (we register a
3033 * pointer to the interface-specific IPA context)
3034 * @evt: the IPA event which triggered the callback
3035 * @data: data associated with the event
3036 *
3037 * Return: None
3038 */
3039static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
3040 unsigned long data)
3041{
3042 struct hdd_ipa_priv *hdd_ipa = NULL;
3043 struct ipa_rx_data *ipa_tx_desc;
3044 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303045 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303047 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048
Mukul Sharma81661ae2015-10-30 20:26:02 +05303049 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003050 ipa_tx_desc = (struct ipa_rx_data *)data;
3051 hdd_ipa = iface_context->hdd_ipa;
3052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003054 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
3055 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003056 iface_context->stats.num_tx_drop++;
3057 return;
3058 }
3059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003060 /*
3061 * When SSR is going on or driver is unloading, just drop the packets.
3062 * During SSR, there is no use in queueing the packets as STA has to
3063 * connect back any way
3064 */
3065 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303066 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003067 ipa_free_skb(ipa_tx_desc);
3068 iface_context->stats.num_tx_drop++;
3069 return;
3070 }
3071
3072 skb = ipa_tx_desc->skb;
3073
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303074 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003075
3076 /*
3077 * If PROD resource is not requested here then there may be cases where
3078 * IPA hardware may be clocked down because of not having proper
3079 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
3080 * workaround to request PROD resource while data is going over CONS
3081 * pipe to prevent the IPA hardware clockdown.
3082 */
3083 hdd_ipa_rm_request(hdd_ipa);
3084
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303085 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086 /*
3087 * If host is still suspended then queue the packets and these will be
3088 * drained later when resume completes. When packet is arrived here and
3089 * host is suspended, this means that there is already resume is in
3090 * progress.
3091 */
3092 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303093 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003094 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
3095 pm_tx_cb->iface_context = iface_context;
3096 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303097 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003098 hdd_ipa->stats.num_tx_queued++;
3099
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303100 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101 return;
3102 }
3103
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303104 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105
3106 /*
3107 * If we are here means, host is not suspended, wait for the work queue
3108 * to finish.
3109 */
3110#ifdef WLAN_OPEN_SOURCE
3111 flush_work(&hdd_ipa->pm_work);
3112#endif
3113
3114 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
3115}
3116
3117/**
3118 * hdd_ipa_suspend() - Suspend IPA
3119 * @hdd_ctx: Global HDD context
3120 *
3121 * Return: 0 on success, negativer errno on error
3122 */
3123int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
3124{
3125 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3126
3127 if (!hdd_ipa_is_enabled(hdd_ctx))
3128 return 0;
3129
3130 /*
3131 * Check if IPA is ready for suspend, If we are here means, there is
3132 * high chance that suspend would go through but just to avoid any race
3133 * condition after suspend started, these checks are conducted before
3134 * allowing to suspend.
3135 */
3136 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3137 return -EAGAIN;
3138
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303139 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140
3141 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303142 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 return -EAGAIN;
3144 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303145 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303147 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303149 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150
3151 return 0;
3152}
3153
3154/**
3155 * hdd_ipa_resume() - Resume IPA following suspend
3156 * hdd_ctx: Global HDD context
3157 *
3158 * Return: 0 on success, negative errno on error
3159 */
3160int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3161{
3162 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3163
3164 if (!hdd_ipa_is_enabled(hdd_ctx))
3165 return 0;
3166
3167 schedule_work(&hdd_ipa->pm_work);
3168
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303169 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303171 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172
3173 return 0;
3174}
3175
3176/**
3177 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3178 * @hdd_ipa: Global HDD IPA context
3179 *
3180 * Return: 0 on success, negative errno on error
3181 */
3182static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3183{
3184 int i, ret = 0;
3185 struct ipa_sys_connect_params *ipa;
3186 uint32_t desc_fifo_sz;
3187
3188 /* The maximum number of descriptors that can be provided to a BAM at
3189 * once is one less than the total number of descriptors that the buffer
3190 * can contain.
3191 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3192 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3193 * be provided at once.
3194 * Because of above requirement, one extra descriptor will be added to
3195 * make sure hardware always has one descriptor.
3196 */
3197 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3198 + sizeof(struct sps_iovec);
3199
3200 /*setup TX pipes */
3201 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3202 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3203
3204 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3205 ipa->desc_fifo_sz = desc_fifo_sz;
3206 ipa->priv = &hdd_ipa->iface_context[i];
3207 ipa->notify = hdd_ipa_i2w_cb;
3208
3209 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3210 ipa->ipa_ep_cfg.hdr.hdr_len =
3211 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3212 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3213 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3214 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3215 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3216 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3217 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3218 } else {
3219 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3220 }
3221 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3222
3223 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3224 ipa->keep_ipa_awake = 1;
3225
3226 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3227 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303228 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003229 " ret: %d", i, ret);
3230 goto setup_sys_pipe_fail;
3231 }
3232 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3233 }
3234
3235 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3236 /*
3237 * Hard code it here, this can be extended if in case
3238 * PROD pipe is also per interface.
3239 * Right now there is no advantage of doing this.
3240 */
3241 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3242
3243 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3244
3245 ipa->client = hdd_ipa->prod_client;
3246
3247 ipa->desc_fifo_sz = desc_fifo_sz;
3248 ipa->priv = hdd_ipa;
3249 ipa->notify = hdd_ipa_w2i_cb;
3250
3251 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3252 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3253 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3254 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3255
3256 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3257 ipa->keep_ipa_awake = 1;
3258
3259 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3260 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303261 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262 "Failed for RX pipe: %d", ret);
3263 goto setup_sys_pipe_fail;
3264 }
3265 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3266 }
3267
3268 return ret;
3269
3270setup_sys_pipe_fail:
3271
3272 while (--i >= 0) {
3273 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303274 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275 sizeof(struct hdd_ipa_sys_pipe));
3276 }
3277
3278 return ret;
3279}
3280
3281/**
3282 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3283 * @hdd_ipa: Global HDD IPA context
3284 *
3285 * Return: None
3286 */
3287static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3288{
3289 int ret = 0, i;
3290 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3291 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3292 ret =
3293 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3294 conn_hdl);
3295 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303296 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297 ret);
3298
3299 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3300 }
3301 }
3302}
3303
3304/**
3305 * hdd_ipa_register_interface() - register IPA interface
3306 * @hdd_ipa: Global IPA context
3307 * @iface_context: Per-interface IPA context
3308 *
3309 * Return: 0 on success, negative errno on error
3310 */
3311static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3312 struct hdd_ipa_iface_context
3313 *iface_context)
3314{
3315 struct ipa_tx_intf tx_intf;
3316 struct ipa_rx_intf rx_intf;
3317 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3318 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3319 char *ifname = iface_context->adapter->dev->name;
3320
3321 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3322 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3323
3324 int num_prop = 1;
3325 int ret = 0;
3326
3327 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3328 num_prop++;
3329
3330 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3331 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303332 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303334 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335 goto register_interface_fail;
3336 }
3337
3338 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3339 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303340 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303342 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003343 goto register_interface_fail;
3344 }
3345
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303346 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3347 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348
3349 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3350 ifname, HDD_IPA_IPV4_NAME_EXT);
3351 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3352 ifname, HDD_IPA_IPV6_NAME_EXT);
3353
3354 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3355 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3356 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3357 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3358
3359 /*
3360 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3361 * mask to identify the interface in IPA hardware
3362 */
3363 rx_prop[IPA_IP_v4].attrib.meta_data =
3364 htonl(iface_context->adapter->sessionId << 16);
3365 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3366
3367 rx_intf.num_props++;
3368 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3369 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3370 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3371 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3372 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3373 rx_prop[IPA_IP_v4].attrib.meta_data =
3374 htonl(iface_context->adapter->sessionId << 16);
3375 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3376
3377 rx_intf.num_props++;
3378 }
3379
3380 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3381 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3382 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3383 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3384 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3385 IPA_RESOURCE_NAME_MAX);
3386 tx_intf.num_props++;
3387
3388 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3389 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3390 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3391 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3392 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3393 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3394 IPA_RESOURCE_NAME_MAX);
3395 tx_intf.num_props++;
3396 }
3397
3398 tx_intf.prop = tx_prop;
3399 rx_intf.prop = rx_prop;
3400
3401 /* Call the ipa api to register interface */
3402 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3403
3404register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303405 qdf_mem_free(tx_prop);
3406 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 return ret;
3408}
3409
3410/**
3411 * hdd_remove_ipa_header() - Remove a specific header from IPA
3412 * @name: Name of the header to be removed
3413 *
3414 * Return: None
3415 */
3416static void hdd_ipa_remove_header(char *name)
3417{
3418 struct ipa_ioc_get_hdr hdrlookup;
3419 int ret = 0, len;
3420 struct ipa_ioc_del_hdr *ipa_hdr;
3421
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303422 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3424 ret = ipa_get_hdr(&hdrlookup);
3425 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303426 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427 name, ret);
3428 return;
3429 }
3430
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303431 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303433 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303435 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 return;
3437 }
3438 ipa_hdr->num_hdls = 1;
3439 ipa_hdr->commit = 0;
3440 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3441 ipa_hdr->hdl[0].status = -1;
3442 ret = ipa_del_hdr(ipa_hdr);
3443 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303444 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445 ret);
3446
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303447 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448}
3449
3450/**
3451 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3452 * @hdd_ipa: Global HDD IPA context
3453 * @iface_context: Interface-specific HDD IPA context
3454 * @mac_addr: Interface MAC address
3455 *
3456 * Return: 0 on success, negativer errno value on error
3457 */
3458static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3459 struct hdd_ipa_iface_context *iface_context,
3460 uint8_t *mac_addr)
3461{
3462 hdd_adapter_t *adapter = iface_context->adapter;
3463 char *ifname;
3464 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3465 int ret = -EINVAL;
3466 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3467 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3468
3469 ifname = adapter->dev->name;
3470
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303471 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 ifname, mac_addr);
3473
3474 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303475 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 + sizeof(struct ipa_hdr_add));
3477 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303478 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 "%s: ipa_hdr allocation failed", ifname);
3480 ret = -ENOMEM;
3481 goto end;
3482 }
3483
3484 ipa_hdr->commit = 0;
3485 ipa_hdr->num_hdrs = 1;
3486
3487 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3488 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3489 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3490 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3491 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303492 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 "ifname=%s, vdev_id=%d",
3494 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3495 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3496 ifname, HDD_IPA_IPV4_NAME_EXT);
3497 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3498 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3499 ipa_hdr->hdr[0].is_partial = 1;
3500 ipa_hdr->hdr[0].hdr_hdl = 0;
3501 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3502 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3503
3504 ret = ipa_add_hdr(ipa_hdr);
3505 } else {
3506 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3507
3508 /* Set the Source MAC */
3509 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3510 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3511
3512 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3513 ifname, HDD_IPA_IPV4_NAME_EXT);
3514 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3515 ipa_hdr->hdr[0].is_partial = 1;
3516 ipa_hdr->hdr[0].hdr_hdl = 0;
3517 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3518 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3519
3520 /* Set the type to IPV4 in the header */
3521 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3522
3523 ret = ipa_add_hdr(ipa_hdr);
3524 }
3525 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303526 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003527 ifname, ret);
3528 goto end;
3529 }
3530
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303531 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3533
3534 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3535 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3536 ifname, HDD_IPA_IPV6_NAME_EXT);
3537
3538 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3539 uc_tx_hdr =
3540 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3541 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3542 } else {
3543 /* Set the type to IPV6 in the header */
3544 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3545 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3546 }
3547
3548 ret = ipa_add_hdr(ipa_hdr);
3549 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303550 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551 "%s: IPv6 add hdr failed: %d", ifname, ret);
3552 goto clean_ipv4_hdr;
3553 }
3554
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303555 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003556 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3557 }
3558
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303559 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560
3561 return ret;
3562
3563clean_ipv4_hdr:
3564 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3565 ifname, HDD_IPA_IPV4_NAME_EXT);
3566 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3567end:
3568 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303569 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003570
3571 return ret;
3572}
3573
3574/**
3575 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3576 * @adapter: Adapter upon which IPA was previously configured
3577 *
3578 * Return: None
3579 */
3580static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3581{
3582 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3583 int ret;
3584 char name_ipa[IPA_RESOURCE_NAME_MAX];
3585
3586 /* Remove the headers */
3587 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3588 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3589 hdd_ipa_remove_header(name_ipa);
3590
3591 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3592 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3593 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3594 hdd_ipa_remove_header(name_ipa);
3595 }
3596 /* unregister the interface with IPA */
3597 ret = ipa_deregister_intf(adapter->dev->name);
3598 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303599 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 "%s: ipa_deregister_intf fail: %d",
3601 adapter->dev->name, ret);
3602}
3603
3604/**
3605 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3606 * @iface_context: interface-specific IPA context
3607 *
3608 * Return: None
3609 */
3610static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3611{
3612 if (iface_context == NULL)
3613 return;
3614
3615 hdd_ipa_clean_hdr(iface_context->adapter);
3616
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303617 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 iface_context->adapter->ipa_context = NULL;
3619 iface_context->adapter = NULL;
3620 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303621 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622 iface_context->ifa_address = 0;
3623 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303624 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303626 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003627 }
3628 iface_context->hdd_ipa->num_iface--;
3629}
3630
3631/**
3632 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3633 * @hdd_ipa: HDD IPA global context
3634 * @adapter: Interface upon which IPA is being setup
3635 * @sta_id: Station ID of the API instance
3636 *
3637 * Return: 0 on success, negative errno value on error
3638 */
3639static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3640 hdd_adapter_t *adapter, uint8_t sta_id)
3641{
3642 struct hdd_ipa_iface_context *iface_context = NULL;
3643 void *tl_context = NULL;
3644 int i, ret = 0;
3645
3646 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3647 * channel change indication. Since these indications are sent by lower
3648 * layer as SAP updates and IPA doesn't have to do anything for these
3649 * updates so ignoring!
3650 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003651 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 return 0;
3653
3654 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3655 if (hdd_ipa->iface_context[i].adapter == NULL) {
3656 iface_context = &(hdd_ipa->iface_context[i]);
3657 break;
3658 }
3659 }
3660
3661 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303662 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 "All the IPA interfaces are in use");
3664 ret = -ENOMEM;
3665 goto end;
3666 }
3667
3668 adapter->ipa_context = iface_context;
3669 iface_context->adapter = adapter;
3670 iface_context->sta_id = sta_id;
Leo Changfdb45c32016-10-28 11:09:23 -07003671 tl_context = cdp_peer_get_vdev_by_sta_id(
3672 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003673 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303674 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003675 "Not able to get TL context sta_id: %d", sta_id);
3676 ret = -EINVAL;
3677 goto end;
3678 }
3679
3680 iface_context->tl_context = tl_context;
3681
3682 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3683 adapter->dev->dev_addr);
3684
3685 if (ret)
3686 goto end;
3687
3688 /* Configure the TX and RX pipes filter rules */
3689 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3690 if (ret)
3691 goto cleanup_header;
3692
3693 hdd_ipa->num_iface++;
3694 return ret;
3695
3696cleanup_header:
3697
3698 hdd_ipa_clean_hdr(adapter);
3699end:
3700 if (iface_context)
3701 hdd_ipa_cleanup_iface(iface_context);
3702 return ret;
3703}
3704
Yun Parka27049a2016-10-11 12:30:49 -07003705#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706/**
3707 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3708 * @mcc_mode: 0=MCC/1=SCC
3709 *
3710 * Return: 0 on success, negative errno value on error
3711 */
3712int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3713{
3714 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303715 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716 hdd_adapter_t *pAdapter;
3717 struct ipa_msg_meta meta;
3718 struct ipa_wlan_msg *msg;
3719 int ret;
3720
3721 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3722 return -EINVAL;
3723
3724 if (!pHddCtx->mcc_mode) {
3725 /* Flush TxRx queue for each adapter before switch to SCC */
3726 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303727 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003729 if (pAdapter->device_mode == QDF_STA_MODE ||
3730 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303731 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003732 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3733 pAdapter->device_mode);
3734 hdd_deinit_tx_rx(pAdapter);
3735 }
3736 status = hdd_get_next_adapter(
3737 pHddCtx, adapter_node, &next);
3738 adapter_node = next;
3739 }
3740 }
3741
3742 /* Send SCC/MCC Switching event to IPA */
3743 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303744 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745 if (msg == NULL) {
3746 hddLog(LOGE, "msg allocation failed");
3747 return -ENOMEM;
3748 }
3749
3750 meta.msg_type = mcc_mode ?
3751 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3752 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3753
3754 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3755
3756 if (ret) {
3757 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3758 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303759 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760 }
3761
3762 return ret;
3763}
Yun Parka27049a2016-10-11 12:30:49 -07003764#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765
3766/**
3767 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3768 * @event: IPA WLAN event to be converted to a string
3769 *
3770 * Return: ASCII string representing the IPA WLAN event
3771 */
3772static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3773{
3774 switch (event) {
3775 case WLAN_CLIENT_CONNECT:
3776 return "WLAN_CLIENT_CONNECT";
3777 case WLAN_CLIENT_DISCONNECT:
3778 return "WLAN_CLIENT_DISCONNECT";
3779 case WLAN_CLIENT_POWER_SAVE_MODE:
3780 return "WLAN_CLIENT_POWER_SAVE_MODE";
3781 case WLAN_CLIENT_NORMAL_MODE:
3782 return "WLAN_CLIENT_NORMAL_MODE";
3783 case SW_ROUTING_ENABLE:
3784 return "SW_ROUTING_ENABLE";
3785 case SW_ROUTING_DISABLE:
3786 return "SW_ROUTING_DISABLE";
3787 case WLAN_AP_CONNECT:
3788 return "WLAN_AP_CONNECT";
3789 case WLAN_AP_DISCONNECT:
3790 return "WLAN_AP_DISCONNECT";
3791 case WLAN_STA_CONNECT:
3792 return "WLAN_STA_CONNECT";
3793 case WLAN_STA_DISCONNECT:
3794 return "WLAN_STA_DISCONNECT";
3795 case WLAN_CLIENT_CONNECT_EX:
3796 return "WLAN_CLIENT_CONNECT_EX";
3797
3798 case IPA_WLAN_EVENT_MAX:
3799 default:
3800 return "UNKNOWN";
3801 }
3802}
3803
3804/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003805 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3806 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3807 *
3808 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3809 */
3810static enum ipa_wlan_event
3811hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3812{
3813 enum ipa_wlan_event ipa_event;
3814
3815 switch (hdd_ipa_event_type) {
3816 case HDD_IPA_CLIENT_CONNECT:
3817 ipa_event = WLAN_CLIENT_CONNECT;
3818 break;
3819 case HDD_IPA_CLIENT_DISCONNECT:
3820 ipa_event = WLAN_CLIENT_DISCONNECT;
3821 break;
3822 case HDD_IPA_AP_CONNECT:
3823 ipa_event = WLAN_AP_CONNECT;
3824 break;
3825 case HDD_IPA_AP_DISCONNECT:
3826 ipa_event = WLAN_AP_DISCONNECT;
3827 break;
3828 case HDD_IPA_STA_CONNECT:
3829 ipa_event = WLAN_STA_CONNECT;
3830 break;
3831 case HDD_IPA_STA_DISCONNECT:
3832 ipa_event = WLAN_STA_DISCONNECT;
3833 break;
3834 case HDD_IPA_CLIENT_CONNECT_EX:
3835 ipa_event = WLAN_CLIENT_CONNECT_EX;
3836 break;
3837 case HDD_IPA_WLAN_EVENT_MAX:
3838 default:
3839 ipa_event = IPA_WLAN_EVENT_MAX;
3840 break;
3841 }
3842 return ipa_event;
3843
3844}
3845
3846/**
3847 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 * @adapter: adapter upon which the event was received
3849 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003850 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851 * @mac_address: MAC address associated with the event
3852 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003853 * This function is meant to be called from within wlan_hdd_ipa.c
3854 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 * Return: 0 on success, negative errno value on error
3856 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003857static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 enum ipa_wlan_event type, uint8_t *mac_addr)
3859{
3860 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3861 struct ipa_msg_meta meta;
3862 struct ipa_wlan_msg *msg;
3863 struct ipa_wlan_msg_ex *msg_ex = NULL;
3864 int ret;
3865
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303866 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3868 mac_addr, sta_id);
3869
3870 if (type >= IPA_WLAN_EVENT_MAX)
3871 return -EINVAL;
3872
3873 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3874 return -EINVAL;
3875
3876 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303877 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 return -EINVAL;
3879 }
3880
3881 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3882 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003883 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 return 0;
3885 }
3886
3887 /*
3888 * During IPA UC resource loading/unloading new events can be issued.
3889 * Store the events separately and handle them later.
3890 */
3891 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3892 ((hdd_ipa->resource_loading) ||
3893 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003894 unsigned int pending_event_count;
3895 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003896
Yun Parkf19e07d2015-11-20 11:34:27 -08003897 hdd_err("IPA resource %s inprogress",
3898 hdd_ipa->resource_loading ? "load":"unload");
3899
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303900 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003901
Anurag Chouhanffb21542016-02-17 14:33:03 +05303902 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003903 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3904 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303905 qdf_list_remove_front(&hdd_ipa->pending_event,
3906 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003907 } else {
3908 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303909 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003910 sizeof(struct ipa_uc_pending_event));
3911 }
3912
3913 if (!pending_event) {
3914 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303915 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916 return -ENOMEM;
3917 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003918
3919 pending_event->adapter = adapter;
3920 pending_event->sta_id = sta_id;
3921 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303922 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303924 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303925 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003926 &pending_event->node);
3927
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303928 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 return 0;
3930 }
3931
3932 hdd_ipa->stats.event[type]++;
3933
Leo Chang3bc8fed2015-11-13 10:59:47 -08003934 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 switch (type) {
3936 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003937 qdf_mutex_acquire(&hdd_ipa->event_lock);
3938
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 /* STA already connected and without disconnect, connect again
3940 * This is Roaming scenario
3941 */
3942 if (hdd_ipa->sta_connected)
3943 hdd_ipa_cleanup_iface(adapter->ipa_context);
3944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3946 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303947 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003949 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950
Yun Park8f289c82016-10-18 16:38:21 -07003951 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3952 (hdd_ipa->sap_num_connected_sta > 0) &&
3953 !hdd_ipa->sta_connected) {
3954 qdf_mutex_release(&hdd_ipa->event_lock);
3955 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003956 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07003957 qdf_mutex_acquire(&hdd_ipa->event_lock);
3958 }
3959
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003960 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003962 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003965
3966 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 break;
3968
3969 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003970 qdf_mutex_acquire(&hdd_ipa->event_lock);
3971
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 /* For DFS channel we get two start_bss event (before and after
3973 * CAC). Also when ACS range includes both DFS and non DFS
3974 * channels, we could possibly change channel many times due to
3975 * RADAR detection and chosen channel may not be a DFS channels.
3976 * So dont return error here. Just discard the event.
3977 */
Yun Park8f289c82016-10-18 16:38:21 -07003978 if (adapter->ipa_context) {
3979 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003981 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3984 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303985 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986 "%s: Evt: %d, Interface setup failed",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05303987 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303988 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003990 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991
Yun Park8f289c82016-10-18 16:38:21 -07003992 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3993 qdf_mutex_release(&hdd_ipa->event_lock);
3994 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003995 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07003996 qdf_mutex_acquire(&hdd_ipa->event_lock);
3997 }
3998
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003999 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07004001 (adapter->ipa_context))->iface_id;
4002
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304003 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 break;
4005
4006 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304007 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008
4009 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304010 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011 "%s: Evt: %d, STA already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304012 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304013 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014 return -EINVAL;
4015 }
Yun Parka37592b2016-06-11 17:10:28 -07004016
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07004018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304020 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 "%s: IPA UC OFFLOAD NOT ENABLED",
4022 msg_ex->name);
4023 } else {
4024 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07004025 if (!hdd_ipa->num_iface &&
4026 (HDD_IPA_UC_NUM_WDI_PIPE ==
4027 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 }
4030
Yun Park74127cf2016-09-18 11:22:41 -07004031 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4032 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07004033 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004035 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004036 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004037 hdd_ipa->vdev_to_iface[adapter->sessionId] =
4038 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 }
4040
Yun Park8f289c82016-10-18 16:38:21 -07004041 hdd_ipa_cleanup_iface(adapter->ipa_context);
4042
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304043 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 break;
4045
4046 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07004047 qdf_mutex_acquire(&hdd_ipa->event_lock);
4048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304050 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051 "%s: Evt: %d, SAP already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304052 adapter->dev->name, type);
Yun Park8f289c82016-10-18 16:38:21 -07004053 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054 return -EINVAL;
4055 }
4056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004057 if ((!hdd_ipa->num_iface) &&
4058 (HDD_IPA_UC_NUM_WDI_PIPE ==
4059 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004060 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 /*
4062 * We disable WDI pipes directly here since
4063 * IPA_OPCODE_TX/RX_SUSPEND message will not be
4064 * processed when unloading WLAN driver is in
4065 * progress
4066 */
4067 hdd_ipa_uc_disable_pipes(hdd_ipa);
4068 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304069 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004070 "NO INTF left but still pipe clean up");
4071 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4072 }
4073 }
4074
4075 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07004076 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004078 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004079 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004080 hdd_ipa->vdev_to_iface[adapter->sessionId] =
4081 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 }
Yun Parka37592b2016-06-11 17:10:28 -07004083
Yun Park8f289c82016-10-18 16:38:21 -07004084 hdd_ipa_cleanup_iface(adapter->ipa_context);
4085
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304086 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 break;
4088
4089 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304091 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004092 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304093 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094 return 0;
4095 }
4096
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304097 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
4099 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07004100 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304101 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102 "%s: STA ID %d found, not valid",
4103 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 return 0;
4105 }
Yun Park312f71a2015-12-08 10:22:42 -08004106
4107 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07004108 if (0 == hdd_ipa->sap_num_connected_sta) {
4109 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004110 hdd_ipa->sta_connected) {
4111 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004112 hdd_ipa_uc_offload_enable_disable(
4113 hdd_get_adapter(hdd_ipa->hdd_ctx,
4114 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004115 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07004116 qdf_mutex_acquire(&hdd_ipa->event_lock);
4117 }
Yun Parka37592b2016-06-11 17:10:28 -07004118
Yun Park312f71a2015-12-08 10:22:42 -08004119 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
4120 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304121 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08004122 "%s: handle 1st con ret %d",
4123 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07004124
4125 if (hdd_ipa_uc_sta_is_enabled(
4126 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004127 hdd_ipa->sta_connected) {
4128 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004129 hdd_ipa_uc_offload_enable_disable(
4130 hdd_get_adapter(
4131 hdd_ipa->hdd_ctx,
4132 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004133 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004134 } else {
4135 qdf_mutex_release(&hdd_ipa->event_lock);
4136 }
Yun Parka37592b2016-06-11 17:10:28 -07004137
Yun Park312f71a2015-12-08 10:22:42 -08004138 return ret;
4139 }
4140 }
4141
4142 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08004143
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304144 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145
4146 meta.msg_type = type;
4147 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
4148 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304149 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150
4151 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304152 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 "msg_ex allocation failed");
4154 return -ENOMEM;
4155 }
4156 strlcpy(msg_ex->name, adapter->dev->name,
4157 IPA_RESOURCE_NAME_MAX);
4158 msg_ex->num_of_attribs = 1;
4159 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4160 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4161 msg_ex->attribs[0].offset =
4162 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4163 } else {
4164 msg_ex->attribs[0].offset =
4165 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4166 }
4167 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4168 IPA_MAC_ADDR_SIZE);
4169
4170 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4171
4172 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304173 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304174 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304175 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 return ret;
4177 }
4178 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 return ret;
4180
4181 case WLAN_CLIENT_DISCONNECT:
4182 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304183 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184 "%s: IPA UC OFFLOAD NOT ENABLED",
4185 msg_ex->name);
4186 return 0;
4187 }
4188
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304189 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304191 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192 "%s: STA ID %d NOT found, not valid",
4193 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304194 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004195 return 0;
4196 }
4197 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07004198
Yun Park9b5030f2016-11-08 12:02:37 -08004199 /* Disable IPA UC TX PIPE when last STA disconnected */
4200 if (!hdd_ipa->sap_num_connected_sta) {
4201 if ((false == hdd_ipa->resource_unloading)
4202 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4203 hdd_ipa->activated_fw_pipe)) {
4204 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4205 }
4206
Yun Park8f289c82016-10-18 16:38:21 -07004207 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004208
4209 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4210 hdd_ipa->sta_connected)
4211 hdd_ipa_uc_offload_enable_disable(
4212 hdd_get_adapter(hdd_ipa->hdd_ctx,
4213 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004214 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07004215 } else {
4216 qdf_mutex_release(&hdd_ipa->event_lock);
4217 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218 break;
4219
4220 default:
4221 return 0;
4222 }
4223
4224 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304225 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304227 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004228 return -ENOMEM;
4229 }
4230
4231 meta.msg_type = type;
4232 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4233 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4234
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304235 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236 msg->name, meta.msg_type);
4237
4238 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4239
4240 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304241 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004242 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304243 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 return ret;
4245 }
4246
4247 hdd_ipa->stats.num_send_msg++;
4248
4249end:
4250 return ret;
4251}
4252
4253/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004254 * hdd_ipa_wlan_evt() - IPA event handler
4255 * @adapter: adapter upon which the event was received
4256 * @sta_id: station id for the event
4257 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4258 * @mac_address: MAC address associated with the event
4259 *
4260 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4261 *
4262 * Return: 0 on success, negative errno value on error
4263 */
4264int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4265 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4266{
4267 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4268
Leo Changa202b522016-10-14 16:13:50 -07004269 /* Data path offload only support for STA and SAP mode */
4270 if ((QDF_STA_MODE == adapter->device_mode) ||
4271 (QDF_SAP_MODE == adapter->device_mode))
4272 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4273
4274 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004275}
4276
4277/**
4278 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4279 * @hdd_ipa: Global HDD IPA context
4280 *
4281 * Return: None
4282 */
4283static void
4284hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4285{
4286 unsigned int pending_event_count;
4287 struct ipa_uc_pending_event *pending_event = NULL;
4288
4289 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4290 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4291 "%s, Pending Event Count %d", __func__, pending_event_count);
4292 if (!pending_event_count) {
4293 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4294 "%s, No Pending Event", __func__);
4295 return;
4296 }
4297
4298 qdf_list_remove_front(&hdd_ipa->pending_event,
4299 (qdf_list_node_t **)&pending_event);
4300 while (pending_event != NULL) {
4301 __hdd_ipa_wlan_evt(pending_event->adapter,
4302 pending_event->type,
4303 pending_event->sta_id,
4304 pending_event->mac_addr);
4305 qdf_mem_free(pending_event);
4306 pending_event = NULL;
4307 qdf_list_remove_front(&hdd_ipa->pending_event,
4308 (qdf_list_node_t **)&pending_event);
4309 }
4310}
4311
4312/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4314 * @state: IPA RM state value
4315 *
4316 * Return: ASCII string representing the IPA RM state
4317 */
4318static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4319{
4320 switch (state) {
4321 case HDD_IPA_RM_RELEASED:
4322 return "RELEASED";
4323 case HDD_IPA_RM_GRANT_PENDING:
4324 return "GRANT_PENDING";
4325 case HDD_IPA_RM_GRANTED:
4326 return "GRANTED";
4327 }
4328
4329 return "UNKNOWN";
4330}
4331
4332/**
4333 * hdd_ipa_init() - IPA initialization function
4334 * @hdd_ctx: HDD global context
4335 *
4336 * Allocate hdd_ipa resources, ipa pipe resource and register
4337 * wlan interface with IPA module.
4338 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304339 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304341QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004342{
4343 struct hdd_ipa_priv *hdd_ipa = NULL;
4344 int ret, i;
4345 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004346 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347
4348 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304349 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350
Yun Park7f171ab2016-07-29 15:44:22 -07004351 if (!pdev) {
4352 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4353 goto fail_return;
4354 }
4355
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304356 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304358 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004359 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360 }
4361
4362 hdd_ctx->hdd_ipa = hdd_ipa;
4363 ghdd_ipa = hdd_ipa;
4364 hdd_ipa->hdd_ctx = hdd_ctx;
4365 hdd_ipa->num_iface = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07004366 cdp_ipa_get_resource(cds_get_context(QDF_MODULE_ID_SOC),
4367 cds_get_context(QDF_MODULE_ID_TXRX),
4368 &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004369 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4370 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4371 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4372 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304373 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004374 "IPA UC resource alloc fail");
4375 goto fail_get_resource;
4376 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377
4378 /* Create the interface context */
4379 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4380 iface_context = &hdd_ipa->iface_context[i];
4381 iface_context->hdd_ipa = hdd_ipa;
4382 iface_context->cons_client =
4383 hdd_ipa_adapter_2_client[i].cons_client;
4384 iface_context->prod_client =
4385 hdd_ipa_adapter_2_client[i].prod_client;
4386 iface_context->iface_id = i;
4387 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304388 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004389 }
4390 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004391 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
4392 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 }
4394
Leo Chang69c39692016-10-12 20:11:12 -07004395 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304396 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304397 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398
4399 ret = hdd_ipa_setup_rm(hdd_ipa);
4400 if (ret)
4401 goto fail_setup_rm;
4402
4403 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4404 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304405 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406 hdd_ipa->sap_num_connected_sta = 0;
4407 hdd_ipa->ipa_tx_packets_diff = 0;
4408 hdd_ipa->ipa_rx_packets_diff = 0;
4409 hdd_ipa->ipa_p_tx_packets = 0;
4410 hdd_ipa->ipa_p_rx_packets = 0;
4411 hdd_ipa->resource_loading = false;
4412 hdd_ipa->resource_unloading = false;
4413 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004414 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415 /* Setup IPA sys_pipe for MCC */
4416 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4417 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4418 if (ret)
4419 goto fail_create_sys_pipe;
4420 }
4421 hdd_ipa_uc_ol_init(hdd_ctx);
4422 } else {
4423 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4424 if (ret)
4425 goto fail_create_sys_pipe;
4426 }
4427
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304428 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429
4430fail_create_sys_pipe:
4431 hdd_ipa_destroy_rm_resource(hdd_ipa);
4432fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304433 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004434fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304435 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004436 hdd_ctx->hdd_ipa = NULL;
4437 ghdd_ipa = NULL;
4438fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304439 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004440}
4441
4442/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004443 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4444 * @hdd_ipa: pointer to HDD IPA struct
4445 *
4446 * Return: none
4447 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004448static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004449{
4450 struct ipa_uc_pending_event *pending_event = NULL;
4451
Anurag Chouhanffb21542016-02-17 14:33:03 +05304452 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4453 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304454 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004455 }
4456
Anurag Chouhanffb21542016-02-17 14:33:03 +05304457 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004458}
4459
4460/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004461 * hdd_ipa_cleanup - IPA cleanup function
4462 * @hdd_ctx: HDD global context
4463 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304464 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304466QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004467{
4468 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4469 int i;
4470 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304471 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004472 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4473
4474 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304475 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476
4477 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4478 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4479 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4480 }
4481
4482 /* Teardown IPA sys_pipe for MCC */
4483 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4484 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4485
4486 hdd_ipa_destroy_rm_resource(hdd_ipa);
4487
4488#ifdef WLAN_OPEN_SOURCE
4489 cancel_work_sync(&hdd_ipa->pm_work);
4490#endif
4491
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304492 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493
Nirav Shahcbc6d722016-03-01 16:24:53 +05304494 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4495 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304496 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004497
4498 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4499 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4500
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304501 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004502 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304503 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304505 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506
4507 /* destory the interface lock */
4508 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4509 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304510 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 }
4512
4513 /* This should never hit but still make sure that there are no pending
4514 * descriptor in IPA hardware
4515 */
4516 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304517 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 "IPA Pending write done: %d Waiting!",
4519 hdd_ipa->pending_hw_desc_cnt);
4520
4521 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4522 usleep_range(100, 100);
4523 }
4524
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304525 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526 "IPA Pending write done: desc: %d %s(%d)!",
4527 hdd_ipa->pending_hw_desc_cnt,
4528 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4529 : "leak", i);
4530 }
4531 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4532 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304533 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304534 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4535 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304537 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304538 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4539 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304541 qdf_mutex_destroy(&hdd_ipa->event_lock);
4542 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004543 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004544
4545#ifdef WLAN_OPEN_SOURCE
4546 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4547 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4548 hdd_ipa->uc_op_work[i].msg = NULL;
4549 }
4550#endif
4551 }
4552
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304553 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004554 hdd_ctx->hdd_ipa = NULL;
4555
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304556 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004557}
4558#endif /* IPA_OFFLOAD */