blob: b42df3a390ea1a15788a5de7a4355df875137f80 [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 {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530365 uint64_t 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
Deepthi Gowri6acee342016-10-28 15:00:38 +0530729 dump_info->time = (uint64_t)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,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530782 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783 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
Yun Park8f289c82016-10-18 16:38:21 -0700990 HDD_IPA_LOG(LOGOFF, "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,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001606 "IPA offload status is already set: (offload_type=%d, vdev_id=%d, enable=%d)",
Yun Park8292dcb2016-10-07 16:46:06 -07001607 offload_type, adapter->sessionId, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001608 return;
1609 }
1610
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301611 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 sizeof(ipa_offload_enable_disable));
1613 ipa_offload_enable_disable.offload_type = offload_type;
1614 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1615 ipa_offload_enable_disable.enable = enable;
1616
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301617 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001618 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 ipa_offload_enable_disable.offload_type,
1620 ipa_offload_enable_disable.vdev_id,
1621 ipa_offload_enable_disable.enable);
1622
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301623 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1625 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301626 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001627 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
1628 __func__,
1629 ipa_offload_enable_disable.offload_type,
1630 ipa_offload_enable_disable.vdev_id,
1631 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001632 } else {
1633 /* Update the IPA offload status */
1634 iface_context->offload_enabled =
1635 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 }
1637}
1638
1639/**
1640 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1641 * @work: uC OP work
1642 *
1643 * Return: None
1644 */
1645static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1646{
1647 struct op_msg_type *msg;
1648 struct uc_op_work_struct *uc_op_work = container_of(work,
1649 struct uc_op_work_struct, work);
1650 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1651
1652 cds_ssr_protect(__func__);
1653
1654 msg = uc_op_work->msg;
1655 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301656 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 "%s, posted msg %d", __func__, msg->op_code);
1658
1659 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1660
1661 cds_ssr_unprotect(__func__);
1662
1663 return;
1664}
1665
1666/**
1667 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1668 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1669 * @op_msg: operation message received from firmware
1670 * @hdd_ctx: Global HDD context
1671 *
1672 * Return: None
1673 */
1674static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1675{
1676 struct hdd_ipa_priv *hdd_ipa;
1677 struct op_msg_type *msg;
1678 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301679 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001680
1681 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301682 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684
1685 msg = (struct op_msg_type *)op_msg;
1686 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1687
1688 if (unlikely(!hdd_ipa))
1689 goto end;
1690
1691 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301692 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 __func__, msg->op_code);
1694 goto end;
1695 }
1696
1697 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1698 if (uc_op_work->msg)
1699 /* When the same uC OPCODE is already pended, just return */
1700 goto end;
1701
1702 uc_op_work->msg = msg;
1703 schedule_work(&uc_op_work->work);
1704 return;
1705
1706end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301707 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708}
1709
1710/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001711 * hdd_ipa_init_uc_op_work - init ipa uc op work
1712 * @work: struct work_struct
1713 * @work_handler: work_handler
1714 *
1715 * Return: none
1716 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001717static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1718 work_func_t work_handler)
1719{
1720 INIT_WORK(work, work_handler);
1721}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001722
1723
1724/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1726 * @hdd_ctx: Global HDD context
1727 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301728 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301730static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731{
1732 struct ipa_wdi_in_params pipe_in;
1733 struct ipa_wdi_out_params pipe_out;
1734 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1735 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1736 uint8_t i;
1737
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301738 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1739 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740
Anurag Chouhanffb21542016-02-17 14:33:03 +05301741 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301742 qdf_mutex_create(&ipa_ctxt->event_lock);
1743 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744
1745 /* TX PIPE */
1746 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1747 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1748 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1749 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1750 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1751 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1752 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1753 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1754 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1755 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1756 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1757 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1758 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301759 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1761 pipe_in.sys.keep_ipa_awake = true;
1762 }
1763
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001764 pipe_in.u.dl.comp_ring_base_pa =
1765 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001766 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001767 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1768 sizeof(qdf_dma_addr_t);
1769 pipe_in.u.dl.ce_ring_base_pa =
1770 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1771 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1772 pipe_in.u.dl.ce_ring_size =
1773 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1774 pipe_in.u.dl.num_tx_buffers =
1775 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776
1777 /* Connect WDI IPA PIPE */
1778 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1779 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301780 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1781 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1782 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1783 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001784 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785 /* WLAN TX PIPE Handle */
1786 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301787 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1789 " CERZ %d, NB %d, CDBPAD 0x%x",
1790 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1791 pipe_in.u.dl.comp_ring_size,
1792 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1793 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1794 pipe_in.u.dl.ce_ring_size,
1795 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001796 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797
1798 /* RX PIPE */
1799 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1800 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1801 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1802 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1803 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1804 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1805 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1806 sizeof(struct sps_iovec);
1807 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1808 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301809 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001810 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1811 pipe_in.sys.keep_ipa_awake = true;
1812 }
1813
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001814 pipe_in.u.ul.rdy_ring_base_pa =
1815 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1816 pipe_in.u.ul.rdy_ring_size =
1817 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1818 pipe_in.u.ul.rdy_ring_rp_pa =
1819 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001820 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001822 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001823 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301824 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1826 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1827 pipe_in.u.ul.rdy_ring_size,
1828 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001829 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830
1831 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001832 ipa_ctxt->tx_comp_doorbell_paddr,
1833 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834
1835 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1836 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1837
1838 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001839 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840 hdd_ipa_uc_fw_op_event_handler);
1841 ipa_ctxt->uc_op_work[i].msg = NULL;
1842 }
1843
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301844 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845}
1846
Leo Change3e49442015-10-26 20:07:13 -07001847/**
1848 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1849 * @hdd_ctx: hdd main context
1850 *
1851 * Force shutdown IPA pipe
1852 * Independent of FW pipe status, IPA pipe shutdonw progress
1853 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1854 * independent from FW pipe status
1855 *
1856 * Return: NONE
1857 */
1858void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1859{
1860 struct hdd_ipa_priv *hdd_ipa;
1861
1862 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1863 return;
1864
1865 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1866 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301867 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001868 "IPA pipes are not down yet, force shutdown");
1869 hdd_ipa_uc_disable_pipes(hdd_ipa);
1870 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301871 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001872 "IPA pipes are down, do nothing");
1873 }
1874
1875 return;
1876}
1877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878/**
1879 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1880 *
1881 * Deinit basic IPA UC host side to be in sync reloaded FW during
1882 * SSR
1883 *
1884 * Return: 0 - Success
1885 */
1886int hdd_ipa_uc_ssr_deinit(void)
1887{
1888 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1889 int idx;
1890 struct hdd_ipa_iface_context *iface_context;
1891
Leo Chang3bc8fed2015-11-13 10:59:47 -08001892 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 return 0;
1894
1895 /* Clean up HDD IPA interfaces */
1896 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1897 (idx < HDD_IPA_MAX_IFACE); idx++) {
1898 iface_context = &hdd_ipa->iface_context[idx];
1899 if (iface_context && iface_context->adapter)
1900 hdd_ipa_cleanup_iface(iface_context);
1901 }
1902
1903 /* After SSR, wlan driver reloads FW again. But we need to protect
1904 * IPA submodule during SSR transient state. So deinit basic IPA
1905 * UC host side to be in sync with reloaded FW during SSR
1906 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001907 if (!hdd_ipa->ipa_pipes_down)
1908 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301910 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001911 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1912 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1913 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1914 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301915 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916
1917 /* Full IPA driver cleanup not required since wlan driver is now
1918 * unloaded and reloaded after SSR.
1919 */
1920 return 0;
1921}
1922
1923/**
1924 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1925 *
1926 * Init basic IPA UC host side to be in sync with reloaded FW after
1927 * SSR to resume IPA UC operations
1928 *
1929 * Return: 0 - Success
1930 */
1931int hdd_ipa_uc_ssr_reinit(void)
1932{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001933
1934 /* After SSR is complete, IPA UC can resume operation. But now wlan
1935 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1936 * and initialization. This is a placeholder func if IPA has to resume
1937 * operations without driver reload.
1938 */
1939 return 0;
1940}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001941
1942/**
1943 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1944 * @hdd_ctx: Global HDD context
1945 * @skb: skb sent to IPA
1946 * @session_id: send packet instance session id
1947 *
1948 * Send TX packet which generated by system to IPA.
1949 * This routine only will be used for function verification
1950 *
1951 * Return: NULL packet sent to IPA properly
1952 * NULL invalid packet drop
1953 * skb packet not sent to IPA. legacy data path should handle
1954 */
1955struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1956 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001957{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001958 struct ipa_header *ipa_header;
1959 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07001960 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001961
1962 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1963 return skb;
1964
Leo Chang07b28f62016-05-11 12:29:22 -07001965 if (!hdd_ipa)
1966 return skb;
1967
1968 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
1969 return skb;
1970
Leo Changcc923e22016-06-16 15:29:03 -07001971 if (skb_headroom(skb) <
1972 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07001973 return skb;
1974
Leo Chang3bc8fed2015-11-13 10:59:47 -08001975 ipa_header = (struct ipa_header *) skb_push(skb,
1976 sizeof(struct ipa_header));
1977 if (!ipa_header) {
1978 /* No headroom, legacy */
1979 return skb;
1980 }
1981 memset(ipa_header, 0, sizeof(*ipa_header));
1982 ipa_header->vdev_id = 0;
1983
1984 frag_header = (struct frag_header *) skb_push(skb,
1985 sizeof(struct frag_header));
1986 if (!frag_header) {
1987 /* No headroom, drop */
1988 kfree_skb(skb);
1989 return NULL;
1990 }
1991 memset(frag_header, 0, sizeof(*frag_header));
1992 frag_header->length = skb->len - sizeof(struct frag_header)
1993 - sizeof(struct ipa_header);
1994
1995 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
1996 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07001997}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998
1999/**
2000 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2001 * @work: scheduled work
2002 *
2003 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2004 * not want to immediately release the wake lock since the system
2005 * would then potentially try to suspend when there is a healthy data
2006 * rate. Deferred work is scheduled and this function handles the
2007 * work. When this function is called, if the IPA resource is still
2008 * released then we release the wake lock.
2009 *
2010 * Return: None
2011 */
2012static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2013{
2014 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2015 struct hdd_ipa_priv,
2016 wake_lock_work);
2017
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302018 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019
2020 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2021 goto end;
2022
2023 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302024 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 WIFI_POWER_EVENT_WAKELOCK_IPA);
2026
2027end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302028 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029}
2030
2031/**
2032 * hdd_ipa_rm_request() - Request resource from IPA
2033 * @hdd_ipa: Global HDD IPA context
2034 *
2035 * Return: 0 on success, negative errno on error
2036 */
2037static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2038{
2039 int ret = 0;
2040
2041 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2042 return 0;
2043
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302044 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002045
2046 switch (hdd_ipa->rm_state) {
2047 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302048 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002049 return 0;
2050 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302051 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002052 return -EINPROGRESS;
2053 case HDD_IPA_RM_RELEASED:
2054 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2055 break;
2056 }
2057
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302058 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002059
2060 ret = ipa_rm_inactivity_timer_request_resource(
2061 IPA_RM_RESOURCE_WLAN_PROD);
2062
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302063 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002064 if (ret == 0) {
2065 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2066 hdd_ipa->stats.num_rm_grant_imm++;
2067 }
2068
2069 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2070 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302071 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002072 WIFI_POWER_EVENT_WAKELOCK_IPA);
2073 hdd_ipa->wake_lock_released = false;
2074 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302075 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076
2077 return ret;
2078}
2079
2080/**
2081 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2082 * @hdd_ipa: Global HDD IPA context
2083 *
2084 * Return: 0 if resources released, negative errno otherwise
2085 */
2086static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2087{
2088 int ret = 0;
2089
2090 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2091 return 0;
2092
2093 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2094 return -EAGAIN;
2095
2096 spin_lock_bh(&hdd_ipa->q_lock);
2097 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2098 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2099 spin_unlock_bh(&hdd_ipa->q_lock);
2100 return -EAGAIN;
2101 }
2102 spin_unlock_bh(&hdd_ipa->q_lock);
2103
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302104 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002105
Nirav Shahcbc6d722016-03-01 16:24:53 +05302106 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302107 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002108 return -EAGAIN;
2109 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302110 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302112 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002113 switch (hdd_ipa->rm_state) {
2114 case HDD_IPA_RM_GRANTED:
2115 break;
2116 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302117 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002118 return -EINPROGRESS;
2119 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302120 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121 return 0;
2122 }
2123
2124 /* IPA driver returns immediately so set the state here to avoid any
2125 * race condition.
2126 */
2127 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2128 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302129 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002130
2131 ret =
2132 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2133
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302134 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135 if (unlikely(ret != 0)) {
2136 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2137 WARN_ON(1);
2138 }
2139
2140 /*
2141 * If wake_lock is released immediately, kernel would try to suspend
2142 * immediately as well, Just avoid ping-pong between suspend-resume
2143 * while there is healthy amount of data transfer going on by
2144 * releasing the wake_lock after some delay.
2145 */
2146 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2147 msecs_to_jiffies
2148 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2149
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302150 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151
2152 return ret;
2153}
2154
2155/**
2156 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2157 * @user_data: user data registered with IPA
2158 * @event: the IPA resource manager event that occurred
2159 * @data: the data associated with the event
2160 *
2161 * Return: None
2162 */
2163static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2164 unsigned long data)
2165{
2166 struct hdd_ipa_priv *hdd_ipa = user_data;
2167
2168 if (unlikely(!hdd_ipa))
2169 return;
2170
2171 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2172 return;
2173
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302174 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002175
2176 switch (event) {
2177 case IPA_RM_RESOURCE_GRANTED:
2178 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2179 /* RM Notification comes with ISR context
2180 * it should be serialized into work queue to avoid
2181 * ISR sleep problem
2182 */
2183 hdd_ipa->uc_rm_work.event = event;
2184 schedule_work(&hdd_ipa->uc_rm_work.work);
2185 break;
2186 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302187 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302189 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002190 hdd_ipa->stats.num_rm_grant++;
2191 break;
2192
2193 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302194 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002195 hdd_ipa->resource_unloading = false;
2196 break;
2197
2198 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302199 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002200 break;
2201 }
2202}
2203
2204/**
2205 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2206 *
2207 * Callback function registered with IPA that is called when IPA wants
2208 * to release the WLAN consumer resource
2209 *
2210 * Return: 0 if the request is granted, negative errno otherwise
2211 */
2212static int hdd_ipa_rm_cons_release(void)
2213{
2214 return 0;
2215}
2216
2217/**
2218 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2219 *
2220 * Callback function registered with IPA that is called when IPA wants
2221 * to access the WLAN consumer resource
2222 *
2223 * Return: 0 if the request is granted, negative errno otherwise
2224 */
2225static int hdd_ipa_rm_cons_request(void)
2226{
Yun Park4d8b60a2015-10-22 13:59:32 -07002227 int ret = 0;
2228
2229 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302230 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002231 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232 __func__);
2233 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002234 ret = -EINPROGRESS;
2235 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302236 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002237 "%s: IPA resource unloading in progress",
2238 __func__);
2239 ghdd_ipa->pending_cons_req = true;
2240 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002242
2243 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002244}
2245
2246/**
2247 * hdd_ipa_set_perf_level() - Set IPA performance level
2248 * @hdd_ctx: Global HDD context
2249 * @tx_packets: Number of packets transmitted in the last sample period
2250 * @rx_packets: Number of packets received in the last sample period
2251 *
2252 * Return: 0 on success, negative errno on error
2253 */
2254int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2255 uint64_t rx_packets)
2256{
2257 uint32_t next_cons_bw, next_prod_bw;
2258 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2259 struct ipa_rm_perf_profile profile;
2260 int ret;
2261
2262 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2263 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2264 return 0;
2265
2266 memset(&profile, 0, sizeof(profile));
2267
2268 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2269 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2270 else if (tx_packets >
2271 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2272 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2273 else
2274 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2275
2276 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2277 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2278 else if (rx_packets >
2279 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2280 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2281 else
2282 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2283
Yun Park8f289c82016-10-18 16:38:21 -07002284 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002285 "CONS perf curr: %d, next: %d",
2286 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Park8f289c82016-10-18 16:38:21 -07002287 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 "PROD perf curr: %d, next: %d",
2289 hdd_ipa->curr_prod_bw, next_prod_bw);
2290
2291 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302292 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002293 "Requesting CONS perf curr: %d, next: %d",
2294 hdd_ipa->curr_cons_bw, next_cons_bw);
2295 profile.max_supported_bandwidth_mbps = next_cons_bw;
2296 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2297 &profile);
2298 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302299 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002300 "RM CONS set perf profile failed: %d", ret);
2301
2302 return ret;
2303 }
2304 hdd_ipa->curr_cons_bw = next_cons_bw;
2305 hdd_ipa->stats.num_cons_perf_req++;
2306 }
2307
2308 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302309 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 "Requesting PROD perf curr: %d, next: %d",
2311 hdd_ipa->curr_prod_bw, next_prod_bw);
2312 profile.max_supported_bandwidth_mbps = next_prod_bw;
2313 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2314 &profile);
2315 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302316 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002317 "RM PROD set perf profile failed: %d", ret);
2318 return ret;
2319 }
2320 hdd_ipa->curr_prod_bw = next_prod_bw;
2321 hdd_ipa->stats.num_prod_perf_req++;
2322 }
2323
2324 return 0;
2325}
2326
2327/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002328 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2329 * @work: struct work_struct
2330 * @work_handler: work_handler
2331 *
2332 * Return: none
2333 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002334static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2335 work_func_t work_handler)
2336{
2337 INIT_WORK(work, work_handler);
2338}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002339
2340/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002341 * hdd_ipa_setup_rm() - Setup IPA resource management
2342 * @hdd_ipa: Global HDD IPA context
2343 *
2344 * Return: 0 on success, negative errno on error
2345 */
2346static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2347{
2348 struct ipa_rm_create_params create_params = { 0 };
2349 int ret;
2350
2351 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2352 return 0;
2353
Rajeev Kumar217f2172016-01-06 18:11:55 -08002354 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2355 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002356 memset(&create_params, 0, sizeof(create_params));
2357 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2358 create_params.reg_params.user_data = hdd_ipa;
2359 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2360 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2361
2362 ret = ipa_rm_create_resource(&create_params);
2363 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302364 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002365 "Create RM resource failed: %d", ret);
2366 goto setup_rm_fail;
2367 }
2368
2369 memset(&create_params, 0, sizeof(create_params));
2370 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2371 create_params.request_resource = hdd_ipa_rm_cons_request;
2372 create_params.release_resource = hdd_ipa_rm_cons_release;
2373 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2374
2375 ret = ipa_rm_create_resource(&create_params);
2376 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302377 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002378 "Create RM CONS resource failed: %d", ret);
2379 goto delete_prod;
2380 }
2381
2382 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2383 IPA_RM_RESOURCE_APPS_CONS);
2384
2385 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2386 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2387 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302388 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002389 ret);
2390 goto timer_init_failed;
2391 }
2392
2393 /* Set the lowest bandwidth to start with */
2394 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2395
2396 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302397 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002398 "Set perf level failed: %d", ret);
2399 goto set_perf_failed;
2400 }
2401
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302402 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002403 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2404 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302405 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002406 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2407 hdd_ipa->wake_lock_released = true;
2408 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2409
2410 return ret;
2411
2412set_perf_failed:
2413 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2414
2415timer_init_failed:
2416 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2417
2418delete_prod:
2419 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2420
2421setup_rm_fail:
2422 return ret;
2423}
2424
2425/**
2426 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2427 * @hdd_ipa: Global HDD IPA context
2428 *
2429 * Destroys all resources associated with the IPA resource manager
2430 *
2431 * Return: None
2432 */
2433static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2434{
2435 int ret;
2436
2437 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2438 return;
2439
2440 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302441 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442
2443#ifdef WLAN_OPEN_SOURCE
2444 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2445#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302446 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002447
2448 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2449
2450 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2451 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302452 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002453 "RM PROD resource delete failed %d", ret);
2454
2455 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2456 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302457 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002458 "RM CONS resource delete failed %d", ret);
2459}
2460
2461/**
2462 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2463 * @skb: network buffer
2464 * @adapter: network adapter
2465 *
2466 * Called when a network buffer is received which should not be routed
2467 * to the IPA module.
2468 *
2469 * Return: None
2470 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302471static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002472 hdd_adapter_t *adapter)
2473{
2474 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2475 unsigned int cpu_index;
2476
2477 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302478 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002479 adapter);
2480 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002481 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002482 return;
2483 }
2484
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002485 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002486 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002487 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 return;
2489 }
2490
2491 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2492 skb->dev = adapter->dev;
2493 skb->protocol = eth_type_trans(skb, skb->dev);
2494 skb->ip_summed = CHECKSUM_NONE;
2495
2496 cpu_index = wlan_hdd_get_cpu();
2497
2498 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2499 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2500 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2501 else
2502 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2503
2504 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2505 adapter->dev->last_rx = jiffies;
2506}
2507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002508/**
Leo Chang69c39692016-10-12 20:11:12 -07002509 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2510 * @hdd_ipa: pointer to hdd ipa context
2511 * @adapter: network adapter
2512 * @skb: data pointer
2513 *
2514 * if exception packet has set forward bit, copied new packet should be
2515 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2516 * put into pm queue and tx procedure will be differed
2517 *
2518 * Return: None
2519 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002520static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2521 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002522{
2523 qdf_nbuf_t copy;
2524 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2525
2526 copy = qdf_nbuf_copy(skb);
2527 if (!copy) {
2528 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2529 return;
2530 }
2531
2532 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2533 /* WLAN subsystem is in suspend, put int queue */
2534 if (hdd_ipa->suspended) {
2535 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2536 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2537 "TX in SUSPEND PUT QUEUE");
2538 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2539 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2540 pm_tx_cb->exception = true;
2541 pm_tx_cb->adapter = adapter;
2542 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2543 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2544 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2545 hdd_ipa->stats.num_tx_queued++;
2546 } else {
2547 /* Resume, put packet into WLAN TX */
2548 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2549 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2550 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2551 "packet tx fail");
2552 } else {
2553 hdd_ipa->stats.num_tx_bcmc++;
2554 hdd_ipa->ipa_tx_forward++;
2555 }
2556 }
2557}
2558
2559/**
2560 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002561 * @priv: pointer to private data registered with IPA (we register a
2562 * pointer to the global IPA context)
2563 * @evt: the IPA event which triggered the callback
2564 * @data: data associated with the event
2565 *
2566 * Return: None
2567 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002568static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569 unsigned long data)
2570{
2571 struct hdd_ipa_priv *hdd_ipa = NULL;
2572 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302573 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002574 uint8_t iface_id;
2575 uint8_t session_id;
2576 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002577 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002578 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002579
2580 hdd_ipa = (struct hdd_ipa_priv *)priv;
2581
2582 switch (evt) {
2583 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302584 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002585
2586 /*
2587 * When SSR is going on or driver is unloading,
2588 * just drop the packets.
2589 */
2590 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2591 if (0 != status) {
2592 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2593 "Invalid context: drop packet");
2594 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2595 kfree_skb(skb);
2596 return;
2597 }
2598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002599 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2600 session_id = (uint8_t)skb->cb[0];
2601 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302602 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002603 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2604 session_id, iface_id);
2605 } else {
2606 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2607 }
2608
2609 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302610 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611 "IPA_RECEIVE: Invalid iface_id: %u",
2612 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302613 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614 "w2i -- skb", skb->data, 8);
2615 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002616 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617 return;
2618 }
2619
2620 iface_context = &hdd_ipa->iface_context[iface_id];
2621 adapter = iface_context->adapter;
2622
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302623 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002624 "w2i -- skb", skb->data, 8);
2625 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2626 hdd_ipa->stats.num_rx_excep++;
2627 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2628 } else {
2629 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2630 }
2631
2632 iface_context->stats.num_rx_ipa_excep++;
2633
2634 /* Disable to forward Intra-BSS Rx packets when
2635 * ap_isolate=1 in hostapd.conf
2636 */
Yun Park046101c2016-09-02 15:32:14 -07002637 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002638 /*
2639 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2640 * all Rx packets to IPA uC, which need to be forwarded
2641 * to other interface.
2642 * And, IPA driver will send back to WLAN host driver
2643 * through exception pipe with fw_desc field set by FW.
2644 * Here we are checking fw_desc field for FORWARD bit
2645 * set, and forward to Tx. Then copy to kernel stack
2646 * only when DISCARD bit is not set.
2647 */
2648 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002649 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302650 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302651 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002652 "Forward packet to Tx (fw_desc=%d)",
2653 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002654 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002656 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002657 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2658 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002659 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002660 break;
2661 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002662 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302663 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664 "Intra-BSS FWD is disabled-skip forward to Tx");
2665 }
2666
2667 hdd_ipa_send_skb_to_network(skb, adapter);
2668 break;
2669
2670 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302671 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002672 "w2i cb wrong event: 0x%x", evt);
2673 return;
2674 }
2675}
2676
2677/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002678 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2679 * @priv: pointer to private data registered with IPA (we register a
2680 * pointer to the global IPA context)
2681 * @evt: the IPA event which triggered the callback
2682 * @data: data associated with the event
2683 *
2684 * Return: None
2685 */
2686static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2687 unsigned long data)
2688{
2689 cds_ssr_protect(__func__);
2690 __hdd_ipa_w2i_cb(priv, evt, data);
2691 cds_ssr_unprotect(__func__);
2692}
2693
2694/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2696 * @skb: packet buffer which was transmitted
2697 *
2698 * Return: None
2699 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302700void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002701{
2702 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2703
Govind Singhb6a89772016-08-12 11:23:35 +05302704 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302705 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002706 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302707 ipa_free_skb((struct ipa_rx_data *)
2708 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709
2710 hdd_ipa->stats.num_tx_comp_cnt++;
2711
2712 atomic_dec(&hdd_ipa->tx_ref_cnt);
2713
2714 hdd_ipa_rm_try_release(hdd_ipa);
2715}
2716
2717/**
2718 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2719 * @iface_context: interface-specific IPA context
2720 * @ipa_tx_desc: packet data descriptor
2721 *
2722 * Return: None
2723 */
2724static void hdd_ipa_send_pkt_to_tl(
2725 struct hdd_ipa_iface_context *iface_context,
2726 struct ipa_rx_data *ipa_tx_desc)
2727{
2728 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2729 uint8_t interface_id;
2730 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302731 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302733 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002734 adapter = iface_context->adapter;
2735 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302736 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002737 ipa_free_skb(ipa_tx_desc);
2738 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302739 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 hdd_ipa_rm_try_release(hdd_ipa);
2741 return;
2742 }
2743
2744 /*
2745 * During CAC period, data packets shouldn't be sent over the air so
2746 * drop all the packets here
2747 */
2748 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2749 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302750 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751 iface_context->stats.num_tx_cac_drop++;
2752 hdd_ipa_rm_try_release(hdd_ipa);
2753 return;
2754 }
2755
2756 interface_id = adapter->sessionId;
2757 ++adapter->stats.tx_packets;
2758
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302759 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002760
2761 skb = ipa_tx_desc->skb;
2762
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302763 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302764 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002765 /* FIXME: This is broken. No such field in cb any more:
2766 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002767 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302768 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002769 ipa_tx_desc->dma_addr
2770 + HDD_IPA_WLAN_FRAG_HEADER
2771 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002772 ipa_tx_desc->skb->len -=
2773 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2774 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302775 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002777 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302778 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779
2780 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2781
2782 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2783 ipa_tx_desc->skb);
2784 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302785 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786 ipa_free_skb(ipa_tx_desc);
2787 iface_context->stats.num_tx_err++;
2788 hdd_ipa_rm_try_release(hdd_ipa);
2789 return;
2790 }
2791
2792 atomic_inc(&hdd_ipa->tx_ref_cnt);
2793
2794 iface_context->stats.num_tx++;
2795
2796}
2797
2798/**
Leo Chang11545d62016-10-17 14:53:50 -07002799 * hdd_ipa_is_present() - get IPA hw status
2800 * @hdd_ctx: pointer to hdd context
2801 *
2802 * ipa_uc_reg_rdyCB is not directly designed to check
2803 * ipa hw status. This is an undocumented function which
2804 * has confirmed with IPA team.
2805 *
2806 * Return: true - ipa hw present
2807 * false - ipa hw not present
2808 */
2809bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2810{
2811 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002812 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002813 return true;
2814 else
2815 return false;
2816}
2817
2818/**
Leo Chang69c39692016-10-12 20:11:12 -07002819 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002820 * @work: pointer to the scheduled work
2821 *
2822 * Called during PM resume to send packets to TL which were queued
2823 * while host was in the process of suspending.
2824 *
2825 * Return: None
2826 */
Leo Chang69c39692016-10-12 20:11:12 -07002827static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002828{
2829 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2830 struct hdd_ipa_priv,
2831 pm_work);
2832 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302833 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002834 uint32_t dequeued = 0;
2835
Leo Chang69c39692016-10-12 20:11:12 -07002836 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2837 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302838 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302839 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2840 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302841 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842
2843 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002844 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002845 if (pm_tx_cb->exception) {
2846 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2847 "FLUSH EXCEPTION");
2848 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2849 } else {
2850 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002851 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002852 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302853 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002854 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302855 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002856 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2857 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858
2859 hdd_ipa->stats.num_tx_dequeued += dequeued;
2860 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2861 hdd_ipa->stats.num_max_pm_queue = dequeued;
2862}
2863
2864/**
2865 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2866 * @priv: pointer to private data registered with IPA (we register a
2867 * pointer to the interface-specific IPA context)
2868 * @evt: the IPA event which triggered the callback
2869 * @data: data associated with the event
2870 *
2871 * Return: None
2872 */
2873static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2874 unsigned long data)
2875{
2876 struct hdd_ipa_priv *hdd_ipa = NULL;
2877 struct ipa_rx_data *ipa_tx_desc;
2878 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302879 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002880 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302881 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002882
Mukul Sharma81661ae2015-10-30 20:26:02 +05302883 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302885 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 dev_kfree_skb_any(skb);
2887 iface_context->stats.num_tx_drop++;
2888 return;
2889 }
2890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891 ipa_tx_desc = (struct ipa_rx_data *)data;
2892
2893 hdd_ipa = iface_context->hdd_ipa;
2894
2895 /*
2896 * When SSR is going on or driver is unloading, just drop the packets.
2897 * During SSR, there is no use in queueing the packets as STA has to
2898 * connect back any way
2899 */
2900 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302901 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902 ipa_free_skb(ipa_tx_desc);
2903 iface_context->stats.num_tx_drop++;
2904 return;
2905 }
2906
2907 skb = ipa_tx_desc->skb;
2908
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302909 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002910
2911 /*
2912 * If PROD resource is not requested here then there may be cases where
2913 * IPA hardware may be clocked down because of not having proper
2914 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2915 * workaround to request PROD resource while data is going over CONS
2916 * pipe to prevent the IPA hardware clockdown.
2917 */
2918 hdd_ipa_rm_request(hdd_ipa);
2919
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302920 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921 /*
2922 * If host is still suspended then queue the packets and these will be
2923 * drained later when resume completes. When packet is arrived here and
2924 * host is suspended, this means that there is already resume is in
2925 * progress.
2926 */
2927 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302928 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002929 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2930 pm_tx_cb->iface_context = iface_context;
2931 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302932 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002933 hdd_ipa->stats.num_tx_queued++;
2934
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302935 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936 return;
2937 }
2938
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302939 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002940
2941 /*
2942 * If we are here means, host is not suspended, wait for the work queue
2943 * to finish.
2944 */
2945#ifdef WLAN_OPEN_SOURCE
2946 flush_work(&hdd_ipa->pm_work);
2947#endif
2948
2949 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2950}
2951
2952/**
2953 * hdd_ipa_suspend() - Suspend IPA
2954 * @hdd_ctx: Global HDD context
2955 *
2956 * Return: 0 on success, negativer errno on error
2957 */
2958int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2959{
2960 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2961
2962 if (!hdd_ipa_is_enabled(hdd_ctx))
2963 return 0;
2964
2965 /*
2966 * Check if IPA is ready for suspend, If we are here means, there is
2967 * high chance that suspend would go through but just to avoid any race
2968 * condition after suspend started, these checks are conducted before
2969 * allowing to suspend.
2970 */
2971 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2972 return -EAGAIN;
2973
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302974 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002975
2976 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302977 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002978 return -EAGAIN;
2979 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302980 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302982 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002983 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302984 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002985
2986 return 0;
2987}
2988
2989/**
2990 * hdd_ipa_resume() - Resume IPA following suspend
2991 * hdd_ctx: Global HDD context
2992 *
2993 * Return: 0 on success, negative errno on error
2994 */
2995int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2996{
2997 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2998
2999 if (!hdd_ipa_is_enabled(hdd_ctx))
3000 return 0;
3001
3002 schedule_work(&hdd_ipa->pm_work);
3003
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303004 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003005 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303006 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007
3008 return 0;
3009}
3010
3011/**
3012 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3013 * @hdd_ipa: Global HDD IPA context
3014 *
3015 * Return: 0 on success, negative errno on error
3016 */
3017static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3018{
3019 int i, ret = 0;
3020 struct ipa_sys_connect_params *ipa;
3021 uint32_t desc_fifo_sz;
3022
3023 /* The maximum number of descriptors that can be provided to a BAM at
3024 * once is one less than the total number of descriptors that the buffer
3025 * can contain.
3026 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3027 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3028 * be provided at once.
3029 * Because of above requirement, one extra descriptor will be added to
3030 * make sure hardware always has one descriptor.
3031 */
3032 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3033 + sizeof(struct sps_iovec);
3034
3035 /*setup TX pipes */
3036 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3037 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3038
3039 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3040 ipa->desc_fifo_sz = desc_fifo_sz;
3041 ipa->priv = &hdd_ipa->iface_context[i];
3042 ipa->notify = hdd_ipa_i2w_cb;
3043
3044 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3045 ipa->ipa_ep_cfg.hdr.hdr_len =
3046 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3047 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3048 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3049 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3050 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3051 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3052 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3053 } else {
3054 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3055 }
3056 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3057
3058 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3059 ipa->keep_ipa_awake = 1;
3060
3061 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3062 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303063 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003064 " ret: %d", i, ret);
3065 goto setup_sys_pipe_fail;
3066 }
3067 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3068 }
3069
3070 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3071 /*
3072 * Hard code it here, this can be extended if in case
3073 * PROD pipe is also per interface.
3074 * Right now there is no advantage of doing this.
3075 */
3076 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3077
3078 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3079
3080 ipa->client = hdd_ipa->prod_client;
3081
3082 ipa->desc_fifo_sz = desc_fifo_sz;
3083 ipa->priv = hdd_ipa;
3084 ipa->notify = hdd_ipa_w2i_cb;
3085
3086 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3087 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3088 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3089 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3090
3091 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3092 ipa->keep_ipa_awake = 1;
3093
3094 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3095 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303096 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 "Failed for RX pipe: %d", ret);
3098 goto setup_sys_pipe_fail;
3099 }
3100 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3101 }
3102
3103 return ret;
3104
3105setup_sys_pipe_fail:
3106
3107 while (--i >= 0) {
3108 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303109 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 sizeof(struct hdd_ipa_sys_pipe));
3111 }
3112
3113 return ret;
3114}
3115
3116/**
3117 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3118 * @hdd_ipa: Global HDD IPA context
3119 *
3120 * Return: None
3121 */
3122static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3123{
3124 int ret = 0, i;
3125 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3126 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3127 ret =
3128 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3129 conn_hdl);
3130 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303131 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132 ret);
3133
3134 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3135 }
3136 }
3137}
3138
3139/**
3140 * hdd_ipa_register_interface() - register IPA interface
3141 * @hdd_ipa: Global IPA context
3142 * @iface_context: Per-interface IPA context
3143 *
3144 * Return: 0 on success, negative errno on error
3145 */
3146static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3147 struct hdd_ipa_iface_context
3148 *iface_context)
3149{
3150 struct ipa_tx_intf tx_intf;
3151 struct ipa_rx_intf rx_intf;
3152 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3153 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3154 char *ifname = iface_context->adapter->dev->name;
3155
3156 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3157 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3158
3159 int num_prop = 1;
3160 int ret = 0;
3161
3162 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3163 num_prop++;
3164
3165 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3166 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303167 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303169 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170 goto register_interface_fail;
3171 }
3172
3173 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3174 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303175 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003176 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303177 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178 goto register_interface_fail;
3179 }
3180
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303181 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3182 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183
3184 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3185 ifname, HDD_IPA_IPV4_NAME_EXT);
3186 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3187 ifname, HDD_IPA_IPV6_NAME_EXT);
3188
3189 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3190 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3191 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3192 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3193
3194 /*
3195 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3196 * mask to identify the interface in IPA hardware
3197 */
3198 rx_prop[IPA_IP_v4].attrib.meta_data =
3199 htonl(iface_context->adapter->sessionId << 16);
3200 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3201
3202 rx_intf.num_props++;
3203 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3204 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3205 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3206 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3207 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3208 rx_prop[IPA_IP_v4].attrib.meta_data =
3209 htonl(iface_context->adapter->sessionId << 16);
3210 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3211
3212 rx_intf.num_props++;
3213 }
3214
3215 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3216 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3217 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3218 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3219 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3220 IPA_RESOURCE_NAME_MAX);
3221 tx_intf.num_props++;
3222
3223 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3224 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3225 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3226 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3227 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3228 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3229 IPA_RESOURCE_NAME_MAX);
3230 tx_intf.num_props++;
3231 }
3232
3233 tx_intf.prop = tx_prop;
3234 rx_intf.prop = rx_prop;
3235
3236 /* Call the ipa api to register interface */
3237 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3238
3239register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303240 qdf_mem_free(tx_prop);
3241 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003242 return ret;
3243}
3244
3245/**
3246 * hdd_remove_ipa_header() - Remove a specific header from IPA
3247 * @name: Name of the header to be removed
3248 *
3249 * Return: None
3250 */
3251static void hdd_ipa_remove_header(char *name)
3252{
3253 struct ipa_ioc_get_hdr hdrlookup;
3254 int ret = 0, len;
3255 struct ipa_ioc_del_hdr *ipa_hdr;
3256
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303257 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3259 ret = ipa_get_hdr(&hdrlookup);
3260 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303261 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262 name, ret);
3263 return;
3264 }
3265
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303266 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303268 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303270 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 return;
3272 }
3273 ipa_hdr->num_hdls = 1;
3274 ipa_hdr->commit = 0;
3275 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3276 ipa_hdr->hdl[0].status = -1;
3277 ret = ipa_del_hdr(ipa_hdr);
3278 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303279 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280 ret);
3281
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303282 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283}
3284
3285/**
3286 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3287 * @hdd_ipa: Global HDD IPA context
3288 * @iface_context: Interface-specific HDD IPA context
3289 * @mac_addr: Interface MAC address
3290 *
3291 * Return: 0 on success, negativer errno value on error
3292 */
3293static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3294 struct hdd_ipa_iface_context *iface_context,
3295 uint8_t *mac_addr)
3296{
3297 hdd_adapter_t *adapter = iface_context->adapter;
3298 char *ifname;
3299 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3300 int ret = -EINVAL;
3301 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3302 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3303
3304 ifname = adapter->dev->name;
3305
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303306 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 ifname, mac_addr);
3308
3309 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303310 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003311 + sizeof(struct ipa_hdr_add));
3312 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303313 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003314 "%s: ipa_hdr allocation failed", ifname);
3315 ret = -ENOMEM;
3316 goto end;
3317 }
3318
3319 ipa_hdr->commit = 0;
3320 ipa_hdr->num_hdrs = 1;
3321
3322 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3323 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3324 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3325 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3326 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303327 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328 "ifname=%s, vdev_id=%d",
3329 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3330 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3331 ifname, HDD_IPA_IPV4_NAME_EXT);
3332 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3333 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3334 ipa_hdr->hdr[0].is_partial = 1;
3335 ipa_hdr->hdr[0].hdr_hdl = 0;
3336 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3337 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3338
3339 ret = ipa_add_hdr(ipa_hdr);
3340 } else {
3341 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3342
3343 /* Set the Source MAC */
3344 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3345 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3346
3347 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3348 ifname, HDD_IPA_IPV4_NAME_EXT);
3349 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3350 ipa_hdr->hdr[0].is_partial = 1;
3351 ipa_hdr->hdr[0].hdr_hdl = 0;
3352 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3353 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3354
3355 /* Set the type to IPV4 in the header */
3356 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3357
3358 ret = ipa_add_hdr(ipa_hdr);
3359 }
3360 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303361 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362 ifname, ret);
3363 goto end;
3364 }
3365
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303366 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3368
3369 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3370 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3371 ifname, HDD_IPA_IPV6_NAME_EXT);
3372
3373 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3374 uc_tx_hdr =
3375 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3376 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3377 } else {
3378 /* Set the type to IPV6 in the header */
3379 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3380 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3381 }
3382
3383 ret = ipa_add_hdr(ipa_hdr);
3384 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303385 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386 "%s: IPv6 add hdr failed: %d", ifname, ret);
3387 goto clean_ipv4_hdr;
3388 }
3389
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303390 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003391 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3392 }
3393
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303394 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003395
3396 return ret;
3397
3398clean_ipv4_hdr:
3399 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3400 ifname, HDD_IPA_IPV4_NAME_EXT);
3401 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3402end:
3403 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303404 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405
3406 return ret;
3407}
3408
3409/**
3410 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3411 * @adapter: Adapter upon which IPA was previously configured
3412 *
3413 * Return: None
3414 */
3415static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3416{
3417 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3418 int ret;
3419 char name_ipa[IPA_RESOURCE_NAME_MAX];
3420
3421 /* Remove the headers */
3422 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3423 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3424 hdd_ipa_remove_header(name_ipa);
3425
3426 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3427 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3428 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3429 hdd_ipa_remove_header(name_ipa);
3430 }
3431 /* unregister the interface with IPA */
3432 ret = ipa_deregister_intf(adapter->dev->name);
3433 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303434 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 "%s: ipa_deregister_intf fail: %d",
3436 adapter->dev->name, ret);
3437}
3438
3439/**
3440 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3441 * @iface_context: interface-specific IPA context
3442 *
3443 * Return: None
3444 */
3445static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3446{
3447 if (iface_context == NULL)
3448 return;
3449
3450 hdd_ipa_clean_hdr(iface_context->adapter);
3451
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303452 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 iface_context->adapter->ipa_context = NULL;
3454 iface_context->adapter = NULL;
3455 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303456 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457 iface_context->ifa_address = 0;
3458 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303459 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303461 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 }
3463 iface_context->hdd_ipa->num_iface--;
3464}
3465
3466/**
3467 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3468 * @hdd_ipa: HDD IPA global context
3469 * @adapter: Interface upon which IPA is being setup
3470 * @sta_id: Station ID of the API instance
3471 *
3472 * Return: 0 on success, negative errno value on error
3473 */
3474static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3475 hdd_adapter_t *adapter, uint8_t sta_id)
3476{
3477 struct hdd_ipa_iface_context *iface_context = NULL;
3478 void *tl_context = NULL;
3479 int i, ret = 0;
3480
3481 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3482 * channel change indication. Since these indications are sent by lower
3483 * layer as SAP updates and IPA doesn't have to do anything for these
3484 * updates so ignoring!
3485 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003486 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 return 0;
3488
3489 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3490 if (hdd_ipa->iface_context[i].adapter == NULL) {
3491 iface_context = &(hdd_ipa->iface_context[i]);
3492 break;
3493 }
3494 }
3495
3496 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303497 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 "All the IPA interfaces are in use");
3499 ret = -ENOMEM;
3500 goto end;
3501 }
3502
3503 adapter->ipa_context = iface_context;
3504 iface_context->adapter = adapter;
3505 iface_context->sta_id = sta_id;
3506 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3507
3508 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303509 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510 "Not able to get TL context sta_id: %d", sta_id);
3511 ret = -EINVAL;
3512 goto end;
3513 }
3514
3515 iface_context->tl_context = tl_context;
3516
3517 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3518 adapter->dev->dev_addr);
3519
3520 if (ret)
3521 goto end;
3522
3523 /* Configure the TX and RX pipes filter rules */
3524 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3525 if (ret)
3526 goto cleanup_header;
3527
3528 hdd_ipa->num_iface++;
3529 return ret;
3530
3531cleanup_header:
3532
3533 hdd_ipa_clean_hdr(adapter);
3534end:
3535 if (iface_context)
3536 hdd_ipa_cleanup_iface(iface_context);
3537 return ret;
3538}
3539
3540/**
3541 * hdd_ipa_msg_free_fn() - Free an IPA message
3542 * @buff: pointer to the IPA message
3543 * @len: length of the IPA message
3544 * @type: type of IPA message
3545 *
3546 * Return: None
3547 */
3548static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3549{
3550 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3551 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303552 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553}
3554
Yun Parka27049a2016-10-11 12:30:49 -07003555#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003556/**
3557 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3558 * @mcc_mode: 0=MCC/1=SCC
3559 *
3560 * Return: 0 on success, negative errno value on error
3561 */
3562int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3563{
3564 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303565 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566 hdd_adapter_t *pAdapter;
3567 struct ipa_msg_meta meta;
3568 struct ipa_wlan_msg *msg;
3569 int ret;
3570
3571 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3572 return -EINVAL;
3573
3574 if (!pHddCtx->mcc_mode) {
3575 /* Flush TxRx queue for each adapter before switch to SCC */
3576 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303577 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003579 if (pAdapter->device_mode == QDF_STA_MODE ||
3580 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303581 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3583 pAdapter->device_mode);
3584 hdd_deinit_tx_rx(pAdapter);
3585 }
3586 status = hdd_get_next_adapter(
3587 pHddCtx, adapter_node, &next);
3588 adapter_node = next;
3589 }
3590 }
3591
3592 /* Send SCC/MCC Switching event to IPA */
3593 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303594 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595 if (msg == NULL) {
3596 hddLog(LOGE, "msg allocation failed");
3597 return -ENOMEM;
3598 }
3599
3600 meta.msg_type = mcc_mode ?
3601 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3602 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3603
3604 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3605
3606 if (ret) {
3607 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3608 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303609 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 }
3611
3612 return ret;
3613}
Yun Parka27049a2016-10-11 12:30:49 -07003614#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003615
3616/**
3617 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3618 * @event: IPA WLAN event to be converted to a string
3619 *
3620 * Return: ASCII string representing the IPA WLAN event
3621 */
3622static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3623{
3624 switch (event) {
3625 case WLAN_CLIENT_CONNECT:
3626 return "WLAN_CLIENT_CONNECT";
3627 case WLAN_CLIENT_DISCONNECT:
3628 return "WLAN_CLIENT_DISCONNECT";
3629 case WLAN_CLIENT_POWER_SAVE_MODE:
3630 return "WLAN_CLIENT_POWER_SAVE_MODE";
3631 case WLAN_CLIENT_NORMAL_MODE:
3632 return "WLAN_CLIENT_NORMAL_MODE";
3633 case SW_ROUTING_ENABLE:
3634 return "SW_ROUTING_ENABLE";
3635 case SW_ROUTING_DISABLE:
3636 return "SW_ROUTING_DISABLE";
3637 case WLAN_AP_CONNECT:
3638 return "WLAN_AP_CONNECT";
3639 case WLAN_AP_DISCONNECT:
3640 return "WLAN_AP_DISCONNECT";
3641 case WLAN_STA_CONNECT:
3642 return "WLAN_STA_CONNECT";
3643 case WLAN_STA_DISCONNECT:
3644 return "WLAN_STA_DISCONNECT";
3645 case WLAN_CLIENT_CONNECT_EX:
3646 return "WLAN_CLIENT_CONNECT_EX";
3647
3648 case IPA_WLAN_EVENT_MAX:
3649 default:
3650 return "UNKNOWN";
3651 }
3652}
3653
3654/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003655 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3656 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3657 *
3658 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3659 */
3660static enum ipa_wlan_event
3661hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3662{
3663 enum ipa_wlan_event ipa_event;
3664
3665 switch (hdd_ipa_event_type) {
3666 case HDD_IPA_CLIENT_CONNECT:
3667 ipa_event = WLAN_CLIENT_CONNECT;
3668 break;
3669 case HDD_IPA_CLIENT_DISCONNECT:
3670 ipa_event = WLAN_CLIENT_DISCONNECT;
3671 break;
3672 case HDD_IPA_AP_CONNECT:
3673 ipa_event = WLAN_AP_CONNECT;
3674 break;
3675 case HDD_IPA_AP_DISCONNECT:
3676 ipa_event = WLAN_AP_DISCONNECT;
3677 break;
3678 case HDD_IPA_STA_CONNECT:
3679 ipa_event = WLAN_STA_CONNECT;
3680 break;
3681 case HDD_IPA_STA_DISCONNECT:
3682 ipa_event = WLAN_STA_DISCONNECT;
3683 break;
3684 case HDD_IPA_CLIENT_CONNECT_EX:
3685 ipa_event = WLAN_CLIENT_CONNECT_EX;
3686 break;
3687 case HDD_IPA_WLAN_EVENT_MAX:
3688 default:
3689 ipa_event = IPA_WLAN_EVENT_MAX;
3690 break;
3691 }
3692 return ipa_event;
3693
3694}
3695
3696/**
3697 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698 * @adapter: adapter upon which the event was received
3699 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003700 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701 * @mac_address: MAC address associated with the event
3702 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003703 * This function is meant to be called from within wlan_hdd_ipa.c
3704 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003705 * Return: 0 on success, negative errno value on error
3706 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003707static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003708 enum ipa_wlan_event type, uint8_t *mac_addr)
3709{
3710 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3711 struct ipa_msg_meta meta;
3712 struct ipa_wlan_msg *msg;
3713 struct ipa_wlan_msg_ex *msg_ex = NULL;
3714 int ret;
3715
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303716 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003717 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3718 mac_addr, sta_id);
3719
3720 if (type >= IPA_WLAN_EVENT_MAX)
3721 return -EINVAL;
3722
3723 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3724 return -EINVAL;
3725
3726 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303727 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003728 return -EINVAL;
3729 }
3730
3731 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3732 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003733 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734 return 0;
3735 }
3736
3737 /*
3738 * During IPA UC resource loading/unloading new events can be issued.
3739 * Store the events separately and handle them later.
3740 */
3741 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3742 ((hdd_ipa->resource_loading) ||
3743 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003744 unsigned int pending_event_count;
3745 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746
Yun Parkf19e07d2015-11-20 11:34:27 -08003747 hdd_err("IPA resource %s inprogress",
3748 hdd_ipa->resource_loading ? "load":"unload");
3749
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303750 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003751
Anurag Chouhanffb21542016-02-17 14:33:03 +05303752 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003753 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3754 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303755 qdf_list_remove_front(&hdd_ipa->pending_event,
3756 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003757 } else {
3758 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303759 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003760 sizeof(struct ipa_uc_pending_event));
3761 }
3762
3763 if (!pending_event) {
3764 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303765 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766 return -ENOMEM;
3767 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003768
3769 pending_event->adapter = adapter;
3770 pending_event->sta_id = sta_id;
3771 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303772 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303774 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303775 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003776 &pending_event->node);
3777
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303778 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 return 0;
3780 }
3781
3782 hdd_ipa->stats.event[type]++;
3783
Leo Chang3bc8fed2015-11-13 10:59:47 -08003784 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 switch (type) {
3786 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003787 qdf_mutex_acquire(&hdd_ipa->event_lock);
3788
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003789 /* STA already connected and without disconnect, connect again
3790 * This is Roaming scenario
3791 */
3792 if (hdd_ipa->sta_connected)
3793 hdd_ipa_cleanup_iface(adapter->ipa_context);
3794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003795 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3796 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303797 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003798 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003799 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800
Yun Park8f289c82016-10-18 16:38:21 -07003801 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3802 (hdd_ipa->sap_num_connected_sta > 0) &&
3803 !hdd_ipa->sta_connected) {
3804 qdf_mutex_release(&hdd_ipa->event_lock);
3805 hdd_ipa_uc_offload_enable_disable(adapter,
3806 SIR_STA_RX_DATA_OFFLOAD, 1);
3807 qdf_mutex_acquire(&hdd_ipa->event_lock);
3808 }
3809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 vdev_to_iface[adapter->sessionId] =
3811 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003812 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003815
3816 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817 break;
3818
3819 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003820 qdf_mutex_acquire(&hdd_ipa->event_lock);
3821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822 /* For DFS channel we get two start_bss event (before and after
3823 * CAC). Also when ACS range includes both DFS and non DFS
3824 * channels, we could possibly change channel many times due to
3825 * RADAR detection and chosen channel may not be a DFS channels.
3826 * So dont return error here. Just discard the event.
3827 */
Yun Park8f289c82016-10-18 16:38:21 -07003828 if (adapter->ipa_context) {
3829 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003831 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3834 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303835 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003836 "%s: Evt: %d, Interface setup failed",
3837 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303838 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003840 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841
Yun Park8f289c82016-10-18 16:38:21 -07003842 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3843 qdf_mutex_release(&hdd_ipa->event_lock);
3844 hdd_ipa_uc_offload_enable_disable(adapter,
3845 SIR_AP_RX_DATA_OFFLOAD, 1);
3846 qdf_mutex_acquire(&hdd_ipa->event_lock);
3847 }
3848
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003849 vdev_to_iface[adapter->sessionId] =
3850 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003851 (adapter->ipa_context))->iface_id;
3852
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303853 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 break;
3855
3856 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303857 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858
3859 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303860 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861 "%s: Evt: %d, STA already disconnected",
3862 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303863 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864 return -EINVAL;
3865 }
Yun Parka37592b2016-06-11 17:10:28 -07003866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303870 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003871 "%s: IPA UC OFFLOAD NOT ENABLED",
3872 msg_ex->name);
3873 } else {
3874 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003875 if (!hdd_ipa->num_iface &&
3876 (HDD_IPA_UC_NUM_WDI_PIPE ==
3877 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 }
3880
Yun Park74127cf2016-09-18 11:22:41 -07003881 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3882 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07003883 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 hdd_ipa_uc_offload_enable_disable(adapter,
3885 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003886 qdf_mutex_acquire(&hdd_ipa->event_lock);
3887 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003888 }
3889
Yun Park8f289c82016-10-18 16:38:21 -07003890 hdd_ipa_cleanup_iface(adapter->ipa_context);
3891
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303892 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003893 break;
3894
3895 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003896 qdf_mutex_acquire(&hdd_ipa->event_lock);
3897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003898 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);
Yun Park8f289c82016-10-18 16:38:21 -07003902 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 return -EINVAL;
3904 }
3905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 if ((!hdd_ipa->num_iface) &&
3907 (HDD_IPA_UC_NUM_WDI_PIPE ==
3908 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003909 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 /*
3911 * We disable WDI pipes directly here since
3912 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3913 * processed when unloading WLAN driver is in
3914 * progress
3915 */
3916 hdd_ipa_uc_disable_pipes(hdd_ipa);
3917 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303918 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919 "NO INTF left but still pipe clean up");
3920 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3921 }
3922 }
3923
3924 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07003925 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 hdd_ipa_uc_offload_enable_disable(adapter,
3927 SIR_AP_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003928 qdf_mutex_acquire(&hdd_ipa->event_lock);
3929 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 }
Yun Parka37592b2016-06-11 17:10:28 -07003931
Yun Park8f289c82016-10-18 16:38:21 -07003932 hdd_ipa_cleanup_iface(adapter->ipa_context);
3933
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303934 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 break;
3936
3937 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938 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)) {
Yun Park8f289c82016-10-18 16:38:21 -07003948 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303949 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 "%s: STA ID %d found, not valid",
3951 adapter->dev->name, sta_id);
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) &&
Yun Park8f289c82016-10-18 16:38:21 -07003958 hdd_ipa->sta_connected) {
3959 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003960 hdd_ipa_uc_offload_enable_disable(
3961 hdd_get_adapter(hdd_ipa->hdd_ctx,
3962 QDF_STA_MODE),
3963 SIR_STA_RX_DATA_OFFLOAD, 1);
Yun Park8f289c82016-10-18 16:38:21 -07003964 qdf_mutex_acquire(&hdd_ipa->event_lock);
3965 }
Yun Parka37592b2016-06-11 17:10:28 -07003966
Yun Park312f71a2015-12-08 10:22:42 -08003967 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3968 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303969 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003970 "%s: handle 1st con ret %d",
3971 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07003972
3973 if (hdd_ipa_uc_sta_is_enabled(
3974 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07003975 hdd_ipa->sta_connected) {
3976 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003977 hdd_ipa_uc_offload_enable_disable(
3978 hdd_get_adapter(
3979 hdd_ipa->hdd_ctx,
3980 QDF_STA_MODE),
3981 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003982 } else {
3983 qdf_mutex_release(&hdd_ipa->event_lock);
3984 }
Yun Parka37592b2016-06-11 17:10:28 -07003985
Yun Park312f71a2015-12-08 10:22:42 -08003986 return ret;
3987 }
3988 }
3989
3990 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003991
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303992 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993
3994 meta.msg_type = type;
3995 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3996 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303997 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998
3999 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304000 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001 "msg_ex allocation failed");
4002 return -ENOMEM;
4003 }
4004 strlcpy(msg_ex->name, adapter->dev->name,
4005 IPA_RESOURCE_NAME_MAX);
4006 msg_ex->num_of_attribs = 1;
4007 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4008 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4009 msg_ex->attribs[0].offset =
4010 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4011 } else {
4012 msg_ex->attribs[0].offset =
4013 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4014 }
4015 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4016 IPA_MAC_ADDR_SIZE);
4017
4018 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4019
4020 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304021 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304023 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 return ret;
4025 }
4026 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 return ret;
4028
4029 case WLAN_CLIENT_DISCONNECT:
4030 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304031 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 "%s: IPA UC OFFLOAD NOT ENABLED",
4033 msg_ex->name);
4034 return 0;
4035 }
4036
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304037 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304039 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004040 "%s: STA ID %d NOT found, not valid",
4041 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304042 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 return 0;
4044 }
4045 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07004046
Yun Park9b5030f2016-11-08 12:02:37 -08004047 /* Disable IPA UC TX PIPE when last STA disconnected */
4048 if (!hdd_ipa->sap_num_connected_sta) {
4049 if ((false == hdd_ipa->resource_unloading)
4050 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4051 hdd_ipa->activated_fw_pipe)) {
4052 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4053 }
4054
Yun Park8f289c82016-10-18 16:38:21 -07004055 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004056
4057 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4058 hdd_ipa->sta_connected)
4059 hdd_ipa_uc_offload_enable_disable(
4060 hdd_get_adapter(hdd_ipa->hdd_ctx,
4061 QDF_STA_MODE),
4062 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004063 } else {
4064 qdf_mutex_release(&hdd_ipa->event_lock);
4065 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 break;
4067
4068 default:
4069 return 0;
4070 }
4071
4072 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304073 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304075 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 return -ENOMEM;
4077 }
4078
4079 meta.msg_type = type;
4080 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4081 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4082
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304083 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004084 msg->name, meta.msg_type);
4085
4086 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4087
4088 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304089 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304091 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004092 return ret;
4093 }
4094
4095 hdd_ipa->stats.num_send_msg++;
4096
4097end:
4098 return ret;
4099}
4100
4101/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004102 * hdd_ipa_wlan_evt() - IPA event handler
4103 * @adapter: adapter upon which the event was received
4104 * @sta_id: station id for the event
4105 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4106 * @mac_address: MAC address associated with the event
4107 *
4108 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4109 *
4110 * Return: 0 on success, negative errno value on error
4111 */
4112int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4113 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4114{
4115 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4116
Leo Changa202b522016-10-14 16:13:50 -07004117 /* Data path offload only support for STA and SAP mode */
4118 if ((QDF_STA_MODE == adapter->device_mode) ||
4119 (QDF_SAP_MODE == adapter->device_mode))
4120 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4121
4122 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004123}
4124
4125/**
4126 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4127 * @hdd_ipa: Global HDD IPA context
4128 *
4129 * Return: None
4130 */
4131static void
4132hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4133{
4134 unsigned int pending_event_count;
4135 struct ipa_uc_pending_event *pending_event = NULL;
4136
4137 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4138 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4139 "%s, Pending Event Count %d", __func__, pending_event_count);
4140 if (!pending_event_count) {
4141 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4142 "%s, No Pending Event", __func__);
4143 return;
4144 }
4145
4146 qdf_list_remove_front(&hdd_ipa->pending_event,
4147 (qdf_list_node_t **)&pending_event);
4148 while (pending_event != NULL) {
4149 __hdd_ipa_wlan_evt(pending_event->adapter,
4150 pending_event->type,
4151 pending_event->sta_id,
4152 pending_event->mac_addr);
4153 qdf_mem_free(pending_event);
4154 pending_event = NULL;
4155 qdf_list_remove_front(&hdd_ipa->pending_event,
4156 (qdf_list_node_t **)&pending_event);
4157 }
4158}
4159
4160/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004161 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4162 * @state: IPA RM state value
4163 *
4164 * Return: ASCII string representing the IPA RM state
4165 */
4166static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4167{
4168 switch (state) {
4169 case HDD_IPA_RM_RELEASED:
4170 return "RELEASED";
4171 case HDD_IPA_RM_GRANT_PENDING:
4172 return "GRANT_PENDING";
4173 case HDD_IPA_RM_GRANTED:
4174 return "GRANTED";
4175 }
4176
4177 return "UNKNOWN";
4178}
4179
4180/**
4181 * hdd_ipa_init() - IPA initialization function
4182 * @hdd_ctx: HDD global context
4183 *
4184 * Allocate hdd_ipa resources, ipa pipe resource and register
4185 * wlan interface with IPA module.
4186 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304187 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304189QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190{
4191 struct hdd_ipa_priv *hdd_ipa = NULL;
4192 int ret, i;
4193 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004194 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004195
4196 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304197 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198
Yun Park7f171ab2016-07-29 15:44:22 -07004199 if (!pdev) {
4200 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4201 goto fail_return;
4202 }
4203
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304204 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304206 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004207 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 }
4209
4210 hdd_ctx->hdd_ipa = hdd_ipa;
4211 ghdd_ipa = hdd_ipa;
4212 hdd_ipa->hdd_ctx = hdd_ctx;
4213 hdd_ipa->num_iface = 0;
Yun Park7f171ab2016-07-29 15:44:22 -07004214 ol_txrx_ipa_uc_get_resource(pdev, &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004215 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4216 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4217 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4218 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304219 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004220 "IPA UC resource alloc fail");
4221 goto fail_get_resource;
4222 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223
4224 /* Create the interface context */
4225 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4226 iface_context = &hdd_ipa->iface_context[i];
4227 iface_context->hdd_ipa = hdd_ipa;
4228 iface_context->cons_client =
4229 hdd_ipa_adapter_2_client[i].cons_client;
4230 iface_context->prod_client =
4231 hdd_ipa_adapter_2_client[i].prod_client;
4232 iface_context->iface_id = i;
4233 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004234 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304235 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004236 }
4237 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Yun Park8f289c82016-10-18 16:38:21 -07004238 vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 }
4240
Leo Chang69c39692016-10-12 20:11:12 -07004241 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304242 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304243 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244
4245 ret = hdd_ipa_setup_rm(hdd_ipa);
4246 if (ret)
4247 goto fail_setup_rm;
4248
4249 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4250 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304251 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252 hdd_ipa->sap_num_connected_sta = 0;
4253 hdd_ipa->ipa_tx_packets_diff = 0;
4254 hdd_ipa->ipa_rx_packets_diff = 0;
4255 hdd_ipa->ipa_p_tx_packets = 0;
4256 hdd_ipa->ipa_p_rx_packets = 0;
4257 hdd_ipa->resource_loading = false;
4258 hdd_ipa->resource_unloading = false;
4259 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004260 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261 /* Setup IPA sys_pipe for MCC */
4262 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4263 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4264 if (ret)
4265 goto fail_create_sys_pipe;
4266 }
4267 hdd_ipa_uc_ol_init(hdd_ctx);
4268 } else {
4269 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4270 if (ret)
4271 goto fail_create_sys_pipe;
4272 }
4273
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304274 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275
4276fail_create_sys_pipe:
4277 hdd_ipa_destroy_rm_resource(hdd_ipa);
4278fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304279 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004280fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304281 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004282 hdd_ctx->hdd_ipa = NULL;
4283 ghdd_ipa = NULL;
4284fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304285 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286}
4287
4288/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004289 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4290 * @hdd_ipa: pointer to HDD IPA struct
4291 *
4292 * Return: none
4293 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004294static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004295{
4296 struct ipa_uc_pending_event *pending_event = NULL;
4297
Anurag Chouhanffb21542016-02-17 14:33:03 +05304298 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4299 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304300 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004301 }
4302
Anurag Chouhanffb21542016-02-17 14:33:03 +05304303 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004304}
4305
4306/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 * hdd_ipa_cleanup - IPA cleanup function
4308 * @hdd_ctx: HDD global context
4309 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304310 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304312QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313{
4314 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4315 int i;
4316 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304317 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4319
4320 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304321 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322
4323 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4324 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4325 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4326 }
4327
4328 /* Teardown IPA sys_pipe for MCC */
4329 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4330 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4331
4332 hdd_ipa_destroy_rm_resource(hdd_ipa);
4333
4334#ifdef WLAN_OPEN_SOURCE
4335 cancel_work_sync(&hdd_ipa->pm_work);
4336#endif
4337
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304338 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339
Nirav Shahcbc6d722016-03-01 16:24:53 +05304340 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4341 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304342 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343
4344 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4345 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4346
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304347 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304349 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304351 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004352
4353 /* destory the interface lock */
4354 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4355 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304356 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357 }
4358
4359 /* This should never hit but still make sure that there are no pending
4360 * descriptor in IPA hardware
4361 */
4362 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304363 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 "IPA Pending write done: %d Waiting!",
4365 hdd_ipa->pending_hw_desc_cnt);
4366
4367 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4368 usleep_range(100, 100);
4369 }
4370
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304371 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372 "IPA Pending write done: desc: %d %s(%d)!",
4373 hdd_ipa->pending_hw_desc_cnt,
4374 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4375 : "leak", i);
4376 }
4377 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4378 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304379 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304380 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4381 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304383 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304384 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4385 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304387 qdf_mutex_destroy(&hdd_ipa->event_lock);
4388 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004389 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004390
4391#ifdef WLAN_OPEN_SOURCE
4392 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4393 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4394 hdd_ipa->uc_op_work[i].msg = NULL;
4395 }
4396#endif
4397 }
4398
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304399 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 hdd_ctx->hdd_ipa = NULL;
4401
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304402 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403}
4404#endif /* IPA_OFFLOAD */