blob: 046921d71abc84931c132b5c68a5c5c84bd6d550 [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 */
38#include <wlan_hdd_includes.h>
39#include <wlan_hdd_ipa.h>
40
41#include <linux/etherdevice.h>
42#include <linux/atomic.h>
43#include <linux/netdevice.h>
44#include <linux/skbuff.h>
45#include <linux/list.h>
46#include <linux/debugfs.h>
47#include <linux/inetdevice.h>
48#include <linux/ip.h>
49#include <wlan_hdd_softap_tx_rx.h>
50#include <ol_txrx_osif_api.h>
51
52#include "cds_sched.h"
53
54#include "wma.h"
55#include "wma_api.h"
56
Dhanashri Atreb08959a2016-03-01 17:28:03 -080057#include "cdp_txrx_ipa.h"
58
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059#define HDD_IPA_DESC_BUFFER_RATIO 4
60#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
61#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
62
63#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
64#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET 12
65#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
181#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
182#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct frag_header)
183
184/**
185 * struct hdd_ipa_cld_hdr - IPA CLD Header
186 * @reserved: reserved fields
187 * @iface_id: interface ID
188 * @sta_id: Station ID
189 *
190 * Packed 32-bit structure
191 * +----------+----------+--------------+--------+
192 * | Reserved | QCMAP ID | interface id | STA ID |
193 * +----------+----------+--------------+--------+
194 */
195struct hdd_ipa_cld_hdr {
196 uint8_t reserved[2];
197 uint8_t iface_id;
198 uint8_t sta_id;
199} __packed;
200
201struct hdd_ipa_rx_hdr {
202 struct hdd_ipa_cld_hdr cld_hdr;
203 struct ethhdr eth;
204} __packed;
205
206struct hdd_ipa_pm_tx_cb {
207 struct hdd_ipa_iface_context *iface_context;
208 struct ipa_rx_data *ipa_tx_desc;
209};
210
211struct hdd_ipa_uc_rx_hdr {
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_sys_pipe {
216 uint32_t conn_hdl;
217 uint8_t conn_hdl_valid;
218 struct ipa_sys_connect_params ipa_sys_params;
219};
220
221struct hdd_ipa_iface_stats {
222 uint64_t num_tx;
223 uint64_t num_tx_drop;
224 uint64_t num_tx_err;
225 uint64_t num_tx_cac_drop;
226 uint64_t num_rx_prefilter;
227 uint64_t num_rx_ipa_excep;
228 uint64_t num_rx_recv;
229 uint64_t num_rx_recv_mul;
230 uint64_t num_rx_send_desc_err;
231 uint64_t max_rx_mul;
232};
233
234struct hdd_ipa_priv;
235
236struct hdd_ipa_iface_context {
237 struct hdd_ipa_priv *hdd_ipa;
238 hdd_adapter_t *adapter;
239 void *tl_context;
240
241 enum ipa_client_type cons_client;
242 enum ipa_client_type prod_client;
243
244 uint8_t iface_id; /* This iface ID */
245 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530246 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 uint32_t ifa_address;
248 struct hdd_ipa_iface_stats stats;
249};
250
251struct hdd_ipa_stats {
252 uint32_t event[IPA_WLAN_EVENT_MAX];
253 uint64_t num_send_msg;
254 uint64_t num_free_msg;
255
256 uint64_t num_rm_grant;
257 uint64_t num_rm_release;
258 uint64_t num_rm_grant_imm;
259 uint64_t num_cons_perf_req;
260 uint64_t num_prod_perf_req;
261
262 uint64_t num_rx_drop;
263 uint64_t num_rx_ipa_tx_dp;
264 uint64_t num_rx_ipa_splice;
265 uint64_t num_rx_ipa_loop;
266 uint64_t num_rx_ipa_tx_dp_err;
267 uint64_t num_rx_ipa_write_done;
268 uint64_t num_max_ipa_tx_mul;
269 uint64_t num_rx_ipa_hw_maxed_out;
270 uint64_t max_pend_q_cnt;
271
272 uint64_t num_tx_comp_cnt;
273 uint64_t num_tx_queued;
274 uint64_t num_tx_dequeued;
275 uint64_t num_max_pm_queue;
276
277 uint64_t num_freeq_empty;
278 uint64_t num_pri_freeq_empty;
279 uint64_t num_rx_excep;
280 uint64_t num_tx_bcmc;
281 uint64_t num_tx_bcmc_err;
282};
283
284struct ipa_uc_stas_map {
285 bool is_reserved;
286 uint8_t sta_id;
287};
288struct op_msg_type {
289 uint8_t msg_t;
290 uint8_t rsvd;
291 uint16_t op_code;
292 uint16_t len;
293 uint16_t rsvd_snd;
294};
295
296struct ipa_uc_fw_stats {
297 uint32_t tx_comp_ring_base;
298 uint32_t tx_comp_ring_size;
299 uint32_t tx_comp_ring_dbell_addr;
300 uint32_t tx_comp_ring_dbell_ind_val;
301 uint32_t tx_comp_ring_dbell_cached_val;
302 uint32_t tx_pkts_enqueued;
303 uint32_t tx_pkts_completed;
304 uint32_t tx_is_suspend;
305 uint32_t tx_reserved;
306 uint32_t rx_ind_ring_base;
307 uint32_t rx_ind_ring_size;
308 uint32_t rx_ind_ring_dbell_addr;
309 uint32_t rx_ind_ring_dbell_ind_val;
310 uint32_t rx_ind_ring_dbell_ind_cached_val;
311 uint32_t rx_ind_ring_rdidx_addr;
312 uint32_t rx_ind_ring_rd_idx_cached_val;
313 uint32_t rx_refill_idx;
314 uint32_t rx_num_pkts_indicated;
315 uint32_t rx_buf_refilled;
316 uint32_t rx_num_ind_drop_no_space;
317 uint32_t rx_num_ind_drop_no_buf;
318 uint32_t rx_is_suspend;
319 uint32_t rx_reserved;
320};
321
322struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530323 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324 hdd_adapter_t *adapter;
325 enum ipa_wlan_event type;
326 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530327 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328};
329
330/**
331 * struct uc_rm_work_struct
332 * @work: uC RM work
333 * @event: IPA RM event
334 */
335struct uc_rm_work_struct {
336 struct work_struct work;
337 enum ipa_rm_event event;
338};
339
340/**
341 * struct uc_op_work_struct
342 * @work: uC OP work
343 * @msg: OP message
344 */
345struct uc_op_work_struct {
346 struct work_struct work;
347 struct op_msg_type *msg;
348};
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 {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530364 unsigned long 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/**
453 * FIXME: The following conversion routines will are just stubs.
454 * 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 */
459void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
460{
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
469uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
470{
471 uint32_t ipa_priv = 0;
472
473 BUG_ON(ptr == NULL);
474 return ipa_priv;
475}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800476#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
477#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
478#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
479#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
480#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
481#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
482
Leo Chang3bc8fed2015-11-13 10:59:47 -0800483#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
484#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
485
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800486#define HDD_IPA_GET_IFACE_ID(_data) \
487 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
488
489#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530490 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491 "%s:%d: "fmt, __func__, __LINE__, ## args)
492
493#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
494 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530495 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
496 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 } while (0)
498
499#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
500 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
501
502#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
503 do { \
504 hdd_ipa->ipa_rx_internel_drop_count++; \
505 } while (0)
506#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
507 do { \
508 hdd_ipa->ipa_rx_net_send_count++; \
509 } while (0)
510#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
511
Leo Chang3bc8fed2015-11-13 10:59:47 -0800512/* Temporary macro to make a build without IPA V2 */
513#ifdef IPA_V2
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800514#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
515do { \
516 pipe_in.u.ul.rdy_ring_rp_va = \
517 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
518 pipe_in.u.ul.rdy_comp_ring_base_pa = \
519 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
520 pipe_in.u.ul.rdy_comp_ring_size = \
521 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
522 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
523 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
524 pipe_in.u.ul.rdy_comp_ring_wp_va = \
525 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800526} while (0)
527#else
528/* Do nothing */
529#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
530#endif /* IPA_V2 */
531
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532static struct hdd_ipa_adapter_2_client {
533 enum ipa_client_type cons_client;
534 enum ipa_client_type prod_client;
535} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
536 {
537 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
538 }, {
539 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
540 }, {
541 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
542 },
543};
544
545/* For Tx pipes, use Ethernet-II Header format */
546struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
547 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800548 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549 0x00000000,
550 0x00000000
551 },
552 {
553 0x00000000
554 },
555 {
556 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
557 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
558 0x0008
559 }
560};
561
562/* For Tx pipes, use 802.3 Header format */
563static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
564 {
565 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
566 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
567 0x00 /* length can be zero */
568 },
569 {
570 /* LLC SNAP header 8 bytes */
571 0xaa, 0xaa,
572 {0x03, 0x00, 0x00, 0x00},
573 0x0008 /* type value(2 bytes) ,filled by wlan */
574 /* 0x0800 - IPV4, 0x86dd - IPV6 */
575 }
576};
577
578static const char *op_string[] = {
579 "TX_SUSPEND",
580 "TX_RESUME",
581 "RX_SUSPEND",
582 "RX_RESUME",
583 "STATS",
584};
585
586static struct hdd_ipa_priv *ghdd_ipa;
587
588/* Local Function Prototypes */
589static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
590 unsigned long data);
591static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
592 unsigned long data);
593
594static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
595
596/**
597 * hdd_ipa_is_enabled() - Is IPA enabled?
598 * @hdd_ctx: Global HDD context
599 *
600 * Return: true if IPA is enabled, false otherwise
601 */
602bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
603{
604 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
605}
606
607/**
608 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
609 * @hdd_ctx: Global HDD context
610 *
611 * Return: true if IPA uC offload is enabled, false otherwise
612 */
613bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
614{
615 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
616}
617
618/**
619 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
620 * @hdd_ctx: Global HDD context
621 *
622 * Return: true if STA mode IPA uC offload is enabled, false otherwise
623 */
624static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
625{
626 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
627}
628
629/**
630 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
631 * @hdd_ipa: Global HDD IPA context
632 *
633 * Return: true if pre-filter is enabled, otherwise false
634 */
635static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
636{
637 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
638 HDD_IPA_PRE_FILTER_ENABLE_MASK);
639}
640
641/**
642 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
643 * @hdd_ipa: Global HDD IPA context
644 *
645 * Return: true if IPv6 is enabled, otherwise false
646 */
647static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
648{
649 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
650}
651
652/**
653 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
654 * @hdd_ipa: Global HDD IPA context
655 *
656 * Return: true if resource manager is enabled, otherwise false
657 */
658static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
659{
660 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
661}
662
663/**
664 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
665 * @hdd_ipa: Global HDD IPA context
666 *
667 * Return: true if resource manager is enabled, otherwise false
668 */
669static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
670{
671 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
672}
673
674/**
675 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
676 * @hdd_ipa: Global HDD IPA context
677 *
678 * Return: true if clock scaling is enabled, otherwise false
679 */
680static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
681{
682 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
683 HDD_IPA_CLK_SCALING_ENABLE_MASK |
684 HDD_IPA_RM_ENABLE_MASK);
685}
686
687/**
688 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
689 * @ctext: pointer to hdd context.
690 *
691 * If rt debug enabled, periodically called, and fill debug buffer
692 *
693 * Return: none
694 */
695static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
696{
697 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
698 struct hdd_ipa_priv *hdd_ipa;
699 struct uc_rt_debug_info *dump_info = NULL;
700
701 if (wlan_hdd_validate_context(hdd_ctx))
702 return;
703
704 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530705 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800706 "%s: IPA UC is not enabled", __func__);
707 return;
708 }
709
710 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
711
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530712 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713 dump_info = &hdd_ipa->rt_bug_buffer[
714 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
715
Anurag Chouhan210db072016-02-22 18:42:15 +0530716 dump_info->time = qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
718 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
719 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
720 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
721 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
722 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
723 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
724 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530725 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726
Anurag Chouhan210db072016-02-22 18:42:15 +0530727 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
729}
730
731/**
732 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
733 * @hdd_ctx: pointer to hdd context.
734 *
735 * If rt debug enabled, dump debug buffer contents based on requirement
736 *
737 * Return: none
738 */
739void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
740{
741 struct hdd_ipa_priv *hdd_ipa;
742 unsigned int dump_count;
743 unsigned int dump_index;
744 struct uc_rt_debug_info *dump_info = NULL;
745
746 if (wlan_hdd_validate_context(hdd_ctx))
747 return;
748
749 hdd_ipa = hdd_ctx->hdd_ipa;
750 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530751 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800752 "%s: IPA UC is not enabled", __func__);
753 return;
754 }
755
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530756 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800757 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530758 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
760
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530761 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 for (dump_count = 0;
763 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
764 dump_count++) {
765 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
766 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
767 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530768 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 "%12lu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
770 dump_info->time, dump_info->ipa_excep_count,
771 dump_info->rx_drop_count, dump_info->net_sent_count,
772 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
773 dump_info->rx_destructor_call,
774 dump_info->rx_discard_count);
775 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530776 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530777 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800778 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
779}
780
781/**
782 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
783 * @ctext: pointer to hdd context.
784 *
785 * periodically called by timer expire
786 * will try to alloc dummy memory and detect out of memory condition
787 * if out of memory detected, dump wlan-ipa stats
788 *
789 * Return: none
790 */
791static void hdd_ipa_uc_rt_debug_handler(void *ctext)
792{
793 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
794 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
795 void *dummy_ptr = NULL;
796
797 if (wlan_hdd_validate_context(hdd_ctx))
798 return;
799
800 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530801 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800802 "%s: IPA RT debug is not enabled", __func__);
803 return;
804 }
805
806 /* Allocate dummy buffer periodically and free immediately. this will
807 * proactively detect OOM and if allocation fails dump ipa stats
808 */
809 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
810 GFP_KERNEL | GFP_ATOMIC);
811 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530812 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813 "%s: Dummy alloc fail", __func__);
814 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
815 hdd_ipa_uc_stat_request(
816 hdd_get_adapter(hdd_ctx, WLAN_HDD_SOFTAP), 1);
817 } else {
818 kfree(dummy_ptr);
819 }
820
Anurag Chouhan210db072016-02-22 18:42:15 +0530821 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822 HDD_IPA_UC_RT_DEBUG_PERIOD);
823}
824
825/**
826 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
827 * @skb: packet pinter
828 *
829 * when free data packet, will be invoked by wlan client and will increase
830 * free counter
831 *
832 * Return: none
833 */
834void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
835{
836 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530837 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 "%s: invalid hdd context", __func__);
839 return;
840 }
841
842 ghdd_ipa->ipa_rx_destructor_count++;
843}
844
845/**
846 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
847 * @hdd_ctx: hdd main context
848 *
849 * free all rt debugging resources
850 *
851 * Return: none
852 */
853static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
854{
855 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
856
Anurag Chouhan210db072016-02-22 18:42:15 +0530857 if (QDF_TIMER_STATE_STOPPED !=
858 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
859 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530861 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530862 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863
864 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530865 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 "%s: IPA RT debug is not enabled", __func__);
867 return;
868 }
869
Anurag Chouhan210db072016-02-22 18:42:15 +0530870 if (QDF_TIMER_STATE_STOPPED !=
871 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
872 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530874 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875}
876
877/**
878 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
879 * @hdd_ctx: hdd main context
880 *
881 * alloc and initialize all rt debugging resources
882 *
883 * Return: none
884 */
885static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
886{
887 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
888
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530889 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530890 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
892 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530893 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 sizeof(struct uc_rt_debug_info) *
895 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
896 hdd_ipa->ipa_tx_forward = 0;
897 hdd_ipa->ipa_rx_discard = 0;
898 hdd_ipa->ipa_rx_net_send_count = 0;
899 hdd_ipa->ipa_rx_internel_drop_count = 0;
900 hdd_ipa->ipa_rx_destructor_count = 0;
901
Anurag Chouhan210db072016-02-22 18:42:15 +0530902 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
904
905 /* Reatime debug enable on feature enable */
906 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530907 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908 "%s: IPA RT debug is not enabled", __func__);
909 return;
910 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530911 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530913 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 HDD_IPA_UC_RT_DEBUG_PERIOD);
915
916}
917
918/**
919 * hdd_ipa_uc_stat_query() - Query the IPA stats
920 * @hdd_ctx: Global HDD context
921 * @ipa_tx_diff: tx packet count diff from previous
922 * tx packet count
923 * @ipa_rx_diff: rx packet count diff from previous
924 * rx packet count
925 *
926 * Return: true if IPA is enabled, false otherwise
927 */
928void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
929 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
930{
931 struct hdd_ipa_priv *hdd_ipa;
932
933 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
934 *ipa_tx_diff = 0;
935 *ipa_rx_diff = 0;
936
937 if (!hdd_ipa_is_enabled(pHddCtx) ||
938 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
939 return;
940 }
941
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530942 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800943 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
944 (false == hdd_ipa->resource_loading)) {
945 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
946 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
947 HDD_IPA_LOG(LOG1, "STAT Query TX DIFF %d, RX DIFF %d",
948 *ipa_tx_diff, *ipa_rx_diff);
949 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530950 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951 return;
952}
953
954/**
955 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
956 * @adapter: network adapter
957 * @reason: STAT REQ Reason
958 *
959 * Return: None
960 */
961void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
962{
963 hdd_context_t *pHddCtx;
964 struct hdd_ipa_priv *hdd_ipa;
965
966 if (!adapter) {
967 return;
968 }
969
970 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
971 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
972 if (!hdd_ipa_is_enabled(pHddCtx) ||
973 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
974 return;
975 }
976
977 HDD_IPA_LOG(LOG1, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530978 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
980 (false == hdd_ipa->resource_loading)) {
981 hdd_ipa->stat_req_reason = reason;
982 wma_cli_set_command(
983 (int)adapter->sessionId,
984 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
985 0, VDEV_CMD);
986 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530987 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988}
989
990/**
991 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
992 * @hdd_ipa: Global HDD IPA context
993 * @sta_add: Should station be added
994 * @sta_id: ID of the station being queried
995 *
996 * Return: true if the station was found
997 */
998static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
999 bool sta_add, uint8_t sta_id)
1000{
1001 bool sta_found = false;
1002 uint8_t idx;
1003 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1004 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1005 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1006 sta_found = true;
1007 break;
1008 }
1009 }
1010 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301011 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 "%s: STA ID %d already exist, cannot add",
1013 __func__, sta_id);
1014 return sta_found;
1015 }
1016 if (sta_add) {
1017 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1018 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1019 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1020 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1021 return sta_found;
1022 }
1023 }
1024 }
1025 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301026 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 "%s: STA ID %d does not exist, cannot delete",
1028 __func__, sta_id);
1029 return sta_found;
1030 }
1031 if (!sta_add) {
1032 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1033 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1034 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1035 hdd_ipa->assoc_stas_map[idx].is_reserved =
1036 false;
1037 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1038 return sta_found;
1039 }
1040 }
1041 }
1042 return sta_found;
1043}
1044
1045/**
1046 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1047 * @hdd_ipa: Global HDD IPA context
1048 *
1049 * Return: 0 on success, negative errno if error
1050 */
1051static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1052{
1053 int result;
1054 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1055
1056 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301057 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001058 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1059 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1061 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301062 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 "%s: Enable TX PIPE fail, code %d",
1064 __func__, result);
1065 return result;
1066 }
1067 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1068 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301069 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 "%s: Resume TX PIPE fail, code %d",
1071 __func__, result);
1072 return result;
1073 }
1074 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1075
1076 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301077 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001078 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1079 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1081 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301082 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 "%s: Enable RX PIPE fail, code %d",
1084 __func__, result);
1085 return result;
1086 }
1087 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1088 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301089 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090 "%s: Resume RX PIPE fail, code %d",
1091 __func__, result);
1092 return result;
1093 }
1094 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001095 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 return 0;
1097}
1098
1099/**
1100 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1101 * @hdd_ipa: Global HDD IPA context
1102 *
1103 * Return: 0 on success, negative errno if error
1104 */
1105static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1106{
1107 int result;
1108
Leo Change3e49442015-10-26 20:07:13 -07001109 hdd_ipa->ipa_pipes_down = true;
1110
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301111 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001112 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1113 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301114 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 "%s: Suspend RX PIPE fail, code %d",
1116 __func__, result);
1117 return result;
1118 }
1119 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1120 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301121 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 "%s: Disable RX PIPE fail, code %d",
1123 __func__, result);
1124 return result;
1125 }
1126
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301127 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1129 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301130 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 "%s: Suspend TX PIPE fail, code %d",
1132 __func__, result);
1133 return result;
1134 }
1135 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1136 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301137 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 "%s: Disable TX PIPE fail, code %d",
1139 __func__, result);
1140 return result;
1141 }
1142
1143 return 0;
1144}
1145
1146/**
1147 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1148 * @hdd_ipa: Global HDD IPA context
1149 *
1150 * Return: 0 on success, negative errno if error
1151 */
1152static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1153{
1154 hdd_ipa->activated_fw_pipe = 0;
1155 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001156
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157 /* If RM feature enabled
1158 * Request PROD Resource first
1159 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001160 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1161 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1162 /* RM PROD request sync return
1163 * enable pipe immediately
1164 */
1165 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301166 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001167 "%s: IPA WDI Pipe activation failed",
1168 __func__);
1169 hdd_ipa->resource_loading = false;
1170 return -EBUSY;
1171 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 }
1173 } else {
1174 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001175 * Just enabled all the PIPEs
1176 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001177 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301178 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001179 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001180 __func__);
1181 hdd_ipa->resource_loading = false;
1182 return -EBUSY;
1183 }
1184 hdd_ipa->resource_loading = false;
1185 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001186
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301187 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001188 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001189 return 0;
1190}
1191
1192/**
1193 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1194 * @hdd_ipa: Global HDD IPA context
1195 *
1196 * Return: None
1197 */
1198static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1199{
1200 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1201
1202 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301203 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301205 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1207}
1208
1209/**
1210 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1211 * @context: User context registered with TL (the IPA Global context is
1212 * registered
1213 * @rxpkt: Packet containing the notification
1214 * @staid: ID of the station associated with the packet
1215 *
1216 * Return: None
1217 */
1218static void
1219hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1220{
1221 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301222 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223
1224 /*
1225 * When SSR is going on or driver is unloading, just return.
1226 */
1227 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
1228 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301229 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 return;
1231 }
1232
1233 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1234 return;
1235
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301236 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 __func__, event);
1238
1239 switch (event) {
1240 case IPA_RM_RESOURCE_GRANTED:
1241 /* Differed RM Granted */
1242 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301243 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244 if ((false == hdd_ipa->resource_unloading) &&
1245 (!hdd_ipa->activated_fw_pipe)) {
1246 hdd_ipa_uc_enable_pipes(hdd_ipa);
1247 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301248 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 break;
1250
1251 case IPA_RM_RESOURCE_RELEASED:
1252 /* Differed RM Released */
1253 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 break;
1255
1256 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301257 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 "%s, invalid event code %d", __func__, event);
1259 break;
1260 }
1261}
1262
1263/**
1264 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1265 * @hdd_ipa: Global HDD IPA context
1266 * @event: IPA resource manager event to be deferred
1267 *
1268 * This function is called when a resource manager event is received
1269 * from firmware in interrupt context. This function will defer the
1270 * handling to the OL RX thread
1271 *
1272 * Return: None
1273 */
1274static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1275{
1276 enum ipa_rm_event event;
1277 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1278 struct uc_rm_work_struct, work);
1279 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1280 struct hdd_ipa_priv, uc_rm_work);
1281
1282 cds_ssr_protect(__func__);
1283 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301284 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001285 "%s, posted event %d", __func__, event);
1286
1287 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1288 cds_ssr_unprotect(__func__);
1289
1290 return;
1291}
1292
1293/**
1294 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
1295 * @hdd_ipa: Global HDD IPA context
1296 *
1297 * Return: None
1298 */
1299static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
1300{
1301 unsigned int pending_event_count;
1302 struct ipa_uc_pending_event *pending_event = NULL;
1303
Anurag Chouhanffb21542016-02-17 14:33:03 +05301304 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301305 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001306 "%s, Pending Event Count %d", __func__, pending_event_count);
1307 if (!pending_event_count) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301308 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001309 "%s, No Pending Event", __func__);
1310 return;
1311 }
1312
Anurag Chouhanffb21542016-02-17 14:33:03 +05301313 qdf_list_remove_front(&hdd_ipa->pending_event,
1314 (qdf_list_node_t **)&pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 while (pending_event != NULL) {
1316 hdd_ipa_wlan_evt(pending_event->adapter,
1317 pending_event->type,
1318 pending_event->sta_id,
1319 pending_event->mac_addr);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301320 qdf_mem_free(pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 pending_event = NULL;
Anurag Chouhanffb21542016-02-17 14:33:03 +05301322 qdf_list_remove_front(&hdd_ipa->pending_event,
1323 (qdf_list_node_t **)&pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324 }
1325}
1326
1327/**
1328 * 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);
1361 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301362 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301363 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 return;
1365 }
1366
1367 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1368
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301369 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001370 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1371
1372 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1373 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301374 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375 hdd_ipa->activated_fw_pipe++;
1376 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1377 hdd_ipa->resource_loading = false;
1378 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001379 if (hdd_ipa->pending_cons_req)
1380 ipa_rm_notify_completion(
1381 IPA_RM_RESOURCE_GRANTED,
1382 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001383 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301385 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 }
1387
1388 if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
1389 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301390 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 hdd_ipa->activated_fw_pipe--;
1392 if (!hdd_ipa->activated_fw_pipe) {
1393 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001394 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1395 ipa_rm_release_resource(
1396 IPA_RM_RESOURCE_WLAN_PROD);
1397 /* Sync return success from IPA
1398 * Enable/resume all the PIPEs */
1399 hdd_ipa->resource_unloading = false;
1400 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1401 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301403 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 }
1405
1406 if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1407 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001408 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301410 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001412 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 "CE RING SIZE: %d\n"
1414 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001415 (unsigned long long)res->ce_sr_base_paddr,
1416 res->ce_sr_ring_size,
1417 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301418 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001420 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421 "COMP RING SIZE: %d\n"
1422 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001423 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001424 (unsigned long long)res->tx_comp_ring_base_paddr,
1425 res->tx_comp_ring_size,
1426 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001427 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301428 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001430 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001431 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001432 "IND RING DBELL : 0x%llx\n"
1433 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 "NUM EXCP PKT : %llu\n"
1435 "NUM TX BCMC : %llu\n"
1436 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001437 (unsigned long long)res->rx_rdy_ring_base_paddr,
1438 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001439 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001440 (unsigned long long)hdd_ipa->ipa_resource.
1441 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 hdd_ipa->stats.num_rx_excep,
1443 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001444 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301445 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1447 "SAP NUM STAs: %d\n"
1448 "STA CONNECTED: %d\n"
1449 "TX PIPE HDL: %d\n"
1450 "RX PIPE HDL : %d\n"
1451 "RSC LOADING : %d\n"
1452 "RSC UNLOADING : %d\n"
1453 "PNDNG CNS RQT : %d",
1454 hdd_ipa->sap_num_connected_sta,
1455 hdd_ipa->sta_connected,
1456 hdd_ipa->tx_pipe_handle,
1457 hdd_ipa->rx_pipe_handle,
1458 (unsigned int)hdd_ipa->resource_loading,
1459 (unsigned int)hdd_ipa->resource_unloading,
1460 (unsigned int)hdd_ipa->pending_cons_req);
1461
1462 /* STATs from FW */
1463 uc_fw_stat = (struct ipa_uc_fw_stats *)
1464 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301465 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 "==== IPA_UC WLAN_FW TX ====\n"
1467 "COMP RING BASE: 0x%x\n"
1468 "COMP RING SIZE: %d\n"
1469 "COMP RING DBELL : 0x%x\n"
1470 "COMP RING DBELL IND VAL : %d\n"
1471 "COMP RING DBELL CACHED VAL : %d\n"
1472 "COMP RING DBELL CACHED VAL : %d\n"
1473 "PKTS ENQ : %d\n"
1474 "PKTS COMP : %d\n"
1475 "IS SUSPEND : %d\n"
1476 "RSVD : 0x%x",
1477 uc_fw_stat->tx_comp_ring_base,
1478 uc_fw_stat->tx_comp_ring_size,
1479 uc_fw_stat->tx_comp_ring_dbell_addr,
1480 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1481 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1482 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1483 uc_fw_stat->tx_pkts_enqueued,
1484 uc_fw_stat->tx_pkts_completed,
1485 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301486 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 "==== IPA_UC WLAN_FW RX ====\n"
1488 "IND RING BASE: 0x%x\n"
1489 "IND RING SIZE: %d\n"
1490 "IND RING DBELL : 0x%x\n"
1491 "IND RING DBELL IND VAL : %d\n"
1492 "IND RING DBELL CACHED VAL : %d\n"
1493 "RDY IND ADDR : 0x%x\n"
1494 "RDY IND CACHE VAL : %d\n"
1495 "RFIL IND : %d\n"
1496 "NUM PKT INDICAT : %d\n"
1497 "BUF REFIL : %d\n"
1498 "NUM DROP NO SPC : %d\n"
1499 "NUM DROP NO BUF : %d\n"
1500 "IS SUSPND : %d\n"
1501 "RSVD : 0x%x\n",
1502 uc_fw_stat->rx_ind_ring_base,
1503 uc_fw_stat->rx_ind_ring_size,
1504 uc_fw_stat->rx_ind_ring_dbell_addr,
1505 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1506 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1507 uc_fw_stat->rx_ind_ring_rdidx_addr,
1508 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1509 uc_fw_stat->rx_refill_idx,
1510 uc_fw_stat->rx_num_pkts_indicated,
1511 uc_fw_stat->rx_buf_refilled,
1512 uc_fw_stat->rx_num_ind_drop_no_space,
1513 uc_fw_stat->rx_num_ind_drop_no_buf,
1514 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1515 /* STATs from IPA */
1516 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301517 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518 "==== IPA_UC IPA TX ====\n"
1519 "NUM PROCD : %d\n"
1520 "CE DBELL : 0x%x\n"
1521 "NUM DBELL FIRED : %d\n"
1522 "COMP RNG FULL : %d\n"
1523 "COMP RNG EMPT : %d\n"
1524 "COMP RNG USE HGH : %d\n"
1525 "COMP RNG USE LOW : %d\n"
1526 "BAM FIFO FULL : %d\n"
1527 "BAM FIFO EMPT : %d\n"
1528 "BAM FIFO USE HGH : %d\n"
1529 "BAM FIFO USE LOW : %d\n"
1530 "NUM DBELL : %d\n"
1531 "NUM UNEXP DBELL : %d\n"
1532 "NUM BAM INT HDL : 0x%x\n"
1533 "NUM BAM INT NON-RUN : 0x%x\n"
1534 "NUM QMB INT HDL : 0x%x",
1535 ipa_stat.tx_ch_stats.num_pkts_processed,
1536 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1537 ipa_stat.tx_ch_stats.num_db_fired,
1538 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1539 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1540 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1541 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1542 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1543 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1544 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1545 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1546 ipa_stat.tx_ch_stats.num_db,
1547 ipa_stat.tx_ch_stats.num_unexpected_db,
1548 ipa_stat.tx_ch_stats.num_bam_int_handled,
1549 ipa_stat.tx_ch_stats.
1550 num_bam_int_in_non_runnning_state,
1551 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1552
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301553 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554 "==== IPA_UC IPA RX ====\n"
1555 "MAX OST PKT : %d\n"
1556 "NUM PKT PRCSD : %d\n"
1557 "RNG RP : 0x%x\n"
1558 "COMP RNG FULL : %d\n"
1559 "COMP RNG EMPT : %d\n"
1560 "COMP RNG USE HGH : %d\n"
1561 "COMP RNG USE LOW : %d\n"
1562 "BAM FIFO FULL : %d\n"
1563 "BAM FIFO EMPT : %d\n"
1564 "BAM FIFO USE HGH : %d\n"
1565 "BAM FIFO USE LOW : %d\n"
1566 "NUM DB : %d\n"
1567 "NUM UNEXP DB : %d\n"
1568 "NUM BAM INT HNDL : 0x%x\n",
1569 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1570 ipa_stat.rx_ch_stats.num_pkts_processed,
1571 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1572 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1573 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1574 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1575 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1576 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1577 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1578 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1579 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1580 ipa_stat.rx_ch_stats.num_db,
1581 ipa_stat.rx_ch_stats.num_unexpected_db,
1582 ipa_stat.rx_ch_stats.num_bam_int_handled);
1583 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1584 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1585 /* STATs from FW */
1586 uc_fw_stat = (struct ipa_uc_fw_stats *)
1587 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301588 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1590 uc_fw_stat->tx_pkts_completed,
1591 hdd_ipa->ipa_p_tx_packets);
1592 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1593 (uc_fw_stat->rx_num_ind_drop_no_space +
1594 uc_fw_stat->rx_num_ind_drop_no_buf +
1595 uc_fw_stat->rx_num_pkts_indicated),
1596 hdd_ipa->ipa_p_rx_packets);
1597
1598 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1599 hdd_ipa->ipa_p_rx_packets =
1600 (uc_fw_stat->rx_num_ind_drop_no_space +
1601 uc_fw_stat->rx_num_ind_drop_no_buf +
1602 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301603 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 } else {
1605 HDD_IPA_LOG(LOGE, "INVALID REASON %d",
1606 hdd_ipa->stat_req_reason);
1607 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301608 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609}
1610
1611
1612/**
1613 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1614 * @adapter: device adapter instance
1615 * @offload_type: MCC or SCC
1616 * @enable: TX offload enable or disable
1617 *
1618 * Return: none
1619 */
1620static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1621 uint32_t offload_type, uint32_t enable)
1622{
1623 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
1624
1625 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1626 * channel change indication. Since these indications are sent by lower
1627 * layer as SAP updates and IPA doesn't have to do anything for these
1628 * updates so ignoring!
1629 */
1630 if (WLAN_HDD_SOFTAP == adapter->device_mode && adapter->ipa_context)
1631 return;
1632
1633 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1634 * channel change indication. Since these indications are sent by lower
1635 * layer as SAP updates and IPA doesn't have to do anything for these
1636 * updates so ignoring!
1637 */
1638 if (adapter->ipa_context)
1639 return;
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,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648 "%s: offload_type=%d, vdev_id=%d, enable=%d", __func__,
1649 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,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 "%s: Failure to enable IPA offload \
1658 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1659 ipa_offload_enable_disable.offload_type,
1660 ipa_offload_enable_disable.vdev_id,
1661 ipa_offload_enable_disable.enable);
1662 }
1663}
1664
1665/**
1666 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1667 * @work: uC OP work
1668 *
1669 * Return: None
1670 */
1671static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1672{
1673 struct op_msg_type *msg;
1674 struct uc_op_work_struct *uc_op_work = container_of(work,
1675 struct uc_op_work_struct, work);
1676 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1677
1678 cds_ssr_protect(__func__);
1679
1680 msg = uc_op_work->msg;
1681 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301682 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 "%s, posted msg %d", __func__, msg->op_code);
1684
1685 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1686
1687 cds_ssr_unprotect(__func__);
1688
1689 return;
1690}
1691
1692/**
1693 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1694 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1695 * @op_msg: operation message received from firmware
1696 * @hdd_ctx: Global HDD context
1697 *
1698 * Return: None
1699 */
1700static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1701{
1702 struct hdd_ipa_priv *hdd_ipa;
1703 struct op_msg_type *msg;
1704 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301705 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706
1707 status = wlan_hdd_validate_context(hdd_ctx);
1708 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301709 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001710 goto end;
1711 }
1712
1713 msg = (struct op_msg_type *)op_msg;
1714 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1715
1716 if (unlikely(!hdd_ipa))
1717 goto end;
1718
1719 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301720 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721 __func__, msg->op_code);
1722 goto end;
1723 }
1724
1725 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1726 if (uc_op_work->msg)
1727 /* When the same uC OPCODE is already pended, just return */
1728 goto end;
1729
1730 uc_op_work->msg = msg;
1731 schedule_work(&uc_op_work->work);
1732 return;
1733
1734end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301735 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001736}
1737
1738/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001739 * hdd_ipa_init_uc_op_work - init ipa uc op work
1740 * @work: struct work_struct
1741 * @work_handler: work_handler
1742 *
1743 * Return: none
1744 */
1745#ifdef CONFIG_CNSS
1746static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1747 work_func_t work_handler)
1748{
1749 cnss_init_work(work, work_handler);
1750}
1751#else
1752static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1753 work_func_t work_handler)
1754{
1755 INIT_WORK(work, work_handler);
1756}
1757#endif
1758
1759
1760/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1762 * @hdd_ctx: Global HDD context
1763 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301764 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001765 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301766static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767{
1768 struct ipa_wdi_in_params pipe_in;
1769 struct ipa_wdi_out_params pipe_out;
1770 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1771 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1772 uint8_t i;
1773
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301774 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1775 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776
Anurag Chouhanffb21542016-02-17 14:33:03 +05301777 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301778 qdf_mutex_create(&ipa_ctxt->event_lock);
1779 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780
1781 /* TX PIPE */
1782 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1783 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1784 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1785 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1786 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1787 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1788 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1789 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1790 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1791 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1792 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1793 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1794 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301795 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001796 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1797 pipe_in.sys.keep_ipa_awake = true;
1798 }
1799
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001800 pipe_in.u.dl.comp_ring_base_pa =
1801 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001802 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001803 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1804 sizeof(qdf_dma_addr_t);
1805 pipe_in.u.dl.ce_ring_base_pa =
1806 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1807 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1808 pipe_in.u.dl.ce_ring_size =
1809 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1810 pipe_in.u.dl.num_tx_buffers =
1811 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001812
1813 /* Connect WDI IPA PIPE */
1814 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1815 /* Micro Controller Doorbell register */
Leo Chang3bc8fed2015-11-13 10:59:47 -08001816 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001817 /* WLAN TX PIPE Handle */
1818 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301819 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001820 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1821 " CERZ %d, NB %d, CDBPAD 0x%x",
1822 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1823 pipe_in.u.dl.comp_ring_size,
1824 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1825 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1826 pipe_in.u.dl.ce_ring_size,
1827 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001828 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001829
1830 /* RX PIPE */
1831 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1832 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1833 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1834 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1835 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1836 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1837 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1838 sizeof(struct sps_iovec);
1839 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1840 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301841 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1843 pipe_in.sys.keep_ipa_awake = true;
1844 }
1845
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001846 pipe_in.u.ul.rdy_ring_base_pa =
1847 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1848 pipe_in.u.ul.rdy_ring_size =
1849 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1850 pipe_in.u.ul.rdy_ring_rp_pa =
1851 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001852 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001854 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301856 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1858 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1859 pipe_in.u.ul.rdy_ring_size,
1860 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001861 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862
1863 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001864 ipa_ctxt->tx_comp_doorbell_paddr,
1865 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866
1867 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1868 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1869
1870 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001871 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872 hdd_ipa_uc_fw_op_event_handler);
1873 ipa_ctxt->uc_op_work[i].msg = NULL;
1874 }
1875
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301876 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877}
1878
Leo Change3e49442015-10-26 20:07:13 -07001879/**
1880 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1881 * @hdd_ctx: hdd main context
1882 *
1883 * Force shutdown IPA pipe
1884 * Independent of FW pipe status, IPA pipe shutdonw progress
1885 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1886 * independent from FW pipe status
1887 *
1888 * Return: NONE
1889 */
1890void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1891{
1892 struct hdd_ipa_priv *hdd_ipa;
1893
1894 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1895 return;
1896
1897 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1898 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301899 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001900 "IPA pipes are not down yet, force shutdown");
1901 hdd_ipa_uc_disable_pipes(hdd_ipa);
1902 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301903 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001904 "IPA pipes are down, do nothing");
1905 }
1906
1907 return;
1908}
1909
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910/**
1911 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1912 *
1913 * Deinit basic IPA UC host side to be in sync reloaded FW during
1914 * SSR
1915 *
1916 * Return: 0 - Success
1917 */
1918int hdd_ipa_uc_ssr_deinit(void)
1919{
1920 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1921 int idx;
1922 struct hdd_ipa_iface_context *iface_context;
1923
Leo Chang3bc8fed2015-11-13 10:59:47 -08001924 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 return 0;
1926
1927 /* Clean up HDD IPA interfaces */
1928 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1929 (idx < HDD_IPA_MAX_IFACE); idx++) {
1930 iface_context = &hdd_ipa->iface_context[idx];
1931 if (iface_context && iface_context->adapter)
1932 hdd_ipa_cleanup_iface(iface_context);
1933 }
1934
1935 /* After SSR, wlan driver reloads FW again. But we need to protect
1936 * IPA submodule during SSR transient state. So deinit basic IPA
1937 * UC host side to be in sync with reloaded FW during SSR
1938 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001939 if (!hdd_ipa->ipa_pipes_down)
1940 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001941
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301942 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001943 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1944 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1945 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1946 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301947 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001948
1949 /* Full IPA driver cleanup not required since wlan driver is now
1950 * unloaded and reloaded after SSR.
1951 */
1952 return 0;
1953}
1954
1955/**
1956 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1957 *
1958 * Init basic IPA UC host side to be in sync with reloaded FW after
1959 * SSR to resume IPA UC operations
1960 *
1961 * Return: 0 - Success
1962 */
1963int hdd_ipa_uc_ssr_reinit(void)
1964{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001965
1966 /* After SSR is complete, IPA UC can resume operation. But now wlan
1967 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1968 * and initialization. This is a placeholder func if IPA has to resume
1969 * operations without driver reload.
1970 */
1971 return 0;
1972}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001973
1974/**
1975 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1976 * @hdd_ctx: Global HDD context
1977 * @skb: skb sent to IPA
1978 * @session_id: send packet instance session id
1979 *
1980 * Send TX packet which generated by system to IPA.
1981 * This routine only will be used for function verification
1982 *
1983 * Return: NULL packet sent to IPA properly
1984 * NULL invalid packet drop
1985 * skb packet not sent to IPA. legacy data path should handle
1986 */
1987struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1988 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001989{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001990 struct ipa_header *ipa_header;
1991 struct frag_header *frag_header;
1992
1993 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1994 return skb;
1995
1996 ipa_header = (struct ipa_header *) skb_push(skb,
1997 sizeof(struct ipa_header));
1998 if (!ipa_header) {
1999 /* No headroom, legacy */
2000 return skb;
2001 }
2002 memset(ipa_header, 0, sizeof(*ipa_header));
2003 ipa_header->vdev_id = 0;
2004
2005 frag_header = (struct frag_header *) skb_push(skb,
2006 sizeof(struct frag_header));
2007 if (!frag_header) {
2008 /* No headroom, drop */
2009 kfree_skb(skb);
2010 return NULL;
2011 }
2012 memset(frag_header, 0, sizeof(*frag_header));
2013 frag_header->length = skb->len - sizeof(struct frag_header)
2014 - sizeof(struct ipa_header);
2015
2016 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2017 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002018}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019
2020/**
2021 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2022 * @work: scheduled work
2023 *
2024 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2025 * not want to immediately release the wake lock since the system
2026 * would then potentially try to suspend when there is a healthy data
2027 * rate. Deferred work is scheduled and this function handles the
2028 * work. When this function is called, if the IPA resource is still
2029 * released then we release the wake lock.
2030 *
2031 * Return: None
2032 */
2033static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2034{
2035 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2036 struct hdd_ipa_priv,
2037 wake_lock_work);
2038
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302039 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002040
2041 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2042 goto end;
2043
2044 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302045 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046 WIFI_POWER_EVENT_WAKELOCK_IPA);
2047
2048end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302049 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050}
2051
2052/**
2053 * hdd_ipa_rm_request() - Request resource from IPA
2054 * @hdd_ipa: Global HDD IPA context
2055 *
2056 * Return: 0 on success, negative errno on error
2057 */
2058static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2059{
2060 int ret = 0;
2061
2062 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2063 return 0;
2064
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302065 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066
2067 switch (hdd_ipa->rm_state) {
2068 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302069 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002070 return 0;
2071 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302072 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002073 return -EINPROGRESS;
2074 case HDD_IPA_RM_RELEASED:
2075 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2076 break;
2077 }
2078
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302079 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002080
2081 ret = ipa_rm_inactivity_timer_request_resource(
2082 IPA_RM_RESOURCE_WLAN_PROD);
2083
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302084 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085 if (ret == 0) {
2086 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2087 hdd_ipa->stats.num_rm_grant_imm++;
2088 }
2089
2090 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2091 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302092 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002093 WIFI_POWER_EVENT_WAKELOCK_IPA);
2094 hdd_ipa->wake_lock_released = false;
2095 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302096 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002097
2098 return ret;
2099}
2100
2101/**
2102 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2103 * @hdd_ipa: Global HDD IPA context
2104 *
2105 * Return: 0 if resources released, negative errno otherwise
2106 */
2107static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2108{
2109 int ret = 0;
2110
2111 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2112 return 0;
2113
2114 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2115 return -EAGAIN;
2116
2117 spin_lock_bh(&hdd_ipa->q_lock);
2118 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2119 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2120 spin_unlock_bh(&hdd_ipa->q_lock);
2121 return -EAGAIN;
2122 }
2123 spin_unlock_bh(&hdd_ipa->q_lock);
2124
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302125 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126
Nirav Shahcbc6d722016-03-01 16:24:53 +05302127 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302128 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002129 return -EAGAIN;
2130 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302131 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002132
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302133 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134 switch (hdd_ipa->rm_state) {
2135 case HDD_IPA_RM_GRANTED:
2136 break;
2137 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302138 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139 return -EINPROGRESS;
2140 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302141 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002142 return 0;
2143 }
2144
2145 /* IPA driver returns immediately so set the state here to avoid any
2146 * race condition.
2147 */
2148 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2149 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302150 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151
2152 ret =
2153 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2154
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302155 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002156 if (unlikely(ret != 0)) {
2157 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2158 WARN_ON(1);
2159 }
2160
2161 /*
2162 * If wake_lock is released immediately, kernel would try to suspend
2163 * immediately as well, Just avoid ping-pong between suspend-resume
2164 * while there is healthy amount of data transfer going on by
2165 * releasing the wake_lock after some delay.
2166 */
2167 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2168 msecs_to_jiffies
2169 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2170
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302171 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002172
2173 return ret;
2174}
2175
2176/**
2177 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2178 * @user_data: user data registered with IPA
2179 * @event: the IPA resource manager event that occurred
2180 * @data: the data associated with the event
2181 *
2182 * Return: None
2183 */
2184static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2185 unsigned long data)
2186{
2187 struct hdd_ipa_priv *hdd_ipa = user_data;
2188
2189 if (unlikely(!hdd_ipa))
2190 return;
2191
2192 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2193 return;
2194
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302195 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002196
2197 switch (event) {
2198 case IPA_RM_RESOURCE_GRANTED:
2199 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2200 /* RM Notification comes with ISR context
2201 * it should be serialized into work queue to avoid
2202 * ISR sleep problem
2203 */
2204 hdd_ipa->uc_rm_work.event = event;
2205 schedule_work(&hdd_ipa->uc_rm_work.work);
2206 break;
2207 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302208 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002209 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302210 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002211 hdd_ipa->stats.num_rm_grant++;
2212 break;
2213
2214 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302215 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002216 hdd_ipa->resource_unloading = false;
2217 break;
2218
2219 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302220 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002221 break;
2222 }
2223}
2224
2225/**
2226 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2227 *
2228 * Callback function registered with IPA that is called when IPA wants
2229 * to release the WLAN consumer resource
2230 *
2231 * Return: 0 if the request is granted, negative errno otherwise
2232 */
2233static int hdd_ipa_rm_cons_release(void)
2234{
2235 return 0;
2236}
2237
2238/**
2239 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2240 *
2241 * Callback function registered with IPA that is called when IPA wants
2242 * to access the WLAN consumer resource
2243 *
2244 * Return: 0 if the request is granted, negative errno otherwise
2245 */
2246static int hdd_ipa_rm_cons_request(void)
2247{
Yun Park4d8b60a2015-10-22 13:59:32 -07002248 int ret = 0;
2249
2250 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302251 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002252 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253 __func__);
2254 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002255 ret = -EINPROGRESS;
2256 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302257 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002258 "%s: IPA resource unloading in progress",
2259 __func__);
2260 ghdd_ipa->pending_cons_req = true;
2261 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002262 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002263
2264 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002265}
2266
2267/**
2268 * hdd_ipa_set_perf_level() - Set IPA performance level
2269 * @hdd_ctx: Global HDD context
2270 * @tx_packets: Number of packets transmitted in the last sample period
2271 * @rx_packets: Number of packets received in the last sample period
2272 *
2273 * Return: 0 on success, negative errno on error
2274 */
2275int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2276 uint64_t rx_packets)
2277{
2278 uint32_t next_cons_bw, next_prod_bw;
2279 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2280 struct ipa_rm_perf_profile profile;
2281 int ret;
2282
2283 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2284 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2285 return 0;
2286
2287 memset(&profile, 0, sizeof(profile));
2288
2289 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2290 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2291 else if (tx_packets >
2292 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2293 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2294 else
2295 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2296
2297 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2298 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2299 else if (rx_packets >
2300 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2301 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2302 else
2303 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2304
2305 HDD_IPA_LOG(LOG1,
2306 "CONS perf curr: %d, next: %d",
2307 hdd_ipa->curr_cons_bw, next_cons_bw);
2308 HDD_IPA_LOG(LOG1,
2309 "PROD perf curr: %d, next: %d",
2310 hdd_ipa->curr_prod_bw, next_prod_bw);
2311
2312 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302313 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002314 "Requesting CONS perf curr: %d, next: %d",
2315 hdd_ipa->curr_cons_bw, next_cons_bw);
2316 profile.max_supported_bandwidth_mbps = next_cons_bw;
2317 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2318 &profile);
2319 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302320 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002321 "RM CONS set perf profile failed: %d", ret);
2322
2323 return ret;
2324 }
2325 hdd_ipa->curr_cons_bw = next_cons_bw;
2326 hdd_ipa->stats.num_cons_perf_req++;
2327 }
2328
2329 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302330 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002331 "Requesting PROD perf curr: %d, next: %d",
2332 hdd_ipa->curr_prod_bw, next_prod_bw);
2333 profile.max_supported_bandwidth_mbps = next_prod_bw;
2334 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2335 &profile);
2336 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302337 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002338 "RM PROD set perf profile failed: %d", ret);
2339 return ret;
2340 }
2341 hdd_ipa->curr_prod_bw = next_prod_bw;
2342 hdd_ipa->stats.num_prod_perf_req++;
2343 }
2344
2345 return 0;
2346}
2347
2348/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002349 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2350 * @work: struct work_struct
2351 * @work_handler: work_handler
2352 *
2353 * Return: none
2354 */
2355#ifdef CONFIG_CNSS
2356static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2357 work_func_t work_handler)
2358{
2359 cnss_init_work(work, work_handler);
2360}
2361#else
2362static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2363 work_func_t work_handler)
2364{
2365 INIT_WORK(work, work_handler);
2366}
2367#endif
2368
2369/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002370 * hdd_ipa_setup_rm() - Setup IPA resource management
2371 * @hdd_ipa: Global HDD IPA context
2372 *
2373 * Return: 0 on success, negative errno on error
2374 */
2375static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2376{
2377 struct ipa_rm_create_params create_params = { 0 };
2378 int ret;
2379
2380 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2381 return 0;
2382
Rajeev Kumar217f2172016-01-06 18:11:55 -08002383 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2384 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002385 memset(&create_params, 0, sizeof(create_params));
2386 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2387 create_params.reg_params.user_data = hdd_ipa;
2388 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2389 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2390
2391 ret = ipa_rm_create_resource(&create_params);
2392 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302393 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002394 "Create RM resource failed: %d", ret);
2395 goto setup_rm_fail;
2396 }
2397
2398 memset(&create_params, 0, sizeof(create_params));
2399 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2400 create_params.request_resource = hdd_ipa_rm_cons_request;
2401 create_params.release_resource = hdd_ipa_rm_cons_release;
2402 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2403
2404 ret = ipa_rm_create_resource(&create_params);
2405 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302406 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002407 "Create RM CONS resource failed: %d", ret);
2408 goto delete_prod;
2409 }
2410
2411 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2412 IPA_RM_RESOURCE_APPS_CONS);
2413
2414 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2415 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2416 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302417 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002418 ret);
2419 goto timer_init_failed;
2420 }
2421
2422 /* Set the lowest bandwidth to start with */
2423 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2424
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 "Set perf level failed: %d", ret);
2428 goto set_perf_failed;
2429 }
2430
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302431 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002432#ifdef CONFIG_CNSS
2433 cnss_init_delayed_work(&hdd_ipa->wake_lock_work,
2434 hdd_ipa_wake_lock_timer_func);
2435#else
2436 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2437 hdd_ipa_wake_lock_timer_func);
2438#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302439 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002440 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2441 hdd_ipa->wake_lock_released = true;
2442 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2443
2444 return ret;
2445
2446set_perf_failed:
2447 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2448
2449timer_init_failed:
2450 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2451
2452delete_prod:
2453 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2454
2455setup_rm_fail:
2456 return ret;
2457}
2458
2459/**
2460 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2461 * @hdd_ipa: Global HDD IPA context
2462 *
2463 * Destroys all resources associated with the IPA resource manager
2464 *
2465 * Return: None
2466 */
2467static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2468{
2469 int ret;
2470
2471 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2472 return;
2473
2474 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302475 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002476
2477#ifdef WLAN_OPEN_SOURCE
2478 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2479#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302480 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002481
2482 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2483
2484 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2485 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302486 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002487 "RM PROD resource delete failed %d", ret);
2488
2489 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
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 "RM CONS resource delete failed %d", ret);
2493}
2494
2495/**
2496 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2497 * @skb: network buffer
2498 * @adapter: network adapter
2499 *
2500 * Called when a network buffer is received which should not be routed
2501 * to the IPA module.
2502 *
2503 * Return: None
2504 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302505static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002506 hdd_adapter_t *adapter)
2507{
2508 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2509 unsigned int cpu_index;
2510
2511 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302512 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002513 adapter);
2514 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302515 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002516 return;
2517 }
2518
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002519 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002520 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302521 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002522 return;
2523 }
2524
2525 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2526 skb->dev = adapter->dev;
2527 skb->protocol = eth_type_trans(skb, skb->dev);
2528 skb->ip_summed = CHECKSUM_NONE;
2529
2530 cpu_index = wlan_hdd_get_cpu();
2531
2532 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2533 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2534 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2535 else
2536 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2537
2538 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2539 adapter->dev->last_rx = jiffies;
2540}
2541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002542/**
2543 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
2544 * @priv: pointer to private data registered with IPA (we register a
2545 * pointer to the global IPA context)
2546 * @evt: the IPA event which triggered the callback
2547 * @data: data associated with the event
2548 *
2549 * Return: None
2550 */
2551static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2552 unsigned long data)
2553{
2554 struct hdd_ipa_priv *hdd_ipa = NULL;
2555 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302556 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557 uint8_t iface_id;
2558 uint8_t session_id;
2559 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302560 qdf_nbuf_t copy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002561 uint8_t fw_desc;
2562 int ret;
2563
2564 hdd_ipa = (struct hdd_ipa_priv *)priv;
2565
2566 switch (evt) {
2567 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302568 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2570 session_id = (uint8_t)skb->cb[0];
2571 iface_id = vdev_to_iface[session_id];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302572 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002573 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2574 session_id, iface_id);
2575 } else {
2576 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2577 }
2578
2579 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302580 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581 "IPA_RECEIVE: Invalid iface_id: %u",
2582 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302583 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002584 "w2i -- skb", skb->data, 8);
2585 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302586 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002587 return;
2588 }
2589
2590 iface_context = &hdd_ipa->iface_context[iface_id];
2591 adapter = iface_context->adapter;
2592
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302593 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594 "w2i -- skb", skb->data, 8);
2595 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2596 hdd_ipa->stats.num_rx_excep++;
2597 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2598 } else {
2599 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2600 }
2601
2602 iface_context->stats.num_rx_ipa_excep++;
2603
2604 /* Disable to forward Intra-BSS Rx packets when
2605 * ap_isolate=1 in hostapd.conf
2606 */
2607 if (adapter->sessionCtx.ap.apDisableIntraBssFwd) {
2608 /*
2609 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2610 * all Rx packets to IPA uC, which need to be forwarded
2611 * to other interface.
2612 * And, IPA driver will send back to WLAN host driver
2613 * through exception pipe with fw_desc field set by FW.
2614 * Here we are checking fw_desc field for FORWARD bit
2615 * set, and forward to Tx. Then copy to kernel stack
2616 * only when DISCARD bit is not set.
2617 */
2618 fw_desc = (uint8_t)skb->cb[1];
2619
Leo Chang3bc8fed2015-11-13 10:59:47 -08002620 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002621 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302622 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002623 "Forward packet to Tx (fw_desc=%d)",
2624 fw_desc);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302625 copy = qdf_nbuf_copy(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002626 if (copy) {
2627 hdd_ipa->ipa_tx_forward++;
2628 ret = hdd_softap_hard_start_xmit(
2629 (struct sk_buff *)copy,
2630 adapter->dev);
2631 if (ret) {
2632 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302633 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634 "Forward packet tx fail");
2635 hdd_ipa->stats.
2636 num_tx_bcmc_err++;
2637 } else {
2638 hdd_ipa->stats.num_tx_bcmc++;
2639 }
2640 }
2641 }
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002642
Leo Chang3bc8fed2015-11-13 10:59:47 -08002643 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002644 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2645 hdd_ipa->ipa_rx_discard++;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302646 qdf_nbuf_free(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002647 break;
2648 }
2649
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002650 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302651 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002652 "Intra-BSS FWD is disabled-skip forward to Tx");
2653 }
2654
2655 hdd_ipa_send_skb_to_network(skb, adapter);
2656 break;
2657
2658 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302659 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660 "w2i cb wrong event: 0x%x", evt);
2661 return;
2662 }
2663}
2664
2665/**
2666 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2667 * @skb: packet buffer which was transmitted
2668 *
2669 * Return: None
2670 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302671void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002672{
2673 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2674
Nirav Shahcbc6d722016-03-01 16:24:53 +05302675 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
2676 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002677 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302678 ipa_free_skb((struct ipa_rx_data *)
2679 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002680
2681 hdd_ipa->stats.num_tx_comp_cnt++;
2682
2683 atomic_dec(&hdd_ipa->tx_ref_cnt);
2684
2685 hdd_ipa_rm_try_release(hdd_ipa);
2686}
2687
2688/**
2689 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2690 * @iface_context: interface-specific IPA context
2691 * @ipa_tx_desc: packet data descriptor
2692 *
2693 * Return: None
2694 */
2695static void hdd_ipa_send_pkt_to_tl(
2696 struct hdd_ipa_iface_context *iface_context,
2697 struct ipa_rx_data *ipa_tx_desc)
2698{
2699 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2700 uint8_t interface_id;
2701 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302702 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002703
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302704 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705 adapter = iface_context->adapter;
2706 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302707 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002708 ipa_free_skb(ipa_tx_desc);
2709 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302710 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711 hdd_ipa_rm_try_release(hdd_ipa);
2712 return;
2713 }
2714
2715 /*
2716 * During CAC period, data packets shouldn't be sent over the air so
2717 * drop all the packets here
2718 */
2719 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2720 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302721 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722 iface_context->stats.num_tx_cac_drop++;
2723 hdd_ipa_rm_try_release(hdd_ipa);
2724 return;
2725 }
2726
2727 interface_id = adapter->sessionId;
2728 ++adapter->stats.tx_packets;
2729
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302730 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731
2732 skb = ipa_tx_desc->skb;
2733
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302734 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302735 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002736 /* FIXME: This is broken. No such field in cb any more:
2737 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302739 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002740 ipa_tx_desc->dma_addr
2741 + HDD_IPA_WLAN_FRAG_HEADER
2742 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 ipa_tx_desc->skb->len -=
2744 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2745 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302746 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002748 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302749 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002750
2751 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2752
2753 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2754 ipa_tx_desc->skb);
2755 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302756 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757 ipa_free_skb(ipa_tx_desc);
2758 iface_context->stats.num_tx_err++;
2759 hdd_ipa_rm_try_release(hdd_ipa);
2760 return;
2761 }
2762
2763 atomic_inc(&hdd_ipa->tx_ref_cnt);
2764
2765 iface_context->stats.num_tx++;
2766
2767}
2768
2769/**
2770 * hdd_ipa_pm_send_pkt_to_tl() - Send queued packets to TL
2771 * @work: pointer to the scheduled work
2772 *
2773 * Called during PM resume to send packets to TL which were queued
2774 * while host was in the process of suspending.
2775 *
2776 * Return: None
2777 */
2778static void hdd_ipa_pm_send_pkt_to_tl(struct work_struct *work)
2779{
2780 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2781 struct hdd_ipa_priv,
2782 pm_work);
2783 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302784 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785 uint32_t dequeued = 0;
2786
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302787 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788
Nirav Shahcbc6d722016-03-01 16:24:53 +05302789 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2790 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302791 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792
2793 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2794
2795 dequeued++;
2796
2797 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
2798 pm_tx_cb->ipa_tx_desc);
2799
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302800 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801 }
2802
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302803 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002804
2805 hdd_ipa->stats.num_tx_dequeued += dequeued;
2806 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2807 hdd_ipa->stats.num_max_pm_queue = dequeued;
2808}
2809
2810/**
2811 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2812 * @priv: pointer to private data registered with IPA (we register a
2813 * pointer to the interface-specific IPA context)
2814 * @evt: the IPA event which triggered the callback
2815 * @data: data associated with the event
2816 *
2817 * Return: None
2818 */
2819static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2820 unsigned long data)
2821{
2822 struct hdd_ipa_priv *hdd_ipa = NULL;
2823 struct ipa_rx_data *ipa_tx_desc;
2824 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302825 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002826 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302827 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002828
Mukul Sharma81661ae2015-10-30 20:26:02 +05302829 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302831 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 dev_kfree_skb_any(skb);
2833 iface_context->stats.num_tx_drop++;
2834 return;
2835 }
2836
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837 ipa_tx_desc = (struct ipa_rx_data *)data;
2838
2839 hdd_ipa = iface_context->hdd_ipa;
2840
2841 /*
2842 * When SSR is going on or driver is unloading, just drop the packets.
2843 * During SSR, there is no use in queueing the packets as STA has to
2844 * connect back any way
2845 */
2846 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2847 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302848 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002849 ipa_free_skb(ipa_tx_desc);
2850 iface_context->stats.num_tx_drop++;
2851 return;
2852 }
2853
2854 skb = ipa_tx_desc->skb;
2855
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302856 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002857
2858 /*
2859 * If PROD resource is not requested here then there may be cases where
2860 * IPA hardware may be clocked down because of not having proper
2861 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2862 * workaround to request PROD resource while data is going over CONS
2863 * pipe to prevent the IPA hardware clockdown.
2864 */
2865 hdd_ipa_rm_request(hdd_ipa);
2866
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302867 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002868 /*
2869 * If host is still suspended then queue the packets and these will be
2870 * drained later when resume completes. When packet is arrived here and
2871 * host is suspended, this means that there is already resume is in
2872 * progress.
2873 */
2874 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302875 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002876 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2877 pm_tx_cb->iface_context = iface_context;
2878 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302879 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002880 hdd_ipa->stats.num_tx_queued++;
2881
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302882 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002883 return;
2884 }
2885
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302886 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002887
2888 /*
2889 * If we are here means, host is not suspended, wait for the work queue
2890 * to finish.
2891 */
2892#ifdef WLAN_OPEN_SOURCE
2893 flush_work(&hdd_ipa->pm_work);
2894#endif
2895
2896 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2897}
2898
2899/**
2900 * hdd_ipa_suspend() - Suspend IPA
2901 * @hdd_ctx: Global HDD context
2902 *
2903 * Return: 0 on success, negativer errno on error
2904 */
2905int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2906{
2907 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2908
2909 if (!hdd_ipa_is_enabled(hdd_ctx))
2910 return 0;
2911
2912 /*
2913 * Check if IPA is ready for suspend, If we are here means, there is
2914 * high chance that suspend would go through but just to avoid any race
2915 * condition after suspend started, these checks are conducted before
2916 * allowing to suspend.
2917 */
2918 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2919 return -EAGAIN;
2920
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302921 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922
2923 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302924 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002925 return -EAGAIN;
2926 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302927 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002928
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302929 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302931 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002932
2933 return 0;
2934}
2935
2936/**
2937 * hdd_ipa_resume() - Resume IPA following suspend
2938 * hdd_ctx: Global HDD context
2939 *
2940 * Return: 0 on success, negative errno on error
2941 */
2942int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2943{
2944 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2945
2946 if (!hdd_ipa_is_enabled(hdd_ctx))
2947 return 0;
2948
2949 schedule_work(&hdd_ipa->pm_work);
2950
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302951 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002952 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302953 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002954
2955 return 0;
2956}
2957
2958/**
2959 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
2960 * @hdd_ipa: Global HDD IPA context
2961 *
2962 * Return: 0 on success, negative errno on error
2963 */
2964static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
2965{
2966 int i, ret = 0;
2967 struct ipa_sys_connect_params *ipa;
2968 uint32_t desc_fifo_sz;
2969
2970 /* The maximum number of descriptors that can be provided to a BAM at
2971 * once is one less than the total number of descriptors that the buffer
2972 * can contain.
2973 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2974 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2975 * be provided at once.
2976 * Because of above requirement, one extra descriptor will be added to
2977 * make sure hardware always has one descriptor.
2978 */
2979 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
2980 + sizeof(struct sps_iovec);
2981
2982 /*setup TX pipes */
2983 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2984 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
2985
2986 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
2987 ipa->desc_fifo_sz = desc_fifo_sz;
2988 ipa->priv = &hdd_ipa->iface_context[i];
2989 ipa->notify = hdd_ipa_i2w_cb;
2990
2991 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2992 ipa->ipa_ep_cfg.hdr.hdr_len =
2993 HDD_IPA_UC_WLAN_TX_HDR_LEN;
2994 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2995 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2996 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2997 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
2998 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2999 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3000 } else {
3001 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3002 }
3003 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3004
3005 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3006 ipa->keep_ipa_awake = 1;
3007
3008 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3009 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303010 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 " ret: %d", i, ret);
3012 goto setup_sys_pipe_fail;
3013 }
3014 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3015 }
3016
3017 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3018 /*
3019 * Hard code it here, this can be extended if in case
3020 * PROD pipe is also per interface.
3021 * Right now there is no advantage of doing this.
3022 */
3023 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3024
3025 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3026
3027 ipa->client = hdd_ipa->prod_client;
3028
3029 ipa->desc_fifo_sz = desc_fifo_sz;
3030 ipa->priv = hdd_ipa;
3031 ipa->notify = hdd_ipa_w2i_cb;
3032
3033 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3034 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3035 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3036 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3037
3038 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3039 ipa->keep_ipa_awake = 1;
3040
3041 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3042 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303043 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003044 "Failed for RX pipe: %d", ret);
3045 goto setup_sys_pipe_fail;
3046 }
3047 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3048 }
3049
3050 return ret;
3051
3052setup_sys_pipe_fail:
3053
3054 while (--i >= 0) {
3055 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303056 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003057 sizeof(struct hdd_ipa_sys_pipe));
3058 }
3059
3060 return ret;
3061}
3062
3063/**
3064 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3065 * @hdd_ipa: Global HDD IPA context
3066 *
3067 * Return: None
3068 */
3069static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3070{
3071 int ret = 0, i;
3072 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3073 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3074 ret =
3075 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3076 conn_hdl);
3077 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303078 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003079 ret);
3080
3081 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3082 }
3083 }
3084}
3085
3086/**
3087 * hdd_ipa_register_interface() - register IPA interface
3088 * @hdd_ipa: Global IPA context
3089 * @iface_context: Per-interface IPA context
3090 *
3091 * Return: 0 on success, negative errno on error
3092 */
3093static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3094 struct hdd_ipa_iface_context
3095 *iface_context)
3096{
3097 struct ipa_tx_intf tx_intf;
3098 struct ipa_rx_intf rx_intf;
3099 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3100 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3101 char *ifname = iface_context->adapter->dev->name;
3102
3103 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3104 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3105
3106 int num_prop = 1;
3107 int ret = 0;
3108
3109 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3110 num_prop++;
3111
3112 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3113 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303114 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003115 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303116 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117 goto register_interface_fail;
3118 }
3119
3120 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3121 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303122 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303124 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125 goto register_interface_fail;
3126 }
3127
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303128 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3129 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003130
3131 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3132 ifname, HDD_IPA_IPV4_NAME_EXT);
3133 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3134 ifname, HDD_IPA_IPV6_NAME_EXT);
3135
3136 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3137 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3138 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3139 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3140
3141 /*
3142 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3143 * mask to identify the interface in IPA hardware
3144 */
3145 rx_prop[IPA_IP_v4].attrib.meta_data =
3146 htonl(iface_context->adapter->sessionId << 16);
3147 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3148
3149 rx_intf.num_props++;
3150 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3151 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3152 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3153 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3154 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3155 rx_prop[IPA_IP_v4].attrib.meta_data =
3156 htonl(iface_context->adapter->sessionId << 16);
3157 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3158
3159 rx_intf.num_props++;
3160 }
3161
3162 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3163 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3164 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3165 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3166 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3167 IPA_RESOURCE_NAME_MAX);
3168 tx_intf.num_props++;
3169
3170 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3171 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3172 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3173 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3174 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3175 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3176 IPA_RESOURCE_NAME_MAX);
3177 tx_intf.num_props++;
3178 }
3179
3180 tx_intf.prop = tx_prop;
3181 rx_intf.prop = rx_prop;
3182
3183 /* Call the ipa api to register interface */
3184 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3185
3186register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303187 qdf_mem_free(tx_prop);
3188 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003189 return ret;
3190}
3191
3192/**
3193 * hdd_remove_ipa_header() - Remove a specific header from IPA
3194 * @name: Name of the header to be removed
3195 *
3196 * Return: None
3197 */
3198static void hdd_ipa_remove_header(char *name)
3199{
3200 struct ipa_ioc_get_hdr hdrlookup;
3201 int ret = 0, len;
3202 struct ipa_ioc_del_hdr *ipa_hdr;
3203
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303204 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3206 ret = ipa_get_hdr(&hdrlookup);
3207 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303208 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209 name, ret);
3210 return;
3211 }
3212
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303213 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303215 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003216 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303217 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003218 return;
3219 }
3220 ipa_hdr->num_hdls = 1;
3221 ipa_hdr->commit = 0;
3222 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3223 ipa_hdr->hdl[0].status = -1;
3224 ret = ipa_del_hdr(ipa_hdr);
3225 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303226 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227 ret);
3228
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303229 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230}
3231
3232/**
3233 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3234 * @hdd_ipa: Global HDD IPA context
3235 * @iface_context: Interface-specific HDD IPA context
3236 * @mac_addr: Interface MAC address
3237 *
3238 * Return: 0 on success, negativer errno value on error
3239 */
3240static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3241 struct hdd_ipa_iface_context *iface_context,
3242 uint8_t *mac_addr)
3243{
3244 hdd_adapter_t *adapter = iface_context->adapter;
3245 char *ifname;
3246 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3247 int ret = -EINVAL;
3248 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3249 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3250
3251 ifname = adapter->dev->name;
3252
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303253 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254 ifname, mac_addr);
3255
3256 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303257 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258 + sizeof(struct ipa_hdr_add));
3259 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303260 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261 "%s: ipa_hdr allocation failed", ifname);
3262 ret = -ENOMEM;
3263 goto end;
3264 }
3265
3266 ipa_hdr->commit = 0;
3267 ipa_hdr->num_hdrs = 1;
3268
3269 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3270 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3271 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3272 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3273 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303274 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275 "ifname=%s, vdev_id=%d",
3276 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3277 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3278 ifname, HDD_IPA_IPV4_NAME_EXT);
3279 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3280 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3281 ipa_hdr->hdr[0].is_partial = 1;
3282 ipa_hdr->hdr[0].hdr_hdl = 0;
3283 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3284 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3285
3286 ret = ipa_add_hdr(ipa_hdr);
3287 } else {
3288 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3289
3290 /* Set the Source MAC */
3291 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3292 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3293
3294 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3295 ifname, HDD_IPA_IPV4_NAME_EXT);
3296 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3297 ipa_hdr->hdr[0].is_partial = 1;
3298 ipa_hdr->hdr[0].hdr_hdl = 0;
3299 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3300 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3301
3302 /* Set the type to IPV4 in the header */
3303 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3304
3305 ret = ipa_add_hdr(ipa_hdr);
3306 }
3307 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303308 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003309 ifname, ret);
3310 goto end;
3311 }
3312
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303313 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003314 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3315
3316 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3317 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3318 ifname, HDD_IPA_IPV6_NAME_EXT);
3319
3320 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3321 uc_tx_hdr =
3322 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3323 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3324 } else {
3325 /* Set the type to IPV6 in the header */
3326 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3327 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3328 }
3329
3330 ret = ipa_add_hdr(ipa_hdr);
3331 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303332 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 "%s: IPv6 add hdr failed: %d", ifname, ret);
3334 goto clean_ipv4_hdr;
3335 }
3336
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303337 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3339 }
3340
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303341 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342
3343 return ret;
3344
3345clean_ipv4_hdr:
3346 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3347 ifname, HDD_IPA_IPV4_NAME_EXT);
3348 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3349end:
3350 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303351 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352
3353 return ret;
3354}
3355
3356/**
3357 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3358 * @adapter: Adapter upon which IPA was previously configured
3359 *
3360 * Return: None
3361 */
3362static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3363{
3364 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3365 int ret;
3366 char name_ipa[IPA_RESOURCE_NAME_MAX];
3367
3368 /* Remove the headers */
3369 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3370 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3371 hdd_ipa_remove_header(name_ipa);
3372
3373 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3374 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3375 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3376 hdd_ipa_remove_header(name_ipa);
3377 }
3378 /* unregister the interface with IPA */
3379 ret = ipa_deregister_intf(adapter->dev->name);
3380 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303381 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382 "%s: ipa_deregister_intf fail: %d",
3383 adapter->dev->name, ret);
3384}
3385
3386/**
3387 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3388 * @iface_context: interface-specific IPA context
3389 *
3390 * Return: None
3391 */
3392static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3393{
3394 if (iface_context == NULL)
3395 return;
3396
3397 hdd_ipa_clean_hdr(iface_context->adapter);
3398
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303399 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400 iface_context->adapter->ipa_context = NULL;
3401 iface_context->adapter = NULL;
3402 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303403 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 iface_context->ifa_address = 0;
3405 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303406 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303408 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 }
3410 iface_context->hdd_ipa->num_iface--;
3411}
3412
3413/**
3414 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3415 * @hdd_ipa: HDD IPA global context
3416 * @adapter: Interface upon which IPA is being setup
3417 * @sta_id: Station ID of the API instance
3418 *
3419 * Return: 0 on success, negative errno value on error
3420 */
3421static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3422 hdd_adapter_t *adapter, uint8_t sta_id)
3423{
3424 struct hdd_ipa_iface_context *iface_context = NULL;
3425 void *tl_context = NULL;
3426 int i, ret = 0;
3427
3428 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3429 * channel change indication. Since these indications are sent by lower
3430 * layer as SAP updates and IPA doesn't have to do anything for these
3431 * updates so ignoring!
3432 */
3433 if (WLAN_HDD_SOFTAP == adapter->device_mode && adapter->ipa_context)
3434 return 0;
3435
3436 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3437 if (hdd_ipa->iface_context[i].adapter == NULL) {
3438 iface_context = &(hdd_ipa->iface_context[i]);
3439 break;
3440 }
3441 }
3442
3443 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303444 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445 "All the IPA interfaces are in use");
3446 ret = -ENOMEM;
3447 goto end;
3448 }
3449
3450 adapter->ipa_context = iface_context;
3451 iface_context->adapter = adapter;
3452 iface_context->sta_id = sta_id;
3453 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3454
3455 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303456 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457 "Not able to get TL context sta_id: %d", sta_id);
3458 ret = -EINVAL;
3459 goto end;
3460 }
3461
3462 iface_context->tl_context = tl_context;
3463
3464 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3465 adapter->dev->dev_addr);
3466
3467 if (ret)
3468 goto end;
3469
3470 /* Configure the TX and RX pipes filter rules */
3471 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3472 if (ret)
3473 goto cleanup_header;
3474
3475 hdd_ipa->num_iface++;
3476 return ret;
3477
3478cleanup_header:
3479
3480 hdd_ipa_clean_hdr(adapter);
3481end:
3482 if (iface_context)
3483 hdd_ipa_cleanup_iface(iface_context);
3484 return ret;
3485}
3486
3487/**
3488 * hdd_ipa_msg_free_fn() - Free an IPA message
3489 * @buff: pointer to the IPA message
3490 * @len: length of the IPA message
3491 * @type: type of IPA message
3492 *
3493 * Return: None
3494 */
3495static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3496{
3497 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3498 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303499 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500}
3501
3502/**
3503 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3504 * @mcc_mode: 0=MCC/1=SCC
3505 *
3506 * Return: 0 on success, negative errno value on error
3507 */
3508int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3509{
3510 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303511 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 hdd_adapter_t *pAdapter;
3513 struct ipa_msg_meta meta;
3514 struct ipa_wlan_msg *msg;
3515 int ret;
3516
3517 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3518 return -EINVAL;
3519
3520 if (!pHddCtx->mcc_mode) {
3521 /* Flush TxRx queue for each adapter before switch to SCC */
3522 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303523 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 pAdapter = adapter_node->pAdapter;
3525 if (pAdapter->device_mode == WLAN_HDD_INFRA_STATION ||
3526 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303527 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3529 pAdapter->device_mode);
3530 hdd_deinit_tx_rx(pAdapter);
3531 }
3532 status = hdd_get_next_adapter(
3533 pHddCtx, adapter_node, &next);
3534 adapter_node = next;
3535 }
3536 }
3537
3538 /* Send SCC/MCC Switching event to IPA */
3539 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303540 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541 if (msg == NULL) {
3542 hddLog(LOGE, "msg allocation failed");
3543 return -ENOMEM;
3544 }
3545
3546 meta.msg_type = mcc_mode ?
3547 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3548 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3549
3550 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3551
3552 if (ret) {
3553 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3554 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303555 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003556 }
3557
3558 return ret;
3559}
3560
3561/**
3562 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3563 * @event: IPA WLAN event to be converted to a string
3564 *
3565 * Return: ASCII string representing the IPA WLAN event
3566 */
3567static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3568{
3569 switch (event) {
3570 case WLAN_CLIENT_CONNECT:
3571 return "WLAN_CLIENT_CONNECT";
3572 case WLAN_CLIENT_DISCONNECT:
3573 return "WLAN_CLIENT_DISCONNECT";
3574 case WLAN_CLIENT_POWER_SAVE_MODE:
3575 return "WLAN_CLIENT_POWER_SAVE_MODE";
3576 case WLAN_CLIENT_NORMAL_MODE:
3577 return "WLAN_CLIENT_NORMAL_MODE";
3578 case SW_ROUTING_ENABLE:
3579 return "SW_ROUTING_ENABLE";
3580 case SW_ROUTING_DISABLE:
3581 return "SW_ROUTING_DISABLE";
3582 case WLAN_AP_CONNECT:
3583 return "WLAN_AP_CONNECT";
3584 case WLAN_AP_DISCONNECT:
3585 return "WLAN_AP_DISCONNECT";
3586 case WLAN_STA_CONNECT:
3587 return "WLAN_STA_CONNECT";
3588 case WLAN_STA_DISCONNECT:
3589 return "WLAN_STA_DISCONNECT";
3590 case WLAN_CLIENT_CONNECT_EX:
3591 return "WLAN_CLIENT_CONNECT_EX";
3592
3593 case IPA_WLAN_EVENT_MAX:
3594 default:
3595 return "UNKNOWN";
3596 }
3597}
3598
3599/**
3600 * hdd_ipa_wlan_evt() - IPA event handler
3601 * @adapter: adapter upon which the event was received
3602 * @sta_id: station id for the event
3603 * @type: the event type
3604 * @mac_address: MAC address associated with the event
3605 *
3606 * Return: 0 on success, negative errno value on error
3607 */
3608int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
3609 enum ipa_wlan_event type, uint8_t *mac_addr)
3610{
3611 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3612 struct ipa_msg_meta meta;
3613 struct ipa_wlan_msg *msg;
3614 struct ipa_wlan_msg_ex *msg_ex = NULL;
3615 int ret;
3616
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303617 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3619 mac_addr, sta_id);
3620
3621 if (type >= IPA_WLAN_EVENT_MAX)
3622 return -EINVAL;
3623
3624 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3625 return -EINVAL;
3626
3627 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303628 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 return -EINVAL;
3630 }
3631
3632 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3633 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3634 (WLAN_HDD_SOFTAP != adapter->device_mode)) {
3635 return 0;
3636 }
3637
3638 /*
3639 * During IPA UC resource loading/unloading new events can be issued.
3640 * Store the events separately and handle them later.
3641 */
3642 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3643 ((hdd_ipa->resource_loading) ||
3644 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003645 unsigned int pending_event_count;
3646 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647
Yun Parkf19e07d2015-11-20 11:34:27 -08003648 hdd_err("IPA resource %s inprogress",
3649 hdd_ipa->resource_loading ? "load":"unload");
3650
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303651 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003652
Anurag Chouhanffb21542016-02-17 14:33:03 +05303653 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003654 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3655 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303656 qdf_list_remove_front(&hdd_ipa->pending_event,
3657 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003658 } else {
3659 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303660 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003661 sizeof(struct ipa_uc_pending_event));
3662 }
3663
3664 if (!pending_event) {
3665 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303666 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 return -ENOMEM;
3668 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003669
3670 pending_event->adapter = adapter;
3671 pending_event->sta_id = sta_id;
3672 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303673 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303675 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303676 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003677 &pending_event->node);
3678
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303679 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 return 0;
3681 }
3682
3683 hdd_ipa->stats.event[type]++;
3684
Leo Chang3bc8fed2015-11-13 10:59:47 -08003685 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686 switch (type) {
3687 case WLAN_STA_CONNECT:
3688 /* STA already connected and without disconnect, connect again
3689 * This is Roaming scenario
3690 */
3691 if (hdd_ipa->sta_connected)
3692 hdd_ipa_cleanup_iface(adapter->ipa_context);
3693
3694 if ((hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) &&
3695 (!hdd_ipa->sta_connected))
3696 hdd_ipa_uc_offload_enable_disable(adapter,
3697 SIR_STA_RX_DATA_OFFLOAD, 1);
3698
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303699 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700
3701 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303702 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3704 msg_ex->name, meta.msg_type);
3705 } else if ((!hdd_ipa->sap_num_connected_sta) &&
3706 (!hdd_ipa->sta_connected)) {
3707 /* Enable IPA UC TX PIPE when STA connected */
3708 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
Yun Park4cab6ee2015-10-27 11:43:40 -07003709 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303710 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303711 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 "handle 1st con ret %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713 hdd_ipa_uc_offload_enable_disable(adapter,
3714 SIR_STA_RX_DATA_OFFLOAD, 0);
3715 goto end;
3716 }
3717 }
3718 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3719 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303720 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 hdd_ipa_uc_offload_enable_disable(adapter,
3722 SIR_STA_RX_DATA_OFFLOAD, 0);
3723 goto end;
3724
3725#ifdef IPA_UC_OFFLOAD
3726 vdev_to_iface[adapter->sessionId] =
3727 ((struct hdd_ipa_iface_context *)
3728 (adapter->ipa_context))->iface_id;
3729#endif /* IPA_UC_OFFLOAD */
3730 }
3731
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303732 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733
3734 hdd_ipa->sta_connected = 1;
3735 break;
3736
3737 case WLAN_AP_CONNECT:
3738 /* For DFS channel we get two start_bss event (before and after
3739 * CAC). Also when ACS range includes both DFS and non DFS
3740 * channels, we could possibly change channel many times due to
3741 * RADAR detection and chosen channel may not be a DFS channels.
3742 * So dont return error here. Just discard the event.
3743 */
3744 if (adapter->ipa_context)
3745 return 0;
3746
3747 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3748 hdd_ipa_uc_offload_enable_disable(adapter,
3749 SIR_AP_RX_DATA_OFFLOAD, 1);
3750 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303751 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003752 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3753 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303754 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755 "%s: Evt: %d, Interface setup failed",
3756 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303757 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758 goto end;
3759
3760#ifdef IPA_UC_OFFLOAD
3761 vdev_to_iface[adapter->sessionId] =
3762 ((struct hdd_ipa_iface_context *)
3763 (adapter->ipa_context))->iface_id;
3764#endif /* IPA_UC_OFFLOAD */
3765 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303766 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767 break;
3768
3769 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303770 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771 hdd_ipa_cleanup_iface(adapter->ipa_context);
3772
3773 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303774 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003775 "%s: Evt: %d, STA already disconnected",
3776 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303777 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 return -EINVAL;
3779 }
3780 hdd_ipa->sta_connected = 0;
3781 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303782 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 "%s: IPA UC OFFLOAD NOT ENABLED",
3784 msg_ex->name);
3785 } else {
3786 /* Disable IPA UC TX PIPE when STA disconnected */
3787 if ((!hdd_ipa->sap_num_connected_sta) ||
3788 ((!hdd_ipa->num_iface) &&
3789 (HDD_IPA_UC_NUM_WDI_PIPE ==
3790 hdd_ipa->activated_fw_pipe))) {
3791 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3792 }
3793 }
3794
3795 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3796 hdd_ipa_uc_offload_enable_disable(adapter,
3797 SIR_STA_RX_DATA_OFFLOAD, 0);
3798 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3799 }
3800
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303801 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802 break;
3803
3804 case WLAN_AP_DISCONNECT:
3805 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303806 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003807 "%s: Evt: %d, SAP already disconnected",
3808 msg_ex->name, meta.msg_type);
3809 return -EINVAL;
3810 }
3811
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303812 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 hdd_ipa_cleanup_iface(adapter->ipa_context);
3814 if ((!hdd_ipa->num_iface) &&
3815 (HDD_IPA_UC_NUM_WDI_PIPE ==
3816 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003817 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 /*
3819 * We disable WDI pipes directly here since
3820 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3821 * processed when unloading WLAN driver is in
3822 * progress
3823 */
3824 hdd_ipa_uc_disable_pipes(hdd_ipa);
3825 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303826 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 "NO INTF left but still pipe clean up");
3828 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3829 }
3830 }
3831
3832 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3833 hdd_ipa_uc_offload_enable_disable(adapter,
3834 SIR_AP_RX_DATA_OFFLOAD, 0);
3835 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3836 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303837 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003838 break;
3839
3840 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303841 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842 adapter->dev->ifindex, sta_id);
3843
3844 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303845 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3847 adapter->dev->name, meta.msg_type);
3848 return 0;
3849 }
3850
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303851 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3853 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303854 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 "%s: STA ID %d found, not valid",
3856 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303857 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 return 0;
3859 }
Yun Park312f71a2015-12-08 10:22:42 -08003860
3861 /* Enable IPA UC Data PIPEs when first STA connected */
3862 if ((0 == hdd_ipa->sap_num_connected_sta) &&
3863 (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3864 !hdd_ipa->sta_connected)) {
3865 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3866 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303867 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303868 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003869 "%s: handle 1st con ret %d",
3870 adapter->dev->name, ret);
3871 return ret;
3872 }
3873 }
3874
3875 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003876
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303877 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
3879 meta.msg_type = type;
3880 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3881 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303882 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883
3884 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303885 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 "msg_ex allocation failed");
3887 return -ENOMEM;
3888 }
3889 strlcpy(msg_ex->name, adapter->dev->name,
3890 IPA_RESOURCE_NAME_MAX);
3891 msg_ex->num_of_attribs = 1;
3892 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
3893 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3894 msg_ex->attribs[0].offset =
3895 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3896 } else {
3897 msg_ex->attribs[0].offset =
3898 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3899 }
3900 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
3901 IPA_MAC_ADDR_SIZE);
3902
3903 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
3904
3905 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303906 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303908 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 return ret;
3910 }
3911 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912 return ret;
3913
3914 case WLAN_CLIENT_DISCONNECT:
3915 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303916 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 "%s: IPA UC OFFLOAD NOT ENABLED",
3918 msg_ex->name);
3919 return 0;
3920 }
3921
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303922 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303924 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 "%s: STA ID %d NOT found, not valid",
3926 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303927 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 return 0;
3929 }
3930 hdd_ipa->sap_num_connected_sta--;
3931 /* Disable IPA UC TX PIPE when last STA disconnected */
3932 if (!hdd_ipa->sap_num_connected_sta
3933 && (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3934 !hdd_ipa->sta_connected)
3935 && (false == hdd_ipa->resource_unloading)
3936 && (HDD_IPA_UC_NUM_WDI_PIPE ==
3937 hdd_ipa->activated_fw_pipe))
3938 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303939 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 break;
3941
3942 default:
3943 return 0;
3944 }
3945
3946 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303947 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303949 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 return -ENOMEM;
3951 }
3952
3953 meta.msg_type = type;
3954 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
3955 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
3956
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303957 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 msg->name, meta.msg_type);
3959
3960 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3961
3962 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303963 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303965 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 return ret;
3967 }
3968
3969 hdd_ipa->stats.num_send_msg++;
3970
3971end:
3972 return ret;
3973}
3974
3975/**
3976 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
3977 * @state: IPA RM state value
3978 *
3979 * Return: ASCII string representing the IPA RM state
3980 */
3981static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
3982{
3983 switch (state) {
3984 case HDD_IPA_RM_RELEASED:
3985 return "RELEASED";
3986 case HDD_IPA_RM_GRANT_PENDING:
3987 return "GRANT_PENDING";
3988 case HDD_IPA_RM_GRANTED:
3989 return "GRANTED";
3990 }
3991
3992 return "UNKNOWN";
3993}
3994
3995/**
3996 * hdd_ipa_init() - IPA initialization function
3997 * @hdd_ctx: HDD global context
3998 *
3999 * Allocate hdd_ipa resources, ipa pipe resource and register
4000 * wlan interface with IPA module.
4001 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304002 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004003 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304004QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005{
4006 struct hdd_ipa_priv *hdd_ipa = NULL;
4007 int ret, i;
4008 struct hdd_ipa_iface_context *iface_context = NULL;
4009
4010 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304011 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304013 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304015 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004016 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 }
4018
4019 hdd_ctx->hdd_ipa = hdd_ipa;
4020 ghdd_ipa = hdd_ipa;
4021 hdd_ipa->hdd_ctx = hdd_ctx;
4022 hdd_ipa->num_iface = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304023 ol_txrx_ipa_uc_get_resource(cds_get_context(QDF_MODULE_ID_TXRX),
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004024 &hdd_ipa->ipa_resource);
4025 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4026 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4027 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4028 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304029 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004030 "IPA UC resource alloc fail");
4031 goto fail_get_resource;
4032 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033
4034 /* Create the interface context */
4035 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4036 iface_context = &hdd_ipa->iface_context[i];
4037 iface_context->hdd_ipa = hdd_ipa;
4038 iface_context->cons_client =
4039 hdd_ipa_adapter_2_client[i].cons_client;
4040 iface_context->prod_client =
4041 hdd_ipa_adapter_2_client[i].prod_client;
4042 iface_context->iface_id = i;
4043 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304044 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 }
4046
4047#ifdef CONFIG_CNSS
4048 cnss_init_work(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
4049#else
4050 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
4051#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304052 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304053 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054
4055 ret = hdd_ipa_setup_rm(hdd_ipa);
4056 if (ret)
4057 goto fail_setup_rm;
4058
4059 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4060 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304061 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062 hdd_ipa->sap_num_connected_sta = 0;
4063 hdd_ipa->ipa_tx_packets_diff = 0;
4064 hdd_ipa->ipa_rx_packets_diff = 0;
4065 hdd_ipa->ipa_p_tx_packets = 0;
4066 hdd_ipa->ipa_p_rx_packets = 0;
4067 hdd_ipa->resource_loading = false;
4068 hdd_ipa->resource_unloading = false;
4069 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004070 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 /* Setup IPA sys_pipe for MCC */
4072 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4073 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4074 if (ret)
4075 goto fail_create_sys_pipe;
4076 }
4077 hdd_ipa_uc_ol_init(hdd_ctx);
4078 } else {
4079 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4080 if (ret)
4081 goto fail_create_sys_pipe;
4082 }
4083
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304084 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004085
4086fail_create_sys_pipe:
4087 hdd_ipa_destroy_rm_resource(hdd_ipa);
4088fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304089 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004090fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304091 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004092 hdd_ctx->hdd_ipa = NULL;
4093 ghdd_ipa = NULL;
4094fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304095 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004096}
4097
4098/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004099 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4100 * @hdd_ipa: pointer to HDD IPA struct
4101 *
4102 * Return: none
4103 */
4104void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
4105{
4106 struct ipa_uc_pending_event *pending_event = NULL;
4107
Anurag Chouhanffb21542016-02-17 14:33:03 +05304108 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4109 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304110 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004111 }
4112
Anurag Chouhanffb21542016-02-17 14:33:03 +05304113 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004114}
4115
4116/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004117 * hdd_ipa_cleanup - IPA cleanup function
4118 * @hdd_ctx: HDD global context
4119 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304120 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304122QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123{
4124 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4125 int i;
4126 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304127 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4129
4130 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304131 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132
4133 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4134 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4135 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4136 }
4137
4138 /* Teardown IPA sys_pipe for MCC */
4139 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4140 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4141
4142 hdd_ipa_destroy_rm_resource(hdd_ipa);
4143
4144#ifdef WLAN_OPEN_SOURCE
4145 cancel_work_sync(&hdd_ipa->pm_work);
4146#endif
4147
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304148 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149
Nirav Shahcbc6d722016-03-01 16:24:53 +05304150 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4151 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304152 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153
4154 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4155 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4156
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304157 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304159 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304161 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162
4163 /* destory the interface lock */
4164 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4165 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304166 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004167 }
4168
4169 /* This should never hit but still make sure that there are no pending
4170 * descriptor in IPA hardware
4171 */
4172 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304173 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174 "IPA Pending write done: %d Waiting!",
4175 hdd_ipa->pending_hw_desc_cnt);
4176
4177 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4178 usleep_range(100, 100);
4179 }
4180
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304181 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004182 "IPA Pending write done: desc: %d %s(%d)!",
4183 hdd_ipa->pending_hw_desc_cnt,
4184 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4185 : "leak", i);
4186 }
4187 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4188 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304189 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 "%s: Disconnect TX PIPE", __func__);
4191 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304192 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193 "%s: Disconnect RX PIPE", __func__);
4194 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304195 qdf_mutex_destroy(&hdd_ipa->event_lock);
4196 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004197 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198
4199#ifdef WLAN_OPEN_SOURCE
4200 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4201 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4202 hdd_ipa->uc_op_work[i].msg = NULL;
4203 }
4204#endif
4205 }
4206
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304207 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 hdd_ctx->hdd_ipa = NULL;
4209
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304210 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004211}
4212#endif /* IPA_OFFLOAD */