blob: 8cdf2eb68eaf8d8cecab16bc50b9c7e73039b391 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
Mohit Khannafa99aea2016-05-12 21:43:13 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
51#include <ol_txrx_osif_api.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070052#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053
54#include "cds_sched.h"
55
56#include "wma.h"
57#include "wma_api.h"
58
Dhanashri Atreb08959a2016-03-01 17:28:03 -080059#include "cdp_txrx_ipa.h"
60
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061#define HDD_IPA_DESC_BUFFER_RATIO 4
62#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
63#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
64
65#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
67/* WDI TX and RX PIPE */
68#define HDD_IPA_UC_NUM_WDI_PIPE 2
69#define HDD_IPA_UC_MAX_PENDING_EVENT 33
70
71#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
72#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
73#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
74#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
75
76#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
77#define HDD_IPA_MAX_IFACE 3
78#define HDD_IPA_MAX_SYSBAM_PIPE 4
79#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
80#define HDD_IPA_ENABLE_MASK BIT(0)
81#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
82#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
83#define HDD_IPA_RM_ENABLE_MASK BIT(3)
84#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
85#define HDD_IPA_UC_ENABLE_MASK BIT(5)
86#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
87#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
88
Yun Parkf19e07d2015-11-20 11:34:27 -080089#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
90
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091typedef enum {
92 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
93 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
94 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
95 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
96 HDD_IPA_UC_OPCODE_STATS = 4,
97 /* keep this last */
98 HDD_IPA_UC_OPCODE_MAX
99} hdd_ipa_uc_op_code;
100
101/**
102 * enum - Reason codes for stat query
103 *
104 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
105 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
106 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
107 */
108enum {
109 HDD_IPA_UC_STAT_REASON_NONE,
110 HDD_IPA_UC_STAT_REASON_DEBUG,
111 HDD_IPA_UC_STAT_REASON_BW_CAL
112};
113
114/**
115 * enum hdd_ipa_rm_state - IPA resource manager state
116 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
117 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
118 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
119 */
120enum hdd_ipa_rm_state {
121 HDD_IPA_RM_RELEASED,
122 HDD_IPA_RM_GRANT_PENDING,
123 HDD_IPA_RM_GRANTED,
124};
125
126struct llc_snap_hdr {
127 uint8_t dsap;
128 uint8_t ssap;
129 uint8_t resv[4];
130 __be16 eth_type;
131} __packed;
132
Leo Chang3bc8fed2015-11-13 10:59:47 -0800133/**
134 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
135 * @eth: ether II header
136 * @llc_snap: LLC snap header
137 *
138 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139struct hdd_ipa_tx_hdr {
140 struct ethhdr eth;
141 struct llc_snap_hdr llc_snap;
142} __packed;
143
Leo Chang3bc8fed2015-11-13 10:59:47 -0800144/**
145 * struct frag_header - fragment header type registered to IPA hardware
146 * @length: fragment length
147 * @reserved1: Reserved not used
148 * @reserved2: Reserved not used
149 *
150 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800152 uint16_t length;
153 uint32_t reserved1;
154 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155} __packed;
156
Leo Chang3bc8fed2015-11-13 10:59:47 -0800157/**
158 * struct ipa_header - ipa header type registered to IPA hardware
159 * @vdev_id: vdev id
160 * @reserved: Reserved not used
161 *
162 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800163struct ipa_header {
164 uint32_t
165 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
166 reserved:24;
167} __packed;
168
Leo Chang3bc8fed2015-11-13 10:59:47 -0800169/**
170 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
171 * @frag_hd: fragment header
172 * @ipa_hd: ipa header
173 * @eth: ether II header
174 *
175 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176struct hdd_ipa_uc_tx_hdr {
177 struct frag_header frag_hd;
178 struct ipa_header ipa_hd;
179 struct ethhdr eth;
180} __packed;
181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182/**
183 * struct hdd_ipa_cld_hdr - IPA CLD Header
184 * @reserved: reserved fields
185 * @iface_id: interface ID
186 * @sta_id: Station ID
187 *
188 * Packed 32-bit structure
189 * +----------+----------+--------------+--------+
190 * | Reserved | QCMAP ID | interface id | STA ID |
191 * +----------+----------+--------------+--------+
192 */
193struct hdd_ipa_cld_hdr {
194 uint8_t reserved[2];
195 uint8_t iface_id;
196 uint8_t sta_id;
197} __packed;
198
199struct hdd_ipa_rx_hdr {
200 struct hdd_ipa_cld_hdr cld_hdr;
201 struct ethhdr eth;
202} __packed;
203
204struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700205 bool exception;
206 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207 struct hdd_ipa_iface_context *iface_context;
208 struct ipa_rx_data *ipa_tx_desc;
209};
210
211struct hdd_ipa_uc_rx_hdr {
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_sys_pipe {
216 uint32_t conn_hdl;
217 uint8_t conn_hdl_valid;
218 struct ipa_sys_connect_params ipa_sys_params;
219};
220
221struct hdd_ipa_iface_stats {
222 uint64_t num_tx;
223 uint64_t num_tx_drop;
224 uint64_t num_tx_err;
225 uint64_t num_tx_cac_drop;
226 uint64_t num_rx_prefilter;
227 uint64_t num_rx_ipa_excep;
228 uint64_t num_rx_recv;
229 uint64_t num_rx_recv_mul;
230 uint64_t num_rx_send_desc_err;
231 uint64_t max_rx_mul;
232};
233
234struct hdd_ipa_priv;
235
236struct hdd_ipa_iface_context {
237 struct hdd_ipa_priv *hdd_ipa;
238 hdd_adapter_t *adapter;
239 void *tl_context;
240
241 enum ipa_client_type cons_client;
242 enum ipa_client_type prod_client;
243
244 uint8_t iface_id; /* This iface ID */
245 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530246 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 uint32_t ifa_address;
248 struct hdd_ipa_iface_stats stats;
Yun Park8292dcb2016-10-07 16:46:06 -0700249 uint32_t offload_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800250};
251
252struct hdd_ipa_stats {
253 uint32_t event[IPA_WLAN_EVENT_MAX];
254 uint64_t num_send_msg;
255 uint64_t num_free_msg;
256
257 uint64_t num_rm_grant;
258 uint64_t num_rm_release;
259 uint64_t num_rm_grant_imm;
260 uint64_t num_cons_perf_req;
261 uint64_t num_prod_perf_req;
262
263 uint64_t num_rx_drop;
264 uint64_t num_rx_ipa_tx_dp;
265 uint64_t num_rx_ipa_splice;
266 uint64_t num_rx_ipa_loop;
267 uint64_t num_rx_ipa_tx_dp_err;
268 uint64_t num_rx_ipa_write_done;
269 uint64_t num_max_ipa_tx_mul;
270 uint64_t num_rx_ipa_hw_maxed_out;
271 uint64_t max_pend_q_cnt;
272
273 uint64_t num_tx_comp_cnt;
274 uint64_t num_tx_queued;
275 uint64_t num_tx_dequeued;
276 uint64_t num_max_pm_queue;
277
278 uint64_t num_freeq_empty;
279 uint64_t num_pri_freeq_empty;
280 uint64_t num_rx_excep;
281 uint64_t num_tx_bcmc;
282 uint64_t num_tx_bcmc_err;
283};
284
285struct ipa_uc_stas_map {
286 bool is_reserved;
287 uint8_t sta_id;
288};
289struct op_msg_type {
290 uint8_t msg_t;
291 uint8_t rsvd;
292 uint16_t op_code;
293 uint16_t len;
294 uint16_t rsvd_snd;
295};
296
297struct ipa_uc_fw_stats {
298 uint32_t tx_comp_ring_base;
299 uint32_t tx_comp_ring_size;
300 uint32_t tx_comp_ring_dbell_addr;
301 uint32_t tx_comp_ring_dbell_ind_val;
302 uint32_t tx_comp_ring_dbell_cached_val;
303 uint32_t tx_pkts_enqueued;
304 uint32_t tx_pkts_completed;
305 uint32_t tx_is_suspend;
306 uint32_t tx_reserved;
307 uint32_t rx_ind_ring_base;
308 uint32_t rx_ind_ring_size;
309 uint32_t rx_ind_ring_dbell_addr;
310 uint32_t rx_ind_ring_dbell_ind_val;
311 uint32_t rx_ind_ring_dbell_ind_cached_val;
312 uint32_t rx_ind_ring_rdidx_addr;
313 uint32_t rx_ind_ring_rd_idx_cached_val;
314 uint32_t rx_refill_idx;
315 uint32_t rx_num_pkts_indicated;
316 uint32_t rx_buf_refilled;
317 uint32_t rx_num_ind_drop_no_space;
318 uint32_t rx_num_ind_drop_no_buf;
319 uint32_t rx_is_suspend;
320 uint32_t rx_reserved;
321};
322
323struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530324 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325 hdd_adapter_t *adapter;
326 enum ipa_wlan_event type;
327 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530328 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329};
330
331/**
332 * struct uc_rm_work_struct
333 * @work: uC RM work
334 * @event: IPA RM event
335 */
336struct uc_rm_work_struct {
337 struct work_struct work;
338 enum ipa_rm_event event;
339};
340
341/**
342 * struct uc_op_work_struct
343 * @work: uC OP work
344 * @msg: OP message
345 */
346struct uc_op_work_struct {
347 struct work_struct work;
348 struct op_msg_type *msg;
349};
350static uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
351
352/**
353 * struct uc_rt_debug_info
354 * @time: system time
355 * @ipa_excep_count: IPA exception packet count
356 * @rx_drop_count: IPA Rx drop packet count
357 * @net_sent_count: IPA Rx packet sent to network stack count
358 * @rx_discard_count: IPA Rx discard packet count
359 * @rx_mcbc_count: IPA Rx BCMC packet count
360 * @tx_mcbc_count: IPA Tx BCMC packet countt
361 * @tx_fwd_count: IPA Tx forward packet count
362 * @rx_destructor_call: IPA Rx packet destructor count
363 */
364struct uc_rt_debug_info {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530365 unsigned long time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800366 uint64_t ipa_excep_count;
367 uint64_t rx_drop_count;
368 uint64_t net_sent_count;
369 uint64_t rx_discard_count;
370 uint64_t rx_mcbc_count;
371 uint64_t tx_mcbc_count;
372 uint64_t tx_fwd_count;
373 uint64_t rx_destructor_call;
374};
375
376struct hdd_ipa_priv {
377 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
378 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
379 uint8_t num_iface;
380 enum hdd_ipa_rm_state rm_state;
381 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530382 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 * APIs as it is taken care gracefully. Without this, kernel would throw
384 * an warning if spin_lock_bh is used while IRQ is disabled
385 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530386 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 struct uc_rm_work_struct uc_rm_work;
388 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530389 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800390 struct delayed_work wake_lock_work;
391 bool wake_lock_released;
392
393 enum ipa_client_type prod_client;
394
395 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530396 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800397 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530398 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399 bool suspended;
400
401 uint32_t pending_hw_desc_cnt;
402 uint32_t hw_desc_cnt;
403 spinlock_t q_lock;
404 uint32_t freeq_cnt;
405 struct list_head free_desc_head;
406
407 uint32_t pend_q_cnt;
408 struct list_head pend_desc_head;
409
410 hdd_context_t *hdd_ctx;
411
412 struct dentry *debugfs_dir;
413 struct hdd_ipa_stats stats;
414
415 struct notifier_block ipv4_notifier;
416 uint32_t curr_prod_bw;
417 uint32_t curr_cons_bw;
418
419 uint8_t activated_fw_pipe;
420 uint8_t sap_num_connected_sta;
421 uint8_t sta_connected;
422 uint32_t tx_pipe_handle;
423 uint32_t rx_pipe_handle;
424 bool resource_loading;
425 bool resource_unloading;
426 bool pending_cons_req;
427 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530428 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530429 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700430 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800431 uint32_t ipa_tx_packets_diff;
432 uint32_t ipa_rx_packets_diff;
433 uint32_t ipa_p_tx_packets;
434 uint32_t ipa_p_rx_packets;
435 uint32_t stat_req_reason;
436 uint64_t ipa_tx_forward;
437 uint64_t ipa_rx_discard;
438 uint64_t ipa_rx_net_send_count;
439 uint64_t ipa_rx_internel_drop_count;
440 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530441 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
443 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530444 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530445 qdf_mutex_t rt_debug_lock;
446 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800447 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800448 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530449 qdf_dma_addr_t tx_comp_doorbell_paddr;
450 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451};
452
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800453/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800454 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800455 * They will be implemented fully by another update.
456 * The stubs will let the compile go ahead, and functionality
457 * is broken.
458 * This should be OK and IPA is not enabled yet
459 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700460static void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800461{
462 void *vaddr;
463 uint32_t ipa_priv = priv;
464
465 vaddr = &ipa_priv; /* just to use the var */
466 vaddr = NULL;
467 return vaddr;
468}
469
Jeff Johnsond7720632016-10-05 16:04:32 -0700470static uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800471{
472 uint32_t ipa_priv = 0;
473
474 BUG_ON(ptr == NULL);
475 return ipa_priv;
476}
Leo Changcc923e22016-06-16 15:29:03 -0700477
478#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
479#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
481#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
482#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
483#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
484#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
485#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700486#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
487 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488
Leo Chang3bc8fed2015-11-13 10:59:47 -0800489#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
490#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492#define HDD_IPA_GET_IFACE_ID(_data) \
493 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
494
495#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530496 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 "%s:%d: "fmt, __func__, __LINE__, ## args)
498
Govind Singhb6a89772016-08-12 11:23:35 +0530499#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
500 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
501 "%s:%d: "fmt, __func__, __LINE__, ## args)
502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
504 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530505 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
506 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507 } while (0)
508
509#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
510 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
511
512#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
513 do { \
514 hdd_ipa->ipa_rx_internel_drop_count++; \
515 } while (0)
516#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
517 do { \
518 hdd_ipa->ipa_rx_net_send_count++; \
519 } while (0)
520#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
521
Leo Chang07b28f62016-05-11 12:29:22 -0700522#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800523#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
524do { \
525 pipe_in.u.ul.rdy_ring_rp_va = \
526 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
527 pipe_in.u.ul.rdy_comp_ring_base_pa = \
528 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
529 pipe_in.u.ul.rdy_comp_ring_size = \
530 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
531 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
532 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
533 pipe_in.u.ul.rdy_comp_ring_wp_va = \
534 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800535} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700536
537#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800538#else
539/* Do nothing */
540#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700541#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700542#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800543
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800544static struct hdd_ipa_adapter_2_client {
545 enum ipa_client_type cons_client;
546 enum ipa_client_type prod_client;
547} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
548 {
549 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
550 }, {
551 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
552 }, {
553 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
554 },
555};
556
557/* For Tx pipes, use Ethernet-II Header format */
558struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
559 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800560 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561 0x00000000,
562 0x00000000
563 },
564 {
565 0x00000000
566 },
567 {
568 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
569 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
570 0x0008
571 }
572};
573
574/* For Tx pipes, use 802.3 Header format */
575static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
576 {
577 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
578 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
579 0x00 /* length can be zero */
580 },
581 {
582 /* LLC SNAP header 8 bytes */
583 0xaa, 0xaa,
584 {0x03, 0x00, 0x00, 0x00},
585 0x0008 /* type value(2 bytes) ,filled by wlan */
586 /* 0x0800 - IPV4, 0x86dd - IPV6 */
587 }
588};
589
590static const char *op_string[] = {
591 "TX_SUSPEND",
592 "TX_RESUME",
593 "RX_SUSPEND",
594 "RX_RESUME",
595 "STATS",
596};
597
598static struct hdd_ipa_priv *ghdd_ipa;
599
600/* Local Function Prototypes */
601static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
602 unsigned long data);
603static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
604 unsigned long data);
605
606static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700607static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800608
609/**
610 * hdd_ipa_is_enabled() - Is IPA enabled?
611 * @hdd_ctx: Global HDD context
612 *
613 * Return: true if IPA is enabled, false otherwise
614 */
615bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
616{
617 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
618}
619
620/**
621 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
622 * @hdd_ctx: Global HDD context
623 *
624 * Return: true if IPA uC offload is enabled, false otherwise
625 */
626bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
627{
628 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
629}
630
631/**
632 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
633 * @hdd_ctx: Global HDD context
634 *
635 * Return: true if STA mode IPA uC offload is enabled, false otherwise
636 */
637static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
638{
639 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
640}
641
642/**
643 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
644 * @hdd_ipa: Global HDD IPA context
645 *
646 * Return: true if pre-filter is enabled, otherwise false
647 */
648static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
649{
650 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
651 HDD_IPA_PRE_FILTER_ENABLE_MASK);
652}
653
654/**
655 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
656 * @hdd_ipa: Global HDD IPA context
657 *
658 * Return: true if IPv6 is enabled, otherwise false
659 */
660static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
661{
662 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
663}
664
665/**
666 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
667 * @hdd_ipa: Global HDD IPA context
668 *
669 * Return: true if resource manager is enabled, otherwise false
670 */
671static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
672{
673 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
674}
675
676/**
677 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
678 * @hdd_ipa: Global HDD IPA context
679 *
680 * Return: true if resource manager is enabled, otherwise false
681 */
682static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
683{
684 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
685}
686
687/**
688 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
689 * @hdd_ipa: Global HDD IPA context
690 *
691 * Return: true if clock scaling is enabled, otherwise false
692 */
693static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
694{
695 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
696 HDD_IPA_CLK_SCALING_ENABLE_MASK |
697 HDD_IPA_RM_ENABLE_MASK);
698}
699
700/**
701 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
702 * @ctext: pointer to hdd context.
703 *
704 * If rt debug enabled, periodically called, and fill debug buffer
705 *
706 * Return: none
707 */
708static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
709{
710 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
711 struct hdd_ipa_priv *hdd_ipa;
712 struct uc_rt_debug_info *dump_info = NULL;
713
714 if (wlan_hdd_validate_context(hdd_ctx))
715 return;
716
717 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530718 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800719 "%s: IPA UC is not enabled", __func__);
720 return;
721 }
722
723 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
724
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530725 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726 dump_info = &hdd_ipa->rt_bug_buffer[
727 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
728
Anurag Chouhan210db072016-02-22 18:42:15 +0530729 dump_info->time = qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
731 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
732 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
733 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
734 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
735 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
736 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
737 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530738 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739
Anurag Chouhan210db072016-02-22 18:42:15 +0530740 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
742}
743
744/**
745 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
746 * @hdd_ctx: pointer to hdd context.
747 *
748 * If rt debug enabled, dump debug buffer contents based on requirement
749 *
750 * Return: none
751 */
752void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
753{
754 struct hdd_ipa_priv *hdd_ipa;
755 unsigned int dump_count;
756 unsigned int dump_index;
757 struct uc_rt_debug_info *dump_info = NULL;
758
759 if (wlan_hdd_validate_context(hdd_ctx))
760 return;
761
762 hdd_ipa = hdd_ctx->hdd_ipa;
763 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530764 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 "%s: IPA UC is not enabled", __func__);
766 return;
767 }
768
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530769 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530771 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
773
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530774 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 for (dump_count = 0;
776 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
777 dump_count++) {
778 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
779 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
780 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530781 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782 "%12lu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
783 dump_info->time, dump_info->ipa_excep_count,
784 dump_info->rx_drop_count, dump_info->net_sent_count,
785 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
786 dump_info->rx_destructor_call,
787 dump_info->rx_discard_count);
788 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530789 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530790 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
792}
793
794/**
795 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
796 * @ctext: pointer to hdd context.
797 *
798 * periodically called by timer expire
799 * will try to alloc dummy memory and detect out of memory condition
800 * if out of memory detected, dump wlan-ipa stats
801 *
802 * Return: none
803 */
804static void hdd_ipa_uc_rt_debug_handler(void *ctext)
805{
806 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
807 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
808 void *dummy_ptr = NULL;
809
810 if (wlan_hdd_validate_context(hdd_ctx))
811 return;
812
813 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530814 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800815 "%s: IPA RT debug is not enabled", __func__);
816 return;
817 }
818
819 /* Allocate dummy buffer periodically and free immediately. this will
820 * proactively detect OOM and if allocation fails dump ipa stats
821 */
822 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
823 GFP_KERNEL | GFP_ATOMIC);
824 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530825 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 "%s: Dummy alloc fail", __func__);
827 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
828 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800829 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 } else {
831 kfree(dummy_ptr);
832 }
833
Anurag Chouhan210db072016-02-22 18:42:15 +0530834 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 HDD_IPA_UC_RT_DEBUG_PERIOD);
836}
837
838/**
839 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
840 * @skb: packet pinter
841 *
842 * when free data packet, will be invoked by wlan client and will increase
843 * free counter
844 *
845 * Return: none
846 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700847static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848{
849 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530850 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 "%s: invalid hdd context", __func__);
852 return;
853 }
854
855 ghdd_ipa->ipa_rx_destructor_count++;
856}
857
858/**
859 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
860 * @hdd_ctx: hdd main context
861 *
862 * free all rt debugging resources
863 *
864 * Return: none
865 */
866static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
867{
868 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
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_fill_timer)) {
872 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_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_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530875 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876
877 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530878 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 "%s: IPA RT debug is not enabled", __func__);
880 return;
881 }
882
Anurag Chouhan210db072016-02-22 18:42:15 +0530883 if (QDF_TIMER_STATE_STOPPED !=
884 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
885 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530887 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888}
889
890/**
891 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
892 * @hdd_ctx: hdd main context
893 *
894 * alloc and initialize all rt debugging resources
895 *
896 * Return: none
897 */
898static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
899{
900 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
901
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530902 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530903 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
905 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530906 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 sizeof(struct uc_rt_debug_info) *
908 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
909 hdd_ipa->ipa_tx_forward = 0;
910 hdd_ipa->ipa_rx_discard = 0;
911 hdd_ipa->ipa_rx_net_send_count = 0;
912 hdd_ipa->ipa_rx_internel_drop_count = 0;
913 hdd_ipa->ipa_rx_destructor_count = 0;
914
Anurag Chouhan210db072016-02-22 18:42:15 +0530915 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
917
918 /* Reatime debug enable on feature enable */
919 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530920 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 "%s: IPA RT debug is not enabled", __func__);
922 return;
923 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530924 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530926 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 HDD_IPA_UC_RT_DEBUG_PERIOD);
928
929}
930
931/**
932 * hdd_ipa_uc_stat_query() - Query the IPA stats
933 * @hdd_ctx: Global HDD context
934 * @ipa_tx_diff: tx packet count diff from previous
935 * tx packet count
936 * @ipa_rx_diff: rx packet count diff from previous
937 * rx packet count
938 *
939 * Return: true if IPA is enabled, false otherwise
940 */
941void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
942 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
943{
944 struct hdd_ipa_priv *hdd_ipa;
945
946 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
947 *ipa_tx_diff = 0;
948 *ipa_rx_diff = 0;
949
950 if (!hdd_ipa_is_enabled(pHddCtx) ||
951 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
952 return;
953 }
954
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530955 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
957 (false == hdd_ipa->resource_loading)) {
958 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
959 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkf8d6a122016-10-11 15:49:43 -0700960 HDD_IPA_LOG(LOGOFF, "STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 *ipa_tx_diff, *ipa_rx_diff);
962 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530963 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964 return;
965}
966
967/**
968 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
969 * @adapter: network adapter
970 * @reason: STAT REQ Reason
971 *
972 * Return: None
973 */
974void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
975{
976 hdd_context_t *pHddCtx;
977 struct hdd_ipa_priv *hdd_ipa;
978
979 if (!adapter) {
980 return;
981 }
982
983 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
984 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
985 if (!hdd_ipa_is_enabled(pHddCtx) ||
986 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
987 return;
988 }
989
990 HDD_IPA_LOG(LOG1, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530991 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
993 (false == hdd_ipa->resource_loading)) {
994 hdd_ipa->stat_req_reason = reason;
995 wma_cli_set_command(
996 (int)adapter->sessionId,
997 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
998 0, VDEV_CMD);
999 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301000 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001}
1002
1003/**
1004 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1005 * @hdd_ipa: Global HDD IPA context
1006 * @sta_add: Should station be added
1007 * @sta_id: ID of the station being queried
1008 *
1009 * Return: true if the station was found
1010 */
1011static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1012 bool sta_add, uint8_t sta_id)
1013{
1014 bool sta_found = false;
1015 uint8_t idx;
1016 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1017 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1018 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1019 sta_found = true;
1020 break;
1021 }
1022 }
1023 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301024 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025 "%s: STA ID %d already exist, cannot add",
1026 __func__, sta_id);
1027 return sta_found;
1028 }
1029 if (sta_add) {
1030 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1031 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1032 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1033 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1034 return sta_found;
1035 }
1036 }
1037 }
1038 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301039 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 "%s: STA ID %d does not exist, cannot delete",
1041 __func__, sta_id);
1042 return sta_found;
1043 }
1044 if (!sta_add) {
1045 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1046 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1047 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1048 hdd_ipa->assoc_stas_map[idx].is_reserved =
1049 false;
1050 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1051 return sta_found;
1052 }
1053 }
1054 }
1055 return sta_found;
1056}
1057
1058/**
1059 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1060 * @hdd_ipa: Global HDD IPA context
1061 *
1062 * Return: 0 on success, negative errno if error
1063 */
1064static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1065{
1066 int result;
1067 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1068
1069 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301070 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001071 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1072 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1074 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301075 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 "%s: Enable TX PIPE fail, code %d",
1077 __func__, result);
1078 return result;
1079 }
1080 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1081 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301082 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 "%s: Resume TX PIPE fail, code %d",
1084 __func__, result);
1085 return result;
1086 }
1087 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1088
1089 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301090 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001091 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1092 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1094 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301095 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 "%s: Enable RX PIPE fail, code %d",
1097 __func__, result);
1098 return result;
1099 }
1100 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1101 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301102 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 "%s: Resume RX PIPE fail, code %d",
1104 __func__, result);
1105 return result;
1106 }
1107 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001108 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 return 0;
1110}
1111
1112/**
1113 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1114 * @hdd_ipa: Global HDD IPA context
1115 *
1116 * Return: 0 on success, negative errno if error
1117 */
1118static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1119{
1120 int result;
1121
Leo Change3e49442015-10-26 20:07:13 -07001122 hdd_ipa->ipa_pipes_down = true;
1123
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301124 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1126 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301127 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 "%s: Suspend RX PIPE fail, code %d",
1129 __func__, result);
1130 return result;
1131 }
1132 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1133 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301134 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 "%s: Disable RX PIPE fail, code %d",
1136 __func__, result);
1137 return result;
1138 }
1139
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301140 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1142 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301143 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 "%s: Suspend TX PIPE fail, code %d",
1145 __func__, result);
1146 return result;
1147 }
1148 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1149 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301150 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 "%s: Disable TX PIPE fail, code %d",
1152 __func__, result);
1153 return result;
1154 }
1155
1156 return 0;
1157}
1158
1159/**
1160 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1161 * @hdd_ipa: Global HDD IPA context
1162 *
1163 * Return: 0 on success, negative errno if error
1164 */
1165static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1166{
1167 hdd_ipa->activated_fw_pipe = 0;
1168 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001169
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001170 /* If RM feature enabled
1171 * Request PROD Resource first
1172 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001173 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1174 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1175 /* RM PROD request sync return
1176 * enable pipe immediately
1177 */
1178 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301179 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001180 "%s: IPA WDI Pipe activation failed",
1181 __func__);
1182 hdd_ipa->resource_loading = false;
1183 return -EBUSY;
1184 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185 }
1186 } else {
1187 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001188 * Just enabled all the PIPEs
1189 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301191 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001192 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 __func__);
1194 hdd_ipa->resource_loading = false;
1195 return -EBUSY;
1196 }
1197 hdd_ipa->resource_loading = false;
1198 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001199
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301200 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001201 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 return 0;
1203}
1204
1205/**
1206 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1207 * @hdd_ipa: Global HDD IPA context
1208 *
1209 * Return: None
1210 */
1211static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1212{
1213 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1214
1215 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301216 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001217 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301218 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1220}
1221
1222/**
1223 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1224 * @context: User context registered with TL (the IPA Global context is
1225 * registered
1226 * @rxpkt: Packet containing the notification
1227 * @staid: ID of the station associated with the packet
1228 *
1229 * Return: None
1230 */
1231static void
1232hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1233{
1234 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301235 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236
1237 /*
1238 * When SSR is going on or driver is unloading, just return.
1239 */
1240 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301241 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243
1244 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1245 return;
1246
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301247 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 __func__, event);
1249
1250 switch (event) {
1251 case IPA_RM_RESOURCE_GRANTED:
1252 /* Differed RM Granted */
1253 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301254 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255 if ((false == hdd_ipa->resource_unloading) &&
1256 (!hdd_ipa->activated_fw_pipe)) {
1257 hdd_ipa_uc_enable_pipes(hdd_ipa);
1258 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301259 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001260 break;
1261
1262 case IPA_RM_RESOURCE_RELEASED:
1263 /* Differed RM Released */
1264 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 break;
1266
1267 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301268 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 "%s, invalid event code %d", __func__, event);
1270 break;
1271 }
1272}
1273
1274/**
1275 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1276 * @hdd_ipa: Global HDD IPA context
1277 * @event: IPA resource manager event to be deferred
1278 *
1279 * This function is called when a resource manager event is received
1280 * from firmware in interrupt context. This function will defer the
1281 * handling to the OL RX thread
1282 *
1283 * Return: None
1284 */
1285static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1286{
1287 enum ipa_rm_event event;
1288 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1289 struct uc_rm_work_struct, work);
1290 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1291 struct hdd_ipa_priv, uc_rm_work);
1292
1293 cds_ssr_protect(__func__);
1294 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301295 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 "%s, posted event %d", __func__, event);
1297
1298 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1299 cds_ssr_unprotect(__func__);
1300
1301 return;
1302}
1303
1304/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1306 * @op_msg: operation message received from firmware
1307 * @usr_ctxt: user context registered with TL (we register the HDD Global
1308 * context)
1309 *
1310 * Return: None
1311 */
1312static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1313{
1314 struct op_msg_type *msg = op_msg;
1315 struct ipa_uc_fw_stats *uc_fw_stat;
1316 struct IpaHwStatsWDIInfoData_t ipa_stat;
1317 struct hdd_ipa_priv *hdd_ipa;
1318 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301319 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320
1321 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301322 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 return;
1324 }
1325
1326 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301327 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1329 return;
1330 }
1331
1332 hdd_ctx = (hdd_context_t *) usr_ctxt;
1333
1334 /*
1335 * When SSR is going on or driver is unloading, just return.
1336 */
1337 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301338 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301339 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 return;
1341 }
1342
1343 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1344
Govind Singhb6a89772016-08-12 11:23:35 +05301345 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001346 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1347
1348 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1349 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301350 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 hdd_ipa->activated_fw_pipe++;
1352 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1353 hdd_ipa->resource_loading = false;
1354 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001355 if (hdd_ipa->pending_cons_req)
1356 ipa_rm_notify_completion(
1357 IPA_RM_RESOURCE_GRANTED,
1358 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001359 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301361 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001362 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301364 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 hdd_ipa->activated_fw_pipe--;
1366 if (!hdd_ipa->activated_fw_pipe) {
1367 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001368 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1369 ipa_rm_release_resource(
1370 IPA_RM_RESOURCE_WLAN_PROD);
1371 /* Sync return success from IPA
1372 * Enable/resume all the PIPEs */
1373 hdd_ipa->resource_unloading = false;
1374 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1375 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301377 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001378 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001380 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301382 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001384 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 "CE RING SIZE: %d\n"
1386 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001387 (unsigned long long)res->ce_sr_base_paddr,
1388 res->ce_sr_ring_size,
1389 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301390 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001392 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393 "COMP RING SIZE: %d\n"
1394 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001395 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001396 (unsigned long long)res->tx_comp_ring_base_paddr,
1397 res->tx_comp_ring_size,
1398 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001399 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301400 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001402 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001404 "IND RING DBELL : 0x%llx\n"
1405 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 "NUM EXCP PKT : %llu\n"
1407 "NUM TX BCMC : %llu\n"
1408 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001409 (unsigned long long)res->rx_rdy_ring_base_paddr,
1410 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001411 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001412 (unsigned long long)hdd_ipa->ipa_resource.
1413 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 hdd_ipa->stats.num_rx_excep,
1415 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001416 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301417 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1419 "SAP NUM STAs: %d\n"
1420 "STA CONNECTED: %d\n"
1421 "TX PIPE HDL: %d\n"
1422 "RX PIPE HDL : %d\n"
1423 "RSC LOADING : %d\n"
1424 "RSC UNLOADING : %d\n"
1425 "PNDNG CNS RQT : %d",
1426 hdd_ipa->sap_num_connected_sta,
1427 hdd_ipa->sta_connected,
1428 hdd_ipa->tx_pipe_handle,
1429 hdd_ipa->rx_pipe_handle,
1430 (unsigned int)hdd_ipa->resource_loading,
1431 (unsigned int)hdd_ipa->resource_unloading,
1432 (unsigned int)hdd_ipa->pending_cons_req);
1433
1434 /* STATs from FW */
1435 uc_fw_stat = (struct ipa_uc_fw_stats *)
1436 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301437 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 "==== IPA_UC WLAN_FW TX ====\n"
1439 "COMP RING BASE: 0x%x\n"
1440 "COMP RING SIZE: %d\n"
1441 "COMP RING DBELL : 0x%x\n"
1442 "COMP RING DBELL IND VAL : %d\n"
1443 "COMP RING DBELL CACHED VAL : %d\n"
1444 "COMP RING DBELL CACHED VAL : %d\n"
1445 "PKTS ENQ : %d\n"
1446 "PKTS COMP : %d\n"
1447 "IS SUSPEND : %d\n"
1448 "RSVD : 0x%x",
1449 uc_fw_stat->tx_comp_ring_base,
1450 uc_fw_stat->tx_comp_ring_size,
1451 uc_fw_stat->tx_comp_ring_dbell_addr,
1452 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1453 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1454 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1455 uc_fw_stat->tx_pkts_enqueued,
1456 uc_fw_stat->tx_pkts_completed,
1457 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301458 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 "==== IPA_UC WLAN_FW RX ====\n"
1460 "IND RING BASE: 0x%x\n"
1461 "IND RING SIZE: %d\n"
1462 "IND RING DBELL : 0x%x\n"
1463 "IND RING DBELL IND VAL : %d\n"
1464 "IND RING DBELL CACHED VAL : %d\n"
1465 "RDY IND ADDR : 0x%x\n"
1466 "RDY IND CACHE VAL : %d\n"
1467 "RFIL IND : %d\n"
1468 "NUM PKT INDICAT : %d\n"
1469 "BUF REFIL : %d\n"
1470 "NUM DROP NO SPC : %d\n"
1471 "NUM DROP NO BUF : %d\n"
1472 "IS SUSPND : %d\n"
1473 "RSVD : 0x%x\n",
1474 uc_fw_stat->rx_ind_ring_base,
1475 uc_fw_stat->rx_ind_ring_size,
1476 uc_fw_stat->rx_ind_ring_dbell_addr,
1477 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1478 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1479 uc_fw_stat->rx_ind_ring_rdidx_addr,
1480 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1481 uc_fw_stat->rx_refill_idx,
1482 uc_fw_stat->rx_num_pkts_indicated,
1483 uc_fw_stat->rx_buf_refilled,
1484 uc_fw_stat->rx_num_ind_drop_no_space,
1485 uc_fw_stat->rx_num_ind_drop_no_buf,
1486 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1487 /* STATs from IPA */
1488 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301489 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 "==== IPA_UC IPA TX ====\n"
1491 "NUM PROCD : %d\n"
1492 "CE DBELL : 0x%x\n"
1493 "NUM DBELL FIRED : %d\n"
1494 "COMP RNG FULL : %d\n"
1495 "COMP RNG EMPT : %d\n"
1496 "COMP RNG USE HGH : %d\n"
1497 "COMP RNG USE LOW : %d\n"
1498 "BAM FIFO FULL : %d\n"
1499 "BAM FIFO EMPT : %d\n"
1500 "BAM FIFO USE HGH : %d\n"
1501 "BAM FIFO USE LOW : %d\n"
1502 "NUM DBELL : %d\n"
1503 "NUM UNEXP DBELL : %d\n"
1504 "NUM BAM INT HDL : 0x%x\n"
1505 "NUM BAM INT NON-RUN : 0x%x\n"
1506 "NUM QMB INT HDL : 0x%x",
1507 ipa_stat.tx_ch_stats.num_pkts_processed,
1508 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1509 ipa_stat.tx_ch_stats.num_db_fired,
1510 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1511 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1512 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1513 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1514 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1515 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1516 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1517 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1518 ipa_stat.tx_ch_stats.num_db,
1519 ipa_stat.tx_ch_stats.num_unexpected_db,
1520 ipa_stat.tx_ch_stats.num_bam_int_handled,
1521 ipa_stat.tx_ch_stats.
1522 num_bam_int_in_non_runnning_state,
1523 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1524
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301525 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 "==== IPA_UC IPA RX ====\n"
1527 "MAX OST PKT : %d\n"
1528 "NUM PKT PRCSD : %d\n"
1529 "RNG RP : 0x%x\n"
1530 "COMP RNG FULL : %d\n"
1531 "COMP RNG EMPT : %d\n"
1532 "COMP RNG USE HGH : %d\n"
1533 "COMP RNG USE LOW : %d\n"
1534 "BAM FIFO FULL : %d\n"
1535 "BAM FIFO EMPT : %d\n"
1536 "BAM FIFO USE HGH : %d\n"
1537 "BAM FIFO USE LOW : %d\n"
1538 "NUM DB : %d\n"
1539 "NUM UNEXP DB : %d\n"
1540 "NUM BAM INT HNDL : 0x%x\n",
1541 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1542 ipa_stat.rx_ch_stats.num_pkts_processed,
1543 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1544 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1545 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1546 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1547 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1548 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1549 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1550 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1551 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1552 ipa_stat.rx_ch_stats.num_db,
1553 ipa_stat.rx_ch_stats.num_unexpected_db,
1554 ipa_stat.rx_ch_stats.num_bam_int_handled);
1555 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1556 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1557 /* STATs from FW */
1558 uc_fw_stat = (struct ipa_uc_fw_stats *)
1559 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301560 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1562 uc_fw_stat->tx_pkts_completed,
1563 hdd_ipa->ipa_p_tx_packets);
1564 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1565 (uc_fw_stat->rx_num_ind_drop_no_space +
1566 uc_fw_stat->rx_num_ind_drop_no_buf +
1567 uc_fw_stat->rx_num_pkts_indicated),
1568 hdd_ipa->ipa_p_rx_packets);
1569
1570 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1571 hdd_ipa->ipa_p_rx_packets =
1572 (uc_fw_stat->rx_num_ind_drop_no_space +
1573 uc_fw_stat->rx_num_ind_drop_no_buf +
1574 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301575 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 } else {
Yun Park8292dcb2016-10-07 16:46:06 -07001577 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
1578 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301580 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581}
1582
1583
1584/**
1585 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1586 * @adapter: device adapter instance
1587 * @offload_type: MCC or SCC
1588 * @enable: TX offload enable or disable
1589 *
1590 * Return: none
1591 */
1592static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1593 uint32_t offload_type, uint32_t enable)
1594{
1595 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07001596 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001597
Yun Parka37592b2016-06-11 17:10:28 -07001598 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 return;
1600
Yun Park8292dcb2016-10-07 16:46:06 -07001601 iface_context = adapter->ipa_context;
1602
1603 if (!iface_context || (enable == iface_context->offload_enabled)) {
1604 /* IPA offload status is already set as desired */
1605 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1606 "offload_type=%d, vdev_id=%d, enable=%d",
1607 offload_type, adapter->sessionId, enable);
1608 WARN_ON(1);
1609 return;
1610 }
1611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1613 * channel change indication. Since these indications are sent by lower
1614 * layer as SAP updates and IPA doesn't have to do anything for these
1615 * updates so ignoring!
Yun Parka37592b2016-06-11 17:10:28 -07001616 */
1617 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 return;
1619
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301620 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621 sizeof(ipa_offload_enable_disable));
1622 ipa_offload_enable_disable.offload_type = offload_type;
1623 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1624 ipa_offload_enable_disable.enable = enable;
1625
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301626 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001627 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 ipa_offload_enable_disable.offload_type,
1629 ipa_offload_enable_disable.vdev_id,
1630 ipa_offload_enable_disable.enable);
1631
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301632 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1634 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301635 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 "%s: Failure to enable IPA offload \
1637 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1638 ipa_offload_enable_disable.offload_type,
1639 ipa_offload_enable_disable.vdev_id,
1640 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001641 } else {
1642 /* Update the IPA offload status */
1643 iface_context->offload_enabled =
1644 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001645 }
1646}
1647
1648/**
1649 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1650 * @work: uC OP work
1651 *
1652 * Return: None
1653 */
1654static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1655{
1656 struct op_msg_type *msg;
1657 struct uc_op_work_struct *uc_op_work = container_of(work,
1658 struct uc_op_work_struct, work);
1659 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1660
1661 cds_ssr_protect(__func__);
1662
1663 msg = uc_op_work->msg;
1664 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301665 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 "%s, posted msg %d", __func__, msg->op_code);
1667
1668 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1669
1670 cds_ssr_unprotect(__func__);
1671
1672 return;
1673}
1674
1675/**
1676 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1677 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1678 * @op_msg: operation message received from firmware
1679 * @hdd_ctx: Global HDD context
1680 *
1681 * Return: None
1682 */
1683static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1684{
1685 struct hdd_ipa_priv *hdd_ipa;
1686 struct op_msg_type *msg;
1687 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301688 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689
1690 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301691 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001692 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693
1694 msg = (struct op_msg_type *)op_msg;
1695 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1696
1697 if (unlikely(!hdd_ipa))
1698 goto end;
1699
1700 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301701 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702 __func__, msg->op_code);
1703 goto end;
1704 }
1705
1706 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1707 if (uc_op_work->msg)
1708 /* When the same uC OPCODE is already pended, just return */
1709 goto end;
1710
1711 uc_op_work->msg = msg;
1712 schedule_work(&uc_op_work->work);
1713 return;
1714
1715end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301716 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001717}
1718
1719/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001720 * hdd_ipa_init_uc_op_work - init ipa uc op work
1721 * @work: struct work_struct
1722 * @work_handler: work_handler
1723 *
1724 * Return: none
1725 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001726static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1727 work_func_t work_handler)
1728{
1729 INIT_WORK(work, work_handler);
1730}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001731
1732
1733/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001734 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1735 * @hdd_ctx: Global HDD context
1736 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301737 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301739static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740{
1741 struct ipa_wdi_in_params pipe_in;
1742 struct ipa_wdi_out_params pipe_out;
1743 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1744 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1745 uint8_t i;
1746
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301747 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1748 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749
Anurag Chouhanffb21542016-02-17 14:33:03 +05301750 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301751 qdf_mutex_create(&ipa_ctxt->event_lock);
1752 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753
1754 /* TX PIPE */
1755 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1756 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1757 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1758 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1759 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1760 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1761 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1762 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1763 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1764 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1765 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1766 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1767 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301768 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001769 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1770 pipe_in.sys.keep_ipa_awake = true;
1771 }
1772
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001773 pipe_in.u.dl.comp_ring_base_pa =
1774 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001775 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001776 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1777 sizeof(qdf_dma_addr_t);
1778 pipe_in.u.dl.ce_ring_base_pa =
1779 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1780 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1781 pipe_in.u.dl.ce_ring_size =
1782 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1783 pipe_in.u.dl.num_tx_buffers =
1784 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785
1786 /* Connect WDI IPA PIPE */
1787 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1788 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301789 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1790 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1791 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1792 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001793 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 /* WLAN TX PIPE Handle */
1795 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301796 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1798 " CERZ %d, NB %d, CDBPAD 0x%x",
1799 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1800 pipe_in.u.dl.comp_ring_size,
1801 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1802 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1803 pipe_in.u.dl.ce_ring_size,
1804 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001805 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001806
1807 /* RX PIPE */
1808 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1809 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1810 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1811 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1812 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1813 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1814 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1815 sizeof(struct sps_iovec);
1816 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1817 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1820 pipe_in.sys.keep_ipa_awake = true;
1821 }
1822
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001823 pipe_in.u.ul.rdy_ring_base_pa =
1824 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1825 pipe_in.u.ul.rdy_ring_size =
1826 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1827 pipe_in.u.ul.rdy_ring_rp_pa =
1828 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001829 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001831 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001832 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301833 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1835 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1836 pipe_in.u.ul.rdy_ring_size,
1837 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001838 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001839
1840 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001841 ipa_ctxt->tx_comp_doorbell_paddr,
1842 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843
1844 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1845 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1846
1847 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001848 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001849 hdd_ipa_uc_fw_op_event_handler);
1850 ipa_ctxt->uc_op_work[i].msg = NULL;
1851 }
1852
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301853 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854}
1855
Leo Change3e49442015-10-26 20:07:13 -07001856/**
1857 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1858 * @hdd_ctx: hdd main context
1859 *
1860 * Force shutdown IPA pipe
1861 * Independent of FW pipe status, IPA pipe shutdonw progress
1862 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1863 * independent from FW pipe status
1864 *
1865 * Return: NONE
1866 */
1867void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1868{
1869 struct hdd_ipa_priv *hdd_ipa;
1870
1871 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1872 return;
1873
1874 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1875 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301876 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001877 "IPA pipes are not down yet, force shutdown");
1878 hdd_ipa_uc_disable_pipes(hdd_ipa);
1879 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301880 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001881 "IPA pipes are down, do nothing");
1882 }
1883
1884 return;
1885}
1886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887/**
1888 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1889 *
1890 * Deinit basic IPA UC host side to be in sync reloaded FW during
1891 * SSR
1892 *
1893 * Return: 0 - Success
1894 */
1895int hdd_ipa_uc_ssr_deinit(void)
1896{
1897 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1898 int idx;
1899 struct hdd_ipa_iface_context *iface_context;
1900
Leo Chang3bc8fed2015-11-13 10:59:47 -08001901 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001902 return 0;
1903
1904 /* Clean up HDD IPA interfaces */
1905 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1906 (idx < HDD_IPA_MAX_IFACE); idx++) {
1907 iface_context = &hdd_ipa->iface_context[idx];
1908 if (iface_context && iface_context->adapter)
1909 hdd_ipa_cleanup_iface(iface_context);
1910 }
1911
1912 /* After SSR, wlan driver reloads FW again. But we need to protect
1913 * IPA submodule during SSR transient state. So deinit basic IPA
1914 * UC host side to be in sync with reloaded FW during SSR
1915 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001916 if (!hdd_ipa->ipa_pipes_down)
1917 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001918
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301919 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001920 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1921 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1922 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1923 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301924 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925
1926 /* Full IPA driver cleanup not required since wlan driver is now
1927 * unloaded and reloaded after SSR.
1928 */
1929 return 0;
1930}
1931
1932/**
1933 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1934 *
1935 * Init basic IPA UC host side to be in sync with reloaded FW after
1936 * SSR to resume IPA UC operations
1937 *
1938 * Return: 0 - Success
1939 */
1940int hdd_ipa_uc_ssr_reinit(void)
1941{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001942
1943 /* After SSR is complete, IPA UC can resume operation. But now wlan
1944 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1945 * and initialization. This is a placeholder func if IPA has to resume
1946 * operations without driver reload.
1947 */
1948 return 0;
1949}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001950
1951/**
1952 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1953 * @hdd_ctx: Global HDD context
1954 * @skb: skb sent to IPA
1955 * @session_id: send packet instance session id
1956 *
1957 * Send TX packet which generated by system to IPA.
1958 * This routine only will be used for function verification
1959 *
1960 * Return: NULL packet sent to IPA properly
1961 * NULL invalid packet drop
1962 * skb packet not sent to IPA. legacy data path should handle
1963 */
1964struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1965 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001966{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001967 struct ipa_header *ipa_header;
1968 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07001969 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001970
1971 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1972 return skb;
1973
Leo Chang07b28f62016-05-11 12:29:22 -07001974 if (!hdd_ipa)
1975 return skb;
1976
1977 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
1978 return skb;
1979
Leo Changcc923e22016-06-16 15:29:03 -07001980 if (skb_headroom(skb) <
1981 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07001982 return skb;
1983
Leo Chang3bc8fed2015-11-13 10:59:47 -08001984 ipa_header = (struct ipa_header *) skb_push(skb,
1985 sizeof(struct ipa_header));
1986 if (!ipa_header) {
1987 /* No headroom, legacy */
1988 return skb;
1989 }
1990 memset(ipa_header, 0, sizeof(*ipa_header));
1991 ipa_header->vdev_id = 0;
1992
1993 frag_header = (struct frag_header *) skb_push(skb,
1994 sizeof(struct frag_header));
1995 if (!frag_header) {
1996 /* No headroom, drop */
1997 kfree_skb(skb);
1998 return NULL;
1999 }
2000 memset(frag_header, 0, sizeof(*frag_header));
2001 frag_header->length = skb->len - sizeof(struct frag_header)
2002 - sizeof(struct ipa_header);
2003
2004 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2005 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002006}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002007
2008/**
2009 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2010 * @work: scheduled work
2011 *
2012 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2013 * not want to immediately release the wake lock since the system
2014 * would then potentially try to suspend when there is a healthy data
2015 * rate. Deferred work is scheduled and this function handles the
2016 * work. When this function is called, if the IPA resource is still
2017 * released then we release the wake lock.
2018 *
2019 * Return: None
2020 */
2021static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2022{
2023 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2024 struct hdd_ipa_priv,
2025 wake_lock_work);
2026
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302027 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028
2029 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2030 goto end;
2031
2032 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302033 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034 WIFI_POWER_EVENT_WAKELOCK_IPA);
2035
2036end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302037 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038}
2039
2040/**
2041 * hdd_ipa_rm_request() - Request resource from IPA
2042 * @hdd_ipa: Global HDD IPA context
2043 *
2044 * Return: 0 on success, negative errno on error
2045 */
2046static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2047{
2048 int ret = 0;
2049
2050 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2051 return 0;
2052
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302053 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002054
2055 switch (hdd_ipa->rm_state) {
2056 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302057 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058 return 0;
2059 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302060 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061 return -EINPROGRESS;
2062 case HDD_IPA_RM_RELEASED:
2063 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2064 break;
2065 }
2066
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302067 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068
2069 ret = ipa_rm_inactivity_timer_request_resource(
2070 IPA_RM_RESOURCE_WLAN_PROD);
2071
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302072 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002073 if (ret == 0) {
2074 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2075 hdd_ipa->stats.num_rm_grant_imm++;
2076 }
2077
2078 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2079 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302080 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002081 WIFI_POWER_EVENT_WAKELOCK_IPA);
2082 hdd_ipa->wake_lock_released = false;
2083 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302084 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085
2086 return ret;
2087}
2088
2089/**
2090 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2091 * @hdd_ipa: Global HDD IPA context
2092 *
2093 * Return: 0 if resources released, negative errno otherwise
2094 */
2095static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2096{
2097 int ret = 0;
2098
2099 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2100 return 0;
2101
2102 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2103 return -EAGAIN;
2104
2105 spin_lock_bh(&hdd_ipa->q_lock);
2106 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2107 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2108 spin_unlock_bh(&hdd_ipa->q_lock);
2109 return -EAGAIN;
2110 }
2111 spin_unlock_bh(&hdd_ipa->q_lock);
2112
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302113 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114
Nirav Shahcbc6d722016-03-01 16:24:53 +05302115 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302116 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117 return -EAGAIN;
2118 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302119 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002120
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302121 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122 switch (hdd_ipa->rm_state) {
2123 case HDD_IPA_RM_GRANTED:
2124 break;
2125 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302126 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002127 return -EINPROGRESS;
2128 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302129 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002130 return 0;
2131 }
2132
2133 /* IPA driver returns immediately so set the state here to avoid any
2134 * race condition.
2135 */
2136 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2137 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302138 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139
2140 ret =
2141 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2142
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302143 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002144 if (unlikely(ret != 0)) {
2145 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2146 WARN_ON(1);
2147 }
2148
2149 /*
2150 * If wake_lock is released immediately, kernel would try to suspend
2151 * immediately as well, Just avoid ping-pong between suspend-resume
2152 * while there is healthy amount of data transfer going on by
2153 * releasing the wake_lock after some delay.
2154 */
2155 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2156 msecs_to_jiffies
2157 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2158
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302159 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002160
2161 return ret;
2162}
2163
2164/**
2165 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2166 * @user_data: user data registered with IPA
2167 * @event: the IPA resource manager event that occurred
2168 * @data: the data associated with the event
2169 *
2170 * Return: None
2171 */
2172static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2173 unsigned long data)
2174{
2175 struct hdd_ipa_priv *hdd_ipa = user_data;
2176
2177 if (unlikely(!hdd_ipa))
2178 return;
2179
2180 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2181 return;
2182
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302183 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002184
2185 switch (event) {
2186 case IPA_RM_RESOURCE_GRANTED:
2187 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2188 /* RM Notification comes with ISR context
2189 * it should be serialized into work queue to avoid
2190 * ISR sleep problem
2191 */
2192 hdd_ipa->uc_rm_work.event = event;
2193 schedule_work(&hdd_ipa->uc_rm_work.work);
2194 break;
2195 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302196 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002197 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302198 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002199 hdd_ipa->stats.num_rm_grant++;
2200 break;
2201
2202 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302203 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002204 hdd_ipa->resource_unloading = false;
2205 break;
2206
2207 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302208 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002209 break;
2210 }
2211}
2212
2213/**
2214 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2215 *
2216 * Callback function registered with IPA that is called when IPA wants
2217 * to release the WLAN consumer resource
2218 *
2219 * Return: 0 if the request is granted, negative errno otherwise
2220 */
2221static int hdd_ipa_rm_cons_release(void)
2222{
2223 return 0;
2224}
2225
2226/**
2227 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2228 *
2229 * Callback function registered with IPA that is called when IPA wants
2230 * to access the WLAN consumer resource
2231 *
2232 * Return: 0 if the request is granted, negative errno otherwise
2233 */
2234static int hdd_ipa_rm_cons_request(void)
2235{
Yun Park4d8b60a2015-10-22 13:59:32 -07002236 int ret = 0;
2237
2238 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302239 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002240 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241 __func__);
2242 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002243 ret = -EINPROGRESS;
2244 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302245 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002246 "%s: IPA resource unloading in progress",
2247 __func__);
2248 ghdd_ipa->pending_cons_req = true;
2249 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002251
2252 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253}
2254
2255/**
2256 * hdd_ipa_set_perf_level() - Set IPA performance level
2257 * @hdd_ctx: Global HDD context
2258 * @tx_packets: Number of packets transmitted in the last sample period
2259 * @rx_packets: Number of packets received in the last sample period
2260 *
2261 * Return: 0 on success, negative errno on error
2262 */
2263int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2264 uint64_t rx_packets)
2265{
2266 uint32_t next_cons_bw, next_prod_bw;
2267 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2268 struct ipa_rm_perf_profile profile;
2269 int ret;
2270
2271 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2272 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2273 return 0;
2274
2275 memset(&profile, 0, sizeof(profile));
2276
2277 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2278 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2279 else if (tx_packets >
2280 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2281 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2282 else
2283 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2284
2285 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2286 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2287 else if (rx_packets >
2288 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2289 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2290 else
2291 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2292
2293 HDD_IPA_LOG(LOG1,
2294 "CONS perf curr: %d, next: %d",
2295 hdd_ipa->curr_cons_bw, next_cons_bw);
2296 HDD_IPA_LOG(LOG1,
2297 "PROD perf curr: %d, next: %d",
2298 hdd_ipa->curr_prod_bw, next_prod_bw);
2299
2300 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302301 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002302 "Requesting CONS perf curr: %d, next: %d",
2303 hdd_ipa->curr_cons_bw, next_cons_bw);
2304 profile.max_supported_bandwidth_mbps = next_cons_bw;
2305 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2306 &profile);
2307 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302308 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002309 "RM CONS set perf profile failed: %d", ret);
2310
2311 return ret;
2312 }
2313 hdd_ipa->curr_cons_bw = next_cons_bw;
2314 hdd_ipa->stats.num_cons_perf_req++;
2315 }
2316
2317 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302318 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002319 "Requesting PROD perf curr: %d, next: %d",
2320 hdd_ipa->curr_prod_bw, next_prod_bw);
2321 profile.max_supported_bandwidth_mbps = next_prod_bw;
2322 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2323 &profile);
2324 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302325 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002326 "RM PROD set perf profile failed: %d", ret);
2327 return ret;
2328 }
2329 hdd_ipa->curr_prod_bw = next_prod_bw;
2330 hdd_ipa->stats.num_prod_perf_req++;
2331 }
2332
2333 return 0;
2334}
2335
2336/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002337 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2338 * @work: struct work_struct
2339 * @work_handler: work_handler
2340 *
2341 * Return: none
2342 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002343static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2344 work_func_t work_handler)
2345{
2346 INIT_WORK(work, work_handler);
2347}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002348
2349/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002350 * hdd_ipa_setup_rm() - Setup IPA resource management
2351 * @hdd_ipa: Global HDD IPA context
2352 *
2353 * Return: 0 on success, negative errno on error
2354 */
2355static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2356{
2357 struct ipa_rm_create_params create_params = { 0 };
2358 int ret;
2359
2360 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2361 return 0;
2362
Rajeev Kumar217f2172016-01-06 18:11:55 -08002363 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2364 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002365 memset(&create_params, 0, sizeof(create_params));
2366 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2367 create_params.reg_params.user_data = hdd_ipa;
2368 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2369 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2370
2371 ret = ipa_rm_create_resource(&create_params);
2372 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302373 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002374 "Create RM resource failed: %d", ret);
2375 goto setup_rm_fail;
2376 }
2377
2378 memset(&create_params, 0, sizeof(create_params));
2379 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2380 create_params.request_resource = hdd_ipa_rm_cons_request;
2381 create_params.release_resource = hdd_ipa_rm_cons_release;
2382 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2383
2384 ret = ipa_rm_create_resource(&create_params);
2385 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302386 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002387 "Create RM CONS resource failed: %d", ret);
2388 goto delete_prod;
2389 }
2390
2391 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2392 IPA_RM_RESOURCE_APPS_CONS);
2393
2394 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2395 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2396 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302397 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002398 ret);
2399 goto timer_init_failed;
2400 }
2401
2402 /* Set the lowest bandwidth to start with */
2403 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2404
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 "Set perf level failed: %d", ret);
2408 goto set_perf_failed;
2409 }
2410
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302411 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2413 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302414 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002415 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2416 hdd_ipa->wake_lock_released = true;
2417 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2418
2419 return ret;
2420
2421set_perf_failed:
2422 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2423
2424timer_init_failed:
2425 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2426
2427delete_prod:
2428 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2429
2430setup_rm_fail:
2431 return ret;
2432}
2433
2434/**
2435 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2436 * @hdd_ipa: Global HDD IPA context
2437 *
2438 * Destroys all resources associated with the IPA resource manager
2439 *
2440 * Return: None
2441 */
2442static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2443{
2444 int ret;
2445
2446 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2447 return;
2448
2449 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302450 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002451
2452#ifdef WLAN_OPEN_SOURCE
2453 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2454#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302455 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002456
2457 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2458
2459 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2460 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302461 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002462 "RM PROD resource delete failed %d", ret);
2463
2464 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2465 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302466 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002467 "RM CONS resource delete failed %d", ret);
2468}
2469
2470/**
2471 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2472 * @skb: network buffer
2473 * @adapter: network adapter
2474 *
2475 * Called when a network buffer is received which should not be routed
2476 * to the IPA module.
2477 *
2478 * Return: None
2479 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302480static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002481 hdd_adapter_t *adapter)
2482{
2483 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2484 unsigned int cpu_index;
2485
2486 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302487 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 adapter);
2489 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002490 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 return;
2492 }
2493
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002494 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002495 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002496 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002497 return;
2498 }
2499
2500 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2501 skb->dev = adapter->dev;
2502 skb->protocol = eth_type_trans(skb, skb->dev);
2503 skb->ip_summed = CHECKSUM_NONE;
2504
2505 cpu_index = wlan_hdd_get_cpu();
2506
2507 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2508 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2509 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2510 else
2511 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2512
2513 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2514 adapter->dev->last_rx = jiffies;
2515}
2516
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002517/**
Leo Chang69c39692016-10-12 20:11:12 -07002518 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2519 * @hdd_ipa: pointer to hdd ipa context
2520 * @adapter: network adapter
2521 * @skb: data pointer
2522 *
2523 * if exception packet has set forward bit, copied new packet should be
2524 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2525 * put into pm queue and tx procedure will be differed
2526 *
2527 * Return: None
2528 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002529static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2530 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002531{
2532 qdf_nbuf_t copy;
2533 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2534
2535 copy = qdf_nbuf_copy(skb);
2536 if (!copy) {
2537 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2538 return;
2539 }
2540
2541 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2542 /* WLAN subsystem is in suspend, put int queue */
2543 if (hdd_ipa->suspended) {
2544 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2545 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2546 "TX in SUSPEND PUT QUEUE");
2547 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2548 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2549 pm_tx_cb->exception = true;
2550 pm_tx_cb->adapter = adapter;
2551 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2552 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2553 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2554 hdd_ipa->stats.num_tx_queued++;
2555 } else {
2556 /* Resume, put packet into WLAN TX */
2557 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2558 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2559 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2560 "packet tx fail");
2561 } else {
2562 hdd_ipa->stats.num_tx_bcmc++;
2563 hdd_ipa->ipa_tx_forward++;
2564 }
2565 }
2566}
2567
2568/**
2569 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002570 * @priv: pointer to private data registered with IPA (we register a
2571 * pointer to the global IPA context)
2572 * @evt: the IPA event which triggered the callback
2573 * @data: data associated with the event
2574 *
2575 * Return: None
2576 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002577static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578 unsigned long data)
2579{
2580 struct hdd_ipa_priv *hdd_ipa = NULL;
2581 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302582 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 uint8_t iface_id;
2584 uint8_t session_id;
2585 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002586 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002587 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002588
2589 hdd_ipa = (struct hdd_ipa_priv *)priv;
2590
2591 switch (evt) {
2592 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302593 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002594
2595 /*
2596 * When SSR is going on or driver is unloading,
2597 * just drop the packets.
2598 */
2599 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2600 if (0 != status) {
2601 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2602 "Invalid context: drop packet");
2603 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2604 kfree_skb(skb);
2605 return;
2606 }
2607
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002608 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2609 session_id = (uint8_t)skb->cb[0];
2610 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302611 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2613 session_id, iface_id);
2614 } else {
2615 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2616 }
2617
2618 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302619 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002620 "IPA_RECEIVE: Invalid iface_id: %u",
2621 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302622 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002623 "w2i -- skb", skb->data, 8);
2624 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002625 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002626 return;
2627 }
2628
2629 iface_context = &hdd_ipa->iface_context[iface_id];
2630 adapter = iface_context->adapter;
2631
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302632 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002633 "w2i -- skb", skb->data, 8);
2634 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2635 hdd_ipa->stats.num_rx_excep++;
2636 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2637 } else {
2638 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2639 }
2640
2641 iface_context->stats.num_rx_ipa_excep++;
2642
2643 /* Disable to forward Intra-BSS Rx packets when
2644 * ap_isolate=1 in hostapd.conf
2645 */
Yun Park046101c2016-09-02 15:32:14 -07002646 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647 /*
2648 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2649 * all Rx packets to IPA uC, which need to be forwarded
2650 * to other interface.
2651 * And, IPA driver will send back to WLAN host driver
2652 * through exception pipe with fw_desc field set by FW.
2653 * Here we are checking fw_desc field for FORWARD bit
2654 * set, and forward to Tx. Then copy to kernel stack
2655 * only when DISCARD bit is not set.
2656 */
2657 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002658 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302659 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302660 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002661 "Forward packet to Tx (fw_desc=%d)",
2662 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002663 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002665 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002666 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2667 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002668 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002669 break;
2670 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002671 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302672 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002673 "Intra-BSS FWD is disabled-skip forward to Tx");
2674 }
2675
2676 hdd_ipa_send_skb_to_network(skb, adapter);
2677 break;
2678
2679 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302680 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002681 "w2i cb wrong event: 0x%x", evt);
2682 return;
2683 }
2684}
2685
2686/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002687 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2688 * @priv: pointer to private data registered with IPA (we register a
2689 * pointer to the global IPA context)
2690 * @evt: the IPA event which triggered the callback
2691 * @data: data associated with the event
2692 *
2693 * Return: None
2694 */
2695static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2696 unsigned long data)
2697{
2698 cds_ssr_protect(__func__);
2699 __hdd_ipa_w2i_cb(priv, evt, data);
2700 cds_ssr_unprotect(__func__);
2701}
2702
2703/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2705 * @skb: packet buffer which was transmitted
2706 *
2707 * Return: None
2708 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302709void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002710{
2711 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2712
Govind Singhb6a89772016-08-12 11:23:35 +05302713 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302714 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002715 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302716 ipa_free_skb((struct ipa_rx_data *)
2717 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002718
2719 hdd_ipa->stats.num_tx_comp_cnt++;
2720
2721 atomic_dec(&hdd_ipa->tx_ref_cnt);
2722
2723 hdd_ipa_rm_try_release(hdd_ipa);
2724}
2725
2726/**
2727 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2728 * @iface_context: interface-specific IPA context
2729 * @ipa_tx_desc: packet data descriptor
2730 *
2731 * Return: None
2732 */
2733static void hdd_ipa_send_pkt_to_tl(
2734 struct hdd_ipa_iface_context *iface_context,
2735 struct ipa_rx_data *ipa_tx_desc)
2736{
2737 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2738 uint8_t interface_id;
2739 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302740 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002741
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302742 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 adapter = iface_context->adapter;
2744 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302745 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746 ipa_free_skb(ipa_tx_desc);
2747 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302748 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002749 hdd_ipa_rm_try_release(hdd_ipa);
2750 return;
2751 }
2752
2753 /*
2754 * During CAC period, data packets shouldn't be sent over the air so
2755 * drop all the packets here
2756 */
2757 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2758 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302759 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002760 iface_context->stats.num_tx_cac_drop++;
2761 hdd_ipa_rm_try_release(hdd_ipa);
2762 return;
2763 }
2764
2765 interface_id = adapter->sessionId;
2766 ++adapter->stats.tx_packets;
2767
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302768 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002769
2770 skb = ipa_tx_desc->skb;
2771
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302772 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302773 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002774 /* FIXME: This is broken. No such field in cb any more:
2775 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302777 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002778 ipa_tx_desc->dma_addr
2779 + HDD_IPA_WLAN_FRAG_HEADER
2780 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002781 ipa_tx_desc->skb->len -=
2782 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2783 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302784 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002786 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302787 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788
2789 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2790
2791 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2792 ipa_tx_desc->skb);
2793 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302794 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002795 ipa_free_skb(ipa_tx_desc);
2796 iface_context->stats.num_tx_err++;
2797 hdd_ipa_rm_try_release(hdd_ipa);
2798 return;
2799 }
2800
2801 atomic_inc(&hdd_ipa->tx_ref_cnt);
2802
2803 iface_context->stats.num_tx++;
2804
2805}
2806
2807/**
Leo Chang11545d62016-10-17 14:53:50 -07002808 * hdd_ipa_is_present() - get IPA hw status
2809 * @hdd_ctx: pointer to hdd context
2810 *
2811 * ipa_uc_reg_rdyCB is not directly designed to check
2812 * ipa hw status. This is an undocumented function which
2813 * has confirmed with IPA team.
2814 *
2815 * Return: true - ipa hw present
2816 * false - ipa hw not present
2817 */
2818bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2819{
2820 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002821 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002822 return true;
2823 else
2824 return false;
2825}
2826
2827/**
Leo Chang69c39692016-10-12 20:11:12 -07002828 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002829 * @work: pointer to the scheduled work
2830 *
2831 * Called during PM resume to send packets to TL which were queued
2832 * while host was in the process of suspending.
2833 *
2834 * Return: None
2835 */
Leo Chang69c39692016-10-12 20:11:12 -07002836static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837{
2838 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2839 struct hdd_ipa_priv,
2840 pm_work);
2841 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302842 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843 uint32_t dequeued = 0;
2844
Leo Chang69c39692016-10-12 20:11:12 -07002845 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2846 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302847 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302848 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2849 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302850 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002851
2852 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002854 if (pm_tx_cb->exception) {
2855 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2856 "FLUSH EXCEPTION");
2857 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2858 } else {
2859 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002861 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302862 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302864 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002865 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2866 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867
2868 hdd_ipa->stats.num_tx_dequeued += dequeued;
2869 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2870 hdd_ipa->stats.num_max_pm_queue = dequeued;
2871}
2872
2873/**
2874 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2875 * @priv: pointer to private data registered with IPA (we register a
2876 * pointer to the interface-specific IPA context)
2877 * @evt: the IPA event which triggered the callback
2878 * @data: data associated with the event
2879 *
2880 * Return: None
2881 */
2882static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2883 unsigned long data)
2884{
2885 struct hdd_ipa_priv *hdd_ipa = NULL;
2886 struct ipa_rx_data *ipa_tx_desc;
2887 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302888 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002889 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302890 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891
Mukul Sharma81661ae2015-10-30 20:26:02 +05302892 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002893 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302894 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002895 dev_kfree_skb_any(skb);
2896 iface_context->stats.num_tx_drop++;
2897 return;
2898 }
2899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002900 ipa_tx_desc = (struct ipa_rx_data *)data;
2901
2902 hdd_ipa = iface_context->hdd_ipa;
2903
2904 /*
2905 * When SSR is going on or driver is unloading, just drop the packets.
2906 * During SSR, there is no use in queueing the packets as STA has to
2907 * connect back any way
2908 */
2909 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302910 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911 ipa_free_skb(ipa_tx_desc);
2912 iface_context->stats.num_tx_drop++;
2913 return;
2914 }
2915
2916 skb = ipa_tx_desc->skb;
2917
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302918 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002919
2920 /*
2921 * If PROD resource is not requested here then there may be cases where
2922 * IPA hardware may be clocked down because of not having proper
2923 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2924 * workaround to request PROD resource while data is going over CONS
2925 * pipe to prevent the IPA hardware clockdown.
2926 */
2927 hdd_ipa_rm_request(hdd_ipa);
2928
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302929 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930 /*
2931 * If host is still suspended then queue the packets and these will be
2932 * drained later when resume completes. When packet is arrived here and
2933 * host is suspended, this means that there is already resume is in
2934 * progress.
2935 */
2936 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302937 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2939 pm_tx_cb->iface_context = iface_context;
2940 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302941 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942 hdd_ipa->stats.num_tx_queued++;
2943
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302944 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945 return;
2946 }
2947
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302948 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002949
2950 /*
2951 * If we are here means, host is not suspended, wait for the work queue
2952 * to finish.
2953 */
2954#ifdef WLAN_OPEN_SOURCE
2955 flush_work(&hdd_ipa->pm_work);
2956#endif
2957
2958 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2959}
2960
2961/**
2962 * hdd_ipa_suspend() - Suspend IPA
2963 * @hdd_ctx: Global HDD context
2964 *
2965 * Return: 0 on success, negativer errno on error
2966 */
2967int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2968{
2969 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2970
2971 if (!hdd_ipa_is_enabled(hdd_ctx))
2972 return 0;
2973
2974 /*
2975 * Check if IPA is ready for suspend, If we are here means, there is
2976 * high chance that suspend would go through but just to avoid any race
2977 * condition after suspend started, these checks are conducted before
2978 * allowing to suspend.
2979 */
2980 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2981 return -EAGAIN;
2982
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302983 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984
2985 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302986 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002987 return -EAGAIN;
2988 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302989 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002990
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302991 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302993 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994
2995 return 0;
2996}
2997
2998/**
2999 * hdd_ipa_resume() - Resume IPA following suspend
3000 * hdd_ctx: Global HDD context
3001 *
3002 * Return: 0 on success, negative errno on error
3003 */
3004int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3005{
3006 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3007
3008 if (!hdd_ipa_is_enabled(hdd_ctx))
3009 return 0;
3010
3011 schedule_work(&hdd_ipa->pm_work);
3012
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303013 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303015 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003016
3017 return 0;
3018}
3019
3020/**
3021 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3022 * @hdd_ipa: Global HDD IPA context
3023 *
3024 * Return: 0 on success, negative errno on error
3025 */
3026static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3027{
3028 int i, ret = 0;
3029 struct ipa_sys_connect_params *ipa;
3030 uint32_t desc_fifo_sz;
3031
3032 /* The maximum number of descriptors that can be provided to a BAM at
3033 * once is one less than the total number of descriptors that the buffer
3034 * can contain.
3035 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3036 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3037 * be provided at once.
3038 * Because of above requirement, one extra descriptor will be added to
3039 * make sure hardware always has one descriptor.
3040 */
3041 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3042 + sizeof(struct sps_iovec);
3043
3044 /*setup TX pipes */
3045 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3046 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3047
3048 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3049 ipa->desc_fifo_sz = desc_fifo_sz;
3050 ipa->priv = &hdd_ipa->iface_context[i];
3051 ipa->notify = hdd_ipa_i2w_cb;
3052
3053 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3054 ipa->ipa_ep_cfg.hdr.hdr_len =
3055 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3056 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3057 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3058 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3059 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3060 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3061 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3062 } else {
3063 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3064 }
3065 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3066
3067 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3068 ipa->keep_ipa_awake = 1;
3069
3070 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3071 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303072 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073 " ret: %d", i, ret);
3074 goto setup_sys_pipe_fail;
3075 }
3076 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3077 }
3078
3079 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3080 /*
3081 * Hard code it here, this can be extended if in case
3082 * PROD pipe is also per interface.
3083 * Right now there is no advantage of doing this.
3084 */
3085 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3086
3087 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3088
3089 ipa->client = hdd_ipa->prod_client;
3090
3091 ipa->desc_fifo_sz = desc_fifo_sz;
3092 ipa->priv = hdd_ipa;
3093 ipa->notify = hdd_ipa_w2i_cb;
3094
3095 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3096 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3097 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3098 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3099
3100 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3101 ipa->keep_ipa_awake = 1;
3102
3103 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3104 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303105 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106 "Failed for RX pipe: %d", ret);
3107 goto setup_sys_pipe_fail;
3108 }
3109 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3110 }
3111
3112 return ret;
3113
3114setup_sys_pipe_fail:
3115
3116 while (--i >= 0) {
3117 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303118 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119 sizeof(struct hdd_ipa_sys_pipe));
3120 }
3121
3122 return ret;
3123}
3124
3125/**
3126 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3127 * @hdd_ipa: Global HDD IPA context
3128 *
3129 * Return: None
3130 */
3131static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3132{
3133 int ret = 0, i;
3134 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3135 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3136 ret =
3137 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3138 conn_hdl);
3139 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303140 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 ret);
3142
3143 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3144 }
3145 }
3146}
3147
3148/**
3149 * hdd_ipa_register_interface() - register IPA interface
3150 * @hdd_ipa: Global IPA context
3151 * @iface_context: Per-interface IPA context
3152 *
3153 * Return: 0 on success, negative errno on error
3154 */
3155static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3156 struct hdd_ipa_iface_context
3157 *iface_context)
3158{
3159 struct ipa_tx_intf tx_intf;
3160 struct ipa_rx_intf rx_intf;
3161 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3162 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3163 char *ifname = iface_context->adapter->dev->name;
3164
3165 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3166 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3167
3168 int num_prop = 1;
3169 int ret = 0;
3170
3171 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3172 num_prop++;
3173
3174 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3175 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303176 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303178 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 goto register_interface_fail;
3180 }
3181
3182 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3183 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303184 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303186 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003187 goto register_interface_fail;
3188 }
3189
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303190 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3191 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192
3193 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3194 ifname, HDD_IPA_IPV4_NAME_EXT);
3195 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3196 ifname, HDD_IPA_IPV6_NAME_EXT);
3197
3198 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3199 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3200 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3201 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3202
3203 /*
3204 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3205 * mask to identify the interface in IPA hardware
3206 */
3207 rx_prop[IPA_IP_v4].attrib.meta_data =
3208 htonl(iface_context->adapter->sessionId << 16);
3209 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3210
3211 rx_intf.num_props++;
3212 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3213 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3214 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3215 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3216 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3217 rx_prop[IPA_IP_v4].attrib.meta_data =
3218 htonl(iface_context->adapter->sessionId << 16);
3219 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3220
3221 rx_intf.num_props++;
3222 }
3223
3224 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3225 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3226 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3227 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3228 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3229 IPA_RESOURCE_NAME_MAX);
3230 tx_intf.num_props++;
3231
3232 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3233 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3234 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3235 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3236 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3237 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3238 IPA_RESOURCE_NAME_MAX);
3239 tx_intf.num_props++;
3240 }
3241
3242 tx_intf.prop = tx_prop;
3243 rx_intf.prop = rx_prop;
3244
3245 /* Call the ipa api to register interface */
3246 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3247
3248register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303249 qdf_mem_free(tx_prop);
3250 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 return ret;
3252}
3253
3254/**
3255 * hdd_remove_ipa_header() - Remove a specific header from IPA
3256 * @name: Name of the header to be removed
3257 *
3258 * Return: None
3259 */
3260static void hdd_ipa_remove_header(char *name)
3261{
3262 struct ipa_ioc_get_hdr hdrlookup;
3263 int ret = 0, len;
3264 struct ipa_ioc_del_hdr *ipa_hdr;
3265
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303266 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3268 ret = ipa_get_hdr(&hdrlookup);
3269 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303270 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 name, ret);
3272 return;
3273 }
3274
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303275 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003276 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303277 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303279 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280 return;
3281 }
3282 ipa_hdr->num_hdls = 1;
3283 ipa_hdr->commit = 0;
3284 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3285 ipa_hdr->hdl[0].status = -1;
3286 ret = ipa_del_hdr(ipa_hdr);
3287 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303288 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289 ret);
3290
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303291 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292}
3293
3294/**
3295 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3296 * @hdd_ipa: Global HDD IPA context
3297 * @iface_context: Interface-specific HDD IPA context
3298 * @mac_addr: Interface MAC address
3299 *
3300 * Return: 0 on success, negativer errno value on error
3301 */
3302static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3303 struct hdd_ipa_iface_context *iface_context,
3304 uint8_t *mac_addr)
3305{
3306 hdd_adapter_t *adapter = iface_context->adapter;
3307 char *ifname;
3308 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3309 int ret = -EINVAL;
3310 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3311 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3312
3313 ifname = adapter->dev->name;
3314
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303315 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316 ifname, mac_addr);
3317
3318 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303319 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320 + sizeof(struct ipa_hdr_add));
3321 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303322 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003323 "%s: ipa_hdr allocation failed", ifname);
3324 ret = -ENOMEM;
3325 goto end;
3326 }
3327
3328 ipa_hdr->commit = 0;
3329 ipa_hdr->num_hdrs = 1;
3330
3331 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3332 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3333 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3334 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3335 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303336 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337 "ifname=%s, vdev_id=%d",
3338 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3339 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3340 ifname, HDD_IPA_IPV4_NAME_EXT);
3341 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3342 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3343 ipa_hdr->hdr[0].is_partial = 1;
3344 ipa_hdr->hdr[0].hdr_hdl = 0;
3345 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3346 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3347
3348 ret = ipa_add_hdr(ipa_hdr);
3349 } else {
3350 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3351
3352 /* Set the Source MAC */
3353 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3354 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3355
3356 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3357 ifname, HDD_IPA_IPV4_NAME_EXT);
3358 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3359 ipa_hdr->hdr[0].is_partial = 1;
3360 ipa_hdr->hdr[0].hdr_hdl = 0;
3361 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3362 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3363
3364 /* Set the type to IPV4 in the header */
3365 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3366
3367 ret = ipa_add_hdr(ipa_hdr);
3368 }
3369 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303370 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 ifname, ret);
3372 goto end;
3373 }
3374
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303375 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003376 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3377
3378 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3379 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3380 ifname, HDD_IPA_IPV6_NAME_EXT);
3381
3382 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3383 uc_tx_hdr =
3384 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3385 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3386 } else {
3387 /* Set the type to IPV6 in the header */
3388 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3389 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3390 }
3391
3392 ret = ipa_add_hdr(ipa_hdr);
3393 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303394 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003395 "%s: IPv6 add hdr failed: %d", ifname, ret);
3396 goto clean_ipv4_hdr;
3397 }
3398
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303399 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3401 }
3402
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303403 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404
3405 return ret;
3406
3407clean_ipv4_hdr:
3408 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3409 ifname, HDD_IPA_IPV4_NAME_EXT);
3410 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3411end:
3412 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303413 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003414
3415 return ret;
3416}
3417
3418/**
3419 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3420 * @adapter: Adapter upon which IPA was previously configured
3421 *
3422 * Return: None
3423 */
3424static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3425{
3426 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3427 int ret;
3428 char name_ipa[IPA_RESOURCE_NAME_MAX];
3429
3430 /* Remove the headers */
3431 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3432 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3433 hdd_ipa_remove_header(name_ipa);
3434
3435 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3436 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3437 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3438 hdd_ipa_remove_header(name_ipa);
3439 }
3440 /* unregister the interface with IPA */
3441 ret = ipa_deregister_intf(adapter->dev->name);
3442 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303443 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 "%s: ipa_deregister_intf fail: %d",
3445 adapter->dev->name, ret);
3446}
3447
3448/**
3449 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3450 * @iface_context: interface-specific IPA context
3451 *
3452 * Return: None
3453 */
3454static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3455{
3456 if (iface_context == NULL)
3457 return;
3458
3459 hdd_ipa_clean_hdr(iface_context->adapter);
3460
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303461 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 iface_context->adapter->ipa_context = NULL;
3463 iface_context->adapter = NULL;
3464 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303465 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466 iface_context->ifa_address = 0;
3467 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303468 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303470 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003471 }
3472 iface_context->hdd_ipa->num_iface--;
3473}
3474
3475/**
3476 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3477 * @hdd_ipa: HDD IPA global context
3478 * @adapter: Interface upon which IPA is being setup
3479 * @sta_id: Station ID of the API instance
3480 *
3481 * Return: 0 on success, negative errno value on error
3482 */
3483static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3484 hdd_adapter_t *adapter, uint8_t sta_id)
3485{
3486 struct hdd_ipa_iface_context *iface_context = NULL;
3487 void *tl_context = NULL;
3488 int i, ret = 0;
3489
3490 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3491 * channel change indication. Since these indications are sent by lower
3492 * layer as SAP updates and IPA doesn't have to do anything for these
3493 * updates so ignoring!
3494 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003495 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496 return 0;
3497
3498 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3499 if (hdd_ipa->iface_context[i].adapter == NULL) {
3500 iface_context = &(hdd_ipa->iface_context[i]);
3501 break;
3502 }
3503 }
3504
3505 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303506 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507 "All the IPA interfaces are in use");
3508 ret = -ENOMEM;
3509 goto end;
3510 }
3511
3512 adapter->ipa_context = iface_context;
3513 iface_context->adapter = adapter;
3514 iface_context->sta_id = sta_id;
3515 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3516
3517 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303518 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003519 "Not able to get TL context sta_id: %d", sta_id);
3520 ret = -EINVAL;
3521 goto end;
3522 }
3523
3524 iface_context->tl_context = tl_context;
3525
3526 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3527 adapter->dev->dev_addr);
3528
3529 if (ret)
3530 goto end;
3531
3532 /* Configure the TX and RX pipes filter rules */
3533 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3534 if (ret)
3535 goto cleanup_header;
3536
3537 hdd_ipa->num_iface++;
3538 return ret;
3539
3540cleanup_header:
3541
3542 hdd_ipa_clean_hdr(adapter);
3543end:
3544 if (iface_context)
3545 hdd_ipa_cleanup_iface(iface_context);
3546 return ret;
3547}
3548
3549/**
3550 * hdd_ipa_msg_free_fn() - Free an IPA message
3551 * @buff: pointer to the IPA message
3552 * @len: length of the IPA message
3553 * @type: type of IPA message
3554 *
3555 * Return: None
3556 */
3557static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3558{
3559 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3560 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303561 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562}
3563
Yun Parka27049a2016-10-11 12:30:49 -07003564#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003565/**
3566 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3567 * @mcc_mode: 0=MCC/1=SCC
3568 *
3569 * Return: 0 on success, negative errno value on error
3570 */
3571int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3572{
3573 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303574 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575 hdd_adapter_t *pAdapter;
3576 struct ipa_msg_meta meta;
3577 struct ipa_wlan_msg *msg;
3578 int ret;
3579
3580 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3581 return -EINVAL;
3582
3583 if (!pHddCtx->mcc_mode) {
3584 /* Flush TxRx queue for each adapter before switch to SCC */
3585 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303586 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003588 if (pAdapter->device_mode == QDF_STA_MODE ||
3589 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303590 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3592 pAdapter->device_mode);
3593 hdd_deinit_tx_rx(pAdapter);
3594 }
3595 status = hdd_get_next_adapter(
3596 pHddCtx, adapter_node, &next);
3597 adapter_node = next;
3598 }
3599 }
3600
3601 /* Send SCC/MCC Switching event to IPA */
3602 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303603 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 if (msg == NULL) {
3605 hddLog(LOGE, "msg allocation failed");
3606 return -ENOMEM;
3607 }
3608
3609 meta.msg_type = mcc_mode ?
3610 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3611 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3612
3613 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3614
3615 if (ret) {
3616 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3617 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303618 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 }
3620
3621 return ret;
3622}
Yun Parka27049a2016-10-11 12:30:49 -07003623#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003624
3625/**
3626 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3627 * @event: IPA WLAN event to be converted to a string
3628 *
3629 * Return: ASCII string representing the IPA WLAN event
3630 */
3631static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3632{
3633 switch (event) {
3634 case WLAN_CLIENT_CONNECT:
3635 return "WLAN_CLIENT_CONNECT";
3636 case WLAN_CLIENT_DISCONNECT:
3637 return "WLAN_CLIENT_DISCONNECT";
3638 case WLAN_CLIENT_POWER_SAVE_MODE:
3639 return "WLAN_CLIENT_POWER_SAVE_MODE";
3640 case WLAN_CLIENT_NORMAL_MODE:
3641 return "WLAN_CLIENT_NORMAL_MODE";
3642 case SW_ROUTING_ENABLE:
3643 return "SW_ROUTING_ENABLE";
3644 case SW_ROUTING_DISABLE:
3645 return "SW_ROUTING_DISABLE";
3646 case WLAN_AP_CONNECT:
3647 return "WLAN_AP_CONNECT";
3648 case WLAN_AP_DISCONNECT:
3649 return "WLAN_AP_DISCONNECT";
3650 case WLAN_STA_CONNECT:
3651 return "WLAN_STA_CONNECT";
3652 case WLAN_STA_DISCONNECT:
3653 return "WLAN_STA_DISCONNECT";
3654 case WLAN_CLIENT_CONNECT_EX:
3655 return "WLAN_CLIENT_CONNECT_EX";
3656
3657 case IPA_WLAN_EVENT_MAX:
3658 default:
3659 return "UNKNOWN";
3660 }
3661}
3662
3663/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003664 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3665 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3666 *
3667 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3668 */
3669static enum ipa_wlan_event
3670hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3671{
3672 enum ipa_wlan_event ipa_event;
3673
3674 switch (hdd_ipa_event_type) {
3675 case HDD_IPA_CLIENT_CONNECT:
3676 ipa_event = WLAN_CLIENT_CONNECT;
3677 break;
3678 case HDD_IPA_CLIENT_DISCONNECT:
3679 ipa_event = WLAN_CLIENT_DISCONNECT;
3680 break;
3681 case HDD_IPA_AP_CONNECT:
3682 ipa_event = WLAN_AP_CONNECT;
3683 break;
3684 case HDD_IPA_AP_DISCONNECT:
3685 ipa_event = WLAN_AP_DISCONNECT;
3686 break;
3687 case HDD_IPA_STA_CONNECT:
3688 ipa_event = WLAN_STA_CONNECT;
3689 break;
3690 case HDD_IPA_STA_DISCONNECT:
3691 ipa_event = WLAN_STA_DISCONNECT;
3692 break;
3693 case HDD_IPA_CLIENT_CONNECT_EX:
3694 ipa_event = WLAN_CLIENT_CONNECT_EX;
3695 break;
3696 case HDD_IPA_WLAN_EVENT_MAX:
3697 default:
3698 ipa_event = IPA_WLAN_EVENT_MAX;
3699 break;
3700 }
3701 return ipa_event;
3702
3703}
3704
3705/**
3706 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 * @adapter: adapter upon which the event was received
3708 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003709 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710 * @mac_address: MAC address associated with the event
3711 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003712 * This function is meant to be called from within wlan_hdd_ipa.c
3713 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714 * Return: 0 on success, negative errno value on error
3715 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003716static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003717 enum ipa_wlan_event type, uint8_t *mac_addr)
3718{
3719 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3720 struct ipa_msg_meta meta;
3721 struct ipa_wlan_msg *msg;
3722 struct ipa_wlan_msg_ex *msg_ex = NULL;
3723 int ret;
3724
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303725 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3727 mac_addr, sta_id);
3728
3729 if (type >= IPA_WLAN_EVENT_MAX)
3730 return -EINVAL;
3731
3732 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3733 return -EINVAL;
3734
3735 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303736 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737 return -EINVAL;
3738 }
3739
3740 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3741 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003742 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003743 return 0;
3744 }
3745
3746 /*
3747 * During IPA UC resource loading/unloading new events can be issued.
3748 * Store the events separately and handle them later.
3749 */
3750 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3751 ((hdd_ipa->resource_loading) ||
3752 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003753 unsigned int pending_event_count;
3754 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755
Yun Parkf19e07d2015-11-20 11:34:27 -08003756 hdd_err("IPA resource %s inprogress",
3757 hdd_ipa->resource_loading ? "load":"unload");
3758
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303759 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003760
Anurag Chouhanffb21542016-02-17 14:33:03 +05303761 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003762 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3763 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303764 qdf_list_remove_front(&hdd_ipa->pending_event,
3765 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003766 } else {
3767 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303768 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003769 sizeof(struct ipa_uc_pending_event));
3770 }
3771
3772 if (!pending_event) {
3773 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303774 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003775 return -ENOMEM;
3776 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003777
3778 pending_event->adapter = adapter;
3779 pending_event->sta_id = sta_id;
3780 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303781 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003782 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303783 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303784 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003785 &pending_event->node);
3786
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303787 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003788 return 0;
3789 }
3790
3791 hdd_ipa->stats.event[type]++;
3792
Leo Chang3bc8fed2015-11-13 10:59:47 -08003793 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003794 switch (type) {
3795 case WLAN_STA_CONNECT:
3796 /* STA already connected and without disconnect, connect again
3797 * This is Roaming scenario
3798 */
3799 if (hdd_ipa->sta_connected)
3800 hdd_ipa_cleanup_iface(adapter->ipa_context);
3801
Yun Parka37592b2016-06-11 17:10:28 -07003802 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3803 (hdd_ipa->sap_num_connected_sta > 0) &&
3804 !hdd_ipa->sta_connected)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805 hdd_ipa_uc_offload_enable_disable(adapter,
3806 SIR_STA_RX_DATA_OFFLOAD, 1);
3807
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303808 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3811 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303812 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003813 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3814 (hdd_ipa->sap_num_connected_sta > 0) &&
3815 !hdd_ipa->sta_connected)
3816 hdd_ipa_uc_offload_enable_disable(adapter,
3817 SIR_STA_RX_DATA_OFFLOAD, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003819 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821 vdev_to_iface[adapter->sessionId] =
3822 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003823 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003824
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303825 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826
3827 hdd_ipa->sta_connected = 1;
3828 break;
3829
3830 case WLAN_AP_CONNECT:
3831 /* For DFS channel we get two start_bss event (before and after
3832 * CAC). Also when ACS range includes both DFS and non DFS
3833 * channels, we could possibly change channel many times due to
3834 * RADAR detection and chosen channel may not be a DFS channels.
3835 * So dont return error here. Just discard the event.
3836 */
3837 if (adapter->ipa_context)
3838 return 0;
3839
Yun Parka37592b2016-06-11 17:10:28 -07003840 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 hdd_ipa_uc_offload_enable_disable(adapter,
3842 SIR_AP_RX_DATA_OFFLOAD, 1);
Yun Parka37592b2016-06-11 17:10:28 -07003843
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303844 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3846 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303847 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 "%s: Evt: %d, Interface setup failed",
3849 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303850 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003852 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 vdev_to_iface[adapter->sessionId] =
3855 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003856 (adapter->ipa_context))->iface_id;
3857
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303858 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859 break;
3860
3861 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303862 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003863 hdd_ipa_cleanup_iface(adapter->ipa_context);
3864
3865 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303866 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 "%s: Evt: %d, STA already disconnected",
3868 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303869 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 return -EINVAL;
3871 }
Yun Parka37592b2016-06-11 17:10:28 -07003872
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003873 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303876 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003877 "%s: IPA UC OFFLOAD NOT ENABLED",
3878 msg_ex->name);
3879 } else {
3880 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003881 if (!hdd_ipa->num_iface &&
3882 (HDD_IPA_UC_NUM_WDI_PIPE ==
3883 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 }
3886
Yun Park74127cf2016-09-18 11:22:41 -07003887 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3888 (hdd_ipa->sap_num_connected_sta > 0)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 hdd_ipa_uc_offload_enable_disable(adapter,
3890 SIR_STA_RX_DATA_OFFLOAD, 0);
3891 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3892 }
3893
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303894 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003895 break;
3896
3897 case WLAN_AP_DISCONNECT:
3898 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303899 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 "%s: Evt: %d, SAP already disconnected",
3901 msg_ex->name, meta.msg_type);
3902 return -EINVAL;
3903 }
3904
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303905 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 hdd_ipa_cleanup_iface(adapter->ipa_context);
3907 if ((!hdd_ipa->num_iface) &&
3908 (HDD_IPA_UC_NUM_WDI_PIPE ==
3909 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003910 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 /*
3912 * We disable WDI pipes directly here since
3913 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3914 * processed when unloading WLAN driver is in
3915 * progress
3916 */
3917 hdd_ipa_uc_disable_pipes(hdd_ipa);
3918 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303919 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 "NO INTF left but still pipe clean up");
3921 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3922 }
3923 }
3924
3925 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3926 hdd_ipa_uc_offload_enable_disable(adapter,
3927 SIR_AP_RX_DATA_OFFLOAD, 0);
3928 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3929 }
Yun Parka37592b2016-06-11 17:10:28 -07003930
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303931 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 break;
3933
3934 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303935 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 adapter->dev->ifindex, sta_id);
3937
3938 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303939 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3941 adapter->dev->name, meta.msg_type);
3942 return 0;
3943 }
3944
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303945 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3947 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303948 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 "%s: STA ID %d found, not valid",
3950 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303951 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003952 return 0;
3953 }
Yun Park312f71a2015-12-08 10:22:42 -08003954
3955 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07003956 if (0 == hdd_ipa->sap_num_connected_sta) {
3957 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3958 hdd_ipa->sta_connected)
3959 hdd_ipa_uc_offload_enable_disable(
3960 hdd_get_adapter(hdd_ipa->hdd_ctx,
3961 QDF_STA_MODE),
3962 SIR_STA_RX_DATA_OFFLOAD, 1);
3963
Yun Park312f71a2015-12-08 10:22:42 -08003964 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3965 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303966 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303967 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003968 "%s: handle 1st con ret %d",
3969 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07003970
3971 if (hdd_ipa_uc_sta_is_enabled(
3972 hdd_ipa->hdd_ctx) &&
3973 hdd_ipa->sta_connected)
3974 hdd_ipa_uc_offload_enable_disable(
3975 hdd_get_adapter(
3976 hdd_ipa->hdd_ctx,
3977 QDF_STA_MODE),
3978 SIR_STA_RX_DATA_OFFLOAD, 0);
3979
Yun Park312f71a2015-12-08 10:22:42 -08003980 return ret;
3981 }
3982 }
3983
3984 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003985
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303986 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987
3988 meta.msg_type = type;
3989 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3990 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303991 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992
3993 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303994 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995 "msg_ex allocation failed");
3996 return -ENOMEM;
3997 }
3998 strlcpy(msg_ex->name, adapter->dev->name,
3999 IPA_RESOURCE_NAME_MAX);
4000 msg_ex->num_of_attribs = 1;
4001 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4002 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4003 msg_ex->attribs[0].offset =
4004 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4005 } else {
4006 msg_ex->attribs[0].offset =
4007 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4008 }
4009 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4010 IPA_MAC_ADDR_SIZE);
4011
4012 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4013
4014 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304015 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304017 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 return ret;
4019 }
4020 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 return ret;
4022
4023 case WLAN_CLIENT_DISCONNECT:
4024 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304025 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004026 "%s: IPA UC OFFLOAD NOT ENABLED",
4027 msg_ex->name);
4028 return 0;
4029 }
4030
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304031 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304033 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 "%s: STA ID %d NOT found, not valid",
4035 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304036 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037 return 0;
4038 }
4039 hdd_ipa->sap_num_connected_sta--;
4040 /* Disable IPA UC TX PIPE when last STA disconnected */
4041 if (!hdd_ipa->sap_num_connected_sta
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 && (false == hdd_ipa->resource_unloading)
4043 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4044 hdd_ipa->activated_fw_pipe))
4045 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Yun Parka37592b2016-06-11 17:10:28 -07004046
4047 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4048 hdd_ipa->sta_connected)
4049 hdd_ipa_uc_offload_enable_disable(
4050 hdd_get_adapter(hdd_ipa->hdd_ctx,
4051 QDF_STA_MODE),
4052 SIR_STA_RX_DATA_OFFLOAD, 0);
4053
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304054 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055 break;
4056
4057 default:
4058 return 0;
4059 }
4060
4061 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304062 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304064 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065 return -ENOMEM;
4066 }
4067
4068 meta.msg_type = type;
4069 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4070 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4071
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304072 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 msg->name, meta.msg_type);
4074
4075 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4076
4077 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304078 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304080 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 return ret;
4082 }
4083
4084 hdd_ipa->stats.num_send_msg++;
4085
4086end:
4087 return ret;
4088}
4089
4090/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004091 * hdd_ipa_wlan_evt() - IPA event handler
4092 * @adapter: adapter upon which the event was received
4093 * @sta_id: station id for the event
4094 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4095 * @mac_address: MAC address associated with the event
4096 *
4097 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4098 *
4099 * Return: 0 on success, negative errno value on error
4100 */
4101int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4102 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4103{
4104 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4105
Leo Changa202b522016-10-14 16:13:50 -07004106 /* Data path offload only support for STA and SAP mode */
4107 if ((QDF_STA_MODE == adapter->device_mode) ||
4108 (QDF_SAP_MODE == adapter->device_mode))
4109 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4110
4111 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004112}
4113
4114/**
4115 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4116 * @hdd_ipa: Global HDD IPA context
4117 *
4118 * Return: None
4119 */
4120static void
4121hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4122{
4123 unsigned int pending_event_count;
4124 struct ipa_uc_pending_event *pending_event = NULL;
4125
4126 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4127 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4128 "%s, Pending Event Count %d", __func__, pending_event_count);
4129 if (!pending_event_count) {
4130 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4131 "%s, No Pending Event", __func__);
4132 return;
4133 }
4134
4135 qdf_list_remove_front(&hdd_ipa->pending_event,
4136 (qdf_list_node_t **)&pending_event);
4137 while (pending_event != NULL) {
4138 __hdd_ipa_wlan_evt(pending_event->adapter,
4139 pending_event->type,
4140 pending_event->sta_id,
4141 pending_event->mac_addr);
4142 qdf_mem_free(pending_event);
4143 pending_event = NULL;
4144 qdf_list_remove_front(&hdd_ipa->pending_event,
4145 (qdf_list_node_t **)&pending_event);
4146 }
4147}
4148
4149/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4151 * @state: IPA RM state value
4152 *
4153 * Return: ASCII string representing the IPA RM state
4154 */
4155static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4156{
4157 switch (state) {
4158 case HDD_IPA_RM_RELEASED:
4159 return "RELEASED";
4160 case HDD_IPA_RM_GRANT_PENDING:
4161 return "GRANT_PENDING";
4162 case HDD_IPA_RM_GRANTED:
4163 return "GRANTED";
4164 }
4165
4166 return "UNKNOWN";
4167}
4168
4169/**
4170 * hdd_ipa_init() - IPA initialization function
4171 * @hdd_ctx: HDD global context
4172 *
4173 * Allocate hdd_ipa resources, ipa pipe resource and register
4174 * wlan interface with IPA module.
4175 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304176 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304178QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179{
4180 struct hdd_ipa_priv *hdd_ipa = NULL;
4181 int ret, i;
4182 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004183 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184
4185 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304186 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187
Yun Park7f171ab2016-07-29 15:44:22 -07004188 if (!pdev) {
4189 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4190 goto fail_return;
4191 }
4192
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304193 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304195 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004196 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 }
4198
4199 hdd_ctx->hdd_ipa = hdd_ipa;
4200 ghdd_ipa = hdd_ipa;
4201 hdd_ipa->hdd_ctx = hdd_ctx;
4202 hdd_ipa->num_iface = 0;
Yun Park7f171ab2016-07-29 15:44:22 -07004203 ol_txrx_ipa_uc_get_resource(pdev, &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004204 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4205 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4206 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4207 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304208 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004209 "IPA UC resource alloc fail");
4210 goto fail_get_resource;
4211 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212
4213 /* Create the interface context */
4214 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4215 iface_context = &hdd_ipa->iface_context[i];
4216 iface_context->hdd_ipa = hdd_ipa;
4217 iface_context->cons_client =
4218 hdd_ipa_adapter_2_client[i].cons_client;
4219 iface_context->prod_client =
4220 hdd_ipa_adapter_2_client[i].prod_client;
4221 iface_context->iface_id = i;
4222 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004223 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304224 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225 }
4226
Leo Chang69c39692016-10-12 20:11:12 -07004227 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304228 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304229 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230
4231 ret = hdd_ipa_setup_rm(hdd_ipa);
4232 if (ret)
4233 goto fail_setup_rm;
4234
4235 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4236 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304237 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 hdd_ipa->sap_num_connected_sta = 0;
4239 hdd_ipa->ipa_tx_packets_diff = 0;
4240 hdd_ipa->ipa_rx_packets_diff = 0;
4241 hdd_ipa->ipa_p_tx_packets = 0;
4242 hdd_ipa->ipa_p_rx_packets = 0;
4243 hdd_ipa->resource_loading = false;
4244 hdd_ipa->resource_unloading = false;
4245 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004246 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247 /* Setup IPA sys_pipe for MCC */
4248 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4249 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4250 if (ret)
4251 goto fail_create_sys_pipe;
4252 }
4253 hdd_ipa_uc_ol_init(hdd_ctx);
4254 } else {
4255 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4256 if (ret)
4257 goto fail_create_sys_pipe;
4258 }
4259
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304260 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261
4262fail_create_sys_pipe:
4263 hdd_ipa_destroy_rm_resource(hdd_ipa);
4264fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304265 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004266fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304267 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004268 hdd_ctx->hdd_ipa = NULL;
4269 ghdd_ipa = NULL;
4270fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304271 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272}
4273
4274/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004275 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4276 * @hdd_ipa: pointer to HDD IPA struct
4277 *
4278 * Return: none
4279 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004280static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004281{
4282 struct ipa_uc_pending_event *pending_event = NULL;
4283
Anurag Chouhanffb21542016-02-17 14:33:03 +05304284 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4285 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304286 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004287 }
4288
Anurag Chouhanffb21542016-02-17 14:33:03 +05304289 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004290}
4291
4292/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 * hdd_ipa_cleanup - IPA cleanup function
4294 * @hdd_ctx: HDD global context
4295 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304296 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304298QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299{
4300 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4301 int i;
4302 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304303 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4305
4306 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304307 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308
4309 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4310 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4311 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4312 }
4313
4314 /* Teardown IPA sys_pipe for MCC */
4315 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4316 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4317
4318 hdd_ipa_destroy_rm_resource(hdd_ipa);
4319
4320#ifdef WLAN_OPEN_SOURCE
4321 cancel_work_sync(&hdd_ipa->pm_work);
4322#endif
4323
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304324 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004325
Nirav Shahcbc6d722016-03-01 16:24:53 +05304326 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4327 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304328 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004329
4330 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4331 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4332
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304333 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304335 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004336
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304337 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338
4339 /* destory the interface lock */
4340 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4341 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304342 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 }
4344
4345 /* This should never hit but still make sure that there are no pending
4346 * descriptor in IPA hardware
4347 */
4348 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304349 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 "IPA Pending write done: %d Waiting!",
4351 hdd_ipa->pending_hw_desc_cnt);
4352
4353 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4354 usleep_range(100, 100);
4355 }
4356
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304357 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358 "IPA Pending write done: desc: %d %s(%d)!",
4359 hdd_ipa->pending_hw_desc_cnt,
4360 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4361 : "leak", i);
4362 }
4363 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4364 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304365 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304366 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4367 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304369 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304370 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4371 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304373 qdf_mutex_destroy(&hdd_ipa->event_lock);
4374 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004375 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004376
4377#ifdef WLAN_OPEN_SOURCE
4378 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4379 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4380 hdd_ipa->uc_op_work[i].msg = NULL;
4381 }
4382#endif
4383 }
4384
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304385 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386 hdd_ctx->hdd_ipa = NULL;
4387
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304388 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389}
4390#endif /* IPA_OFFLOAD */