blob: 27736c9a410480738358e89dc7b097d9c09ce1a6 [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/**
Guolei Bianca144d82016-11-10 11:07:42 +0800642 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
643 * @hdd_ipa: Global HDD IPA context
644 *
645 * Return: None
646 */
647#ifdef IPA_UC_STA_OFFLOAD
648static inline void hdd_ipa_uc_sta_reset_sta_connected(
649 struct hdd_ipa_priv *hdd_ipa)
650{
651 vos_lock_acquire(&hdd_ipa->event_lock);
652 hdd_ipa->sta_connected = 0;
653 vos_lock_release(&hdd_ipa->event_lock);
654}
655#else
656static inline void hdd_ipa_uc_sta_reset_sta_connected(
657 struct hdd_ipa_priv *hdd_ipa)
658{
659}
660#endif
661
662/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
664 * @hdd_ipa: Global HDD IPA context
665 *
666 * Return: true if pre-filter is enabled, otherwise false
667 */
668static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
669{
670 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
671 HDD_IPA_PRE_FILTER_ENABLE_MASK);
672}
673
674/**
675 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
676 * @hdd_ipa: Global HDD IPA context
677 *
678 * Return: true if IPv6 is enabled, otherwise false
679 */
680static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
681{
682 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
683}
684
685/**
686 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
687 * @hdd_ipa: Global HDD IPA context
688 *
689 * Return: true if resource manager is enabled, otherwise false
690 */
691static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
692{
693 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
694}
695
696/**
697 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
698 * @hdd_ipa: Global HDD IPA context
699 *
700 * Return: true if resource manager is enabled, otherwise false
701 */
702static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
703{
704 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
705}
706
707/**
708 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
709 * @hdd_ipa: Global HDD IPA context
710 *
711 * Return: true if clock scaling is enabled, otherwise false
712 */
713static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
714{
715 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
716 HDD_IPA_CLK_SCALING_ENABLE_MASK |
717 HDD_IPA_RM_ENABLE_MASK);
718}
719
720/**
721 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
722 * @ctext: pointer to hdd context.
723 *
724 * If rt debug enabled, periodically called, and fill debug buffer
725 *
726 * Return: none
727 */
728static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
729{
730 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
731 struct hdd_ipa_priv *hdd_ipa;
732 struct uc_rt_debug_info *dump_info = NULL;
733
734 if (wlan_hdd_validate_context(hdd_ctx))
735 return;
736
737 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530738 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 "%s: IPA UC is not enabled", __func__);
740 return;
741 }
742
743 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
744
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530745 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746 dump_info = &hdd_ipa->rt_bug_buffer[
747 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
748
Deepthi Gowri6acee342016-10-28 15:00:38 +0530749 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800750 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
751 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
752 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
753 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
754 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
755 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
756 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
757 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530758 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759
Anurag Chouhan210db072016-02-22 18:42:15 +0530760 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
762}
763
764/**
765 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
766 * @hdd_ctx: pointer to hdd context.
767 *
768 * If rt debug enabled, dump debug buffer contents based on requirement
769 *
770 * Return: none
771 */
772void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
773{
774 struct hdd_ipa_priv *hdd_ipa;
775 unsigned int dump_count;
776 unsigned int dump_index;
777 struct uc_rt_debug_info *dump_info = NULL;
778
779 if (wlan_hdd_validate_context(hdd_ctx))
780 return;
781
782 hdd_ipa = hdd_ctx->hdd_ipa;
783 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530784 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785 "%s: IPA UC is not enabled", __func__);
786 return;
787 }
788
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 ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530791 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
793
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530794 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800795 for (dump_count = 0;
796 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
797 dump_count++) {
798 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
799 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
800 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530801 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530802 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 dump_info->time, dump_info->ipa_excep_count,
804 dump_info->rx_drop_count, dump_info->net_sent_count,
805 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
806 dump_info->rx_destructor_call,
807 dump_info->rx_discard_count);
808 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530809 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530810 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800811 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
812}
813
814/**
815 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
816 * @ctext: pointer to hdd context.
817 *
818 * periodically called by timer expire
819 * will try to alloc dummy memory and detect out of memory condition
820 * if out of memory detected, dump wlan-ipa stats
821 *
822 * Return: none
823 */
824static void hdd_ipa_uc_rt_debug_handler(void *ctext)
825{
826 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
827 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
828 void *dummy_ptr = NULL;
829
830 if (wlan_hdd_validate_context(hdd_ctx))
831 return;
832
833 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530834 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 "%s: IPA RT debug is not enabled", __func__);
836 return;
837 }
838
839 /* Allocate dummy buffer periodically and free immediately. this will
840 * proactively detect OOM and if allocation fails dump ipa stats
841 */
842 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
843 GFP_KERNEL | GFP_ATOMIC);
844 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530845 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800846 "%s: Dummy alloc fail", __func__);
847 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
848 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800849 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 } else {
851 kfree(dummy_ptr);
852 }
853
Anurag Chouhan210db072016-02-22 18:42:15 +0530854 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855 HDD_IPA_UC_RT_DEBUG_PERIOD);
856}
857
858/**
859 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
860 * @skb: packet pinter
861 *
862 * when free data packet, will be invoked by wlan client and will increase
863 * free counter
864 *
865 * Return: none
866 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700867static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800868{
869 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530870 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800871 "%s: invalid hdd context", __func__);
872 return;
873 }
874
875 ghdd_ipa->ipa_rx_destructor_count++;
876}
877
878/**
879 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
880 * @hdd_ctx: hdd main context
881 *
882 * free all rt debugging resources
883 *
884 * Return: none
885 */
886static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
887{
888 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
889
Anurag Chouhan210db072016-02-22 18:42:15 +0530890 if (QDF_TIMER_STATE_STOPPED !=
891 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
892 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530894 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530895 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896
897 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530898 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899 "%s: IPA RT debug is not enabled", __func__);
900 return;
901 }
902
Anurag Chouhan210db072016-02-22 18:42:15 +0530903 if (QDF_TIMER_STATE_STOPPED !=
904 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
905 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800906 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530907 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908}
909
910/**
911 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
912 * @hdd_ctx: hdd main context
913 *
914 * alloc and initialize all rt debugging resources
915 *
916 * Return: none
917 */
918static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
919{
920 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
921
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530922 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530924 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 sizeof(struct uc_rt_debug_info) *
926 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
927 hdd_ipa->ipa_tx_forward = 0;
928 hdd_ipa->ipa_rx_discard = 0;
929 hdd_ipa->ipa_rx_net_send_count = 0;
930 hdd_ipa->ipa_rx_internel_drop_count = 0;
931 hdd_ipa->ipa_rx_destructor_count = 0;
932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 /* Reatime debug enable on feature enable */
934 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530935 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800936 "%s: IPA RT debug is not enabled", __func__);
937 return;
938 }
Yun Parkdfc1da52016-11-15 14:50:11 -0800939
940 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
941 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
942 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
943 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
944
Anurag Chouhan210db072016-02-22 18:42:15 +0530945 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800946 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530947 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 HDD_IPA_UC_RT_DEBUG_PERIOD);
949
950}
951
952/**
953 * hdd_ipa_uc_stat_query() - Query the IPA stats
954 * @hdd_ctx: Global HDD context
955 * @ipa_tx_diff: tx packet count diff from previous
956 * tx packet count
957 * @ipa_rx_diff: rx packet count diff from previous
958 * rx packet count
959 *
960 * Return: true if IPA is enabled, false otherwise
961 */
962void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
963 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
964{
965 struct hdd_ipa_priv *hdd_ipa;
966
967 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
968 *ipa_tx_diff = 0;
969 *ipa_rx_diff = 0;
970
971 if (!hdd_ipa_is_enabled(pHddCtx) ||
972 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
973 return;
974 }
975
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530976 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
978 (false == hdd_ipa->resource_loading)) {
979 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
980 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkf8d6a122016-10-11 15:49:43 -0700981 HDD_IPA_LOG(LOGOFF, "STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982 *ipa_tx_diff, *ipa_rx_diff);
983 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530984 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800985 return;
986}
987
988/**
989 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
990 * @adapter: network adapter
991 * @reason: STAT REQ Reason
992 *
993 * Return: None
994 */
995void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
996{
997 hdd_context_t *pHddCtx;
998 struct hdd_ipa_priv *hdd_ipa;
999
1000 if (!adapter) {
1001 return;
1002 }
1003
1004 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
1005 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
1006 if (!hdd_ipa_is_enabled(pHddCtx) ||
1007 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1008 return;
1009 }
1010
Yun Park8f289c82016-10-18 16:38:21 -07001011 HDD_IPA_LOG(LOGOFF, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301012 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1014 (false == hdd_ipa->resource_loading)) {
1015 hdd_ipa->stat_req_reason = reason;
1016 wma_cli_set_command(
1017 (int)adapter->sessionId,
1018 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
1019 0, VDEV_CMD);
1020 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301021 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022}
1023
1024/**
1025 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1026 * @hdd_ipa: Global HDD IPA context
1027 * @sta_add: Should station be added
1028 * @sta_id: ID of the station being queried
1029 *
1030 * Return: true if the station was found
1031 */
1032static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1033 bool sta_add, uint8_t sta_id)
1034{
1035 bool sta_found = false;
1036 uint8_t idx;
1037 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1038 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1039 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1040 sta_found = true;
1041 break;
1042 }
1043 }
1044 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301045 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 "%s: STA ID %d already exist, cannot add",
1047 __func__, sta_id);
1048 return sta_found;
1049 }
1050 if (sta_add) {
1051 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1052 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1053 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1054 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1055 return sta_found;
1056 }
1057 }
1058 }
1059 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301060 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 "%s: STA ID %d does not exist, cannot delete",
1062 __func__, sta_id);
1063 return sta_found;
1064 }
1065 if (!sta_add) {
1066 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1067 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1068 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1069 hdd_ipa->assoc_stas_map[idx].is_reserved =
1070 false;
1071 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1072 return sta_found;
1073 }
1074 }
1075 }
1076 return sta_found;
1077}
1078
1079/**
1080 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1081 * @hdd_ipa: Global HDD IPA context
1082 *
1083 * Return: 0 on success, negative errno if error
1084 */
1085static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1086{
1087 int result;
1088 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001089 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090
1091 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301092 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001093 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1094 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1096 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301097 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 "%s: Enable TX PIPE fail, code %d",
1099 __func__, result);
1100 return result;
1101 }
1102 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1103 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301104 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 "%s: Resume TX PIPE fail, code %d",
1106 __func__, result);
1107 return result;
1108 }
Leo Changfdb45c32016-10-28 11:09:23 -07001109 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, true, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001110
1111 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301112 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001113 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1114 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1116 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301117 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118 "%s: Enable RX PIPE fail, code %d",
1119 __func__, result);
1120 return result;
1121 }
1122 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1123 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301124 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 "%s: Resume RX PIPE fail, code %d",
1126 __func__, result);
1127 return result;
1128 }
Leo Changfdb45c32016-10-28 11:09:23 -07001129 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001130 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 return 0;
1132}
1133
1134/**
1135 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1136 * @hdd_ipa: Global HDD IPA context
1137 *
1138 * Return: 0 on success, negative errno if error
1139 */
1140static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1141{
1142 int result;
1143
Leo Change3e49442015-10-26 20:07:13 -07001144 hdd_ipa->ipa_pipes_down = true;
1145
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301146 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1148 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301149 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001150 "%s: Suspend RX PIPE fail, code %d",
1151 __func__, result);
1152 return result;
1153 }
1154 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1155 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301156 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 "%s: Disable RX PIPE fail, code %d",
1158 __func__, result);
1159 return result;
1160 }
1161
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301162 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1164 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301165 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001166 "%s: Suspend TX PIPE fail, code %d",
1167 __func__, result);
1168 return result;
1169 }
1170 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1171 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301172 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001173 "%s: Disable TX PIPE fail, code %d",
1174 __func__, result);
1175 return result;
1176 }
1177
1178 return 0;
1179}
1180
1181/**
1182 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1183 * @hdd_ipa: Global HDD IPA context
1184 *
1185 * Return: 0 on success, negative errno if error
1186 */
1187static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1188{
1189 hdd_ipa->activated_fw_pipe = 0;
1190 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001191
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 /* If RM feature enabled
1193 * Request PROD Resource first
1194 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001195 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1196 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1197 /* RM PROD request sync return
1198 * enable pipe immediately
1199 */
1200 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301201 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001202 "%s: IPA WDI Pipe activation failed",
1203 __func__);
1204 hdd_ipa->resource_loading = false;
1205 return -EBUSY;
1206 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 }
1208 } else {
1209 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001210 * Just enabled all the PIPEs
1211 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301213 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001214 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001215 __func__);
1216 hdd_ipa->resource_loading = false;
1217 return -EBUSY;
1218 }
1219 hdd_ipa->resource_loading = false;
1220 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001221
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301222 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001223 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224 return 0;
1225}
1226
1227/**
1228 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1229 * @hdd_ipa: Global HDD IPA context
1230 *
1231 * Return: None
1232 */
1233static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1234{
1235 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001236 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237
1238 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301239 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Leo Changfdb45c32016-10-28 11:09:23 -07001240 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301241 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Leo Changfdb45c32016-10-28 11:09:23 -07001242 cdp_ipa_set_active(soc, cds_ctx->pdev_txrx_ctx, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243}
1244
1245/**
1246 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1247 * @context: User context registered with TL (the IPA Global context is
1248 * registered
1249 * @rxpkt: Packet containing the notification
1250 * @staid: ID of the station associated with the packet
1251 *
1252 * Return: None
1253 */
1254static void
1255hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1256{
1257 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301258 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259
1260 /*
1261 * When SSR is going on or driver is unloading, just return.
1262 */
1263 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301264 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266
1267 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1268 return;
1269
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301270 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 __func__, event);
1272
1273 switch (event) {
1274 case IPA_RM_RESOURCE_GRANTED:
1275 /* Differed RM Granted */
1276 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301277 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001278 if ((false == hdd_ipa->resource_unloading) &&
1279 (!hdd_ipa->activated_fw_pipe)) {
1280 hdd_ipa_uc_enable_pipes(hdd_ipa);
1281 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301282 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001283 break;
1284
1285 case IPA_RM_RESOURCE_RELEASED:
1286 /* Differed RM Released */
1287 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 break;
1289
1290 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301291 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001292 "%s, invalid event code %d", __func__, event);
1293 break;
1294 }
1295}
1296
1297/**
1298 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1299 * @hdd_ipa: Global HDD IPA context
1300 * @event: IPA resource manager event to be deferred
1301 *
1302 * This function is called when a resource manager event is received
1303 * from firmware in interrupt context. This function will defer the
1304 * handling to the OL RX thread
1305 *
1306 * Return: None
1307 */
1308static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1309{
1310 enum ipa_rm_event event;
1311 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1312 struct uc_rm_work_struct, work);
1313 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1314 struct hdd_ipa_priv, uc_rm_work);
1315
1316 cds_ssr_protect(__func__);
1317 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301318 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001319 "%s, posted event %d", __func__, event);
1320
1321 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1322 cds_ssr_unprotect(__func__);
1323
1324 return;
1325}
1326
1327/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1329 * @op_msg: operation message received from firmware
1330 * @usr_ctxt: user context registered with TL (we register the HDD Global
1331 * context)
1332 *
1333 * Return: None
1334 */
1335static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1336{
1337 struct op_msg_type *msg = op_msg;
1338 struct ipa_uc_fw_stats *uc_fw_stat;
1339 struct IpaHwStatsWDIInfoData_t ipa_stat;
1340 struct hdd_ipa_priv *hdd_ipa;
1341 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301342 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343
1344 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301345 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001346 return;
1347 }
1348
1349 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301350 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1352 return;
1353 }
1354
1355 hdd_ctx = (hdd_context_t *) usr_ctxt;
1356
1357 /*
1358 * When SSR is going on or driver is unloading, just return.
1359 */
1360 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301361 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301362 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 return;
1364 }
1365
1366 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1367
Govind Singhb6a89772016-08-12 11:23:35 +05301368 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001369 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1370
1371 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1372 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301373 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 hdd_ipa->activated_fw_pipe++;
1375 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1376 hdd_ipa->resource_loading = false;
1377 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001378 if (hdd_ipa->pending_cons_req)
1379 ipa_rm_notify_completion(
1380 IPA_RM_RESOURCE_GRANTED,
1381 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001382 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301384 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001385 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301387 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 hdd_ipa->activated_fw_pipe--;
1389 if (!hdd_ipa->activated_fw_pipe) {
1390 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001391 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1392 ipa_rm_release_resource(
1393 IPA_RM_RESOURCE_WLAN_PROD);
1394 /* Sync return success from IPA
1395 * Enable/resume all the PIPEs */
1396 hdd_ipa->resource_unloading = false;
1397 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1398 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301400 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001401 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001403 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301405 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001407 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001408 "CE RING SIZE: %d\n"
1409 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001410 (unsigned long long)res->ce_sr_base_paddr,
1411 res->ce_sr_ring_size,
1412 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301413 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001415 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001416 "COMP RING SIZE: %d\n"
1417 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001418 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001419 (unsigned long long)res->tx_comp_ring_base_paddr,
1420 res->tx_comp_ring_size,
1421 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001422 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301423 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001425 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001427 "IND RING DBELL : 0x%llx\n"
1428 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 "NUM EXCP PKT : %llu\n"
1430 "NUM TX BCMC : %llu\n"
1431 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001432 (unsigned long long)res->rx_rdy_ring_base_paddr,
1433 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001434 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001435 (unsigned long long)hdd_ipa->ipa_resource.
1436 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 hdd_ipa->stats.num_rx_excep,
1438 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001439 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301440 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1442 "SAP NUM STAs: %d\n"
1443 "STA CONNECTED: %d\n"
1444 "TX PIPE HDL: %d\n"
1445 "RX PIPE HDL : %d\n"
1446 "RSC LOADING : %d\n"
1447 "RSC UNLOADING : %d\n"
1448 "PNDNG CNS RQT : %d",
1449 hdd_ipa->sap_num_connected_sta,
1450 hdd_ipa->sta_connected,
1451 hdd_ipa->tx_pipe_handle,
1452 hdd_ipa->rx_pipe_handle,
1453 (unsigned int)hdd_ipa->resource_loading,
1454 (unsigned int)hdd_ipa->resource_unloading,
1455 (unsigned int)hdd_ipa->pending_cons_req);
1456
1457 /* STATs from FW */
1458 uc_fw_stat = (struct ipa_uc_fw_stats *)
1459 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301460 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 "==== IPA_UC WLAN_FW TX ====\n"
1462 "COMP RING BASE: 0x%x\n"
1463 "COMP RING SIZE: %d\n"
1464 "COMP RING DBELL : 0x%x\n"
1465 "COMP RING DBELL IND VAL : %d\n"
1466 "COMP RING DBELL CACHED VAL : %d\n"
1467 "COMP RING DBELL CACHED VAL : %d\n"
1468 "PKTS ENQ : %d\n"
1469 "PKTS COMP : %d\n"
1470 "IS SUSPEND : %d\n"
1471 "RSVD : 0x%x",
1472 uc_fw_stat->tx_comp_ring_base,
1473 uc_fw_stat->tx_comp_ring_size,
1474 uc_fw_stat->tx_comp_ring_dbell_addr,
1475 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1476 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1477 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1478 uc_fw_stat->tx_pkts_enqueued,
1479 uc_fw_stat->tx_pkts_completed,
1480 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301481 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001482 "==== IPA_UC WLAN_FW RX ====\n"
1483 "IND RING BASE: 0x%x\n"
1484 "IND RING SIZE: %d\n"
1485 "IND RING DBELL : 0x%x\n"
1486 "IND RING DBELL IND VAL : %d\n"
1487 "IND RING DBELL CACHED VAL : %d\n"
1488 "RDY IND ADDR : 0x%x\n"
1489 "RDY IND CACHE VAL : %d\n"
1490 "RFIL IND : %d\n"
1491 "NUM PKT INDICAT : %d\n"
1492 "BUF REFIL : %d\n"
1493 "NUM DROP NO SPC : %d\n"
1494 "NUM DROP NO BUF : %d\n"
1495 "IS SUSPND : %d\n"
1496 "RSVD : 0x%x\n",
1497 uc_fw_stat->rx_ind_ring_base,
1498 uc_fw_stat->rx_ind_ring_size,
1499 uc_fw_stat->rx_ind_ring_dbell_addr,
1500 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1501 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1502 uc_fw_stat->rx_ind_ring_rdidx_addr,
1503 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1504 uc_fw_stat->rx_refill_idx,
1505 uc_fw_stat->rx_num_pkts_indicated,
1506 uc_fw_stat->rx_buf_refilled,
1507 uc_fw_stat->rx_num_ind_drop_no_space,
1508 uc_fw_stat->rx_num_ind_drop_no_buf,
1509 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1510 /* STATs from IPA */
1511 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301512 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513 "==== IPA_UC IPA TX ====\n"
1514 "NUM PROCD : %d\n"
1515 "CE DBELL : 0x%x\n"
1516 "NUM DBELL FIRED : %d\n"
1517 "COMP RNG FULL : %d\n"
1518 "COMP RNG EMPT : %d\n"
1519 "COMP RNG USE HGH : %d\n"
1520 "COMP RNG USE LOW : %d\n"
1521 "BAM FIFO FULL : %d\n"
1522 "BAM FIFO EMPT : %d\n"
1523 "BAM FIFO USE HGH : %d\n"
1524 "BAM FIFO USE LOW : %d\n"
1525 "NUM DBELL : %d\n"
1526 "NUM UNEXP DBELL : %d\n"
1527 "NUM BAM INT HDL : 0x%x\n"
1528 "NUM BAM INT NON-RUN : 0x%x\n"
1529 "NUM QMB INT HDL : 0x%x",
1530 ipa_stat.tx_ch_stats.num_pkts_processed,
1531 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1532 ipa_stat.tx_ch_stats.num_db_fired,
1533 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1534 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1535 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1536 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1537 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1538 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1539 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1540 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1541 ipa_stat.tx_ch_stats.num_db,
1542 ipa_stat.tx_ch_stats.num_unexpected_db,
1543 ipa_stat.tx_ch_stats.num_bam_int_handled,
1544 ipa_stat.tx_ch_stats.
1545 num_bam_int_in_non_runnning_state,
1546 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1547
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301548 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549 "==== IPA_UC IPA RX ====\n"
1550 "MAX OST PKT : %d\n"
1551 "NUM PKT PRCSD : %d\n"
1552 "RNG RP : 0x%x\n"
1553 "COMP RNG FULL : %d\n"
1554 "COMP RNG EMPT : %d\n"
1555 "COMP RNG USE HGH : %d\n"
1556 "COMP RNG USE LOW : %d\n"
1557 "BAM FIFO FULL : %d\n"
1558 "BAM FIFO EMPT : %d\n"
1559 "BAM FIFO USE HGH : %d\n"
1560 "BAM FIFO USE LOW : %d\n"
1561 "NUM DB : %d\n"
1562 "NUM UNEXP DB : %d\n"
1563 "NUM BAM INT HNDL : 0x%x\n",
1564 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1565 ipa_stat.rx_ch_stats.num_pkts_processed,
1566 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1567 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1568 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1569 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1570 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1571 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1572 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1573 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1574 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1575 ipa_stat.rx_ch_stats.num_db,
1576 ipa_stat.rx_ch_stats.num_unexpected_db,
1577 ipa_stat.rx_ch_stats.num_bam_int_handled);
1578 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1579 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1580 /* STATs from FW */
1581 uc_fw_stat = (struct ipa_uc_fw_stats *)
1582 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301583 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1585 uc_fw_stat->tx_pkts_completed,
1586 hdd_ipa->ipa_p_tx_packets);
1587 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1588 (uc_fw_stat->rx_num_ind_drop_no_space +
1589 uc_fw_stat->rx_num_ind_drop_no_buf +
1590 uc_fw_stat->rx_num_pkts_indicated),
1591 hdd_ipa->ipa_p_rx_packets);
1592
1593 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1594 hdd_ipa->ipa_p_rx_packets =
1595 (uc_fw_stat->rx_num_ind_drop_no_space +
1596 uc_fw_stat->rx_num_ind_drop_no_buf +
1597 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301598 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 } else {
Yun Park8292dcb2016-10-07 16:46:06 -07001600 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
1601 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001602 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301603 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604}
1605
1606
1607/**
1608 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1609 * @adapter: device adapter instance
1610 * @offload_type: MCC or SCC
1611 * @enable: TX offload enable or disable
1612 *
1613 * Return: none
1614 */
1615static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1616 uint32_t offload_type, uint32_t enable)
1617{
1618 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07001619 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620
Yun Parka37592b2016-06-11 17:10:28 -07001621 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 return;
1623
Yun Park8292dcb2016-10-07 16:46:06 -07001624 iface_context = adapter->ipa_context;
1625
1626 if (!iface_context || (enable == iface_context->offload_enabled)) {
1627 /* IPA offload status is already set as desired */
1628 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001629 "IPA offload status is already set: (offload_type=%d, vdev_id=%d, enable=%d)",
Yun Park8292dcb2016-10-07 16:46:06 -07001630 offload_type, adapter->sessionId, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001631 return;
1632 }
1633
Yun Park4540e862016-11-10 16:30:06 -08001634 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
1635 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1636 "invalid session id: %d, offload_type=%d, enable=%d",
1637 adapter->sessionId, offload_type, enable);
1638 return;
1639 }
1640
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301641 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 sizeof(ipa_offload_enable_disable));
1643 ipa_offload_enable_disable.offload_type = offload_type;
1644 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1645 ipa_offload_enable_disable.enable = enable;
1646
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301647 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001648 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001649 ipa_offload_enable_disable.offload_type,
1650 ipa_offload_enable_disable.vdev_id,
1651 ipa_offload_enable_disable.enable);
1652
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301653 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001654 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1655 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301656 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001657 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
1658 __func__,
1659 ipa_offload_enable_disable.offload_type,
1660 ipa_offload_enable_disable.vdev_id,
1661 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001662 } else {
1663 /* Update the IPA offload status */
1664 iface_context->offload_enabled =
1665 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 }
1667}
1668
1669/**
1670 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1671 * @work: uC OP work
1672 *
1673 * Return: None
1674 */
1675static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1676{
1677 struct op_msg_type *msg;
1678 struct uc_op_work_struct *uc_op_work = container_of(work,
1679 struct uc_op_work_struct, work);
1680 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1681
1682 cds_ssr_protect(__func__);
1683
1684 msg = uc_op_work->msg;
1685 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301686 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001687 "%s, posted msg %d", __func__, msg->op_code);
1688
1689 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1690
1691 cds_ssr_unprotect(__func__);
1692
1693 return;
1694}
1695
1696/**
1697 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1698 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1699 * @op_msg: operation message received from firmware
1700 * @hdd_ctx: Global HDD context
1701 *
1702 * Return: None
1703 */
1704static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1705{
1706 struct hdd_ipa_priv *hdd_ipa;
1707 struct op_msg_type *msg;
1708 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301709 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001710
1711 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301712 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001713 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714
1715 msg = (struct op_msg_type *)op_msg;
1716 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1717
1718 if (unlikely(!hdd_ipa))
1719 goto end;
1720
1721 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301722 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723 __func__, msg->op_code);
1724 goto end;
1725 }
1726
1727 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1728 if (uc_op_work->msg)
1729 /* When the same uC OPCODE is already pended, just return */
1730 goto end;
1731
1732 uc_op_work->msg = msg;
1733 schedule_work(&uc_op_work->work);
1734 return;
1735
1736end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301737 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738}
1739
1740/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001741 * hdd_ipa_init_uc_op_work - init ipa uc op work
1742 * @work: struct work_struct
1743 * @work_handler: work_handler
1744 *
1745 * Return: none
1746 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001747static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1748 work_func_t work_handler)
1749{
1750 INIT_WORK(work, work_handler);
1751}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001752
1753
1754/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1756 * @hdd_ctx: Global HDD context
1757 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301758 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301760static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761{
1762 struct ipa_wdi_in_params pipe_in;
1763 struct ipa_wdi_out_params pipe_out;
1764 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1765 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1766 uint8_t i;
Leo Changfdb45c32016-10-28 11:09:23 -07001767 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301769 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1770 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771
Anurag Chouhanffb21542016-02-17 14:33:03 +05301772 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301773 qdf_mutex_create(&ipa_ctxt->event_lock);
1774 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001775
1776 /* TX PIPE */
1777 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1778 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1779 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1780 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1781 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1782 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1783 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1784 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1785 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1786 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1787 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1788 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1789 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301790 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1792 pipe_in.sys.keep_ipa_awake = true;
1793 }
1794
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001795 pipe_in.u.dl.comp_ring_base_pa =
1796 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001797 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001798 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1799 sizeof(qdf_dma_addr_t);
1800 pipe_in.u.dl.ce_ring_base_pa =
1801 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1802 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1803 pipe_in.u.dl.ce_ring_size =
1804 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1805 pipe_in.u.dl.num_tx_buffers =
1806 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001807
1808 /* Connect WDI IPA PIPE */
1809 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1810 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301811 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1812 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1813 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1814 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001815 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001816 /* WLAN TX PIPE Handle */
1817 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301818 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1820 " CERZ %d, NB %d, CDBPAD 0x%x",
1821 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1822 pipe_in.u.dl.comp_ring_size,
1823 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1824 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1825 pipe_in.u.dl.ce_ring_size,
1826 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001827 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828
1829 /* RX PIPE */
1830 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1831 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1832 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1833 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1834 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1835 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1836 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1837 sizeof(struct sps_iovec);
1838 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1839 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301840 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1842 pipe_in.sys.keep_ipa_awake = true;
1843 }
1844
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001845 pipe_in.u.ul.rdy_ring_base_pa =
1846 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1847 pipe_in.u.ul.rdy_ring_size =
1848 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1849 pipe_in.u.ul.rdy_ring_rp_pa =
1850 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001851 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001853 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301855 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1857 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1858 pipe_in.u.ul.rdy_ring_size,
1859 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001860 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861
Leo Changfdb45c32016-10-28 11:09:23 -07001862 cdp_ipa_set_doorbell_paddr(soc, cds_ctx->pdev_txrx_ctx,
1863 ipa_ctxt->tx_comp_doorbell_paddr,
1864 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001865
Leo Changfdb45c32016-10-28 11:09:23 -07001866 cdp_ipa_register_op_cb(soc, cds_ctx->pdev_txrx_ctx,
1867 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001868
1869 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001870 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001871 hdd_ipa_uc_fw_op_event_handler);
1872 ipa_ctxt->uc_op_work[i].msg = NULL;
1873 }
1874
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301875 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001876}
1877
Leo Change3e49442015-10-26 20:07:13 -07001878/**
1879 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1880 * @hdd_ctx: hdd main context
1881 *
1882 * Force shutdown IPA pipe
1883 * Independent of FW pipe status, IPA pipe shutdonw progress
1884 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1885 * independent from FW pipe status
1886 *
1887 * Return: NONE
1888 */
1889void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1890{
1891 struct hdd_ipa_priv *hdd_ipa;
1892
1893 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1894 return;
1895
1896 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1897 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301898 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001899 "IPA pipes are not down yet, force shutdown");
1900 hdd_ipa_uc_disable_pipes(hdd_ipa);
1901 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301902 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001903 "IPA pipes are down, do nothing");
1904 }
1905
1906 return;
1907}
1908
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909/**
Govind Singh9c58eba2016-09-02 16:23:06 +05301910 * hdd_ipa_msg_free_fn() - Free an IPA message
1911 * @buff: pointer to the IPA message
1912 * @len: length of the IPA message
1913 * @type: type of IPA message
1914 *
1915 * Return: None
1916 */
1917static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
1918{
1919 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "msg type:%d, len:%d", type, len);
1920 ghdd_ipa->stats.num_free_msg++;
1921 qdf_mem_free(buff);
1922}
1923
1924
1925/**
1926 * hdd_ipa_send_disconnect() - ipa send disconnect clients
1927 * adapter: pointer to hdd adapter
1928 * Send disconnect evnt to IPA driver during SSR
1929 *
1930 * Return: 0 - Success
1931 */
1932static int hdd_ipa_send_disconnect(hdd_adapter_t *adapter)
1933{
1934 struct ipa_msg_meta meta;
1935 struct ipa_wlan_msg *msg;
1936 int ret = 0;
1937 int i;
1938
1939 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
1940 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
1941 continue;
1942 if ((adapter->aStaInfo[i].isUsed) &&
1943 (!adapter->aStaInfo[i].isDeauthInProgress)) {
1944 meta.msg_len = sizeof(struct ipa_wlan_msg);
1945 msg = qdf_mem_malloc(meta.msg_len);
1946 if (msg == NULL) {
1947 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1948 "msg allocation failed");
1949 return -ENOMEM;
1950 }
1951 meta.msg_type = WLAN_CLIENT_DISCONNECT;
1952 strlcpy(msg->name, adapter->dev->name,
1953 IPA_RESOURCE_NAME_MAX);
1954 memcpy(msg->mac_addr, adapter->aStaInfo[i].macAddrSTA.bytes,
1955 ETH_ALEN);
1956 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
1957 msg->name, meta.msg_type);
1958 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
1959 if (ret) {
1960 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1961 "%s: Evt: %d fail:%d",
1962 msg->name, meta.msg_type, ret);
1963 qdf_mem_free(msg);
1964 return ret;
1965 }
1966 }
1967 }
1968
1969 return ret;
1970}
1971
1972/**
1973 * hdd_ipa_uc_disconnect_client() - disconnect ipa sap clients
1974 * hdd_ctx: pointer to hdd context
1975 * Send disconnect evnt to IPA driver during SSR
1976 *
1977 * Return: 0 - Success
1978 */
1979static int hdd_ipa_uc_disconnect_client(hdd_context_t *hdd_ctx)
1980{
1981 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
1982 QDF_STATUS status;
1983 hdd_adapter_t *adapter;
1984 int ret = 0;
1985
1986
1987 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1988 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
1989 adapter = adapter_node->pAdapter;
1990 if (adapter->device_mode == QDF_SAP_MODE)
1991 hdd_ipa_send_disconnect(adapter);
1992 status = hdd_get_next_adapter(
1993 hdd_ctx, adapter_node, &next);
1994 adapter_node = next;
1995 }
1996
1997 return ret;
1998}
1999
2000/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002001 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
2002 *
2003 * Deinit basic IPA UC host side to be in sync reloaded FW during
2004 * SSR
2005 *
2006 * Return: 0 - Success
2007 */
2008int hdd_ipa_uc_ssr_deinit(void)
2009{
2010 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2011 int idx;
2012 struct hdd_ipa_iface_context *iface_context;
2013
Leo Chang3bc8fed2015-11-13 10:59:47 -08002014 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 return 0;
2016
Govind Singh9c58eba2016-09-02 16:23:06 +05302017 /* send disconnect to ipa driver for connected clients */
2018 hdd_ipa_uc_disconnect_client(hdd_ipa->hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019 /* Clean up HDD IPA interfaces */
2020 for (idx = 0; (hdd_ipa->num_iface > 0) &&
2021 (idx < HDD_IPA_MAX_IFACE); idx++) {
2022 iface_context = &hdd_ipa->iface_context[idx];
2023 if (iface_context && iface_context->adapter)
2024 hdd_ipa_cleanup_iface(iface_context);
2025 }
2026
2027 /* After SSR, wlan driver reloads FW again. But we need to protect
2028 * IPA submodule during SSR transient state. So deinit basic IPA
2029 * UC host side to be in sync with reloaded FW during SSR
2030 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08002031 if (!hdd_ipa->ipa_pipes_down)
2032 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002033
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302034 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
2036 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
2037 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
2038 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302039 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002040
Guolei Bianca144d82016-11-10 11:07:42 +08002041 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
2042 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
2043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044 /* Full IPA driver cleanup not required since wlan driver is now
2045 * unloaded and reloaded after SSR.
2046 */
2047 return 0;
2048}
2049
2050/**
2051 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
2052 *
2053 * Init basic IPA UC host side to be in sync with reloaded FW after
2054 * SSR to resume IPA UC operations
2055 *
2056 * Return: 0 - Success
2057 */
2058int hdd_ipa_uc_ssr_reinit(void)
2059{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002060
2061 /* After SSR is complete, IPA UC can resume operation. But now wlan
2062 * driver will be unloaded and reloaded, which takes care of IPA cleanup
2063 * and initialization. This is a placeholder func if IPA has to resume
2064 * operations without driver reload.
2065 */
2066 return 0;
2067}
Leo Chang3bc8fed2015-11-13 10:59:47 -08002068
2069/**
2070 * hdd_ipa_tx_packet_ipa() - send packet to IPA
2071 * @hdd_ctx: Global HDD context
2072 * @skb: skb sent to IPA
2073 * @session_id: send packet instance session id
2074 *
2075 * Send TX packet which generated by system to IPA.
2076 * This routine only will be used for function verification
2077 *
2078 * Return: NULL packet sent to IPA properly
2079 * NULL invalid packet drop
2080 * skb packet not sent to IPA. legacy data path should handle
2081 */
2082struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
2083 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07002084{
Leo Chang3bc8fed2015-11-13 10:59:47 -08002085 struct ipa_header *ipa_header;
2086 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07002087 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002088
2089 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2090 return skb;
2091
Leo Chang07b28f62016-05-11 12:29:22 -07002092 if (!hdd_ipa)
2093 return skb;
2094
2095 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
2096 return skb;
2097
Leo Changcc923e22016-06-16 15:29:03 -07002098 if (skb_headroom(skb) <
2099 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07002100 return skb;
2101
Leo Chang3bc8fed2015-11-13 10:59:47 -08002102 ipa_header = (struct ipa_header *) skb_push(skb,
2103 sizeof(struct ipa_header));
2104 if (!ipa_header) {
2105 /* No headroom, legacy */
2106 return skb;
2107 }
2108 memset(ipa_header, 0, sizeof(*ipa_header));
2109 ipa_header->vdev_id = 0;
2110
2111 frag_header = (struct frag_header *) skb_push(skb,
2112 sizeof(struct frag_header));
2113 if (!frag_header) {
2114 /* No headroom, drop */
2115 kfree_skb(skb);
2116 return NULL;
2117 }
2118 memset(frag_header, 0, sizeof(*frag_header));
2119 frag_header->length = skb->len - sizeof(struct frag_header)
2120 - sizeof(struct ipa_header);
2121
2122 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2123 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002124}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002125
2126/**
2127 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2128 * @work: scheduled work
2129 *
2130 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2131 * not want to immediately release the wake lock since the system
2132 * would then potentially try to suspend when there is a healthy data
2133 * rate. Deferred work is scheduled and this function handles the
2134 * work. When this function is called, if the IPA resource is still
2135 * released then we release the wake lock.
2136 *
2137 * Return: None
2138 */
2139static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2140{
2141 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2142 struct hdd_ipa_priv,
2143 wake_lock_work);
2144
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302145 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002146
2147 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2148 goto end;
2149
2150 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302151 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152 WIFI_POWER_EVENT_WAKELOCK_IPA);
2153
2154end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302155 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002156}
2157
2158/**
2159 * hdd_ipa_rm_request() - Request resource from IPA
2160 * @hdd_ipa: Global HDD IPA context
2161 *
2162 * Return: 0 on success, negative errno on error
2163 */
2164static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2165{
2166 int ret = 0;
2167
2168 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2169 return 0;
2170
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302171 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002172
2173 switch (hdd_ipa->rm_state) {
2174 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302175 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002176 return 0;
2177 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302178 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179 return -EINPROGRESS;
2180 case HDD_IPA_RM_RELEASED:
2181 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2182 break;
2183 }
2184
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302185 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002186
2187 ret = ipa_rm_inactivity_timer_request_resource(
2188 IPA_RM_RESOURCE_WLAN_PROD);
2189
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302190 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002191 if (ret == 0) {
2192 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2193 hdd_ipa->stats.num_rm_grant_imm++;
2194 }
2195
2196 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2197 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302198 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002199 WIFI_POWER_EVENT_WAKELOCK_IPA);
2200 hdd_ipa->wake_lock_released = false;
2201 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302202 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002203
2204 return ret;
2205}
2206
2207/**
2208 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2209 * @hdd_ipa: Global HDD IPA context
2210 *
2211 * Return: 0 if resources released, negative errno otherwise
2212 */
2213static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2214{
2215 int ret = 0;
2216
2217 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2218 return 0;
2219
2220 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2221 return -EAGAIN;
2222
2223 spin_lock_bh(&hdd_ipa->q_lock);
2224 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2225 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2226 spin_unlock_bh(&hdd_ipa->q_lock);
2227 return -EAGAIN;
2228 }
2229 spin_unlock_bh(&hdd_ipa->q_lock);
2230
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302231 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232
Nirav Shahcbc6d722016-03-01 16:24:53 +05302233 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302234 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002235 return -EAGAIN;
2236 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302237 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002238
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302239 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002240 switch (hdd_ipa->rm_state) {
2241 case HDD_IPA_RM_GRANTED:
2242 break;
2243 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302244 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002245 return -EINPROGRESS;
2246 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302247 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002248 return 0;
2249 }
2250
2251 /* IPA driver returns immediately so set the state here to avoid any
2252 * race condition.
2253 */
2254 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2255 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302256 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002257
2258 ret =
2259 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2260
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302261 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002262 if (unlikely(ret != 0)) {
2263 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2264 WARN_ON(1);
2265 }
2266
2267 /*
2268 * If wake_lock is released immediately, kernel would try to suspend
2269 * immediately as well, Just avoid ping-pong between suspend-resume
2270 * while there is healthy amount of data transfer going on by
2271 * releasing the wake_lock after some delay.
2272 */
2273 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2274 msecs_to_jiffies
2275 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2276
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302277 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002278
2279 return ret;
2280}
2281
2282/**
2283 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2284 * @user_data: user data registered with IPA
2285 * @event: the IPA resource manager event that occurred
2286 * @data: the data associated with the event
2287 *
2288 * Return: None
2289 */
2290static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2291 unsigned long data)
2292{
2293 struct hdd_ipa_priv *hdd_ipa = user_data;
2294
2295 if (unlikely(!hdd_ipa))
2296 return;
2297
2298 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2299 return;
2300
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302301 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002302
2303 switch (event) {
2304 case IPA_RM_RESOURCE_GRANTED:
2305 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2306 /* RM Notification comes with ISR context
2307 * it should be serialized into work queue to avoid
2308 * ISR sleep problem
2309 */
2310 hdd_ipa->uc_rm_work.event = event;
2311 schedule_work(&hdd_ipa->uc_rm_work.work);
2312 break;
2313 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302314 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302316 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002317 hdd_ipa->stats.num_rm_grant++;
2318 break;
2319
2320 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302321 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002322 hdd_ipa->resource_unloading = false;
2323 break;
2324
2325 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302326 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002327 break;
2328 }
2329}
2330
2331/**
2332 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2333 *
2334 * Callback function registered with IPA that is called when IPA wants
2335 * to release the WLAN consumer resource
2336 *
2337 * Return: 0 if the request is granted, negative errno otherwise
2338 */
2339static int hdd_ipa_rm_cons_release(void)
2340{
2341 return 0;
2342}
2343
2344/**
2345 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2346 *
2347 * Callback function registered with IPA that is called when IPA wants
2348 * to access the WLAN consumer resource
2349 *
2350 * Return: 0 if the request is granted, negative errno otherwise
2351 */
2352static int hdd_ipa_rm_cons_request(void)
2353{
Yun Park4d8b60a2015-10-22 13:59:32 -07002354 int ret = 0;
2355
2356 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302357 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002358 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002359 __func__);
2360 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002361 ret = -EINPROGRESS;
2362 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302363 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002364 "%s: IPA resource unloading in progress",
2365 __func__);
2366 ghdd_ipa->pending_cons_req = true;
2367 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002369
2370 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002371}
2372
2373/**
2374 * hdd_ipa_set_perf_level() - Set IPA performance level
2375 * @hdd_ctx: Global HDD context
2376 * @tx_packets: Number of packets transmitted in the last sample period
2377 * @rx_packets: Number of packets received in the last sample period
2378 *
2379 * Return: 0 on success, negative errno on error
2380 */
2381int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2382 uint64_t rx_packets)
2383{
2384 uint32_t next_cons_bw, next_prod_bw;
2385 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2386 struct ipa_rm_perf_profile profile;
2387 int ret;
2388
2389 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2390 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2391 return 0;
2392
2393 memset(&profile, 0, sizeof(profile));
2394
2395 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2396 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2397 else if (tx_packets >
2398 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2399 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2400 else
2401 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2402
2403 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2404 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2405 else if (rx_packets >
2406 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2407 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2408 else
2409 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2410
Yun Park8f289c82016-10-18 16:38:21 -07002411 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412 "CONS perf curr: %d, next: %d",
2413 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Park8f289c82016-10-18 16:38:21 -07002414 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002415 "PROD perf curr: %d, next: %d",
2416 hdd_ipa->curr_prod_bw, next_prod_bw);
2417
2418 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302419 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002420 "Requesting CONS perf curr: %d, next: %d",
2421 hdd_ipa->curr_cons_bw, next_cons_bw);
2422 profile.max_supported_bandwidth_mbps = next_cons_bw;
2423 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2424 &profile);
2425 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302426 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002427 "RM CONS set perf profile failed: %d", ret);
2428
2429 return ret;
2430 }
2431 hdd_ipa->curr_cons_bw = next_cons_bw;
2432 hdd_ipa->stats.num_cons_perf_req++;
2433 }
2434
2435 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302436 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002437 "Requesting PROD perf curr: %d, next: %d",
2438 hdd_ipa->curr_prod_bw, next_prod_bw);
2439 profile.max_supported_bandwidth_mbps = next_prod_bw;
2440 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2441 &profile);
2442 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302443 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002444 "RM PROD set perf profile failed: %d", ret);
2445 return ret;
2446 }
2447 hdd_ipa->curr_prod_bw = next_prod_bw;
2448 hdd_ipa->stats.num_prod_perf_req++;
2449 }
2450
2451 return 0;
2452}
2453
2454/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002455 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2456 * @work: struct work_struct
2457 * @work_handler: work_handler
2458 *
2459 * Return: none
2460 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002461static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2462 work_func_t work_handler)
2463{
2464 INIT_WORK(work, work_handler);
2465}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002466
2467/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002468 * hdd_ipa_setup_rm() - Setup IPA resource management
2469 * @hdd_ipa: Global HDD IPA context
2470 *
2471 * Return: 0 on success, negative errno on error
2472 */
2473static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2474{
2475 struct ipa_rm_create_params create_params = { 0 };
2476 int ret;
2477
2478 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2479 return 0;
2480
Rajeev Kumar217f2172016-01-06 18:11:55 -08002481 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2482 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002483 memset(&create_params, 0, sizeof(create_params));
2484 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2485 create_params.reg_params.user_data = hdd_ipa;
2486 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2487 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2488
2489 ret = ipa_rm_create_resource(&create_params);
2490 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302491 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002492 "Create RM resource failed: %d", ret);
2493 goto setup_rm_fail;
2494 }
2495
2496 memset(&create_params, 0, sizeof(create_params));
2497 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2498 create_params.request_resource = hdd_ipa_rm_cons_request;
2499 create_params.release_resource = hdd_ipa_rm_cons_release;
2500 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2501
2502 ret = ipa_rm_create_resource(&create_params);
2503 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302504 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002505 "Create RM CONS resource failed: %d", ret);
2506 goto delete_prod;
2507 }
2508
2509 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2510 IPA_RM_RESOURCE_APPS_CONS);
2511
2512 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2513 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2514 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302515 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002516 ret);
2517 goto timer_init_failed;
2518 }
2519
2520 /* Set the lowest bandwidth to start with */
2521 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2522
2523 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302524 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002525 "Set perf level failed: %d", ret);
2526 goto set_perf_failed;
2527 }
2528
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302529 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2531 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302532 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002533 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2534 hdd_ipa->wake_lock_released = true;
2535 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2536
2537 return ret;
2538
2539set_perf_failed:
2540 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2541
2542timer_init_failed:
2543 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2544
2545delete_prod:
2546 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2547
2548setup_rm_fail:
2549 return ret;
2550}
2551
2552/**
2553 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2554 * @hdd_ipa: Global HDD IPA context
2555 *
2556 * Destroys all resources associated with the IPA resource manager
2557 *
2558 * Return: None
2559 */
2560static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2561{
2562 int ret;
2563
2564 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2565 return;
2566
2567 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302568 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569
2570#ifdef WLAN_OPEN_SOURCE
2571 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2572#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302573 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002574
2575 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2576
2577 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2578 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302579 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 "RM PROD resource delete failed %d", ret);
2581
2582 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2583 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302584 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002585 "RM CONS resource delete failed %d", ret);
2586}
2587
2588/**
2589 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2590 * @skb: network buffer
2591 * @adapter: network adapter
2592 *
2593 * Called when a network buffer is received which should not be routed
2594 * to the IPA module.
2595 *
2596 * Return: None
2597 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302598static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002599 hdd_adapter_t *adapter)
2600{
2601 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2602 unsigned int cpu_index;
2603
2604 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302605 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002606 adapter);
2607 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002608 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 return;
2610 }
2611
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002612 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002614 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 return;
2616 }
2617
2618 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2619 skb->dev = adapter->dev;
2620 skb->protocol = eth_type_trans(skb, skb->dev);
2621 skb->ip_summed = CHECKSUM_NONE;
2622
2623 cpu_index = wlan_hdd_get_cpu();
2624
2625 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2626 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2627 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2628 else
2629 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2630
2631 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2632 adapter->dev->last_rx = jiffies;
2633}
2634
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002635/**
Leo Chang69c39692016-10-12 20:11:12 -07002636 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2637 * @hdd_ipa: pointer to hdd ipa context
2638 * @adapter: network adapter
2639 * @skb: data pointer
2640 *
2641 * if exception packet has set forward bit, copied new packet should be
2642 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2643 * put into pm queue and tx procedure will be differed
2644 *
2645 * Return: None
2646 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002647static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2648 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002649{
2650 qdf_nbuf_t copy;
2651 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2652
2653 copy = qdf_nbuf_copy(skb);
2654 if (!copy) {
2655 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2656 return;
2657 }
2658
2659 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2660 /* WLAN subsystem is in suspend, put int queue */
2661 if (hdd_ipa->suspended) {
2662 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2663 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2664 "TX in SUSPEND PUT QUEUE");
2665 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2666 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2667 pm_tx_cb->exception = true;
2668 pm_tx_cb->adapter = adapter;
2669 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2670 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2671 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2672 hdd_ipa->stats.num_tx_queued++;
2673 } else {
2674 /* Resume, put packet into WLAN TX */
2675 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2676 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2677 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2678 "packet tx fail");
2679 } else {
2680 hdd_ipa->stats.num_tx_bcmc++;
2681 hdd_ipa->ipa_tx_forward++;
2682 }
2683 }
2684}
2685
2686/**
2687 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688 * @priv: pointer to private data registered with IPA (we register a
2689 * pointer to the global IPA context)
2690 * @evt: the IPA event which triggered the callback
2691 * @data: data associated with the event
2692 *
2693 * Return: None
2694 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002695static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002696 unsigned long data)
2697{
2698 struct hdd_ipa_priv *hdd_ipa = NULL;
2699 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302700 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002701 uint8_t iface_id;
2702 uint8_t session_id;
2703 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002705 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002706
2707 hdd_ipa = (struct hdd_ipa_priv *)priv;
2708
2709 switch (evt) {
2710 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302711 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002712
2713 /*
2714 * When SSR is going on or driver is unloading,
2715 * just drop the packets.
2716 */
2717 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2718 if (0 != status) {
2719 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2720 "Invalid context: drop packet");
2721 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2722 kfree_skb(skb);
2723 return;
2724 }
2725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002726 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2727 session_id = (uint8_t)skb->cb[0];
2728 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302729 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002730 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2731 session_id, iface_id);
2732 } else {
2733 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2734 }
2735
2736 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302737 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738 "IPA_RECEIVE: Invalid iface_id: %u",
2739 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302740 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002741 "w2i -- skb", skb->data, 8);
2742 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002743 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 return;
2745 }
2746
2747 iface_context = &hdd_ipa->iface_context[iface_id];
2748 adapter = iface_context->adapter;
2749
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302750 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751 "w2i -- skb", skb->data, 8);
2752 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2753 hdd_ipa->stats.num_rx_excep++;
2754 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2755 } else {
2756 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2757 }
2758
2759 iface_context->stats.num_rx_ipa_excep++;
2760
2761 /* Disable to forward Intra-BSS Rx packets when
2762 * ap_isolate=1 in hostapd.conf
2763 */
Yun Park046101c2016-09-02 15:32:14 -07002764 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002765 /*
2766 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2767 * all Rx packets to IPA uC, which need to be forwarded
2768 * to other interface.
2769 * And, IPA driver will send back to WLAN host driver
2770 * through exception pipe with fw_desc field set by FW.
2771 * Here we are checking fw_desc field for FORWARD bit
2772 * set, and forward to Tx. Then copy to kernel stack
2773 * only when DISCARD bit is not set.
2774 */
2775 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002776 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302777 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302778 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779 "Forward packet to Tx (fw_desc=%d)",
2780 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002781 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002783 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002784 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2785 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002786 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002787 break;
2788 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002789 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302790 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791 "Intra-BSS FWD is disabled-skip forward to Tx");
2792 }
2793
2794 hdd_ipa_send_skb_to_network(skb, adapter);
2795 break;
2796
2797 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302798 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799 "w2i cb wrong event: 0x%x", evt);
2800 return;
2801 }
2802}
2803
2804/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002805 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2806 * @priv: pointer to private data registered with IPA (we register a
2807 * pointer to the global IPA context)
2808 * @evt: the IPA event which triggered the callback
2809 * @data: data associated with the event
2810 *
2811 * Return: None
2812 */
2813static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2814 unsigned long data)
2815{
2816 cds_ssr_protect(__func__);
2817 __hdd_ipa_w2i_cb(priv, evt, data);
2818 cds_ssr_unprotect(__func__);
2819}
2820
2821/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002822 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2823 * @skb: packet buffer which was transmitted
2824 *
2825 * Return: None
2826 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302827void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002828{
2829 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2830
Govind Singhb6a89772016-08-12 11:23:35 +05302831 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302832 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002833 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302834 ipa_free_skb((struct ipa_rx_data *)
2835 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002836
2837 hdd_ipa->stats.num_tx_comp_cnt++;
2838
2839 atomic_dec(&hdd_ipa->tx_ref_cnt);
2840
2841 hdd_ipa_rm_try_release(hdd_ipa);
2842}
2843
2844/**
2845 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2846 * @iface_context: interface-specific IPA context
2847 * @ipa_tx_desc: packet data descriptor
2848 *
2849 * Return: None
2850 */
2851static void hdd_ipa_send_pkt_to_tl(
2852 struct hdd_ipa_iface_context *iface_context,
2853 struct ipa_rx_data *ipa_tx_desc)
2854{
2855 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2856 uint8_t interface_id;
2857 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302858 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002859
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302860 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002861 adapter = iface_context->adapter;
2862 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302863 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864 ipa_free_skb(ipa_tx_desc);
2865 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302866 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867 hdd_ipa_rm_try_release(hdd_ipa);
2868 return;
2869 }
2870
2871 /*
2872 * During CAC period, data packets shouldn't be sent over the air so
2873 * drop all the packets here
2874 */
2875 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2876 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302877 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878 iface_context->stats.num_tx_cac_drop++;
2879 hdd_ipa_rm_try_release(hdd_ipa);
2880 return;
2881 }
2882
2883 interface_id = adapter->sessionId;
2884 ++adapter->stats.tx_packets;
2885
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302886 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002887
2888 skb = ipa_tx_desc->skb;
2889
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302890 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302891 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002892 /* FIXME: This is broken. No such field in cb any more:
2893 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002894 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302895 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002896 ipa_tx_desc->dma_addr
2897 + HDD_IPA_WLAN_FRAG_HEADER
2898 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899 ipa_tx_desc->skb->len -=
2900 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2901 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302902 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002904 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302905 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906
2907 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2908
Leo Changfdb45c32016-10-28 11:09:23 -07002909 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
2910 iface_context->tl_context, ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302912 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913 ipa_free_skb(ipa_tx_desc);
2914 iface_context->stats.num_tx_err++;
2915 hdd_ipa_rm_try_release(hdd_ipa);
2916 return;
2917 }
2918
2919 atomic_inc(&hdd_ipa->tx_ref_cnt);
2920
2921 iface_context->stats.num_tx++;
2922
2923}
2924
2925/**
Leo Chang11545d62016-10-17 14:53:50 -07002926 * hdd_ipa_is_present() - get IPA hw status
2927 * @hdd_ctx: pointer to hdd context
2928 *
2929 * ipa_uc_reg_rdyCB is not directly designed to check
2930 * ipa hw status. This is an undocumented function which
2931 * has confirmed with IPA team.
2932 *
2933 * Return: true - ipa hw present
2934 * false - ipa hw not present
2935 */
2936bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2937{
2938 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002939 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002940 return true;
2941 else
2942 return false;
2943}
2944
2945/**
Leo Chang69c39692016-10-12 20:11:12 -07002946 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947 * @work: pointer to the scheduled work
2948 *
2949 * Called during PM resume to send packets to TL which were queued
2950 * while host was in the process of suspending.
2951 *
2952 * Return: None
2953 */
Leo Chang69c39692016-10-12 20:11:12 -07002954static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955{
2956 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2957 struct hdd_ipa_priv,
2958 pm_work);
2959 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302960 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002961 uint32_t dequeued = 0;
2962
Leo Chang69c39692016-10-12 20:11:12 -07002963 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2964 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302965 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302966 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2967 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302968 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002969
2970 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002971 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002972 if (pm_tx_cb->exception) {
2973 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2974 "FLUSH EXCEPTION");
2975 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2976 } else {
2977 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002978 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002979 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302980 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302982 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002983 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2984 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002985
2986 hdd_ipa->stats.num_tx_dequeued += dequeued;
2987 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2988 hdd_ipa->stats.num_max_pm_queue = dequeued;
2989}
2990
2991/**
2992 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2993 * @priv: pointer to private data registered with IPA (we register a
2994 * pointer to the interface-specific IPA context)
2995 * @evt: the IPA event which triggered the callback
2996 * @data: data associated with the event
2997 *
2998 * Return: None
2999 */
3000static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
3001 unsigned long data)
3002{
3003 struct hdd_ipa_priv *hdd_ipa = NULL;
3004 struct ipa_rx_data *ipa_tx_desc;
3005 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303006 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303008 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003009
Mukul Sharma81661ae2015-10-30 20:26:02 +05303010 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05303012 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 dev_kfree_skb_any(skb);
3014 iface_context->stats.num_tx_drop++;
3015 return;
3016 }
3017
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 ipa_tx_desc = (struct ipa_rx_data *)data;
3019
3020 hdd_ipa = iface_context->hdd_ipa;
3021
3022 /*
3023 * When SSR is going on or driver is unloading, just drop the packets.
3024 * During SSR, there is no use in queueing the packets as STA has to
3025 * connect back any way
3026 */
3027 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303028 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 ipa_free_skb(ipa_tx_desc);
3030 iface_context->stats.num_tx_drop++;
3031 return;
3032 }
3033
3034 skb = ipa_tx_desc->skb;
3035
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303036 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037
3038 /*
3039 * If PROD resource is not requested here then there may be cases where
3040 * IPA hardware may be clocked down because of not having proper
3041 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
3042 * workaround to request PROD resource while data is going over CONS
3043 * pipe to prevent the IPA hardware clockdown.
3044 */
3045 hdd_ipa_rm_request(hdd_ipa);
3046
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303047 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048 /*
3049 * If host is still suspended then queue the packets and these will be
3050 * drained later when resume completes. When packet is arrived here and
3051 * host is suspended, this means that there is already resume is in
3052 * progress.
3053 */
3054 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303055 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003056 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
3057 pm_tx_cb->iface_context = iface_context;
3058 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303059 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003060 hdd_ipa->stats.num_tx_queued++;
3061
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303062 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063 return;
3064 }
3065
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303066 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003067
3068 /*
3069 * If we are here means, host is not suspended, wait for the work queue
3070 * to finish.
3071 */
3072#ifdef WLAN_OPEN_SOURCE
3073 flush_work(&hdd_ipa->pm_work);
3074#endif
3075
3076 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
3077}
3078
3079/**
3080 * hdd_ipa_suspend() - Suspend IPA
3081 * @hdd_ctx: Global HDD context
3082 *
3083 * Return: 0 on success, negativer errno on error
3084 */
3085int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
3086{
3087 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3088
3089 if (!hdd_ipa_is_enabled(hdd_ctx))
3090 return 0;
3091
3092 /*
3093 * Check if IPA is ready for suspend, If we are here means, there is
3094 * high chance that suspend would go through but just to avoid any race
3095 * condition after suspend started, these checks are conducted before
3096 * allowing to suspend.
3097 */
3098 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3099 return -EAGAIN;
3100
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303101 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102
3103 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303104 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 return -EAGAIN;
3106 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303107 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303109 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303111 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112
3113 return 0;
3114}
3115
3116/**
3117 * hdd_ipa_resume() - Resume IPA following suspend
3118 * hdd_ctx: Global HDD context
3119 *
3120 * Return: 0 on success, negative errno on error
3121 */
3122int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3123{
3124 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3125
3126 if (!hdd_ipa_is_enabled(hdd_ctx))
3127 return 0;
3128
3129 schedule_work(&hdd_ipa->pm_work);
3130
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303131 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303133 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134
3135 return 0;
3136}
3137
3138/**
3139 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3140 * @hdd_ipa: Global HDD IPA context
3141 *
3142 * Return: 0 on success, negative errno on error
3143 */
3144static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3145{
3146 int i, ret = 0;
3147 struct ipa_sys_connect_params *ipa;
3148 uint32_t desc_fifo_sz;
3149
3150 /* The maximum number of descriptors that can be provided to a BAM at
3151 * once is one less than the total number of descriptors that the buffer
3152 * can contain.
3153 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3154 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3155 * be provided at once.
3156 * Because of above requirement, one extra descriptor will be added to
3157 * make sure hardware always has one descriptor.
3158 */
3159 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3160 + sizeof(struct sps_iovec);
3161
3162 /*setup TX pipes */
3163 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3164 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3165
3166 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3167 ipa->desc_fifo_sz = desc_fifo_sz;
3168 ipa->priv = &hdd_ipa->iface_context[i];
3169 ipa->notify = hdd_ipa_i2w_cb;
3170
3171 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3172 ipa->ipa_ep_cfg.hdr.hdr_len =
3173 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3174 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3175 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3176 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3177 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3178 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3179 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3180 } else {
3181 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3182 }
3183 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3184
3185 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3186 ipa->keep_ipa_awake = 1;
3187
3188 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3189 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303190 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003191 " ret: %d", i, ret);
3192 goto setup_sys_pipe_fail;
3193 }
3194 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3195 }
3196
3197 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3198 /*
3199 * Hard code it here, this can be extended if in case
3200 * PROD pipe is also per interface.
3201 * Right now there is no advantage of doing this.
3202 */
3203 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3204
3205 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3206
3207 ipa->client = hdd_ipa->prod_client;
3208
3209 ipa->desc_fifo_sz = desc_fifo_sz;
3210 ipa->priv = hdd_ipa;
3211 ipa->notify = hdd_ipa_w2i_cb;
3212
3213 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3214 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3215 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3216 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3217
3218 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3219 ipa->keep_ipa_awake = 1;
3220
3221 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3222 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303223 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224 "Failed for RX pipe: %d", ret);
3225 goto setup_sys_pipe_fail;
3226 }
3227 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3228 }
3229
3230 return ret;
3231
3232setup_sys_pipe_fail:
3233
3234 while (--i >= 0) {
3235 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303236 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003237 sizeof(struct hdd_ipa_sys_pipe));
3238 }
3239
3240 return ret;
3241}
3242
3243/**
3244 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3245 * @hdd_ipa: Global HDD IPA context
3246 *
3247 * Return: None
3248 */
3249static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3250{
3251 int ret = 0, i;
3252 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3253 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3254 ret =
3255 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3256 conn_hdl);
3257 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303258 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259 ret);
3260
3261 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3262 }
3263 }
3264}
3265
3266/**
3267 * hdd_ipa_register_interface() - register IPA interface
3268 * @hdd_ipa: Global IPA context
3269 * @iface_context: Per-interface IPA context
3270 *
3271 * Return: 0 on success, negative errno on error
3272 */
3273static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3274 struct hdd_ipa_iface_context
3275 *iface_context)
3276{
3277 struct ipa_tx_intf tx_intf;
3278 struct ipa_rx_intf rx_intf;
3279 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3280 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3281 char *ifname = iface_context->adapter->dev->name;
3282
3283 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3284 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3285
3286 int num_prop = 1;
3287 int ret = 0;
3288
3289 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3290 num_prop++;
3291
3292 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3293 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303294 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003295 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303296 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297 goto register_interface_fail;
3298 }
3299
3300 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3301 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303302 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303304 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305 goto register_interface_fail;
3306 }
3307
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303308 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3309 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310
3311 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3312 ifname, HDD_IPA_IPV4_NAME_EXT);
3313 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3314 ifname, HDD_IPA_IPV6_NAME_EXT);
3315
3316 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3317 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3318 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3319 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3320
3321 /*
3322 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3323 * mask to identify the interface in IPA hardware
3324 */
3325 rx_prop[IPA_IP_v4].attrib.meta_data =
3326 htonl(iface_context->adapter->sessionId << 16);
3327 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3328
3329 rx_intf.num_props++;
3330 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3331 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3332 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3333 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3334 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3335 rx_prop[IPA_IP_v4].attrib.meta_data =
3336 htonl(iface_context->adapter->sessionId << 16);
3337 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3338
3339 rx_intf.num_props++;
3340 }
3341
3342 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3343 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3344 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3345 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3346 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3347 IPA_RESOURCE_NAME_MAX);
3348 tx_intf.num_props++;
3349
3350 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3351 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3352 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3353 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3354 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3355 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3356 IPA_RESOURCE_NAME_MAX);
3357 tx_intf.num_props++;
3358 }
3359
3360 tx_intf.prop = tx_prop;
3361 rx_intf.prop = rx_prop;
3362
3363 /* Call the ipa api to register interface */
3364 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3365
3366register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303367 qdf_mem_free(tx_prop);
3368 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369 return ret;
3370}
3371
3372/**
3373 * hdd_remove_ipa_header() - Remove a specific header from IPA
3374 * @name: Name of the header to be removed
3375 *
3376 * Return: None
3377 */
3378static void hdd_ipa_remove_header(char *name)
3379{
3380 struct ipa_ioc_get_hdr hdrlookup;
3381 int ret = 0, len;
3382 struct ipa_ioc_del_hdr *ipa_hdr;
3383
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303384 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3386 ret = ipa_get_hdr(&hdrlookup);
3387 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303388 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389 name, ret);
3390 return;
3391 }
3392
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303393 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003394 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303395 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303397 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003398 return;
3399 }
3400 ipa_hdr->num_hdls = 1;
3401 ipa_hdr->commit = 0;
3402 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3403 ipa_hdr->hdl[0].status = -1;
3404 ret = ipa_del_hdr(ipa_hdr);
3405 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303406 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 ret);
3408
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303409 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410}
3411
3412/**
3413 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3414 * @hdd_ipa: Global HDD IPA context
3415 * @iface_context: Interface-specific HDD IPA context
3416 * @mac_addr: Interface MAC address
3417 *
3418 * Return: 0 on success, negativer errno value on error
3419 */
3420static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3421 struct hdd_ipa_iface_context *iface_context,
3422 uint8_t *mac_addr)
3423{
3424 hdd_adapter_t *adapter = iface_context->adapter;
3425 char *ifname;
3426 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3427 int ret = -EINVAL;
3428 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3429 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3430
3431 ifname = adapter->dev->name;
3432
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303433 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 ifname, mac_addr);
3435
3436 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303437 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 + sizeof(struct ipa_hdr_add));
3439 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303440 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 "%s: ipa_hdr allocation failed", ifname);
3442 ret = -ENOMEM;
3443 goto end;
3444 }
3445
3446 ipa_hdr->commit = 0;
3447 ipa_hdr->num_hdrs = 1;
3448
3449 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3450 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3451 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3452 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3453 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303454 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455 "ifname=%s, vdev_id=%d",
3456 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3457 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3458 ifname, HDD_IPA_IPV4_NAME_EXT);
3459 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3460 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3461 ipa_hdr->hdr[0].is_partial = 1;
3462 ipa_hdr->hdr[0].hdr_hdl = 0;
3463 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3464 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3465
3466 ret = ipa_add_hdr(ipa_hdr);
3467 } else {
3468 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3469
3470 /* Set the Source MAC */
3471 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3472 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3473
3474 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3475 ifname, HDD_IPA_IPV4_NAME_EXT);
3476 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3477 ipa_hdr->hdr[0].is_partial = 1;
3478 ipa_hdr->hdr[0].hdr_hdl = 0;
3479 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3480 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3481
3482 /* Set the type to IPV4 in the header */
3483 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3484
3485 ret = ipa_add_hdr(ipa_hdr);
3486 }
3487 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303488 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 ifname, ret);
3490 goto end;
3491 }
3492
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303493 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3495
3496 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3497 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3498 ifname, HDD_IPA_IPV6_NAME_EXT);
3499
3500 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3501 uc_tx_hdr =
3502 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3503 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3504 } else {
3505 /* Set the type to IPV6 in the header */
3506 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3507 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3508 }
3509
3510 ret = ipa_add_hdr(ipa_hdr);
3511 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303512 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513 "%s: IPv6 add hdr failed: %d", ifname, ret);
3514 goto clean_ipv4_hdr;
3515 }
3516
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303517 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3519 }
3520
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303521 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522
3523 return ret;
3524
3525clean_ipv4_hdr:
3526 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3527 ifname, HDD_IPA_IPV4_NAME_EXT);
3528 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3529end:
3530 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303531 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532
3533 return ret;
3534}
3535
3536/**
3537 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3538 * @adapter: Adapter upon which IPA was previously configured
3539 *
3540 * Return: None
3541 */
3542static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3543{
3544 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3545 int ret;
3546 char name_ipa[IPA_RESOURCE_NAME_MAX];
3547
3548 /* Remove the headers */
3549 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3550 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3551 hdd_ipa_remove_header(name_ipa);
3552
3553 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3554 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3555 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3556 hdd_ipa_remove_header(name_ipa);
3557 }
3558 /* unregister the interface with IPA */
3559 ret = ipa_deregister_intf(adapter->dev->name);
3560 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303561 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 "%s: ipa_deregister_intf fail: %d",
3563 adapter->dev->name, ret);
3564}
3565
3566/**
3567 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3568 * @iface_context: interface-specific IPA context
3569 *
3570 * Return: None
3571 */
3572static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3573{
3574 if (iface_context == NULL)
3575 return;
3576
3577 hdd_ipa_clean_hdr(iface_context->adapter);
3578
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303579 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 iface_context->adapter->ipa_context = NULL;
3581 iface_context->adapter = NULL;
3582 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303583 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 iface_context->ifa_address = 0;
3585 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303586 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303588 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 }
3590 iface_context->hdd_ipa->num_iface--;
3591}
3592
3593/**
3594 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3595 * @hdd_ipa: HDD IPA global context
3596 * @adapter: Interface upon which IPA is being setup
3597 * @sta_id: Station ID of the API instance
3598 *
3599 * Return: 0 on success, negative errno value on error
3600 */
3601static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3602 hdd_adapter_t *adapter, uint8_t sta_id)
3603{
3604 struct hdd_ipa_iface_context *iface_context = NULL;
3605 void *tl_context = NULL;
3606 int i, ret = 0;
3607
3608 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3609 * channel change indication. Since these indications are sent by lower
3610 * layer as SAP updates and IPA doesn't have to do anything for these
3611 * updates so ignoring!
3612 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003613 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614 return 0;
3615
3616 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3617 if (hdd_ipa->iface_context[i].adapter == NULL) {
3618 iface_context = &(hdd_ipa->iface_context[i]);
3619 break;
3620 }
3621 }
3622
3623 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303624 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 "All the IPA interfaces are in use");
3626 ret = -ENOMEM;
3627 goto end;
3628 }
3629
3630 adapter->ipa_context = iface_context;
3631 iface_context->adapter = adapter;
3632 iface_context->sta_id = sta_id;
Leo Changfdb45c32016-10-28 11:09:23 -07003633 tl_context = cdp_peer_get_vdev_by_sta_id(
3634 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303636 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 "Not able to get TL context sta_id: %d", sta_id);
3638 ret = -EINVAL;
3639 goto end;
3640 }
3641
3642 iface_context->tl_context = tl_context;
3643
3644 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3645 adapter->dev->dev_addr);
3646
3647 if (ret)
3648 goto end;
3649
3650 /* Configure the TX and RX pipes filter rules */
3651 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3652 if (ret)
3653 goto cleanup_header;
3654
3655 hdd_ipa->num_iface++;
3656 return ret;
3657
3658cleanup_header:
3659
3660 hdd_ipa_clean_hdr(adapter);
3661end:
3662 if (iface_context)
3663 hdd_ipa_cleanup_iface(iface_context);
3664 return ret;
3665}
3666
Yun Parka27049a2016-10-11 12:30:49 -07003667#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668/**
3669 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3670 * @mcc_mode: 0=MCC/1=SCC
3671 *
3672 * Return: 0 on success, negative errno value on error
3673 */
3674int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3675{
3676 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303677 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678 hdd_adapter_t *pAdapter;
3679 struct ipa_msg_meta meta;
3680 struct ipa_wlan_msg *msg;
3681 int ret;
3682
3683 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3684 return -EINVAL;
3685
3686 if (!pHddCtx->mcc_mode) {
3687 /* Flush TxRx queue for each adapter before switch to SCC */
3688 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303689 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003690 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003691 if (pAdapter->device_mode == QDF_STA_MODE ||
3692 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303693 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3695 pAdapter->device_mode);
3696 hdd_deinit_tx_rx(pAdapter);
3697 }
3698 status = hdd_get_next_adapter(
3699 pHddCtx, adapter_node, &next);
3700 adapter_node = next;
3701 }
3702 }
3703
3704 /* Send SCC/MCC Switching event to IPA */
3705 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303706 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 if (msg == NULL) {
3708 hddLog(LOGE, "msg allocation failed");
3709 return -ENOMEM;
3710 }
3711
3712 meta.msg_type = mcc_mode ?
3713 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3714 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3715
3716 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3717
3718 if (ret) {
3719 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3720 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303721 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003722 }
3723
3724 return ret;
3725}
Yun Parka27049a2016-10-11 12:30:49 -07003726#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727
3728/**
3729 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3730 * @event: IPA WLAN event to be converted to a string
3731 *
3732 * Return: ASCII string representing the IPA WLAN event
3733 */
3734static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3735{
3736 switch (event) {
3737 case WLAN_CLIENT_CONNECT:
3738 return "WLAN_CLIENT_CONNECT";
3739 case WLAN_CLIENT_DISCONNECT:
3740 return "WLAN_CLIENT_DISCONNECT";
3741 case WLAN_CLIENT_POWER_SAVE_MODE:
3742 return "WLAN_CLIENT_POWER_SAVE_MODE";
3743 case WLAN_CLIENT_NORMAL_MODE:
3744 return "WLAN_CLIENT_NORMAL_MODE";
3745 case SW_ROUTING_ENABLE:
3746 return "SW_ROUTING_ENABLE";
3747 case SW_ROUTING_DISABLE:
3748 return "SW_ROUTING_DISABLE";
3749 case WLAN_AP_CONNECT:
3750 return "WLAN_AP_CONNECT";
3751 case WLAN_AP_DISCONNECT:
3752 return "WLAN_AP_DISCONNECT";
3753 case WLAN_STA_CONNECT:
3754 return "WLAN_STA_CONNECT";
3755 case WLAN_STA_DISCONNECT:
3756 return "WLAN_STA_DISCONNECT";
3757 case WLAN_CLIENT_CONNECT_EX:
3758 return "WLAN_CLIENT_CONNECT_EX";
3759
3760 case IPA_WLAN_EVENT_MAX:
3761 default:
3762 return "UNKNOWN";
3763 }
3764}
3765
3766/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003767 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3768 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3769 *
3770 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3771 */
3772static enum ipa_wlan_event
3773hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3774{
3775 enum ipa_wlan_event ipa_event;
3776
3777 switch (hdd_ipa_event_type) {
3778 case HDD_IPA_CLIENT_CONNECT:
3779 ipa_event = WLAN_CLIENT_CONNECT;
3780 break;
3781 case HDD_IPA_CLIENT_DISCONNECT:
3782 ipa_event = WLAN_CLIENT_DISCONNECT;
3783 break;
3784 case HDD_IPA_AP_CONNECT:
3785 ipa_event = WLAN_AP_CONNECT;
3786 break;
3787 case HDD_IPA_AP_DISCONNECT:
3788 ipa_event = WLAN_AP_DISCONNECT;
3789 break;
3790 case HDD_IPA_STA_CONNECT:
3791 ipa_event = WLAN_STA_CONNECT;
3792 break;
3793 case HDD_IPA_STA_DISCONNECT:
3794 ipa_event = WLAN_STA_DISCONNECT;
3795 break;
3796 case HDD_IPA_CLIENT_CONNECT_EX:
3797 ipa_event = WLAN_CLIENT_CONNECT_EX;
3798 break;
3799 case HDD_IPA_WLAN_EVENT_MAX:
3800 default:
3801 ipa_event = IPA_WLAN_EVENT_MAX;
3802 break;
3803 }
3804 return ipa_event;
3805
3806}
3807
3808/**
3809 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 * @adapter: adapter upon which the event was received
3811 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003812 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 * @mac_address: MAC address associated with the event
3814 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003815 * This function is meant to be called from within wlan_hdd_ipa.c
3816 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817 * Return: 0 on success, negative errno value on error
3818 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003819static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 enum ipa_wlan_event type, uint8_t *mac_addr)
3821{
3822 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3823 struct ipa_msg_meta meta;
3824 struct ipa_wlan_msg *msg;
3825 struct ipa_wlan_msg_ex *msg_ex = NULL;
3826 int ret;
3827
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303828 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3830 mac_addr, sta_id);
3831
3832 if (type >= IPA_WLAN_EVENT_MAX)
3833 return -EINVAL;
3834
3835 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3836 return -EINVAL;
3837
3838 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303839 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840 return -EINVAL;
3841 }
3842
3843 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3844 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003845 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846 return 0;
3847 }
3848
3849 /*
3850 * During IPA UC resource loading/unloading new events can be issued.
3851 * Store the events separately and handle them later.
3852 */
3853 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3854 ((hdd_ipa->resource_loading) ||
3855 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003856 unsigned int pending_event_count;
3857 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858
Yun Parkf19e07d2015-11-20 11:34:27 -08003859 hdd_err("IPA resource %s inprogress",
3860 hdd_ipa->resource_loading ? "load":"unload");
3861
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303862 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003863
Anurag Chouhanffb21542016-02-17 14:33:03 +05303864 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003865 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3866 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303867 qdf_list_remove_front(&hdd_ipa->pending_event,
3868 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003869 } else {
3870 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303871 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003872 sizeof(struct ipa_uc_pending_event));
3873 }
3874
3875 if (!pending_event) {
3876 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303877 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 return -ENOMEM;
3879 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003880
3881 pending_event->adapter = adapter;
3882 pending_event->sta_id = sta_id;
3883 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303884 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303886 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303887 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003888 &pending_event->node);
3889
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303890 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 return 0;
3892 }
3893
3894 hdd_ipa->stats.event[type]++;
3895
Leo Chang3bc8fed2015-11-13 10:59:47 -08003896 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 switch (type) {
3898 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003899 qdf_mutex_acquire(&hdd_ipa->event_lock);
3900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003901 /* STA already connected and without disconnect, connect again
3902 * This is Roaming scenario
3903 */
3904 if (hdd_ipa->sta_connected)
3905 hdd_ipa_cleanup_iface(adapter->ipa_context);
3906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3908 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303909 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003911 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912
Yun Park8f289c82016-10-18 16:38:21 -07003913 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3914 (hdd_ipa->sap_num_connected_sta > 0) &&
3915 !hdd_ipa->sta_connected) {
3916 qdf_mutex_release(&hdd_ipa->event_lock);
3917 hdd_ipa_uc_offload_enable_disable(adapter,
3918 SIR_STA_RX_DATA_OFFLOAD, 1);
3919 qdf_mutex_acquire(&hdd_ipa->event_lock);
3920 }
3921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922 vdev_to_iface[adapter->sessionId] =
3923 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003924 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003927
3928 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 break;
3930
3931 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003932 qdf_mutex_acquire(&hdd_ipa->event_lock);
3933
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934 /* For DFS channel we get two start_bss event (before and after
3935 * CAC). Also when ACS range includes both DFS and non DFS
3936 * channels, we could possibly change channel many times due to
3937 * RADAR detection and chosen channel may not be a DFS channels.
3938 * So dont return error here. Just discard the event.
3939 */
Yun Park8f289c82016-10-18 16:38:21 -07003940 if (adapter->ipa_context) {
3941 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003943 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3946 if (ret) {
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, Interface setup failed",
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 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003952 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953
Yun Park8f289c82016-10-18 16:38:21 -07003954 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3955 qdf_mutex_release(&hdd_ipa->event_lock);
3956 hdd_ipa_uc_offload_enable_disable(adapter,
3957 SIR_AP_RX_DATA_OFFLOAD, 1);
3958 qdf_mutex_acquire(&hdd_ipa->event_lock);
3959 }
3960
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 vdev_to_iface[adapter->sessionId] =
3962 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003963 (adapter->ipa_context))->iface_id;
3964
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303965 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 break;
3967
3968 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303969 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970
3971 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303972 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 "%s: Evt: %d, STA already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05303974 adapter->dev->name, type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303975 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 return -EINVAL;
3977 }
Yun Parka37592b2016-06-11 17:10:28 -07003978
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003980
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303982 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 "%s: IPA UC OFFLOAD NOT ENABLED",
3984 msg_ex->name);
3985 } else {
3986 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003987 if (!hdd_ipa->num_iface &&
3988 (HDD_IPA_UC_NUM_WDI_PIPE ==
3989 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 }
3992
Yun Park74127cf2016-09-18 11:22:41 -07003993 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3994 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07003995 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 hdd_ipa_uc_offload_enable_disable(adapter,
3997 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003998 qdf_mutex_acquire(&hdd_ipa->event_lock);
3999 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 }
4001
Yun Park8f289c82016-10-18 16:38:21 -07004002 hdd_ipa_cleanup_iface(adapter->ipa_context);
4003
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304004 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 break;
4006
4007 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07004008 qdf_mutex_acquire(&hdd_ipa->event_lock);
4009
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304011 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 "%s: Evt: %d, SAP already disconnected",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304013 adapter->dev->name, type);
Yun Park8f289c82016-10-18 16:38:21 -07004014 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015 return -EINVAL;
4016 }
4017
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 if ((!hdd_ipa->num_iface) &&
4019 (HDD_IPA_UC_NUM_WDI_PIPE ==
4020 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004021 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 /*
4023 * We disable WDI pipes directly here since
4024 * IPA_OPCODE_TX/RX_SUSPEND message will not be
4025 * processed when unloading WLAN driver is in
4026 * progress
4027 */
4028 hdd_ipa_uc_disable_pipes(hdd_ipa);
4029 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304030 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 "NO INTF left but still pipe clean up");
4032 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4033 }
4034 }
4035
4036 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07004037 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 hdd_ipa_uc_offload_enable_disable(adapter,
4039 SIR_AP_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004040 qdf_mutex_acquire(&hdd_ipa->event_lock);
4041 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 }
Yun Parka37592b2016-06-11 17:10:28 -07004043
Yun Park8f289c82016-10-18 16:38:21 -07004044 hdd_ipa_cleanup_iface(adapter->ipa_context);
4045
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304046 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047 break;
4048
4049 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304051 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304053 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054 return 0;
4055 }
4056
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304057 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
4059 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07004060 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304061 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062 "%s: STA ID %d found, not valid",
4063 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 return 0;
4065 }
Yun Park312f71a2015-12-08 10:22:42 -08004066
4067 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07004068 if (0 == hdd_ipa->sap_num_connected_sta) {
4069 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004070 hdd_ipa->sta_connected) {
4071 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004072 hdd_ipa_uc_offload_enable_disable(
4073 hdd_get_adapter(hdd_ipa->hdd_ctx,
4074 QDF_STA_MODE),
4075 SIR_STA_RX_DATA_OFFLOAD, 1);
Yun Park8f289c82016-10-18 16:38:21 -07004076 qdf_mutex_acquire(&hdd_ipa->event_lock);
4077 }
Yun Parka37592b2016-06-11 17:10:28 -07004078
Yun Park312f71a2015-12-08 10:22:42 -08004079 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
4080 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304081 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08004082 "%s: handle 1st con ret %d",
4083 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07004084
4085 if (hdd_ipa_uc_sta_is_enabled(
4086 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004087 hdd_ipa->sta_connected) {
4088 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004089 hdd_ipa_uc_offload_enable_disable(
4090 hdd_get_adapter(
4091 hdd_ipa->hdd_ctx,
4092 QDF_STA_MODE),
4093 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004094 } else {
4095 qdf_mutex_release(&hdd_ipa->event_lock);
4096 }
Yun Parka37592b2016-06-11 17:10:28 -07004097
Yun Park312f71a2015-12-08 10:22:42 -08004098 return ret;
4099 }
4100 }
4101
4102 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08004103
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304104 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105
4106 meta.msg_type = type;
4107 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
4108 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304109 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110
4111 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304112 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004113 "msg_ex allocation failed");
4114 return -ENOMEM;
4115 }
4116 strlcpy(msg_ex->name, adapter->dev->name,
4117 IPA_RESOURCE_NAME_MAX);
4118 msg_ex->num_of_attribs = 1;
4119 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4120 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4121 msg_ex->attribs[0].offset =
4122 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4123 } else {
4124 msg_ex->attribs[0].offset =
4125 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4126 }
4127 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4128 IPA_MAC_ADDR_SIZE);
4129
4130 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4131
4132 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304133 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05304134 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304135 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004136 return ret;
4137 }
4138 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139 return ret;
4140
4141 case WLAN_CLIENT_DISCONNECT:
4142 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304143 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 "%s: IPA UC OFFLOAD NOT ENABLED",
4145 msg_ex->name);
4146 return 0;
4147 }
4148
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304149 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304151 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 "%s: STA ID %d NOT found, not valid",
4153 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304154 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155 return 0;
4156 }
4157 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07004158
Yun Park9b5030f2016-11-08 12:02:37 -08004159 /* Disable IPA UC TX PIPE when last STA disconnected */
4160 if (!hdd_ipa->sap_num_connected_sta) {
4161 if ((false == hdd_ipa->resource_unloading)
4162 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4163 hdd_ipa->activated_fw_pipe)) {
4164 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4165 }
4166
Yun Park8f289c82016-10-18 16:38:21 -07004167 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004168
4169 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4170 hdd_ipa->sta_connected)
4171 hdd_ipa_uc_offload_enable_disable(
4172 hdd_get_adapter(hdd_ipa->hdd_ctx,
4173 QDF_STA_MODE),
4174 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004175 } else {
4176 qdf_mutex_release(&hdd_ipa->event_lock);
4177 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 break;
4179
4180 default:
4181 return 0;
4182 }
4183
4184 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304185 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304187 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 return -ENOMEM;
4189 }
4190
4191 meta.msg_type = type;
4192 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4193 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4194
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304195 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196 msg->name, meta.msg_type);
4197
4198 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4199
4200 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304201 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304203 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204 return ret;
4205 }
4206
4207 hdd_ipa->stats.num_send_msg++;
4208
4209end:
4210 return ret;
4211}
4212
4213/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004214 * hdd_ipa_wlan_evt() - IPA event handler
4215 * @adapter: adapter upon which the event was received
4216 * @sta_id: station id for the event
4217 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4218 * @mac_address: MAC address associated with the event
4219 *
4220 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4221 *
4222 * Return: 0 on success, negative errno value on error
4223 */
4224int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4225 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4226{
4227 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4228
Leo Changa202b522016-10-14 16:13:50 -07004229 /* Data path offload only support for STA and SAP mode */
4230 if ((QDF_STA_MODE == adapter->device_mode) ||
4231 (QDF_SAP_MODE == adapter->device_mode))
4232 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4233
4234 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004235}
4236
4237/**
4238 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4239 * @hdd_ipa: Global HDD IPA context
4240 *
4241 * Return: None
4242 */
4243static void
4244hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4245{
4246 unsigned int pending_event_count;
4247 struct ipa_uc_pending_event *pending_event = NULL;
4248
4249 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4250 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4251 "%s, Pending Event Count %d", __func__, pending_event_count);
4252 if (!pending_event_count) {
4253 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4254 "%s, No Pending Event", __func__);
4255 return;
4256 }
4257
4258 qdf_list_remove_front(&hdd_ipa->pending_event,
4259 (qdf_list_node_t **)&pending_event);
4260 while (pending_event != NULL) {
4261 __hdd_ipa_wlan_evt(pending_event->adapter,
4262 pending_event->type,
4263 pending_event->sta_id,
4264 pending_event->mac_addr);
4265 qdf_mem_free(pending_event);
4266 pending_event = NULL;
4267 qdf_list_remove_front(&hdd_ipa->pending_event,
4268 (qdf_list_node_t **)&pending_event);
4269 }
4270}
4271
4272/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4274 * @state: IPA RM state value
4275 *
4276 * Return: ASCII string representing the IPA RM state
4277 */
4278static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4279{
4280 switch (state) {
4281 case HDD_IPA_RM_RELEASED:
4282 return "RELEASED";
4283 case HDD_IPA_RM_GRANT_PENDING:
4284 return "GRANT_PENDING";
4285 case HDD_IPA_RM_GRANTED:
4286 return "GRANTED";
4287 }
4288
4289 return "UNKNOWN";
4290}
4291
4292/**
4293 * hdd_ipa_init() - IPA initialization function
4294 * @hdd_ctx: HDD global context
4295 *
4296 * Allocate hdd_ipa resources, ipa pipe resource and register
4297 * wlan interface with IPA module.
4298 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304299 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304301QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302{
4303 struct hdd_ipa_priv *hdd_ipa = NULL;
4304 int ret, i;
4305 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004306 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307
4308 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304309 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310
Yun Park7f171ab2016-07-29 15:44:22 -07004311 if (!pdev) {
4312 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4313 goto fail_return;
4314 }
4315
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304316 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304318 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004319 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 }
4321
4322 hdd_ctx->hdd_ipa = hdd_ipa;
4323 ghdd_ipa = hdd_ipa;
4324 hdd_ipa->hdd_ctx = hdd_ctx;
4325 hdd_ipa->num_iface = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07004326 cdp_ipa_get_resource(cds_get_context(QDF_MODULE_ID_SOC),
4327 cds_get_context(QDF_MODULE_ID_TXRX),
4328 &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004329 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4330 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4331 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4332 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304333 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004334 "IPA UC resource alloc fail");
4335 goto fail_get_resource;
4336 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004337
4338 /* Create the interface context */
4339 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4340 iface_context = &hdd_ipa->iface_context[i];
4341 iface_context->hdd_ipa = hdd_ipa;
4342 iface_context->cons_client =
4343 hdd_ipa_adapter_2_client[i].cons_client;
4344 iface_context->prod_client =
4345 hdd_ipa_adapter_2_client[i].prod_client;
4346 iface_context->iface_id = i;
4347 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004348 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304349 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004350 }
4351 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Yun Park8f289c82016-10-18 16:38:21 -07004352 vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 }
4354
Leo Chang69c39692016-10-12 20:11:12 -07004355 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304356 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304357 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358
4359 ret = hdd_ipa_setup_rm(hdd_ipa);
4360 if (ret)
4361 goto fail_setup_rm;
4362
4363 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4364 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304365 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366 hdd_ipa->sap_num_connected_sta = 0;
4367 hdd_ipa->ipa_tx_packets_diff = 0;
4368 hdd_ipa->ipa_rx_packets_diff = 0;
4369 hdd_ipa->ipa_p_tx_packets = 0;
4370 hdd_ipa->ipa_p_rx_packets = 0;
4371 hdd_ipa->resource_loading = false;
4372 hdd_ipa->resource_unloading = false;
4373 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004374 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 /* Setup IPA sys_pipe for MCC */
4376 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4377 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4378 if (ret)
4379 goto fail_create_sys_pipe;
4380 }
4381 hdd_ipa_uc_ol_init(hdd_ctx);
4382 } else {
4383 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4384 if (ret)
4385 goto fail_create_sys_pipe;
4386 }
4387
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304388 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389
4390fail_create_sys_pipe:
4391 hdd_ipa_destroy_rm_resource(hdd_ipa);
4392fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304393 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004394fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304395 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004396 hdd_ctx->hdd_ipa = NULL;
4397 ghdd_ipa = NULL;
4398fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304399 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400}
4401
4402/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004403 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4404 * @hdd_ipa: pointer to HDD IPA struct
4405 *
4406 * Return: none
4407 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004408static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004409{
4410 struct ipa_uc_pending_event *pending_event = NULL;
4411
Anurag Chouhanffb21542016-02-17 14:33:03 +05304412 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4413 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304414 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004415 }
4416
Anurag Chouhanffb21542016-02-17 14:33:03 +05304417 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004418}
4419
4420/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421 * hdd_ipa_cleanup - IPA cleanup function
4422 * @hdd_ctx: HDD global context
4423 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304424 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004425 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304426QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427{
4428 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4429 int i;
4430 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304431 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4433
4434 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304435 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436
4437 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4438 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4439 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4440 }
4441
4442 /* Teardown IPA sys_pipe for MCC */
4443 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4444 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4445
4446 hdd_ipa_destroy_rm_resource(hdd_ipa);
4447
4448#ifdef WLAN_OPEN_SOURCE
4449 cancel_work_sync(&hdd_ipa->pm_work);
4450#endif
4451
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304452 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453
Nirav Shahcbc6d722016-03-01 16:24:53 +05304454 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4455 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304456 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004457
4458 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4459 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4460
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304461 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004462 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304463 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304465 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466
4467 /* destory the interface lock */
4468 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4469 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304470 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004471 }
4472
4473 /* This should never hit but still make sure that there are no pending
4474 * descriptor in IPA hardware
4475 */
4476 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304477 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 "IPA Pending write done: %d Waiting!",
4479 hdd_ipa->pending_hw_desc_cnt);
4480
4481 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4482 usleep_range(100, 100);
4483 }
4484
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304485 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 "IPA Pending write done: desc: %d %s(%d)!",
4487 hdd_ipa->pending_hw_desc_cnt,
4488 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4489 : "leak", i);
4490 }
4491 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4492 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304493 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304494 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4495 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004496 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304497 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304498 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4499 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304501 qdf_mutex_destroy(&hdd_ipa->event_lock);
4502 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004503 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504
4505#ifdef WLAN_OPEN_SOURCE
4506 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4507 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4508 hdd_ipa->uc_op_work[i].msg = NULL;
4509 }
4510#endif
4511 }
4512
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304513 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514 hdd_ctx->hdd_ipa = NULL;
4515
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304516 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004517}
4518#endif /* IPA_OFFLOAD */