blob: 2748ac8c7bdb67b33a5398ec98b2862b4901c3ae [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"
57
Dhanashri Atreb08959a2016-03-01 17:28:03 -080058#include "cdp_txrx_ipa.h"
59
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060#define HDD_IPA_DESC_BUFFER_RATIO 4
61#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
62#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
63
64#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080065#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
66/* WDI TX and RX PIPE */
67#define HDD_IPA_UC_NUM_WDI_PIPE 2
68#define HDD_IPA_UC_MAX_PENDING_EVENT 33
69
70#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
71#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
72#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
73#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
74
75#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
76#define HDD_IPA_MAX_IFACE 3
77#define HDD_IPA_MAX_SYSBAM_PIPE 4
78#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
79#define HDD_IPA_ENABLE_MASK BIT(0)
80#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
81#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
82#define HDD_IPA_RM_ENABLE_MASK BIT(3)
83#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
84#define HDD_IPA_UC_ENABLE_MASK BIT(5)
85#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
86#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
87
Yun Parkf19e07d2015-11-20 11:34:27 -080088#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
89
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080090typedef enum {
91 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
92 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
93 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
94 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
95 HDD_IPA_UC_OPCODE_STATS = 4,
96 /* keep this last */
97 HDD_IPA_UC_OPCODE_MAX
98} hdd_ipa_uc_op_code;
99
100/**
101 * enum - Reason codes for stat query
102 *
103 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
104 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
105 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
106 */
107enum {
108 HDD_IPA_UC_STAT_REASON_NONE,
109 HDD_IPA_UC_STAT_REASON_DEBUG,
110 HDD_IPA_UC_STAT_REASON_BW_CAL
111};
112
113/**
114 * enum hdd_ipa_rm_state - IPA resource manager state
115 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
116 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
117 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
118 */
119enum hdd_ipa_rm_state {
120 HDD_IPA_RM_RELEASED,
121 HDD_IPA_RM_GRANT_PENDING,
122 HDD_IPA_RM_GRANTED,
123};
124
125struct llc_snap_hdr {
126 uint8_t dsap;
127 uint8_t ssap;
128 uint8_t resv[4];
129 __be16 eth_type;
130} __packed;
131
Leo Chang3bc8fed2015-11-13 10:59:47 -0800132/**
133 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
134 * @eth: ether II header
135 * @llc_snap: LLC snap header
136 *
137 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138struct hdd_ipa_tx_hdr {
139 struct ethhdr eth;
140 struct llc_snap_hdr llc_snap;
141} __packed;
142
Leo Chang3bc8fed2015-11-13 10:59:47 -0800143/**
144 * struct frag_header - fragment header type registered to IPA hardware
145 * @length: fragment length
146 * @reserved1: Reserved not used
147 * @reserved2: Reserved not used
148 *
149 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800151 uint16_t length;
152 uint32_t reserved1;
153 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800154} __packed;
155
Leo Chang3bc8fed2015-11-13 10:59:47 -0800156/**
157 * struct ipa_header - ipa header type registered to IPA hardware
158 * @vdev_id: vdev id
159 * @reserved: Reserved not used
160 *
161 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800162struct ipa_header {
163 uint32_t
164 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
165 reserved:24;
166} __packed;
167
Leo Chang3bc8fed2015-11-13 10:59:47 -0800168/**
169 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
170 * @frag_hd: fragment header
171 * @ipa_hd: ipa header
172 * @eth: ether II header
173 *
174 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800175struct hdd_ipa_uc_tx_hdr {
176 struct frag_header frag_hd;
177 struct ipa_header ipa_hd;
178 struct ethhdr eth;
179} __packed;
180
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800181/**
182 * struct hdd_ipa_cld_hdr - IPA CLD Header
183 * @reserved: reserved fields
184 * @iface_id: interface ID
185 * @sta_id: Station ID
186 *
187 * Packed 32-bit structure
188 * +----------+----------+--------------+--------+
189 * | Reserved | QCMAP ID | interface id | STA ID |
190 * +----------+----------+--------------+--------+
191 */
192struct hdd_ipa_cld_hdr {
193 uint8_t reserved[2];
194 uint8_t iface_id;
195 uint8_t sta_id;
196} __packed;
197
198struct hdd_ipa_rx_hdr {
199 struct hdd_ipa_cld_hdr cld_hdr;
200 struct ethhdr eth;
201} __packed;
202
203struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700204 bool exception;
205 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800206 struct hdd_ipa_iface_context *iface_context;
207 struct ipa_rx_data *ipa_tx_desc;
208};
209
210struct hdd_ipa_uc_rx_hdr {
211 struct ethhdr eth;
212} __packed;
213
214struct hdd_ipa_sys_pipe {
215 uint32_t conn_hdl;
216 uint8_t conn_hdl_valid;
217 struct ipa_sys_connect_params ipa_sys_params;
218};
219
220struct hdd_ipa_iface_stats {
221 uint64_t num_tx;
222 uint64_t num_tx_drop;
223 uint64_t num_tx_err;
224 uint64_t num_tx_cac_drop;
225 uint64_t num_rx_prefilter;
226 uint64_t num_rx_ipa_excep;
227 uint64_t num_rx_recv;
228 uint64_t num_rx_recv_mul;
229 uint64_t num_rx_send_desc_err;
230 uint64_t max_rx_mul;
231};
232
233struct hdd_ipa_priv;
234
235struct hdd_ipa_iface_context {
236 struct hdd_ipa_priv *hdd_ipa;
237 hdd_adapter_t *adapter;
238 void *tl_context;
239
240 enum ipa_client_type cons_client;
241 enum ipa_client_type prod_client;
242
243 uint8_t iface_id; /* This iface ID */
244 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530245 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246 uint32_t ifa_address;
247 struct hdd_ipa_iface_stats stats;
Yun Park8292dcb2016-10-07 16:46:06 -0700248 uint32_t offload_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800249};
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};
349static uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
350
351/**
352 * struct uc_rt_debug_info
353 * @time: system time
354 * @ipa_excep_count: IPA exception packet count
355 * @rx_drop_count: IPA Rx drop packet count
356 * @net_sent_count: IPA Rx packet sent to network stack count
357 * @rx_discard_count: IPA Rx discard packet count
358 * @rx_mcbc_count: IPA Rx BCMC packet count
359 * @tx_mcbc_count: IPA Tx BCMC packet countt
360 * @tx_fwd_count: IPA Tx forward packet count
361 * @rx_destructor_call: IPA Rx packet destructor count
362 */
363struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530364 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365 uint64_t ipa_excep_count;
366 uint64_t rx_drop_count;
367 uint64_t net_sent_count;
368 uint64_t rx_discard_count;
369 uint64_t rx_mcbc_count;
370 uint64_t tx_mcbc_count;
371 uint64_t tx_fwd_count;
372 uint64_t rx_destructor_call;
373};
374
375struct hdd_ipa_priv {
376 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
377 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
378 uint8_t num_iface;
379 enum hdd_ipa_rm_state rm_state;
380 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530381 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800382 * APIs as it is taken care gracefully. Without this, kernel would throw
383 * an warning if spin_lock_bh is used while IRQ is disabled
384 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530385 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800386 struct uc_rm_work_struct uc_rm_work;
387 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530388 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800389 struct delayed_work wake_lock_work;
390 bool wake_lock_released;
391
392 enum ipa_client_type prod_client;
393
394 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530395 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530397 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800398 bool suspended;
399
400 uint32_t pending_hw_desc_cnt;
401 uint32_t hw_desc_cnt;
402 spinlock_t q_lock;
403 uint32_t freeq_cnt;
404 struct list_head free_desc_head;
405
406 uint32_t pend_q_cnt;
407 struct list_head pend_desc_head;
408
409 hdd_context_t *hdd_ctx;
410
411 struct dentry *debugfs_dir;
412 struct hdd_ipa_stats stats;
413
414 struct notifier_block ipv4_notifier;
415 uint32_t curr_prod_bw;
416 uint32_t curr_cons_bw;
417
418 uint8_t activated_fw_pipe;
419 uint8_t sap_num_connected_sta;
420 uint8_t sta_connected;
421 uint32_t tx_pipe_handle;
422 uint32_t rx_pipe_handle;
423 bool resource_loading;
424 bool resource_unloading;
425 bool pending_cons_req;
426 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530427 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530428 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700429 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800430 uint32_t ipa_tx_packets_diff;
431 uint32_t ipa_rx_packets_diff;
432 uint32_t ipa_p_tx_packets;
433 uint32_t ipa_p_rx_packets;
434 uint32_t stat_req_reason;
435 uint64_t ipa_tx_forward;
436 uint64_t ipa_rx_discard;
437 uint64_t ipa_rx_net_send_count;
438 uint64_t ipa_rx_internel_drop_count;
439 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530440 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
442 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530443 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530444 qdf_mutex_t rt_debug_lock;
445 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800446 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800447 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530448 qdf_dma_addr_t tx_comp_doorbell_paddr;
449 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800450};
451
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800452/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800453 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800454 * They will be implemented fully by another update.
455 * The stubs will let the compile go ahead, and functionality
456 * is broken.
457 * This should be OK and IPA is not enabled yet
458 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700459static void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800460{
461 void *vaddr;
462 uint32_t ipa_priv = priv;
463
464 vaddr = &ipa_priv; /* just to use the var */
465 vaddr = NULL;
466 return vaddr;
467}
468
Jeff Johnsond7720632016-10-05 16:04:32 -0700469static uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800470{
471 uint32_t ipa_priv = 0;
472
473 BUG_ON(ptr == NULL);
474 return ipa_priv;
475}
Leo Changcc923e22016-06-16 15:29:03 -0700476
477#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
478#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800479#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
480#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
481#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
482#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
483#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
484#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700485#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
486 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800487
Leo Chang3bc8fed2015-11-13 10:59:47 -0800488#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
489#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491#define HDD_IPA_GET_IFACE_ID(_data) \
492 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
493
494#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530495 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496 "%s:%d: "fmt, __func__, __LINE__, ## args)
497
Govind Singhb6a89772016-08-12 11:23:35 +0530498#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
499 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
500 "%s:%d: "fmt, __func__, __LINE__, ## args)
501
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800502#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
503 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530504 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
505 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506 } while (0)
507
508#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
509 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
510
511#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
512 do { \
513 hdd_ipa->ipa_rx_internel_drop_count++; \
514 } while (0)
515#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
516 do { \
517 hdd_ipa->ipa_rx_net_send_count++; \
518 } while (0)
519#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
520
Leo Chang07b28f62016-05-11 12:29:22 -0700521#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800522#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
523do { \
524 pipe_in.u.ul.rdy_ring_rp_va = \
525 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
526 pipe_in.u.ul.rdy_comp_ring_base_pa = \
527 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
528 pipe_in.u.ul.rdy_comp_ring_size = \
529 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
530 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
531 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
532 pipe_in.u.ul.rdy_comp_ring_wp_va = \
533 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800534} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700535
536#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800537#else
538/* Do nothing */
539#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700540#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700541#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543static struct hdd_ipa_adapter_2_client {
544 enum ipa_client_type cons_client;
545 enum ipa_client_type prod_client;
546} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
547 {
548 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
549 }, {
550 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
551 }, {
552 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
553 },
554};
555
556/* For Tx pipes, use Ethernet-II Header format */
557struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
558 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800559 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560 0x00000000,
561 0x00000000
562 },
563 {
564 0x00000000
565 },
566 {
567 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
568 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
569 0x0008
570 }
571};
572
573/* For Tx pipes, use 802.3 Header format */
574static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
575 {
576 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
577 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
578 0x00 /* length can be zero */
579 },
580 {
581 /* LLC SNAP header 8 bytes */
582 0xaa, 0xaa,
583 {0x03, 0x00, 0x00, 0x00},
584 0x0008 /* type value(2 bytes) ,filled by wlan */
585 /* 0x0800 - IPV4, 0x86dd - IPV6 */
586 }
587};
588
589static const char *op_string[] = {
590 "TX_SUSPEND",
591 "TX_RESUME",
592 "RX_SUSPEND",
593 "RX_RESUME",
594 "STATS",
595};
596
597static struct hdd_ipa_priv *ghdd_ipa;
598
599/* Local Function Prototypes */
600static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
601 unsigned long data);
602static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
603 unsigned long data);
604
605static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700606static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607
608/**
609 * hdd_ipa_is_enabled() - Is IPA enabled?
610 * @hdd_ctx: Global HDD context
611 *
612 * Return: true if IPA is enabled, false otherwise
613 */
614bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
615{
616 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
617}
618
619/**
620 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
621 * @hdd_ctx: Global HDD context
622 *
623 * Return: true if IPA uC offload is enabled, false otherwise
624 */
625bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
626{
627 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
628}
629
630/**
631 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
632 * @hdd_ctx: Global HDD context
633 *
634 * Return: true if STA mode IPA uC offload is enabled, false otherwise
635 */
636static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
637{
638 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
639}
640
641/**
642 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
643 * @hdd_ipa: Global HDD IPA context
644 *
645 * Return: true if pre-filter is enabled, otherwise false
646 */
647static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
648{
649 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
650 HDD_IPA_PRE_FILTER_ENABLE_MASK);
651}
652
653/**
654 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
655 * @hdd_ipa: Global HDD IPA context
656 *
657 * Return: true if IPv6 is enabled, otherwise false
658 */
659static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
660{
661 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
662}
663
664/**
665 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
666 * @hdd_ipa: Global HDD IPA context
667 *
668 * Return: true if resource manager is enabled, otherwise false
669 */
670static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
671{
672 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
673}
674
675/**
676 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
677 * @hdd_ipa: Global HDD IPA context
678 *
679 * Return: true if resource manager is enabled, otherwise false
680 */
681static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
682{
683 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
684}
685
686/**
687 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
688 * @hdd_ipa: Global HDD IPA context
689 *
690 * Return: true if clock scaling is enabled, otherwise false
691 */
692static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
693{
694 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
695 HDD_IPA_CLK_SCALING_ENABLE_MASK |
696 HDD_IPA_RM_ENABLE_MASK);
697}
698
699/**
700 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
701 * @ctext: pointer to hdd context.
702 *
703 * If rt debug enabled, periodically called, and fill debug buffer
704 *
705 * Return: none
706 */
707static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
708{
709 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
710 struct hdd_ipa_priv *hdd_ipa;
711 struct uc_rt_debug_info *dump_info = NULL;
712
713 if (wlan_hdd_validate_context(hdd_ctx))
714 return;
715
716 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530717 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800718 "%s: IPA UC is not enabled", __func__);
719 return;
720 }
721
722 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
723
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530724 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800725 dump_info = &hdd_ipa->rt_bug_buffer[
726 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
727
Deepthi Gowri6acee342016-10-28 15:00:38 +0530728 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
730 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
731 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
732 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
733 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
734 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
735 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
736 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530737 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738
Anurag Chouhan210db072016-02-22 18:42:15 +0530739 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800740 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
741}
742
743/**
744 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
745 * @hdd_ctx: pointer to hdd context.
746 *
747 * If rt debug enabled, dump debug buffer contents based on requirement
748 *
749 * Return: none
750 */
751void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
752{
753 struct hdd_ipa_priv *hdd_ipa;
754 unsigned int dump_count;
755 unsigned int dump_index;
756 struct uc_rt_debug_info *dump_info = NULL;
757
758 if (wlan_hdd_validate_context(hdd_ctx))
759 return;
760
761 hdd_ipa = hdd_ctx->hdd_ipa;
762 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530763 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 "%s: IPA UC is not enabled", __func__);
765 return;
766 }
767
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530768 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530770 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
772
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530773 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 for (dump_count = 0;
775 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
776 dump_count++) {
777 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
778 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
779 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530780 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530781 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 dump_info->time, dump_info->ipa_excep_count,
783 dump_info->rx_drop_count, dump_info->net_sent_count,
784 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
785 dump_info->rx_destructor_call,
786 dump_info->rx_discard_count);
787 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530788 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530789 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800790 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
791}
792
793/**
794 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
795 * @ctext: pointer to hdd context.
796 *
797 * periodically called by timer expire
798 * will try to alloc dummy memory and detect out of memory condition
799 * if out of memory detected, dump wlan-ipa stats
800 *
801 * Return: none
802 */
803static void hdd_ipa_uc_rt_debug_handler(void *ctext)
804{
805 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
806 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
807 void *dummy_ptr = NULL;
808
809 if (wlan_hdd_validate_context(hdd_ctx))
810 return;
811
812 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530813 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 "%s: IPA RT debug is not enabled", __func__);
815 return;
816 }
817
818 /* Allocate dummy buffer periodically and free immediately. this will
819 * proactively detect OOM and if allocation fails dump ipa stats
820 */
821 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
822 GFP_KERNEL | GFP_ATOMIC);
823 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530824 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 "%s: Dummy alloc fail", __func__);
826 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
827 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800828 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 } else {
830 kfree(dummy_ptr);
831 }
832
Anurag Chouhan210db072016-02-22 18:42:15 +0530833 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834 HDD_IPA_UC_RT_DEBUG_PERIOD);
835}
836
837/**
838 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
839 * @skb: packet pinter
840 *
841 * when free data packet, will be invoked by wlan client and will increase
842 * free counter
843 *
844 * Return: none
845 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700846static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847{
848 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530849 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 "%s: invalid hdd context", __func__);
851 return;
852 }
853
854 ghdd_ipa->ipa_rx_destructor_count++;
855}
856
857/**
858 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
859 * @hdd_ctx: hdd main context
860 *
861 * free all rt debugging resources
862 *
863 * Return: none
864 */
865static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
866{
867 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
868
Anurag Chouhan210db072016-02-22 18:42:15 +0530869 if (QDF_TIMER_STATE_STOPPED !=
870 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
871 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530873 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530874 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875
876 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530877 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878 "%s: IPA RT debug is not enabled", __func__);
879 return;
880 }
881
Anurag Chouhan210db072016-02-22 18:42:15 +0530882 if (QDF_TIMER_STATE_STOPPED !=
883 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
884 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530886 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887}
888
889/**
890 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
891 * @hdd_ctx: hdd main context
892 *
893 * alloc and initialize all rt debugging resources
894 *
895 * Return: none
896 */
897static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
898{
899 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
900
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530901 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530902 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
904 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530905 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800906 sizeof(struct uc_rt_debug_info) *
907 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
908 hdd_ipa->ipa_tx_forward = 0;
909 hdd_ipa->ipa_rx_discard = 0;
910 hdd_ipa->ipa_rx_net_send_count = 0;
911 hdd_ipa->ipa_rx_internel_drop_count = 0;
912 hdd_ipa->ipa_rx_destructor_count = 0;
913
Anurag Chouhan210db072016-02-22 18:42:15 +0530914 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
916
917 /* Reatime debug enable on feature enable */
918 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530919 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800920 "%s: IPA RT debug is not enabled", __func__);
921 return;
922 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530923 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530925 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800926 HDD_IPA_UC_RT_DEBUG_PERIOD);
927
928}
929
930/**
931 * hdd_ipa_uc_stat_query() - Query the IPA stats
932 * @hdd_ctx: Global HDD context
933 * @ipa_tx_diff: tx packet count diff from previous
934 * tx packet count
935 * @ipa_rx_diff: rx packet count diff from previous
936 * rx packet count
937 *
938 * Return: true if IPA is enabled, false otherwise
939 */
940void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
941 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
942{
943 struct hdd_ipa_priv *hdd_ipa;
944
945 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
946 *ipa_tx_diff = 0;
947 *ipa_rx_diff = 0;
948
949 if (!hdd_ipa_is_enabled(pHddCtx) ||
950 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
951 return;
952 }
953
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530954 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
956 (false == hdd_ipa->resource_loading)) {
957 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
958 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkf8d6a122016-10-11 15:49:43 -0700959 HDD_IPA_LOG(LOGOFF, "STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 *ipa_tx_diff, *ipa_rx_diff);
961 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530962 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 return;
964}
965
966/**
967 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
968 * @adapter: network adapter
969 * @reason: STAT REQ Reason
970 *
971 * Return: None
972 */
973void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
974{
975 hdd_context_t *pHddCtx;
976 struct hdd_ipa_priv *hdd_ipa;
977
978 if (!adapter) {
979 return;
980 }
981
982 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
983 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
984 if (!hdd_ipa_is_enabled(pHddCtx) ||
985 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
986 return;
987 }
988
Yun Park8f289c82016-10-18 16:38:21 -0700989 HDD_IPA_LOG(LOGOFF, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530990 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
992 (false == hdd_ipa->resource_loading)) {
993 hdd_ipa->stat_req_reason = reason;
994 wma_cli_set_command(
995 (int)adapter->sessionId,
996 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
997 0, VDEV_CMD);
998 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530999 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000}
1001
1002/**
1003 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1004 * @hdd_ipa: Global HDD IPA context
1005 * @sta_add: Should station be added
1006 * @sta_id: ID of the station being queried
1007 *
1008 * Return: true if the station was found
1009 */
1010static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1011 bool sta_add, uint8_t sta_id)
1012{
1013 bool sta_found = false;
1014 uint8_t idx;
1015 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1016 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1017 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1018 sta_found = true;
1019 break;
1020 }
1021 }
1022 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301023 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001024 "%s: STA ID %d already exist, cannot add",
1025 __func__, sta_id);
1026 return sta_found;
1027 }
1028 if (sta_add) {
1029 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1030 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1031 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1032 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1033 return sta_found;
1034 }
1035 }
1036 }
1037 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301038 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 "%s: STA ID %d does not exist, cannot delete",
1040 __func__, sta_id);
1041 return sta_found;
1042 }
1043 if (!sta_add) {
1044 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1045 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1046 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1047 hdd_ipa->assoc_stas_map[idx].is_reserved =
1048 false;
1049 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1050 return sta_found;
1051 }
1052 }
1053 }
1054 return sta_found;
1055}
1056
1057/**
1058 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1059 * @hdd_ipa: Global HDD IPA context
1060 *
1061 * Return: 0 on success, negative errno if error
1062 */
1063static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1064{
1065 int result;
1066 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001067 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068
1069 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301070 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001071 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1072 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1074 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301075 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 "%s: Enable TX PIPE fail, code %d",
1077 __func__, result);
1078 return result;
1079 }
1080 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1081 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301082 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 "%s: Resume TX PIPE fail, code %d",
1084 __func__, result);
1085 return result;
1086 }
Leo Changfdb45c32016-10-28 11:09:23 -07001087 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, true, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088
1089 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301090 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001091 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1092 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1094 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301095 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 "%s: Enable RX PIPE fail, code %d",
1097 __func__, result);
1098 return result;
1099 }
1100 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1101 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301102 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 "%s: Resume RX PIPE fail, code %d",
1104 __func__, result);
1105 return result;
1106 }
Leo Changfdb45c32016-10-28 11:09:23 -07001107 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001108 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 return 0;
1110}
1111
1112/**
1113 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1114 * @hdd_ipa: Global HDD IPA context
1115 *
1116 * Return: 0 on success, negative errno if error
1117 */
1118static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1119{
1120 int result;
1121
Leo Change3e49442015-10-26 20:07:13 -07001122 hdd_ipa->ipa_pipes_down = true;
1123
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301124 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1126 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301127 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 "%s: Suspend RX PIPE fail, code %d",
1129 __func__, result);
1130 return result;
1131 }
1132 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1133 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301134 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 "%s: Disable RX PIPE fail, code %d",
1136 __func__, result);
1137 return result;
1138 }
1139
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301140 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1142 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301143 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 "%s: Suspend TX PIPE fail, code %d",
1145 __func__, result);
1146 return result;
1147 }
1148 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1149 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301150 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 "%s: Disable TX PIPE fail, code %d",
1152 __func__, result);
1153 return result;
1154 }
1155
1156 return 0;
1157}
1158
1159/**
1160 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1161 * @hdd_ipa: Global HDD IPA context
1162 *
1163 * Return: 0 on success, negative errno if error
1164 */
1165static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1166{
1167 hdd_ipa->activated_fw_pipe = 0;
1168 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001169
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001170 /* If RM feature enabled
1171 * Request PROD Resource first
1172 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001173 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1174 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1175 /* RM PROD request sync return
1176 * enable pipe immediately
1177 */
1178 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301179 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001180 "%s: IPA WDI Pipe activation failed",
1181 __func__);
1182 hdd_ipa->resource_loading = false;
1183 return -EBUSY;
1184 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185 }
1186 } else {
1187 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001188 * Just enabled all the PIPEs
1189 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301191 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001192 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 __func__);
1194 hdd_ipa->resource_loading = false;
1195 return -EBUSY;
1196 }
1197 hdd_ipa->resource_loading = false;
1198 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001199
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301200 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001201 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 return 0;
1203}
1204
1205/**
1206 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1207 * @hdd_ipa: Global HDD IPA context
1208 *
1209 * Return: None
1210 */
1211static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1212{
1213 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001214 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215
1216 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301217 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Leo Changfdb45c32016-10-28 11:09:23 -07001218 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301219 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Leo Changfdb45c32016-10-28 11:09:23 -07001220 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221}
1222
1223/**
1224 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1225 * @context: User context registered with TL (the IPA Global context is
1226 * registered
1227 * @rxpkt: Packet containing the notification
1228 * @staid: ID of the station associated with the packet
1229 *
1230 * Return: None
1231 */
1232static void
1233hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1234{
1235 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301236 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237
1238 /*
1239 * When SSR is going on or driver is unloading, just return.
1240 */
1241 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301242 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244
1245 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1246 return;
1247
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301248 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 __func__, event);
1250
1251 switch (event) {
1252 case IPA_RM_RESOURCE_GRANTED:
1253 /* Differed RM Granted */
1254 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301255 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256 if ((false == hdd_ipa->resource_unloading) &&
1257 (!hdd_ipa->activated_fw_pipe)) {
1258 hdd_ipa_uc_enable_pipes(hdd_ipa);
1259 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301260 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 break;
1262
1263 case IPA_RM_RESOURCE_RELEASED:
1264 /* Differed RM Released */
1265 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266 break;
1267
1268 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301269 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001270 "%s, invalid event code %d", __func__, event);
1271 break;
1272 }
1273}
1274
1275/**
1276 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1277 * @hdd_ipa: Global HDD IPA context
1278 * @event: IPA resource manager event to be deferred
1279 *
1280 * This function is called when a resource manager event is received
1281 * from firmware in interrupt context. This function will defer the
1282 * handling to the OL RX thread
1283 *
1284 * Return: None
1285 */
1286static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1287{
1288 enum ipa_rm_event event;
1289 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1290 struct uc_rm_work_struct, work);
1291 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1292 struct hdd_ipa_priv, uc_rm_work);
1293
1294 cds_ssr_protect(__func__);
1295 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301296 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001297 "%s, posted event %d", __func__, event);
1298
1299 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1300 cds_ssr_unprotect(__func__);
1301
1302 return;
1303}
1304
1305/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001306 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1307 * @op_msg: operation message received from firmware
1308 * @usr_ctxt: user context registered with TL (we register the HDD Global
1309 * context)
1310 *
1311 * Return: None
1312 */
1313static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1314{
1315 struct op_msg_type *msg = op_msg;
1316 struct ipa_uc_fw_stats *uc_fw_stat;
1317 struct IpaHwStatsWDIInfoData_t ipa_stat;
1318 struct hdd_ipa_priv *hdd_ipa;
1319 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301320 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321
1322 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301323 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324 return;
1325 }
1326
1327 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301328 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001329 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1330 return;
1331 }
1332
1333 hdd_ctx = (hdd_context_t *) usr_ctxt;
1334
1335 /*
1336 * When SSR is going on or driver is unloading, just return.
1337 */
1338 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301339 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301340 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001341 return;
1342 }
1343
1344 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1345
Govind Singhb6a89772016-08-12 11:23:35 +05301346 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1348
1349 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1350 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301351 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001352 hdd_ipa->activated_fw_pipe++;
1353 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1354 hdd_ipa->resource_loading = false;
1355 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001356 if (hdd_ipa->pending_cons_req)
1357 ipa_rm_notify_completion(
1358 IPA_RM_RESOURCE_GRANTED,
1359 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001360 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301362 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001363 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301365 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 hdd_ipa->activated_fw_pipe--;
1367 if (!hdd_ipa->activated_fw_pipe) {
1368 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001369 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1370 ipa_rm_release_resource(
1371 IPA_RM_RESOURCE_WLAN_PROD);
1372 /* Sync return success from IPA
1373 * Enable/resume all the PIPEs */
1374 hdd_ipa->resource_unloading = false;
1375 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1376 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301378 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001379 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001381 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301383 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001385 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 "CE RING SIZE: %d\n"
1387 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001388 (unsigned long long)res->ce_sr_base_paddr,
1389 res->ce_sr_ring_size,
1390 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301391 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001392 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001393 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001394 "COMP RING SIZE: %d\n"
1395 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001396 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001397 (unsigned long long)res->tx_comp_ring_base_paddr,
1398 res->tx_comp_ring_size,
1399 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001400 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301401 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001403 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001405 "IND RING DBELL : 0x%llx\n"
1406 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 "NUM EXCP PKT : %llu\n"
1408 "NUM TX BCMC : %llu\n"
1409 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001410 (unsigned long long)res->rx_rdy_ring_base_paddr,
1411 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001412 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001413 (unsigned long long)hdd_ipa->ipa_resource.
1414 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 hdd_ipa->stats.num_rx_excep,
1416 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001417 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301418 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1420 "SAP NUM STAs: %d\n"
1421 "STA CONNECTED: %d\n"
1422 "TX PIPE HDL: %d\n"
1423 "RX PIPE HDL : %d\n"
1424 "RSC LOADING : %d\n"
1425 "RSC UNLOADING : %d\n"
1426 "PNDNG CNS RQT : %d",
1427 hdd_ipa->sap_num_connected_sta,
1428 hdd_ipa->sta_connected,
1429 hdd_ipa->tx_pipe_handle,
1430 hdd_ipa->rx_pipe_handle,
1431 (unsigned int)hdd_ipa->resource_loading,
1432 (unsigned int)hdd_ipa->resource_unloading,
1433 (unsigned int)hdd_ipa->pending_cons_req);
1434
1435 /* STATs from FW */
1436 uc_fw_stat = (struct ipa_uc_fw_stats *)
1437 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301438 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 "==== IPA_UC WLAN_FW TX ====\n"
1440 "COMP RING BASE: 0x%x\n"
1441 "COMP RING SIZE: %d\n"
1442 "COMP RING DBELL : 0x%x\n"
1443 "COMP RING DBELL IND VAL : %d\n"
1444 "COMP RING DBELL CACHED VAL : %d\n"
1445 "COMP RING DBELL CACHED VAL : %d\n"
1446 "PKTS ENQ : %d\n"
1447 "PKTS COMP : %d\n"
1448 "IS SUSPEND : %d\n"
1449 "RSVD : 0x%x",
1450 uc_fw_stat->tx_comp_ring_base,
1451 uc_fw_stat->tx_comp_ring_size,
1452 uc_fw_stat->tx_comp_ring_dbell_addr,
1453 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1454 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1455 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1456 uc_fw_stat->tx_pkts_enqueued,
1457 uc_fw_stat->tx_pkts_completed,
1458 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
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 RX ====\n"
1461 "IND RING BASE: 0x%x\n"
1462 "IND RING SIZE: %d\n"
1463 "IND RING DBELL : 0x%x\n"
1464 "IND RING DBELL IND VAL : %d\n"
1465 "IND RING DBELL CACHED VAL : %d\n"
1466 "RDY IND ADDR : 0x%x\n"
1467 "RDY IND CACHE VAL : %d\n"
1468 "RFIL IND : %d\n"
1469 "NUM PKT INDICAT : %d\n"
1470 "BUF REFIL : %d\n"
1471 "NUM DROP NO SPC : %d\n"
1472 "NUM DROP NO BUF : %d\n"
1473 "IS SUSPND : %d\n"
1474 "RSVD : 0x%x\n",
1475 uc_fw_stat->rx_ind_ring_base,
1476 uc_fw_stat->rx_ind_ring_size,
1477 uc_fw_stat->rx_ind_ring_dbell_addr,
1478 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1479 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1480 uc_fw_stat->rx_ind_ring_rdidx_addr,
1481 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1482 uc_fw_stat->rx_refill_idx,
1483 uc_fw_stat->rx_num_pkts_indicated,
1484 uc_fw_stat->rx_buf_refilled,
1485 uc_fw_stat->rx_num_ind_drop_no_space,
1486 uc_fw_stat->rx_num_ind_drop_no_buf,
1487 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1488 /* STATs from IPA */
1489 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301490 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491 "==== IPA_UC IPA TX ====\n"
1492 "NUM PROCD : %d\n"
1493 "CE DBELL : 0x%x\n"
1494 "NUM DBELL FIRED : %d\n"
1495 "COMP RNG FULL : %d\n"
1496 "COMP RNG EMPT : %d\n"
1497 "COMP RNG USE HGH : %d\n"
1498 "COMP RNG USE LOW : %d\n"
1499 "BAM FIFO FULL : %d\n"
1500 "BAM FIFO EMPT : %d\n"
1501 "BAM FIFO USE HGH : %d\n"
1502 "BAM FIFO USE LOW : %d\n"
1503 "NUM DBELL : %d\n"
1504 "NUM UNEXP DBELL : %d\n"
1505 "NUM BAM INT HDL : 0x%x\n"
1506 "NUM BAM INT NON-RUN : 0x%x\n"
1507 "NUM QMB INT HDL : 0x%x",
1508 ipa_stat.tx_ch_stats.num_pkts_processed,
1509 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1510 ipa_stat.tx_ch_stats.num_db_fired,
1511 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1512 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1513 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1514 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1515 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1516 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1517 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1518 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1519 ipa_stat.tx_ch_stats.num_db,
1520 ipa_stat.tx_ch_stats.num_unexpected_db,
1521 ipa_stat.tx_ch_stats.num_bam_int_handled,
1522 ipa_stat.tx_ch_stats.
1523 num_bam_int_in_non_runnning_state,
1524 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1525
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301526 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527 "==== IPA_UC IPA RX ====\n"
1528 "MAX OST PKT : %d\n"
1529 "NUM PKT PRCSD : %d\n"
1530 "RNG RP : 0x%x\n"
1531 "COMP RNG FULL : %d\n"
1532 "COMP RNG EMPT : %d\n"
1533 "COMP RNG USE HGH : %d\n"
1534 "COMP RNG USE LOW : %d\n"
1535 "BAM FIFO FULL : %d\n"
1536 "BAM FIFO EMPT : %d\n"
1537 "BAM FIFO USE HGH : %d\n"
1538 "BAM FIFO USE LOW : %d\n"
1539 "NUM DB : %d\n"
1540 "NUM UNEXP DB : %d\n"
1541 "NUM BAM INT HNDL : 0x%x\n",
1542 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1543 ipa_stat.rx_ch_stats.num_pkts_processed,
1544 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1545 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1546 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1547 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1548 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1549 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1550 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1551 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1552 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1553 ipa_stat.rx_ch_stats.num_db,
1554 ipa_stat.rx_ch_stats.num_unexpected_db,
1555 ipa_stat.rx_ch_stats.num_bam_int_handled);
1556 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1557 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1558 /* STATs from FW */
1559 uc_fw_stat = (struct ipa_uc_fw_stats *)
1560 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301561 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1563 uc_fw_stat->tx_pkts_completed,
1564 hdd_ipa->ipa_p_tx_packets);
1565 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1566 (uc_fw_stat->rx_num_ind_drop_no_space +
1567 uc_fw_stat->rx_num_ind_drop_no_buf +
1568 uc_fw_stat->rx_num_pkts_indicated),
1569 hdd_ipa->ipa_p_rx_packets);
1570
1571 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1572 hdd_ipa->ipa_p_rx_packets =
1573 (uc_fw_stat->rx_num_ind_drop_no_space +
1574 uc_fw_stat->rx_num_ind_drop_no_buf +
1575 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301576 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 } else {
Yun Park8292dcb2016-10-07 16:46:06 -07001578 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
1579 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301581 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582}
1583
1584
1585/**
1586 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1587 * @adapter: device adapter instance
1588 * @offload_type: MCC or SCC
1589 * @enable: TX offload enable or disable
1590 *
1591 * Return: none
1592 */
1593static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1594 uint32_t offload_type, uint32_t enable)
1595{
1596 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07001597 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598
Yun Parka37592b2016-06-11 17:10:28 -07001599 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 return;
1601
Yun Park8292dcb2016-10-07 16:46:06 -07001602 iface_context = adapter->ipa_context;
1603
1604 if (!iface_context || (enable == iface_context->offload_enabled)) {
1605 /* IPA offload status is already set as desired */
1606 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001607 "IPA offload status is already set: (offload_type=%d, vdev_id=%d, enable=%d)",
Yun Park8292dcb2016-10-07 16:46:06 -07001608 offload_type, adapter->sessionId, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001609 return;
1610 }
1611
Yun Park4540e862016-11-10 16:30:06 -08001612 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
1613 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1614 "invalid session id: %d, offload_type=%d, enable=%d",
1615 adapter->sessionId, offload_type, enable);
1616 return;
1617 }
1618
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301619 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 sizeof(ipa_offload_enable_disable));
1621 ipa_offload_enable_disable.offload_type = offload_type;
1622 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1623 ipa_offload_enable_disable.enable = enable;
1624
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301625 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001626 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627 ipa_offload_enable_disable.offload_type,
1628 ipa_offload_enable_disable.vdev_id,
1629 ipa_offload_enable_disable.enable);
1630
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301631 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1633 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301634 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001635 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
1636 __func__,
1637 ipa_offload_enable_disable.offload_type,
1638 ipa_offload_enable_disable.vdev_id,
1639 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001640 } else {
1641 /* Update the IPA offload status */
1642 iface_context->offload_enabled =
1643 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 }
1645}
1646
1647/**
1648 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1649 * @work: uC OP work
1650 *
1651 * Return: None
1652 */
1653static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1654{
1655 struct op_msg_type *msg;
1656 struct uc_op_work_struct *uc_op_work = container_of(work,
1657 struct uc_op_work_struct, work);
1658 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1659
1660 cds_ssr_protect(__func__);
1661
1662 msg = uc_op_work->msg;
1663 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301664 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001665 "%s, posted msg %d", __func__, msg->op_code);
1666
1667 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1668
1669 cds_ssr_unprotect(__func__);
1670
1671 return;
1672}
1673
1674/**
1675 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1676 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1677 * @op_msg: operation message received from firmware
1678 * @hdd_ctx: Global HDD context
1679 *
1680 * Return: None
1681 */
1682static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1683{
1684 struct hdd_ipa_priv *hdd_ipa;
1685 struct op_msg_type *msg;
1686 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301687 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688
1689 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301690 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001692
1693 msg = (struct op_msg_type *)op_msg;
1694 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1695
1696 if (unlikely(!hdd_ipa))
1697 goto end;
1698
1699 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301700 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 __func__, msg->op_code);
1702 goto end;
1703 }
1704
1705 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1706 if (uc_op_work->msg)
1707 /* When the same uC OPCODE is already pended, just return */
1708 goto end;
1709
1710 uc_op_work->msg = msg;
1711 schedule_work(&uc_op_work->work);
1712 return;
1713
1714end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301715 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716}
1717
1718/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001719 * hdd_ipa_init_uc_op_work - init ipa uc op work
1720 * @work: struct work_struct
1721 * @work_handler: work_handler
1722 *
1723 * Return: none
1724 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001725static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1726 work_func_t work_handler)
1727{
1728 INIT_WORK(work, work_handler);
1729}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001730
1731
1732/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001733 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1734 * @hdd_ctx: Global HDD context
1735 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301736 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301738static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739{
1740 struct ipa_wdi_in_params pipe_in;
1741 struct ipa_wdi_out_params pipe_out;
1742 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1743 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1744 uint8_t i;
Leo Changfdb45c32016-10-28 11:09:23 -07001745 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301747 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1748 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749
Anurag Chouhanffb21542016-02-17 14:33:03 +05301750 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301751 qdf_mutex_create(&ipa_ctxt->event_lock);
1752 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753
1754 /* TX PIPE */
1755 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1756 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1757 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1758 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1759 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1760 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1761 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1762 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1763 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1764 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1765 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1766 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1767 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301768 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1770 pipe_in.sys.keep_ipa_awake = true;
1771 }
1772
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001773 pipe_in.u.dl.comp_ring_base_pa =
1774 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001775 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001776 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1777 sizeof(qdf_dma_addr_t);
1778 pipe_in.u.dl.ce_ring_base_pa =
1779 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1780 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1781 pipe_in.u.dl.ce_ring_size =
1782 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1783 pipe_in.u.dl.num_tx_buffers =
1784 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785
1786 /* Connect WDI IPA PIPE */
1787 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1788 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301789 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1790 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1791 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1792 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001793 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 /* WLAN TX PIPE Handle */
1795 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301796 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1798 " CERZ %d, NB %d, CDBPAD 0x%x",
1799 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1800 pipe_in.u.dl.comp_ring_size,
1801 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1802 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1803 pipe_in.u.dl.ce_ring_size,
1804 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001805 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001806
1807 /* RX PIPE */
1808 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1809 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1810 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1811 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1812 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1813 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1814 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1815 sizeof(struct sps_iovec);
1816 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1817 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1820 pipe_in.sys.keep_ipa_awake = true;
1821 }
1822
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001823 pipe_in.u.ul.rdy_ring_base_pa =
1824 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1825 pipe_in.u.ul.rdy_ring_size =
1826 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1827 pipe_in.u.ul.rdy_ring_rp_pa =
1828 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001829 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001831 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001832 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301833 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1835 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1836 pipe_in.u.ul.rdy_ring_size,
1837 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001838 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001839
Leo Changfdb45c32016-10-28 11:09:23 -07001840 cdp_ipa_set_doorbell_paddr(soc, cds_ctx->pdev_txrx_ctx,
1841 ipa_ctxt->tx_comp_doorbell_paddr,
1842 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843
Leo Changfdb45c32016-10-28 11:09:23 -07001844 cdp_ipa_register_op_cb(soc, cds_ctx->pdev_txrx_ctx,
1845 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846
1847 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001848 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001849 hdd_ipa_uc_fw_op_event_handler);
1850 ipa_ctxt->uc_op_work[i].msg = NULL;
1851 }
1852
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301853 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854}
1855
Leo Change3e49442015-10-26 20:07:13 -07001856/**
1857 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1858 * @hdd_ctx: hdd main context
1859 *
1860 * Force shutdown IPA pipe
1861 * Independent of FW pipe status, IPA pipe shutdonw progress
1862 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1863 * independent from FW pipe status
1864 *
1865 * Return: NONE
1866 */
1867void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1868{
1869 struct hdd_ipa_priv *hdd_ipa;
1870
1871 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1872 return;
1873
1874 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1875 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301876 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001877 "IPA pipes are not down yet, force shutdown");
1878 hdd_ipa_uc_disable_pipes(hdd_ipa);
1879 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301880 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001881 "IPA pipes are down, do nothing");
1882 }
1883
1884 return;
1885}
1886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887/**
Govind Singh9c58eba2016-09-02 16:23:06 +05301888 * hdd_ipa_msg_free_fn() - Free an IPA message
1889 * @buff: pointer to the IPA message
1890 * @len: length of the IPA message
1891 * @type: type of IPA message
1892 *
1893 * Return: None
1894 */
1895static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
1896{
1897 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "msg type:%d, len:%d", type, len);
1898 ghdd_ipa->stats.num_free_msg++;
1899 qdf_mem_free(buff);
1900}
1901
1902
1903/**
1904 * hdd_ipa_send_disconnect() - ipa send disconnect clients
1905 * adapter: pointer to hdd adapter
1906 * Send disconnect evnt to IPA driver during SSR
1907 *
1908 * Return: 0 - Success
1909 */
1910static int hdd_ipa_send_disconnect(hdd_adapter_t *adapter)
1911{
1912 struct ipa_msg_meta meta;
1913 struct ipa_wlan_msg *msg;
1914 int ret = 0;
1915 int i;
1916
1917 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
1918 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
1919 continue;
1920 if ((adapter->aStaInfo[i].isUsed) &&
1921 (!adapter->aStaInfo[i].isDeauthInProgress)) {
1922 meta.msg_len = sizeof(struct ipa_wlan_msg);
1923 msg = qdf_mem_malloc(meta.msg_len);
1924 if (msg == NULL) {
1925 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1926 "msg allocation failed");
1927 return -ENOMEM;
1928 }
1929 meta.msg_type = WLAN_CLIENT_DISCONNECT;
1930 strlcpy(msg->name, adapter->dev->name,
1931 IPA_RESOURCE_NAME_MAX);
1932 memcpy(msg->mac_addr, adapter->aStaInfo[i].macAddrSTA.bytes,
1933 ETH_ALEN);
1934 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
1935 msg->name, meta.msg_type);
1936 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
1937 if (ret) {
1938 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1939 "%s: Evt: %d fail:%d",
1940 msg->name, meta.msg_type, ret);
1941 qdf_mem_free(msg);
1942 return ret;
1943 }
1944 }
1945 }
1946
1947 return ret;
1948}
1949
1950/**
1951 * hdd_ipa_uc_disconnect_client() - disconnect ipa sap clients
1952 * hdd_ctx: pointer to hdd context
1953 * Send disconnect evnt to IPA driver during SSR
1954 *
1955 * Return: 0 - Success
1956 */
1957static int hdd_ipa_uc_disconnect_client(hdd_context_t *hdd_ctx)
1958{
1959 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
1960 QDF_STATUS status;
1961 hdd_adapter_t *adapter;
1962 int ret = 0;
1963
1964
1965 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1966 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
1967 adapter = adapter_node->pAdapter;
1968 if (adapter->device_mode == QDF_SAP_MODE)
1969 hdd_ipa_send_disconnect(adapter);
1970 status = hdd_get_next_adapter(
1971 hdd_ctx, adapter_node, &next);
1972 adapter_node = next;
1973 }
1974
1975 return ret;
1976}
1977
1978/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001979 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1980 *
1981 * Deinit basic IPA UC host side to be in sync reloaded FW during
1982 * SSR
1983 *
1984 * Return: 0 - Success
1985 */
1986int hdd_ipa_uc_ssr_deinit(void)
1987{
1988 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1989 int idx;
1990 struct hdd_ipa_iface_context *iface_context;
1991
Leo Chang3bc8fed2015-11-13 10:59:47 -08001992 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001993 return 0;
1994
Govind Singh9c58eba2016-09-02 16:23:06 +05301995 /* send disconnect to ipa driver for connected clients */
1996 hdd_ipa_uc_disconnect_client(hdd_ipa->hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997 /* Clean up HDD IPA interfaces */
1998 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1999 (idx < HDD_IPA_MAX_IFACE); idx++) {
2000 iface_context = &hdd_ipa->iface_context[idx];
2001 if (iface_context && iface_context->adapter)
2002 hdd_ipa_cleanup_iface(iface_context);
2003 }
2004
2005 /* After SSR, wlan driver reloads FW again. But we need to protect
2006 * IPA submodule during SSR transient state. So deinit basic IPA
2007 * UC host side to be in sync with reloaded FW during SSR
2008 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08002009 if (!hdd_ipa->ipa_pipes_down)
2010 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002011
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302012 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002013 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
2014 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
2015 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
2016 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302017 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018
2019 /* Full IPA driver cleanup not required since wlan driver is now
2020 * unloaded and reloaded after SSR.
2021 */
2022 return 0;
2023}
2024
2025/**
2026 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
2027 *
2028 * Init basic IPA UC host side to be in sync with reloaded FW after
2029 * SSR to resume IPA UC operations
2030 *
2031 * Return: 0 - Success
2032 */
2033int hdd_ipa_uc_ssr_reinit(void)
2034{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035
2036 /* After SSR is complete, IPA UC can resume operation. But now wlan
2037 * driver will be unloaded and reloaded, which takes care of IPA cleanup
2038 * and initialization. This is a placeholder func if IPA has to resume
2039 * operations without driver reload.
2040 */
2041 return 0;
2042}
Leo Chang3bc8fed2015-11-13 10:59:47 -08002043
2044/**
2045 * hdd_ipa_tx_packet_ipa() - send packet to IPA
2046 * @hdd_ctx: Global HDD context
2047 * @skb: skb sent to IPA
2048 * @session_id: send packet instance session id
2049 *
2050 * Send TX packet which generated by system to IPA.
2051 * This routine only will be used for function verification
2052 *
2053 * Return: NULL packet sent to IPA properly
2054 * NULL invalid packet drop
2055 * skb packet not sent to IPA. legacy data path should handle
2056 */
2057struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
2058 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07002059{
Leo Chang3bc8fed2015-11-13 10:59:47 -08002060 struct ipa_header *ipa_header;
2061 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07002062 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002063
2064 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2065 return skb;
2066
Leo Chang07b28f62016-05-11 12:29:22 -07002067 if (!hdd_ipa)
2068 return skb;
2069
2070 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
2071 return skb;
2072
Leo Changcc923e22016-06-16 15:29:03 -07002073 if (skb_headroom(skb) <
2074 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07002075 return skb;
2076
Leo Chang3bc8fed2015-11-13 10:59:47 -08002077 ipa_header = (struct ipa_header *) skb_push(skb,
2078 sizeof(struct ipa_header));
2079 if (!ipa_header) {
2080 /* No headroom, legacy */
2081 return skb;
2082 }
2083 memset(ipa_header, 0, sizeof(*ipa_header));
2084 ipa_header->vdev_id = 0;
2085
2086 frag_header = (struct frag_header *) skb_push(skb,
2087 sizeof(struct frag_header));
2088 if (!frag_header) {
2089 /* No headroom, drop */
2090 kfree_skb(skb);
2091 return NULL;
2092 }
2093 memset(frag_header, 0, sizeof(*frag_header));
2094 frag_header->length = skb->len - sizeof(struct frag_header)
2095 - sizeof(struct ipa_header);
2096
2097 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2098 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002099}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002100
2101/**
2102 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2103 * @work: scheduled work
2104 *
2105 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2106 * not want to immediately release the wake lock since the system
2107 * would then potentially try to suspend when there is a healthy data
2108 * rate. Deferred work is scheduled and this function handles the
2109 * work. When this function is called, if the IPA resource is still
2110 * released then we release the wake lock.
2111 *
2112 * Return: None
2113 */
2114static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2115{
2116 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2117 struct hdd_ipa_priv,
2118 wake_lock_work);
2119
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302120 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121
2122 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2123 goto end;
2124
2125 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302126 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002127 WIFI_POWER_EVENT_WAKELOCK_IPA);
2128
2129end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302130 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131}
2132
2133/**
2134 * hdd_ipa_rm_request() - Request resource from IPA
2135 * @hdd_ipa: Global HDD IPA context
2136 *
2137 * Return: 0 on success, negative errno on error
2138 */
2139static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2140{
2141 int ret = 0;
2142
2143 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2144 return 0;
2145
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302146 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002147
2148 switch (hdd_ipa->rm_state) {
2149 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302150 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151 return 0;
2152 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302153 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002154 return -EINPROGRESS;
2155 case HDD_IPA_RM_RELEASED:
2156 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2157 break;
2158 }
2159
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302160 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002161
2162 ret = ipa_rm_inactivity_timer_request_resource(
2163 IPA_RM_RESOURCE_WLAN_PROD);
2164
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302165 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166 if (ret == 0) {
2167 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2168 hdd_ipa->stats.num_rm_grant_imm++;
2169 }
2170
2171 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2172 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302173 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002174 WIFI_POWER_EVENT_WAKELOCK_IPA);
2175 hdd_ipa->wake_lock_released = false;
2176 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302177 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002178
2179 return ret;
2180}
2181
2182/**
2183 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2184 * @hdd_ipa: Global HDD IPA context
2185 *
2186 * Return: 0 if resources released, negative errno otherwise
2187 */
2188static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2189{
2190 int ret = 0;
2191
2192 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2193 return 0;
2194
2195 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2196 return -EAGAIN;
2197
2198 spin_lock_bh(&hdd_ipa->q_lock);
2199 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2200 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2201 spin_unlock_bh(&hdd_ipa->q_lock);
2202 return -EAGAIN;
2203 }
2204 spin_unlock_bh(&hdd_ipa->q_lock);
2205
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302206 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002207
Nirav Shahcbc6d722016-03-01 16:24:53 +05302208 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302209 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002210 return -EAGAIN;
2211 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302212 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002213
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302214 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002215 switch (hdd_ipa->rm_state) {
2216 case HDD_IPA_RM_GRANTED:
2217 break;
2218 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302219 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002220 return -EINPROGRESS;
2221 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302222 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002223 return 0;
2224 }
2225
2226 /* IPA driver returns immediately so set the state here to avoid any
2227 * race condition.
2228 */
2229 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2230 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302231 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232
2233 ret =
2234 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2235
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302236 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002237 if (unlikely(ret != 0)) {
2238 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2239 WARN_ON(1);
2240 }
2241
2242 /*
2243 * If wake_lock is released immediately, kernel would try to suspend
2244 * immediately as well, Just avoid ping-pong between suspend-resume
2245 * while there is healthy amount of data transfer going on by
2246 * releasing the wake_lock after some delay.
2247 */
2248 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2249 msecs_to_jiffies
2250 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2251
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302252 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253
2254 return ret;
2255}
2256
2257/**
2258 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2259 * @user_data: user data registered with IPA
2260 * @event: the IPA resource manager event that occurred
2261 * @data: the data associated with the event
2262 *
2263 * Return: None
2264 */
2265static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2266 unsigned long data)
2267{
2268 struct hdd_ipa_priv *hdd_ipa = user_data;
2269
2270 if (unlikely(!hdd_ipa))
2271 return;
2272
2273 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2274 return;
2275
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302276 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002277
2278 switch (event) {
2279 case IPA_RM_RESOURCE_GRANTED:
2280 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2281 /* RM Notification comes with ISR context
2282 * it should be serialized into work queue to avoid
2283 * ISR sleep problem
2284 */
2285 hdd_ipa->uc_rm_work.event = event;
2286 schedule_work(&hdd_ipa->uc_rm_work.work);
2287 break;
2288 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302289 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002290 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302291 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002292 hdd_ipa->stats.num_rm_grant++;
2293 break;
2294
2295 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302296 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002297 hdd_ipa->resource_unloading = false;
2298 break;
2299
2300 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302301 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002302 break;
2303 }
2304}
2305
2306/**
2307 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2308 *
2309 * Callback function registered with IPA that is called when IPA wants
2310 * to release the WLAN consumer resource
2311 *
2312 * Return: 0 if the request is granted, negative errno otherwise
2313 */
2314static int hdd_ipa_rm_cons_release(void)
2315{
2316 return 0;
2317}
2318
2319/**
2320 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2321 *
2322 * Callback function registered with IPA that is called when IPA wants
2323 * to access the WLAN consumer resource
2324 *
2325 * Return: 0 if the request is granted, negative errno otherwise
2326 */
2327static int hdd_ipa_rm_cons_request(void)
2328{
Yun Park4d8b60a2015-10-22 13:59:32 -07002329 int ret = 0;
2330
2331 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302332 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002333 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002334 __func__);
2335 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002336 ret = -EINPROGRESS;
2337 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302338 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002339 "%s: IPA resource unloading in progress",
2340 __func__);
2341 ghdd_ipa->pending_cons_req = true;
2342 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002343 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002344
2345 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002346}
2347
2348/**
2349 * hdd_ipa_set_perf_level() - Set IPA performance level
2350 * @hdd_ctx: Global HDD context
2351 * @tx_packets: Number of packets transmitted in the last sample period
2352 * @rx_packets: Number of packets received in the last sample period
2353 *
2354 * Return: 0 on success, negative errno on error
2355 */
2356int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2357 uint64_t rx_packets)
2358{
2359 uint32_t next_cons_bw, next_prod_bw;
2360 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2361 struct ipa_rm_perf_profile profile;
2362 int ret;
2363
2364 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2365 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2366 return 0;
2367
2368 memset(&profile, 0, sizeof(profile));
2369
2370 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2371 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2372 else if (tx_packets >
2373 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2374 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2375 else
2376 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2377
2378 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2379 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2380 else if (rx_packets >
2381 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2382 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2383 else
2384 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2385
Yun Park8f289c82016-10-18 16:38:21 -07002386 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002387 "CONS perf curr: %d, next: %d",
2388 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Park8f289c82016-10-18 16:38:21 -07002389 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002390 "PROD perf curr: %d, next: %d",
2391 hdd_ipa->curr_prod_bw, next_prod_bw);
2392
2393 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302394 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002395 "Requesting CONS perf curr: %d, next: %d",
2396 hdd_ipa->curr_cons_bw, next_cons_bw);
2397 profile.max_supported_bandwidth_mbps = next_cons_bw;
2398 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2399 &profile);
2400 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302401 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002402 "RM CONS set perf profile failed: %d", ret);
2403
2404 return ret;
2405 }
2406 hdd_ipa->curr_cons_bw = next_cons_bw;
2407 hdd_ipa->stats.num_cons_perf_req++;
2408 }
2409
2410 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302411 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412 "Requesting PROD perf curr: %d, next: %d",
2413 hdd_ipa->curr_prod_bw, next_prod_bw);
2414 profile.max_supported_bandwidth_mbps = next_prod_bw;
2415 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2416 &profile);
2417 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302418 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002419 "RM PROD set perf profile failed: %d", ret);
2420 return ret;
2421 }
2422 hdd_ipa->curr_prod_bw = next_prod_bw;
2423 hdd_ipa->stats.num_prod_perf_req++;
2424 }
2425
2426 return 0;
2427}
2428
2429/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002430 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2431 * @work: struct work_struct
2432 * @work_handler: work_handler
2433 *
2434 * Return: none
2435 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002436static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2437 work_func_t work_handler)
2438{
2439 INIT_WORK(work, work_handler);
2440}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002441
2442/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002443 * hdd_ipa_setup_rm() - Setup IPA resource management
2444 * @hdd_ipa: Global HDD IPA context
2445 *
2446 * Return: 0 on success, negative errno on error
2447 */
2448static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2449{
2450 struct ipa_rm_create_params create_params = { 0 };
2451 int ret;
2452
2453 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2454 return 0;
2455
Rajeev Kumar217f2172016-01-06 18:11:55 -08002456 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2457 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002458 memset(&create_params, 0, sizeof(create_params));
2459 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2460 create_params.reg_params.user_data = hdd_ipa;
2461 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2462 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2463
2464 ret = ipa_rm_create_resource(&create_params);
2465 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302466 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002467 "Create RM resource failed: %d", ret);
2468 goto setup_rm_fail;
2469 }
2470
2471 memset(&create_params, 0, sizeof(create_params));
2472 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2473 create_params.request_resource = hdd_ipa_rm_cons_request;
2474 create_params.release_resource = hdd_ipa_rm_cons_release;
2475 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2476
2477 ret = ipa_rm_create_resource(&create_params);
2478 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302479 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002480 "Create RM CONS resource failed: %d", ret);
2481 goto delete_prod;
2482 }
2483
2484 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2485 IPA_RM_RESOURCE_APPS_CONS);
2486
2487 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2488 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2489 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302490 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 ret);
2492 goto timer_init_failed;
2493 }
2494
2495 /* Set the lowest bandwidth to start with */
2496 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2497
2498 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302499 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002500 "Set perf level failed: %d", ret);
2501 goto set_perf_failed;
2502 }
2503
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302504 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002505 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2506 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302507 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002508 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2509 hdd_ipa->wake_lock_released = true;
2510 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2511
2512 return ret;
2513
2514set_perf_failed:
2515 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2516
2517timer_init_failed:
2518 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2519
2520delete_prod:
2521 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2522
2523setup_rm_fail:
2524 return ret;
2525}
2526
2527/**
2528 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2529 * @hdd_ipa: Global HDD IPA context
2530 *
2531 * Destroys all resources associated with the IPA resource manager
2532 *
2533 * Return: None
2534 */
2535static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2536{
2537 int ret;
2538
2539 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2540 return;
2541
2542 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302543 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002544
2545#ifdef WLAN_OPEN_SOURCE
2546 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2547#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302548 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002549
2550 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2551
2552 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2553 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302554 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002555 "RM PROD resource delete failed %d", ret);
2556
2557 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2558 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302559 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002560 "RM CONS resource delete failed %d", ret);
2561}
2562
2563/**
2564 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2565 * @skb: network buffer
2566 * @adapter: network adapter
2567 *
2568 * Called when a network buffer is received which should not be routed
2569 * to the IPA module.
2570 *
2571 * Return: None
2572 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302573static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002574 hdd_adapter_t *adapter)
2575{
2576 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2577 unsigned int cpu_index;
2578
2579 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302580 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581 adapter);
2582 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002583 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002584 return;
2585 }
2586
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002587 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002588 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002589 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002590 return;
2591 }
2592
2593 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2594 skb->dev = adapter->dev;
2595 skb->protocol = eth_type_trans(skb, skb->dev);
2596 skb->ip_summed = CHECKSUM_NONE;
2597
2598 cpu_index = wlan_hdd_get_cpu();
2599
2600 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2601 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2602 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2603 else
2604 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2605
2606 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2607 adapter->dev->last_rx = jiffies;
2608}
2609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002610/**
Leo Chang69c39692016-10-12 20:11:12 -07002611 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2612 * @hdd_ipa: pointer to hdd ipa context
2613 * @adapter: network adapter
2614 * @skb: data pointer
2615 *
2616 * if exception packet has set forward bit, copied new packet should be
2617 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2618 * put into pm queue and tx procedure will be differed
2619 *
2620 * Return: None
2621 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002622static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2623 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002624{
2625 qdf_nbuf_t copy;
2626 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2627
2628 copy = qdf_nbuf_copy(skb);
2629 if (!copy) {
2630 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2631 return;
2632 }
2633
2634 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2635 /* WLAN subsystem is in suspend, put int queue */
2636 if (hdd_ipa->suspended) {
2637 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2638 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2639 "TX in SUSPEND PUT QUEUE");
2640 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2641 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2642 pm_tx_cb->exception = true;
2643 pm_tx_cb->adapter = adapter;
2644 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2645 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2646 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2647 hdd_ipa->stats.num_tx_queued++;
2648 } else {
2649 /* Resume, put packet into WLAN TX */
2650 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2651 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2652 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2653 "packet tx fail");
2654 } else {
2655 hdd_ipa->stats.num_tx_bcmc++;
2656 hdd_ipa->ipa_tx_forward++;
2657 }
2658 }
2659}
2660
2661/**
2662 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002663 * @priv: pointer to private data registered with IPA (we register a
2664 * pointer to the global IPA context)
2665 * @evt: the IPA event which triggered the callback
2666 * @data: data associated with the event
2667 *
2668 * Return: None
2669 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002670static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002671 unsigned long data)
2672{
2673 struct hdd_ipa_priv *hdd_ipa = NULL;
2674 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302675 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002676 uint8_t iface_id;
2677 uint8_t session_id;
2678 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002680 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681
2682 hdd_ipa = (struct hdd_ipa_priv *)priv;
2683
2684 switch (evt) {
2685 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302686 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002687
2688 /*
2689 * When SSR is going on or driver is unloading,
2690 * just drop the packets.
2691 */
2692 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2693 if (0 != status) {
2694 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2695 "Invalid context: drop packet");
2696 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2697 kfree_skb(skb);
2698 return;
2699 }
2700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002701 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2702 session_id = (uint8_t)skb->cb[0];
2703 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302704 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2706 session_id, iface_id);
2707 } else {
2708 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2709 }
2710
2711 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302712 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002713 "IPA_RECEIVE: Invalid iface_id: %u",
2714 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302715 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002716 "w2i -- skb", skb->data, 8);
2717 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002718 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002719 return;
2720 }
2721
2722 iface_context = &hdd_ipa->iface_context[iface_id];
2723 adapter = iface_context->adapter;
2724
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302725 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002726 "w2i -- skb", skb->data, 8);
2727 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2728 hdd_ipa->stats.num_rx_excep++;
2729 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2730 } else {
2731 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2732 }
2733
2734 iface_context->stats.num_rx_ipa_excep++;
2735
2736 /* Disable to forward Intra-BSS Rx packets when
2737 * ap_isolate=1 in hostapd.conf
2738 */
Yun Park046101c2016-09-02 15:32:14 -07002739 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 /*
2741 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2742 * all Rx packets to IPA uC, which need to be forwarded
2743 * to other interface.
2744 * And, IPA driver will send back to WLAN host driver
2745 * through exception pipe with fw_desc field set by FW.
2746 * Here we are checking fw_desc field for FORWARD bit
2747 * set, and forward to Tx. Then copy to kernel stack
2748 * only when DISCARD bit is not set.
2749 */
2750 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002751 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302752 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302753 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002754 "Forward packet to Tx (fw_desc=%d)",
2755 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002756 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002758 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002759 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2760 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002761 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002762 break;
2763 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002764 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302765 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002766 "Intra-BSS FWD is disabled-skip forward to Tx");
2767 }
2768
2769 hdd_ipa_send_skb_to_network(skb, adapter);
2770 break;
2771
2772 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302773 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774 "w2i cb wrong event: 0x%x", evt);
2775 return;
2776 }
2777}
2778
2779/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002780 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2781 * @priv: pointer to private data registered with IPA (we register a
2782 * pointer to the global IPA context)
2783 * @evt: the IPA event which triggered the callback
2784 * @data: data associated with the event
2785 *
2786 * Return: None
2787 */
2788static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2789 unsigned long data)
2790{
2791 cds_ssr_protect(__func__);
2792 __hdd_ipa_w2i_cb(priv, evt, data);
2793 cds_ssr_unprotect(__func__);
2794}
2795
2796/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002797 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2798 * @skb: packet buffer which was transmitted
2799 *
2800 * Return: None
2801 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302802void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803{
2804 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2805
Govind Singhb6a89772016-08-12 11:23:35 +05302806 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302807 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002808 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302809 ipa_free_skb((struct ipa_rx_data *)
2810 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811
2812 hdd_ipa->stats.num_tx_comp_cnt++;
2813
2814 atomic_dec(&hdd_ipa->tx_ref_cnt);
2815
2816 hdd_ipa_rm_try_release(hdd_ipa);
2817}
2818
2819/**
2820 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2821 * @iface_context: interface-specific IPA context
2822 * @ipa_tx_desc: packet data descriptor
2823 *
2824 * Return: None
2825 */
2826static void hdd_ipa_send_pkt_to_tl(
2827 struct hdd_ipa_iface_context *iface_context,
2828 struct ipa_rx_data *ipa_tx_desc)
2829{
2830 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2831 uint8_t interface_id;
2832 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302833 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002834
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302835 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002836 adapter = iface_context->adapter;
2837 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302838 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002839 ipa_free_skb(ipa_tx_desc);
2840 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302841 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842 hdd_ipa_rm_try_release(hdd_ipa);
2843 return;
2844 }
2845
2846 /*
2847 * During CAC period, data packets shouldn't be sent over the air so
2848 * drop all the packets here
2849 */
2850 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2851 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302852 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853 iface_context->stats.num_tx_cac_drop++;
2854 hdd_ipa_rm_try_release(hdd_ipa);
2855 return;
2856 }
2857
2858 interface_id = adapter->sessionId;
2859 ++adapter->stats.tx_packets;
2860
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302861 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862
2863 skb = ipa_tx_desc->skb;
2864
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302865 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302866 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002867 /* FIXME: This is broken. No such field in cb any more:
2868 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302870 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002871 ipa_tx_desc->dma_addr
2872 + HDD_IPA_WLAN_FRAG_HEADER
2873 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874 ipa_tx_desc->skb->len -=
2875 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2876 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302877 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002879 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302880 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881
2882 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2883
Leo Changfdb45c32016-10-28 11:09:23 -07002884 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
2885 iface_context->tl_context, ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302887 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002888 ipa_free_skb(ipa_tx_desc);
2889 iface_context->stats.num_tx_err++;
2890 hdd_ipa_rm_try_release(hdd_ipa);
2891 return;
2892 }
2893
2894 atomic_inc(&hdd_ipa->tx_ref_cnt);
2895
2896 iface_context->stats.num_tx++;
2897
2898}
2899
2900/**
Leo Chang11545d62016-10-17 14:53:50 -07002901 * hdd_ipa_is_present() - get IPA hw status
2902 * @hdd_ctx: pointer to hdd context
2903 *
2904 * ipa_uc_reg_rdyCB is not directly designed to check
2905 * ipa hw status. This is an undocumented function which
2906 * has confirmed with IPA team.
2907 *
2908 * Return: true - ipa hw present
2909 * false - ipa hw not present
2910 */
2911bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2912{
2913 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002914 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002915 return true;
2916 else
2917 return false;
2918}
2919
2920/**
Leo Chang69c39692016-10-12 20:11:12 -07002921 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922 * @work: pointer to the scheduled work
2923 *
2924 * Called during PM resume to send packets to TL which were queued
2925 * while host was in the process of suspending.
2926 *
2927 * Return: None
2928 */
Leo Chang69c39692016-10-12 20:11:12 -07002929static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930{
2931 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2932 struct hdd_ipa_priv,
2933 pm_work);
2934 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302935 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936 uint32_t dequeued = 0;
2937
Leo Chang69c39692016-10-12 20:11:12 -07002938 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2939 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302940 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302941 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2942 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302943 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944
2945 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002946 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002947 if (pm_tx_cb->exception) {
2948 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2949 "FLUSH EXCEPTION");
2950 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2951 } else {
2952 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002954 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302955 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002956 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302957 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002958 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2959 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960
2961 hdd_ipa->stats.num_tx_dequeued += dequeued;
2962 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2963 hdd_ipa->stats.num_max_pm_queue = dequeued;
2964}
2965
2966/**
2967 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2968 * @priv: pointer to private data registered with IPA (we register a
2969 * pointer to the interface-specific IPA context)
2970 * @evt: the IPA event which triggered the callback
2971 * @data: data associated with the event
2972 *
2973 * Return: None
2974 */
2975static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2976 unsigned long data)
2977{
2978 struct hdd_ipa_priv *hdd_ipa = NULL;
2979 struct ipa_rx_data *ipa_tx_desc;
2980 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302981 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302983 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984
Mukul Sharma81661ae2015-10-30 20:26:02 +05302985 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302987 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 dev_kfree_skb_any(skb);
2989 iface_context->stats.num_tx_drop++;
2990 return;
2991 }
2992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993 ipa_tx_desc = (struct ipa_rx_data *)data;
2994
2995 hdd_ipa = iface_context->hdd_ipa;
2996
2997 /*
2998 * When SSR is going on or driver is unloading, just drop the packets.
2999 * During SSR, there is no use in queueing the packets as STA has to
3000 * connect back any way
3001 */
3002 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303003 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004 ipa_free_skb(ipa_tx_desc);
3005 iface_context->stats.num_tx_drop++;
3006 return;
3007 }
3008
3009 skb = ipa_tx_desc->skb;
3010
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303011 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003012
3013 /*
3014 * If PROD resource is not requested here then there may be cases where
3015 * IPA hardware may be clocked down because of not having proper
3016 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
3017 * workaround to request PROD resource while data is going over CONS
3018 * pipe to prevent the IPA hardware clockdown.
3019 */
3020 hdd_ipa_rm_request(hdd_ipa);
3021
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303022 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003023 /*
3024 * If host is still suspended then queue the packets and these will be
3025 * drained later when resume completes. When packet is arrived here and
3026 * host is suspended, this means that there is already resume is in
3027 * progress.
3028 */
3029 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303030 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
3032 pm_tx_cb->iface_context = iface_context;
3033 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303034 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003035 hdd_ipa->stats.num_tx_queued++;
3036
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303037 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003038 return;
3039 }
3040
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303041 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003042
3043 /*
3044 * If we are here means, host is not suspended, wait for the work queue
3045 * to finish.
3046 */
3047#ifdef WLAN_OPEN_SOURCE
3048 flush_work(&hdd_ipa->pm_work);
3049#endif
3050
3051 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
3052}
3053
3054/**
3055 * hdd_ipa_suspend() - Suspend IPA
3056 * @hdd_ctx: Global HDD context
3057 *
3058 * Return: 0 on success, negativer errno on error
3059 */
3060int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
3061{
3062 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3063
3064 if (!hdd_ipa_is_enabled(hdd_ctx))
3065 return 0;
3066
3067 /*
3068 * Check if IPA is ready for suspend, If we are here means, there is
3069 * high chance that suspend would go through but just to avoid any race
3070 * condition after suspend started, these checks are conducted before
3071 * allowing to suspend.
3072 */
3073 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3074 return -EAGAIN;
3075
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303076 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077
3078 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303079 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080 return -EAGAIN;
3081 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303082 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003083
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303084 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303086 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003087
3088 return 0;
3089}
3090
3091/**
3092 * hdd_ipa_resume() - Resume IPA following suspend
3093 * hdd_ctx: Global HDD context
3094 *
3095 * Return: 0 on success, negative errno on error
3096 */
3097int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3098{
3099 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3100
3101 if (!hdd_ipa_is_enabled(hdd_ctx))
3102 return 0;
3103
3104 schedule_work(&hdd_ipa->pm_work);
3105
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303106 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003107 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303108 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109
3110 return 0;
3111}
3112
3113/**
3114 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3115 * @hdd_ipa: Global HDD IPA context
3116 *
3117 * Return: 0 on success, negative errno on error
3118 */
3119static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3120{
3121 int i, ret = 0;
3122 struct ipa_sys_connect_params *ipa;
3123 uint32_t desc_fifo_sz;
3124
3125 /* The maximum number of descriptors that can be provided to a BAM at
3126 * once is one less than the total number of descriptors that the buffer
3127 * can contain.
3128 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3129 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3130 * be provided at once.
3131 * Because of above requirement, one extra descriptor will be added to
3132 * make sure hardware always has one descriptor.
3133 */
3134 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3135 + sizeof(struct sps_iovec);
3136
3137 /*setup TX pipes */
3138 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3139 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3140
3141 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3142 ipa->desc_fifo_sz = desc_fifo_sz;
3143 ipa->priv = &hdd_ipa->iface_context[i];
3144 ipa->notify = hdd_ipa_i2w_cb;
3145
3146 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3147 ipa->ipa_ep_cfg.hdr.hdr_len =
3148 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3149 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3150 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3151 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3152 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3153 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3154 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3155 } else {
3156 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3157 }
3158 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3159
3160 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3161 ipa->keep_ipa_awake = 1;
3162
3163 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3164 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303165 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166 " ret: %d", i, ret);
3167 goto setup_sys_pipe_fail;
3168 }
3169 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3170 }
3171
3172 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3173 /*
3174 * Hard code it here, this can be extended if in case
3175 * PROD pipe is also per interface.
3176 * Right now there is no advantage of doing this.
3177 */
3178 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3179
3180 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3181
3182 ipa->client = hdd_ipa->prod_client;
3183
3184 ipa->desc_fifo_sz = desc_fifo_sz;
3185 ipa->priv = hdd_ipa;
3186 ipa->notify = hdd_ipa_w2i_cb;
3187
3188 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3189 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3190 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3191 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3192
3193 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3194 ipa->keep_ipa_awake = 1;
3195
3196 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3197 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303198 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199 "Failed for RX pipe: %d", ret);
3200 goto setup_sys_pipe_fail;
3201 }
3202 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3203 }
3204
3205 return ret;
3206
3207setup_sys_pipe_fail:
3208
3209 while (--i >= 0) {
3210 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303211 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 sizeof(struct hdd_ipa_sys_pipe));
3213 }
3214
3215 return ret;
3216}
3217
3218/**
3219 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3220 * @hdd_ipa: Global HDD IPA context
3221 *
3222 * Return: None
3223 */
3224static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3225{
3226 int ret = 0, i;
3227 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3228 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3229 ret =
3230 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3231 conn_hdl);
3232 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303233 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234 ret);
3235
3236 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3237 }
3238 }
3239}
3240
3241/**
3242 * hdd_ipa_register_interface() - register IPA interface
3243 * @hdd_ipa: Global IPA context
3244 * @iface_context: Per-interface IPA context
3245 *
3246 * Return: 0 on success, negative errno on error
3247 */
3248static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3249 struct hdd_ipa_iface_context
3250 *iface_context)
3251{
3252 struct ipa_tx_intf tx_intf;
3253 struct ipa_rx_intf rx_intf;
3254 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3255 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3256 char *ifname = iface_context->adapter->dev->name;
3257
3258 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3259 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3260
3261 int num_prop = 1;
3262 int ret = 0;
3263
3264 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3265 num_prop++;
3266
3267 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3268 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303269 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303271 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 goto register_interface_fail;
3273 }
3274
3275 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3276 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303277 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303279 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280 goto register_interface_fail;
3281 }
3282
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303283 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3284 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003285
3286 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3287 ifname, HDD_IPA_IPV4_NAME_EXT);
3288 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3289 ifname, HDD_IPA_IPV6_NAME_EXT);
3290
3291 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3292 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3293 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3294 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3295
3296 /*
3297 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3298 * mask to identify the interface in IPA hardware
3299 */
3300 rx_prop[IPA_IP_v4].attrib.meta_data =
3301 htonl(iface_context->adapter->sessionId << 16);
3302 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3303
3304 rx_intf.num_props++;
3305 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3306 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3307 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3308 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3309 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3310 rx_prop[IPA_IP_v4].attrib.meta_data =
3311 htonl(iface_context->adapter->sessionId << 16);
3312 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3313
3314 rx_intf.num_props++;
3315 }
3316
3317 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3318 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3319 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3320 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3321 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3322 IPA_RESOURCE_NAME_MAX);
3323 tx_intf.num_props++;
3324
3325 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3326 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3327 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3328 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3329 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3330 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3331 IPA_RESOURCE_NAME_MAX);
3332 tx_intf.num_props++;
3333 }
3334
3335 tx_intf.prop = tx_prop;
3336 rx_intf.prop = rx_prop;
3337
3338 /* Call the ipa api to register interface */
3339 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3340
3341register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303342 qdf_mem_free(tx_prop);
3343 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 return ret;
3345}
3346
3347/**
3348 * hdd_remove_ipa_header() - Remove a specific header from IPA
3349 * @name: Name of the header to be removed
3350 *
3351 * Return: None
3352 */
3353static void hdd_ipa_remove_header(char *name)
3354{
3355 struct ipa_ioc_get_hdr hdrlookup;
3356 int ret = 0, len;
3357 struct ipa_ioc_del_hdr *ipa_hdr;
3358
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303359 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3361 ret = ipa_get_hdr(&hdrlookup);
3362 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303363 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 name, ret);
3365 return;
3366 }
3367
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303368 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303370 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303372 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 return;
3374 }
3375 ipa_hdr->num_hdls = 1;
3376 ipa_hdr->commit = 0;
3377 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3378 ipa_hdr->hdl[0].status = -1;
3379 ret = ipa_del_hdr(ipa_hdr);
3380 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303381 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382 ret);
3383
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303384 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385}
3386
3387/**
3388 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3389 * @hdd_ipa: Global HDD IPA context
3390 * @iface_context: Interface-specific HDD IPA context
3391 * @mac_addr: Interface MAC address
3392 *
3393 * Return: 0 on success, negativer errno value on error
3394 */
3395static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3396 struct hdd_ipa_iface_context *iface_context,
3397 uint8_t *mac_addr)
3398{
3399 hdd_adapter_t *adapter = iface_context->adapter;
3400 char *ifname;
3401 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3402 int ret = -EINVAL;
3403 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3404 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3405
3406 ifname = adapter->dev->name;
3407
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303408 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 ifname, mac_addr);
3410
3411 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303412 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 + sizeof(struct ipa_hdr_add));
3414 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303415 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 "%s: ipa_hdr allocation failed", ifname);
3417 ret = -ENOMEM;
3418 goto end;
3419 }
3420
3421 ipa_hdr->commit = 0;
3422 ipa_hdr->num_hdrs = 1;
3423
3424 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3425 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3426 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3427 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3428 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303429 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 "ifname=%s, vdev_id=%d",
3431 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3432 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3433 ifname, HDD_IPA_IPV4_NAME_EXT);
3434 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3435 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3436 ipa_hdr->hdr[0].is_partial = 1;
3437 ipa_hdr->hdr[0].hdr_hdl = 0;
3438 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3439 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3440
3441 ret = ipa_add_hdr(ipa_hdr);
3442 } else {
3443 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3444
3445 /* Set the Source MAC */
3446 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3447 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3448
3449 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3450 ifname, HDD_IPA_IPV4_NAME_EXT);
3451 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3452 ipa_hdr->hdr[0].is_partial = 1;
3453 ipa_hdr->hdr[0].hdr_hdl = 0;
3454 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3455 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3456
3457 /* Set the type to IPV4 in the header */
3458 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3459
3460 ret = ipa_add_hdr(ipa_hdr);
3461 }
3462 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303463 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464 ifname, ret);
3465 goto end;
3466 }
3467
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303468 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3470
3471 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3472 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3473 ifname, HDD_IPA_IPV6_NAME_EXT);
3474
3475 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3476 uc_tx_hdr =
3477 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3478 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3479 } else {
3480 /* Set the type to IPV6 in the header */
3481 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3482 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3483 }
3484
3485 ret = ipa_add_hdr(ipa_hdr);
3486 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303487 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 "%s: IPv6 add hdr failed: %d", ifname, ret);
3489 goto clean_ipv4_hdr;
3490 }
3491
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303492 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3494 }
3495
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303496 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497
3498 return ret;
3499
3500clean_ipv4_hdr:
3501 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3502 ifname, HDD_IPA_IPV4_NAME_EXT);
3503 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3504end:
3505 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303506 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507
3508 return ret;
3509}
3510
3511/**
3512 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3513 * @adapter: Adapter upon which IPA was previously configured
3514 *
3515 * Return: None
3516 */
3517static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3518{
3519 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3520 int ret;
3521 char name_ipa[IPA_RESOURCE_NAME_MAX];
3522
3523 /* Remove the headers */
3524 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3525 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3526 hdd_ipa_remove_header(name_ipa);
3527
3528 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3529 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3530 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3531 hdd_ipa_remove_header(name_ipa);
3532 }
3533 /* unregister the interface with IPA */
3534 ret = ipa_deregister_intf(adapter->dev->name);
3535 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303536 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537 "%s: ipa_deregister_intf fail: %d",
3538 adapter->dev->name, ret);
3539}
3540
3541/**
3542 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3543 * @iface_context: interface-specific IPA context
3544 *
3545 * Return: None
3546 */
3547static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3548{
3549 if (iface_context == NULL)
3550 return;
3551
3552 hdd_ipa_clean_hdr(iface_context->adapter);
3553
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303554 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555 iface_context->adapter->ipa_context = NULL;
3556 iface_context->adapter = NULL;
3557 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303558 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 iface_context->ifa_address = 0;
3560 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303561 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303563 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 }
3565 iface_context->hdd_ipa->num_iface--;
3566}
3567
3568/**
3569 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3570 * @hdd_ipa: HDD IPA global context
3571 * @adapter: Interface upon which IPA is being setup
3572 * @sta_id: Station ID of the API instance
3573 *
3574 * Return: 0 on success, negative errno value on error
3575 */
3576static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3577 hdd_adapter_t *adapter, uint8_t sta_id)
3578{
3579 struct hdd_ipa_iface_context *iface_context = NULL;
3580 void *tl_context = NULL;
3581 int i, ret = 0;
3582
3583 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3584 * channel change indication. Since these indications are sent by lower
3585 * layer as SAP updates and IPA doesn't have to do anything for these
3586 * updates so ignoring!
3587 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003588 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 return 0;
3590
3591 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3592 if (hdd_ipa->iface_context[i].adapter == NULL) {
3593 iface_context = &(hdd_ipa->iface_context[i]);
3594 break;
3595 }
3596 }
3597
3598 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303599 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 "All the IPA interfaces are in use");
3601 ret = -ENOMEM;
3602 goto end;
3603 }
3604
3605 adapter->ipa_context = iface_context;
3606 iface_context->adapter = adapter;
3607 iface_context->sta_id = sta_id;
Leo Changfdb45c32016-10-28 11:09:23 -07003608 tl_context = cdp_peer_get_vdev_by_sta_id(
3609 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303611 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003612 "Not able to get TL context sta_id: %d", sta_id);
3613 ret = -EINVAL;
3614 goto end;
3615 }
3616
3617 iface_context->tl_context = tl_context;
3618
3619 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3620 adapter->dev->dev_addr);
3621
3622 if (ret)
3623 goto end;
3624
3625 /* Configure the TX and RX pipes filter rules */
3626 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3627 if (ret)
3628 goto cleanup_header;
3629
3630 hdd_ipa->num_iface++;
3631 return ret;
3632
3633cleanup_header:
3634
3635 hdd_ipa_clean_hdr(adapter);
3636end:
3637 if (iface_context)
3638 hdd_ipa_cleanup_iface(iface_context);
3639 return ret;
3640}
3641
Yun Parka27049a2016-10-11 12:30:49 -07003642#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643/**
3644 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3645 * @mcc_mode: 0=MCC/1=SCC
3646 *
3647 * Return: 0 on success, negative errno value on error
3648 */
3649int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3650{
3651 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303652 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 hdd_adapter_t *pAdapter;
3654 struct ipa_msg_meta meta;
3655 struct ipa_wlan_msg *msg;
3656 int ret;
3657
3658 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3659 return -EINVAL;
3660
3661 if (!pHddCtx->mcc_mode) {
3662 /* Flush TxRx queue for each adapter before switch to SCC */
3663 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303664 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003666 if (pAdapter->device_mode == QDF_STA_MODE ||
3667 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303668 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003669 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3670 pAdapter->device_mode);
3671 hdd_deinit_tx_rx(pAdapter);
3672 }
3673 status = hdd_get_next_adapter(
3674 pHddCtx, adapter_node, &next);
3675 adapter_node = next;
3676 }
3677 }
3678
3679 /* Send SCC/MCC Switching event to IPA */
3680 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303681 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003682 if (msg == NULL) {
3683 hddLog(LOGE, "msg allocation failed");
3684 return -ENOMEM;
3685 }
3686
3687 meta.msg_type = mcc_mode ?
3688 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3689 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3690
3691 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3692
3693 if (ret) {
3694 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3695 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303696 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 }
3698
3699 return ret;
3700}
Yun Parka27049a2016-10-11 12:30:49 -07003701#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702
3703/**
3704 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3705 * @event: IPA WLAN event to be converted to a string
3706 *
3707 * Return: ASCII string representing the IPA WLAN event
3708 */
3709static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3710{
3711 switch (event) {
3712 case WLAN_CLIENT_CONNECT:
3713 return "WLAN_CLIENT_CONNECT";
3714 case WLAN_CLIENT_DISCONNECT:
3715 return "WLAN_CLIENT_DISCONNECT";
3716 case WLAN_CLIENT_POWER_SAVE_MODE:
3717 return "WLAN_CLIENT_POWER_SAVE_MODE";
3718 case WLAN_CLIENT_NORMAL_MODE:
3719 return "WLAN_CLIENT_NORMAL_MODE";
3720 case SW_ROUTING_ENABLE:
3721 return "SW_ROUTING_ENABLE";
3722 case SW_ROUTING_DISABLE:
3723 return "SW_ROUTING_DISABLE";
3724 case WLAN_AP_CONNECT:
3725 return "WLAN_AP_CONNECT";
3726 case WLAN_AP_DISCONNECT:
3727 return "WLAN_AP_DISCONNECT";
3728 case WLAN_STA_CONNECT:
3729 return "WLAN_STA_CONNECT";
3730 case WLAN_STA_DISCONNECT:
3731 return "WLAN_STA_DISCONNECT";
3732 case WLAN_CLIENT_CONNECT_EX:
3733 return "WLAN_CLIENT_CONNECT_EX";
3734
3735 case IPA_WLAN_EVENT_MAX:
3736 default:
3737 return "UNKNOWN";
3738 }
3739}
3740
3741/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003742 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3743 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3744 *
3745 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3746 */
3747static enum ipa_wlan_event
3748hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3749{
3750 enum ipa_wlan_event ipa_event;
3751
3752 switch (hdd_ipa_event_type) {
3753 case HDD_IPA_CLIENT_CONNECT:
3754 ipa_event = WLAN_CLIENT_CONNECT;
3755 break;
3756 case HDD_IPA_CLIENT_DISCONNECT:
3757 ipa_event = WLAN_CLIENT_DISCONNECT;
3758 break;
3759 case HDD_IPA_AP_CONNECT:
3760 ipa_event = WLAN_AP_CONNECT;
3761 break;
3762 case HDD_IPA_AP_DISCONNECT:
3763 ipa_event = WLAN_AP_DISCONNECT;
3764 break;
3765 case HDD_IPA_STA_CONNECT:
3766 ipa_event = WLAN_STA_CONNECT;
3767 break;
3768 case HDD_IPA_STA_DISCONNECT:
3769 ipa_event = WLAN_STA_DISCONNECT;
3770 break;
3771 case HDD_IPA_CLIENT_CONNECT_EX:
3772 ipa_event = WLAN_CLIENT_CONNECT_EX;
3773 break;
3774 case HDD_IPA_WLAN_EVENT_MAX:
3775 default:
3776 ipa_event = IPA_WLAN_EVENT_MAX;
3777 break;
3778 }
3779 return ipa_event;
3780
3781}
3782
3783/**
3784 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 * @adapter: adapter upon which the event was received
3786 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003787 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003788 * @mac_address: MAC address associated with the event
3789 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003790 * This function is meant to be called from within wlan_hdd_ipa.c
3791 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792 * Return: 0 on success, negative errno value on error
3793 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003794static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003795 enum ipa_wlan_event type, uint8_t *mac_addr)
3796{
3797 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3798 struct ipa_msg_meta meta;
3799 struct ipa_wlan_msg *msg;
3800 struct ipa_wlan_msg_ex *msg_ex = NULL;
3801 int ret;
3802
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303803 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003804 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3805 mac_addr, sta_id);
3806
3807 if (type >= IPA_WLAN_EVENT_MAX)
3808 return -EINVAL;
3809
3810 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3811 return -EINVAL;
3812
3813 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303814 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815 return -EINVAL;
3816 }
3817
3818 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3819 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003820 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821 return 0;
3822 }
3823
3824 /*
3825 * During IPA UC resource loading/unloading new events can be issued.
3826 * Store the events separately and handle them later.
3827 */
3828 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3829 ((hdd_ipa->resource_loading) ||
3830 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003831 unsigned int pending_event_count;
3832 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833
Yun Parkf19e07d2015-11-20 11:34:27 -08003834 hdd_err("IPA resource %s inprogress",
3835 hdd_ipa->resource_loading ? "load":"unload");
3836
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303837 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003838
Anurag Chouhanffb21542016-02-17 14:33:03 +05303839 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003840 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3841 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303842 qdf_list_remove_front(&hdd_ipa->pending_event,
3843 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003844 } else {
3845 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303846 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003847 sizeof(struct ipa_uc_pending_event));
3848 }
3849
3850 if (!pending_event) {
3851 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303852 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853 return -ENOMEM;
3854 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003855
3856 pending_event->adapter = adapter;
3857 pending_event->sta_id = sta_id;
3858 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303859 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303861 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303862 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003863 &pending_event->node);
3864
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303865 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003866 return 0;
3867 }
3868
3869 hdd_ipa->stats.event[type]++;
3870
Leo Chang3bc8fed2015-11-13 10:59:47 -08003871 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 switch (type) {
3873 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003874 qdf_mutex_acquire(&hdd_ipa->event_lock);
3875
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876 /* STA already connected and without disconnect, connect again
3877 * This is Roaming scenario
3878 */
3879 if (hdd_ipa->sta_connected)
3880 hdd_ipa_cleanup_iface(adapter->ipa_context);
3881
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3883 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303884 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003886 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003887
Yun Park8f289c82016-10-18 16:38:21 -07003888 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3889 (hdd_ipa->sap_num_connected_sta > 0) &&
3890 !hdd_ipa->sta_connected) {
3891 qdf_mutex_release(&hdd_ipa->event_lock);
3892 hdd_ipa_uc_offload_enable_disable(adapter,
3893 SIR_STA_RX_DATA_OFFLOAD, 1);
3894 qdf_mutex_acquire(&hdd_ipa->event_lock);
3895 }
3896
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 vdev_to_iface[adapter->sessionId] =
3898 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003899 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003901 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003902
3903 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 break;
3905
3906 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003907 qdf_mutex_acquire(&hdd_ipa->event_lock);
3908
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 /* For DFS channel we get two start_bss event (before and after
3910 * CAC). Also when ACS range includes both DFS and non DFS
3911 * channels, we could possibly change channel many times due to
3912 * RADAR detection and chosen channel may not be a DFS channels.
3913 * So dont return error here. Just discard the event.
3914 */
Yun Park8f289c82016-10-18 16:38:21 -07003915 if (adapter->ipa_context) {
3916 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3921 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303922 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 "%s: Evt: %d, Interface setup failed",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05303924 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303925 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003927 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928
Yun Park8f289c82016-10-18 16:38:21 -07003929 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3930 qdf_mutex_release(&hdd_ipa->event_lock);
3931 hdd_ipa_uc_offload_enable_disable(adapter,
3932 SIR_AP_RX_DATA_OFFLOAD, 1);
3933 qdf_mutex_acquire(&hdd_ipa->event_lock);
3934 }
3935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 vdev_to_iface[adapter->sessionId] =
3937 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003938 (adapter->ipa_context))->iface_id;
3939
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303940 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003941 break;
3942
3943 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303944 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945
3946 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303947 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948 "%s: Evt: %d, STA already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05303949 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303950 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951 return -EINVAL;
3952 }
Yun Parka37592b2016-06-11 17:10:28 -07003953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003955
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303957 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 "%s: IPA UC OFFLOAD NOT ENABLED",
3959 msg_ex->name);
3960 } else {
3961 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003962 if (!hdd_ipa->num_iface &&
3963 (HDD_IPA_UC_NUM_WDI_PIPE ==
3964 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003965 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 }
3967
Yun Park74127cf2016-09-18 11:22:41 -07003968 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3969 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07003970 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 hdd_ipa_uc_offload_enable_disable(adapter,
3972 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003973 qdf_mutex_acquire(&hdd_ipa->event_lock);
3974 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 }
3976
Yun Park8f289c82016-10-18 16:38:21 -07003977 hdd_ipa_cleanup_iface(adapter->ipa_context);
3978
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303979 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 break;
3981
3982 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003983 qdf_mutex_acquire(&hdd_ipa->event_lock);
3984
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303986 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987 "%s: Evt: %d, SAP already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05303988 adapter->dev->name, type);
Yun Park8f289c82016-10-18 16:38:21 -07003989 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 return -EINVAL;
3991 }
3992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 if ((!hdd_ipa->num_iface) &&
3994 (HDD_IPA_UC_NUM_WDI_PIPE ==
3995 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003996 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997 /*
3998 * We disable WDI pipes directly here since
3999 * IPA_OPCODE_TX/RX_SUSPEND message will not be
4000 * processed when unloading WLAN driver is in
4001 * progress
4002 */
4003 hdd_ipa_uc_disable_pipes(hdd_ipa);
4004 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304005 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 "NO INTF left but still pipe clean up");
4007 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4008 }
4009 }
4010
4011 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07004012 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 hdd_ipa_uc_offload_enable_disable(adapter,
4014 SIR_AP_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004015 qdf_mutex_acquire(&hdd_ipa->event_lock);
4016 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 }
Yun Parka37592b2016-06-11 17:10:28 -07004018
Yun Park8f289c82016-10-18 16:38:21 -07004019 hdd_ipa_cleanup_iface(adapter->ipa_context);
4020
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304021 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 break;
4023
4024 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304026 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304028 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 return 0;
4030 }
4031
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304032 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
4034 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07004035 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304036 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037 "%s: STA ID %d found, not valid",
4038 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 return 0;
4040 }
Yun Park312f71a2015-12-08 10:22:42 -08004041
4042 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07004043 if (0 == hdd_ipa->sap_num_connected_sta) {
4044 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004045 hdd_ipa->sta_connected) {
4046 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004047 hdd_ipa_uc_offload_enable_disable(
4048 hdd_get_adapter(hdd_ipa->hdd_ctx,
4049 QDF_STA_MODE),
4050 SIR_STA_RX_DATA_OFFLOAD, 1);
Yun Park8f289c82016-10-18 16:38:21 -07004051 qdf_mutex_acquire(&hdd_ipa->event_lock);
4052 }
Yun Parka37592b2016-06-11 17:10:28 -07004053
Yun Park312f71a2015-12-08 10:22:42 -08004054 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
4055 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304056 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08004057 "%s: handle 1st con ret %d",
4058 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07004059
4060 if (hdd_ipa_uc_sta_is_enabled(
4061 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004062 hdd_ipa->sta_connected) {
4063 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004064 hdd_ipa_uc_offload_enable_disable(
4065 hdd_get_adapter(
4066 hdd_ipa->hdd_ctx,
4067 QDF_STA_MODE),
4068 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004069 } else {
4070 qdf_mutex_release(&hdd_ipa->event_lock);
4071 }
Yun Parka37592b2016-06-11 17:10:28 -07004072
Yun Park312f71a2015-12-08 10:22:42 -08004073 return ret;
4074 }
4075 }
4076
4077 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08004078
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304079 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080
4081 meta.msg_type = type;
4082 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
4083 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304084 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004085
4086 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304087 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004088 "msg_ex allocation failed");
4089 return -ENOMEM;
4090 }
4091 strlcpy(msg_ex->name, adapter->dev->name,
4092 IPA_RESOURCE_NAME_MAX);
4093 msg_ex->num_of_attribs = 1;
4094 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4095 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4096 msg_ex->attribs[0].offset =
4097 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4098 } else {
4099 msg_ex->attribs[0].offset =
4100 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4101 }
4102 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4103 IPA_MAC_ADDR_SIZE);
4104
4105 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4106
4107 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304108 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304109 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304110 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004111 return ret;
4112 }
4113 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 return ret;
4115
4116 case WLAN_CLIENT_DISCONNECT:
4117 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304118 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004119 "%s: IPA UC OFFLOAD NOT ENABLED",
4120 msg_ex->name);
4121 return 0;
4122 }
4123
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304124 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004125 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304126 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004127 "%s: STA ID %d NOT found, not valid",
4128 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304129 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 return 0;
4131 }
4132 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07004133
Yun Park9b5030f2016-11-08 12:02:37 -08004134 /* Disable IPA UC TX PIPE when last STA disconnected */
4135 if (!hdd_ipa->sap_num_connected_sta) {
4136 if ((false == hdd_ipa->resource_unloading)
4137 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4138 hdd_ipa->activated_fw_pipe)) {
4139 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4140 }
4141
Yun Park8f289c82016-10-18 16:38:21 -07004142 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004143
4144 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4145 hdd_ipa->sta_connected)
4146 hdd_ipa_uc_offload_enable_disable(
4147 hdd_get_adapter(hdd_ipa->hdd_ctx,
4148 QDF_STA_MODE),
4149 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004150 } else {
4151 qdf_mutex_release(&hdd_ipa->event_lock);
4152 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 break;
4154
4155 default:
4156 return 0;
4157 }
4158
4159 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304160 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304162 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 return -ENOMEM;
4164 }
4165
4166 meta.msg_type = type;
4167 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4168 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4169
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304170 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 msg->name, meta.msg_type);
4172
4173 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4174
4175 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304176 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304178 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 return ret;
4180 }
4181
4182 hdd_ipa->stats.num_send_msg++;
4183
4184end:
4185 return ret;
4186}
4187
4188/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004189 * hdd_ipa_wlan_evt() - IPA event handler
4190 * @adapter: adapter upon which the event was received
4191 * @sta_id: station id for the event
4192 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4193 * @mac_address: MAC address associated with the event
4194 *
4195 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4196 *
4197 * Return: 0 on success, negative errno value on error
4198 */
4199int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4200 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4201{
4202 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4203
Leo Changa202b522016-10-14 16:13:50 -07004204 /* Data path offload only support for STA and SAP mode */
4205 if ((QDF_STA_MODE == adapter->device_mode) ||
4206 (QDF_SAP_MODE == adapter->device_mode))
4207 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4208
4209 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004210}
4211
4212/**
4213 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4214 * @hdd_ipa: Global HDD IPA context
4215 *
4216 * Return: None
4217 */
4218static void
4219hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4220{
4221 unsigned int pending_event_count;
4222 struct ipa_uc_pending_event *pending_event = NULL;
4223
4224 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4225 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4226 "%s, Pending Event Count %d", __func__, pending_event_count);
4227 if (!pending_event_count) {
4228 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4229 "%s, No Pending Event", __func__);
4230 return;
4231 }
4232
4233 qdf_list_remove_front(&hdd_ipa->pending_event,
4234 (qdf_list_node_t **)&pending_event);
4235 while (pending_event != NULL) {
4236 __hdd_ipa_wlan_evt(pending_event->adapter,
4237 pending_event->type,
4238 pending_event->sta_id,
4239 pending_event->mac_addr);
4240 qdf_mem_free(pending_event);
4241 pending_event = NULL;
4242 qdf_list_remove_front(&hdd_ipa->pending_event,
4243 (qdf_list_node_t **)&pending_event);
4244 }
4245}
4246
4247/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4249 * @state: IPA RM state value
4250 *
4251 * Return: ASCII string representing the IPA RM state
4252 */
4253static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4254{
4255 switch (state) {
4256 case HDD_IPA_RM_RELEASED:
4257 return "RELEASED";
4258 case HDD_IPA_RM_GRANT_PENDING:
4259 return "GRANT_PENDING";
4260 case HDD_IPA_RM_GRANTED:
4261 return "GRANTED";
4262 }
4263
4264 return "UNKNOWN";
4265}
4266
4267/**
4268 * hdd_ipa_init() - IPA initialization function
4269 * @hdd_ctx: HDD global context
4270 *
4271 * Allocate hdd_ipa resources, ipa pipe resource and register
4272 * wlan interface with IPA module.
4273 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304274 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304276QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004277{
4278 struct hdd_ipa_priv *hdd_ipa = NULL;
4279 int ret, i;
4280 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004281 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282
4283 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304284 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285
Yun Park7f171ab2016-07-29 15:44:22 -07004286 if (!pdev) {
4287 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4288 goto fail_return;
4289 }
4290
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304291 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304293 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004294 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 }
4296
4297 hdd_ctx->hdd_ipa = hdd_ipa;
4298 ghdd_ipa = hdd_ipa;
4299 hdd_ipa->hdd_ctx = hdd_ctx;
4300 hdd_ipa->num_iface = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07004301 cdp_ipa_get_resource(cds_get_context(QDF_MODULE_ID_SOC),
4302 cds_get_context(QDF_MODULE_ID_TXRX),
4303 &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004304 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4305 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4306 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4307 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304308 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004309 "IPA UC resource alloc fail");
4310 goto fail_get_resource;
4311 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312
4313 /* Create the interface context */
4314 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4315 iface_context = &hdd_ipa->iface_context[i];
4316 iface_context->hdd_ipa = hdd_ipa;
4317 iface_context->cons_client =
4318 hdd_ipa_adapter_2_client[i].cons_client;
4319 iface_context->prod_client =
4320 hdd_ipa_adapter_2_client[i].prod_client;
4321 iface_context->iface_id = i;
4322 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004323 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304324 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004325 }
4326 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Yun Park8f289c82016-10-18 16:38:21 -07004327 vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 }
4329
Leo Chang69c39692016-10-12 20:11:12 -07004330 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304331 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304332 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333
4334 ret = hdd_ipa_setup_rm(hdd_ipa);
4335 if (ret)
4336 goto fail_setup_rm;
4337
4338 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4339 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304340 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 hdd_ipa->sap_num_connected_sta = 0;
4342 hdd_ipa->ipa_tx_packets_diff = 0;
4343 hdd_ipa->ipa_rx_packets_diff = 0;
4344 hdd_ipa->ipa_p_tx_packets = 0;
4345 hdd_ipa->ipa_p_rx_packets = 0;
4346 hdd_ipa->resource_loading = false;
4347 hdd_ipa->resource_unloading = false;
4348 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004349 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 /* Setup IPA sys_pipe for MCC */
4351 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4352 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4353 if (ret)
4354 goto fail_create_sys_pipe;
4355 }
4356 hdd_ipa_uc_ol_init(hdd_ctx);
4357 } else {
4358 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4359 if (ret)
4360 goto fail_create_sys_pipe;
4361 }
4362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304363 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364
4365fail_create_sys_pipe:
4366 hdd_ipa_destroy_rm_resource(hdd_ipa);
4367fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304368 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004369fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304370 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004371 hdd_ctx->hdd_ipa = NULL;
4372 ghdd_ipa = NULL;
4373fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304374 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375}
4376
4377/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004378 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4379 * @hdd_ipa: pointer to HDD IPA struct
4380 *
4381 * Return: none
4382 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004383static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004384{
4385 struct ipa_uc_pending_event *pending_event = NULL;
4386
Anurag Chouhanffb21542016-02-17 14:33:03 +05304387 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4388 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304389 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004390 }
4391
Anurag Chouhanffb21542016-02-17 14:33:03 +05304392 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004393}
4394
4395/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 * hdd_ipa_cleanup - IPA cleanup function
4397 * @hdd_ctx: HDD global context
4398 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304399 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304401QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402{
4403 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4404 int i;
4405 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304406 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004407 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4408
4409 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304410 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411
4412 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4413 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4414 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4415 }
4416
4417 /* Teardown IPA sys_pipe for MCC */
4418 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4419 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4420
4421 hdd_ipa_destroy_rm_resource(hdd_ipa);
4422
4423#ifdef WLAN_OPEN_SOURCE
4424 cancel_work_sync(&hdd_ipa->pm_work);
4425#endif
4426
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304427 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428
Nirav Shahcbc6d722016-03-01 16:24:53 +05304429 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4430 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304431 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432
4433 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4434 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4435
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304436 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304438 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304440 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441
4442 /* destory the interface lock */
4443 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4444 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304445 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 }
4447
4448 /* This should never hit but still make sure that there are no pending
4449 * descriptor in IPA hardware
4450 */
4451 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304452 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453 "IPA Pending write done: %d Waiting!",
4454 hdd_ipa->pending_hw_desc_cnt);
4455
4456 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4457 usleep_range(100, 100);
4458 }
4459
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304460 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004461 "IPA Pending write done: desc: %d %s(%d)!",
4462 hdd_ipa->pending_hw_desc_cnt,
4463 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4464 : "leak", i);
4465 }
4466 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4467 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304468 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304469 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4470 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004471 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304472 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304473 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4474 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004475 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304476 qdf_mutex_destroy(&hdd_ipa->event_lock);
4477 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004478 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004479
4480#ifdef WLAN_OPEN_SOURCE
4481 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4482 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4483 hdd_ipa->uc_op_work[i].msg = NULL;
4484 }
4485#endif
4486 }
4487
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304488 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489 hdd_ctx->hdd_ipa = NULL;
4490
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304491 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004492}
4493#endif /* IPA_OFFLOAD */