blob: 7576c5702caae36a9d104be14a4391b7cc2163b4 [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,
Yun Park8f289c82016-10-18 16:38:21 -07001606 "IPA offload status is already set: \
1607 (offload_type=%d, vdev_id=%d, enable=%d)",
Yun Park8292dcb2016-10-07 16:46:06 -07001608 offload_type, adapter->sessionId, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001609 return;
1610 }
1611
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301612 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613 sizeof(ipa_offload_enable_disable));
1614 ipa_offload_enable_disable.offload_type = offload_type;
1615 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1616 ipa_offload_enable_disable.enable = enable;
1617
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301618 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001619 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 ipa_offload_enable_disable.offload_type,
1621 ipa_offload_enable_disable.vdev_id,
1622 ipa_offload_enable_disable.enable);
1623
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301624 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1626 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301627 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 "%s: Failure to enable IPA offload \
1629 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1630 ipa_offload_enable_disable.offload_type,
1631 ipa_offload_enable_disable.vdev_id,
1632 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001633 } else {
1634 /* Update the IPA offload status */
1635 iface_context->offload_enabled =
1636 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 }
1638}
1639
1640/**
1641 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1642 * @work: uC OP work
1643 *
1644 * Return: None
1645 */
1646static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1647{
1648 struct op_msg_type *msg;
1649 struct uc_op_work_struct *uc_op_work = container_of(work,
1650 struct uc_op_work_struct, work);
1651 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1652
1653 cds_ssr_protect(__func__);
1654
1655 msg = uc_op_work->msg;
1656 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301657 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 "%s, posted msg %d", __func__, msg->op_code);
1659
1660 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1661
1662 cds_ssr_unprotect(__func__);
1663
1664 return;
1665}
1666
1667/**
1668 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1669 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1670 * @op_msg: operation message received from firmware
1671 * @hdd_ctx: Global HDD context
1672 *
1673 * Return: None
1674 */
1675static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1676{
1677 struct hdd_ipa_priv *hdd_ipa;
1678 struct op_msg_type *msg;
1679 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301680 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681
1682 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301683 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685
1686 msg = (struct op_msg_type *)op_msg;
1687 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1688
1689 if (unlikely(!hdd_ipa))
1690 goto end;
1691
1692 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301693 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 __func__, msg->op_code);
1695 goto end;
1696 }
1697
1698 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1699 if (uc_op_work->msg)
1700 /* When the same uC OPCODE is already pended, just return */
1701 goto end;
1702
1703 uc_op_work->msg = msg;
1704 schedule_work(&uc_op_work->work);
1705 return;
1706
1707end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301708 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709}
1710
1711/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001712 * hdd_ipa_init_uc_op_work - init ipa uc op work
1713 * @work: struct work_struct
1714 * @work_handler: work_handler
1715 *
1716 * Return: none
1717 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001718static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1719 work_func_t work_handler)
1720{
1721 INIT_WORK(work, work_handler);
1722}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001723
1724
1725/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001726 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1727 * @hdd_ctx: Global HDD context
1728 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301729 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301731static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732{
1733 struct ipa_wdi_in_params pipe_in;
1734 struct ipa_wdi_out_params pipe_out;
1735 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1736 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1737 uint8_t i;
1738
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301739 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1740 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001741
Anurag Chouhanffb21542016-02-17 14:33:03 +05301742 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301743 qdf_mutex_create(&ipa_ctxt->event_lock);
1744 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001745
1746 /* TX PIPE */
1747 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1748 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1749 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1750 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1751 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1752 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1753 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1754 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1755 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1756 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1757 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1758 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1759 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301760 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1762 pipe_in.sys.keep_ipa_awake = true;
1763 }
1764
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001765 pipe_in.u.dl.comp_ring_base_pa =
1766 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001767 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001768 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1769 sizeof(qdf_dma_addr_t);
1770 pipe_in.u.dl.ce_ring_base_pa =
1771 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1772 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1773 pipe_in.u.dl.ce_ring_size =
1774 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1775 pipe_in.u.dl.num_tx_buffers =
1776 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001777
1778 /* Connect WDI IPA PIPE */
1779 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1780 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301781 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1782 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1783 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1784 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001785 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786 /* WLAN TX PIPE Handle */
1787 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301788 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001789 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1790 " CERZ %d, NB %d, CDBPAD 0x%x",
1791 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1792 pipe_in.u.dl.comp_ring_size,
1793 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1794 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1795 pipe_in.u.dl.ce_ring_size,
1796 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001797 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798
1799 /* RX PIPE */
1800 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1801 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1802 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1803 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1804 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1805 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1806 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1807 sizeof(struct sps_iovec);
1808 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1809 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301810 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001811 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1812 pipe_in.sys.keep_ipa_awake = true;
1813 }
1814
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001815 pipe_in.u.ul.rdy_ring_base_pa =
1816 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1817 pipe_in.u.ul.rdy_ring_size =
1818 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1819 pipe_in.u.ul.rdy_ring_rp_pa =
1820 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001821 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001822 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001823 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001824 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301825 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001826 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1827 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1828 pipe_in.u.ul.rdy_ring_size,
1829 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001830 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831
1832 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001833 ipa_ctxt->tx_comp_doorbell_paddr,
1834 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835
1836 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1837 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1838
1839 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001840 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841 hdd_ipa_uc_fw_op_event_handler);
1842 ipa_ctxt->uc_op_work[i].msg = NULL;
1843 }
1844
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301845 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846}
1847
Leo Change3e49442015-10-26 20:07:13 -07001848/**
1849 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1850 * @hdd_ctx: hdd main context
1851 *
1852 * Force shutdown IPA pipe
1853 * Independent of FW pipe status, IPA pipe shutdonw progress
1854 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1855 * independent from FW pipe status
1856 *
1857 * Return: NONE
1858 */
1859void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1860{
1861 struct hdd_ipa_priv *hdd_ipa;
1862
1863 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1864 return;
1865
1866 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1867 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301868 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001869 "IPA pipes are not down yet, force shutdown");
1870 hdd_ipa_uc_disable_pipes(hdd_ipa);
1871 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301872 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001873 "IPA pipes are down, do nothing");
1874 }
1875
1876 return;
1877}
1878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001879/**
1880 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1881 *
1882 * Deinit basic IPA UC host side to be in sync reloaded FW during
1883 * SSR
1884 *
1885 * Return: 0 - Success
1886 */
1887int hdd_ipa_uc_ssr_deinit(void)
1888{
1889 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1890 int idx;
1891 struct hdd_ipa_iface_context *iface_context;
1892
Leo Chang3bc8fed2015-11-13 10:59:47 -08001893 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894 return 0;
1895
1896 /* Clean up HDD IPA interfaces */
1897 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1898 (idx < HDD_IPA_MAX_IFACE); idx++) {
1899 iface_context = &hdd_ipa->iface_context[idx];
1900 if (iface_context && iface_context->adapter)
1901 hdd_ipa_cleanup_iface(iface_context);
1902 }
1903
1904 /* After SSR, wlan driver reloads FW again. But we need to protect
1905 * IPA submodule during SSR transient state. So deinit basic IPA
1906 * UC host side to be in sync with reloaded FW during SSR
1907 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001908 if (!hdd_ipa->ipa_pipes_down)
1909 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301911 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1913 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1914 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1915 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301916 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001917
1918 /* Full IPA driver cleanup not required since wlan driver is now
1919 * unloaded and reloaded after SSR.
1920 */
1921 return 0;
1922}
1923
1924/**
1925 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1926 *
1927 * Init basic IPA UC host side to be in sync with reloaded FW after
1928 * SSR to resume IPA UC operations
1929 *
1930 * Return: 0 - Success
1931 */
1932int hdd_ipa_uc_ssr_reinit(void)
1933{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001934
1935 /* After SSR is complete, IPA UC can resume operation. But now wlan
1936 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1937 * and initialization. This is a placeholder func if IPA has to resume
1938 * operations without driver reload.
1939 */
1940 return 0;
1941}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001942
1943/**
1944 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1945 * @hdd_ctx: Global HDD context
1946 * @skb: skb sent to IPA
1947 * @session_id: send packet instance session id
1948 *
1949 * Send TX packet which generated by system to IPA.
1950 * This routine only will be used for function verification
1951 *
1952 * Return: NULL packet sent to IPA properly
1953 * NULL invalid packet drop
1954 * skb packet not sent to IPA. legacy data path should handle
1955 */
1956struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1957 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001958{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001959 struct ipa_header *ipa_header;
1960 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07001961 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001962
1963 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1964 return skb;
1965
Leo Chang07b28f62016-05-11 12:29:22 -07001966 if (!hdd_ipa)
1967 return skb;
1968
1969 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
1970 return skb;
1971
Leo Changcc923e22016-06-16 15:29:03 -07001972 if (skb_headroom(skb) <
1973 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07001974 return skb;
1975
Leo Chang3bc8fed2015-11-13 10:59:47 -08001976 ipa_header = (struct ipa_header *) skb_push(skb,
1977 sizeof(struct ipa_header));
1978 if (!ipa_header) {
1979 /* No headroom, legacy */
1980 return skb;
1981 }
1982 memset(ipa_header, 0, sizeof(*ipa_header));
1983 ipa_header->vdev_id = 0;
1984
1985 frag_header = (struct frag_header *) skb_push(skb,
1986 sizeof(struct frag_header));
1987 if (!frag_header) {
1988 /* No headroom, drop */
1989 kfree_skb(skb);
1990 return NULL;
1991 }
1992 memset(frag_header, 0, sizeof(*frag_header));
1993 frag_header->length = skb->len - sizeof(struct frag_header)
1994 - sizeof(struct ipa_header);
1995
1996 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
1997 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07001998}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999
2000/**
2001 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2002 * @work: scheduled work
2003 *
2004 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2005 * not want to immediately release the wake lock since the system
2006 * would then potentially try to suspend when there is a healthy data
2007 * rate. Deferred work is scheduled and this function handles the
2008 * work. When this function is called, if the IPA resource is still
2009 * released then we release the wake lock.
2010 *
2011 * Return: None
2012 */
2013static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2014{
2015 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2016 struct hdd_ipa_priv,
2017 wake_lock_work);
2018
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302019 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020
2021 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2022 goto end;
2023
2024 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302025 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002026 WIFI_POWER_EVENT_WAKELOCK_IPA);
2027
2028end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302029 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030}
2031
2032/**
2033 * hdd_ipa_rm_request() - Request resource from IPA
2034 * @hdd_ipa: Global HDD IPA context
2035 *
2036 * Return: 0 on success, negative errno on error
2037 */
2038static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2039{
2040 int ret = 0;
2041
2042 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2043 return 0;
2044
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302045 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046
2047 switch (hdd_ipa->rm_state) {
2048 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302049 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050 return 0;
2051 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302052 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002053 return -EINPROGRESS;
2054 case HDD_IPA_RM_RELEASED:
2055 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2056 break;
2057 }
2058
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302059 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002060
2061 ret = ipa_rm_inactivity_timer_request_resource(
2062 IPA_RM_RESOURCE_WLAN_PROD);
2063
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302064 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 if (ret == 0) {
2066 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2067 hdd_ipa->stats.num_rm_grant_imm++;
2068 }
2069
2070 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2071 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302072 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002073 WIFI_POWER_EVENT_WAKELOCK_IPA);
2074 hdd_ipa->wake_lock_released = false;
2075 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302076 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002077
2078 return ret;
2079}
2080
2081/**
2082 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2083 * @hdd_ipa: Global HDD IPA context
2084 *
2085 * Return: 0 if resources released, negative errno otherwise
2086 */
2087static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2088{
2089 int ret = 0;
2090
2091 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2092 return 0;
2093
2094 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2095 return -EAGAIN;
2096
2097 spin_lock_bh(&hdd_ipa->q_lock);
2098 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2099 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2100 spin_unlock_bh(&hdd_ipa->q_lock);
2101 return -EAGAIN;
2102 }
2103 spin_unlock_bh(&hdd_ipa->q_lock);
2104
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302105 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002106
Nirav Shahcbc6d722016-03-01 16:24:53 +05302107 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302108 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002109 return -EAGAIN;
2110 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302111 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302113 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114 switch (hdd_ipa->rm_state) {
2115 case HDD_IPA_RM_GRANTED:
2116 break;
2117 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302118 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 return -EINPROGRESS;
2120 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302121 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122 return 0;
2123 }
2124
2125 /* IPA driver returns immediately so set the state here to avoid any
2126 * race condition.
2127 */
2128 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2129 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302130 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131
2132 ret =
2133 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2134
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302135 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002136 if (unlikely(ret != 0)) {
2137 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2138 WARN_ON(1);
2139 }
2140
2141 /*
2142 * If wake_lock is released immediately, kernel would try to suspend
2143 * immediately as well, Just avoid ping-pong between suspend-resume
2144 * while there is healthy amount of data transfer going on by
2145 * releasing the wake_lock after some delay.
2146 */
2147 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2148 msecs_to_jiffies
2149 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2150
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302151 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152
2153 return ret;
2154}
2155
2156/**
2157 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2158 * @user_data: user data registered with IPA
2159 * @event: the IPA resource manager event that occurred
2160 * @data: the data associated with the event
2161 *
2162 * Return: None
2163 */
2164static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2165 unsigned long data)
2166{
2167 struct hdd_ipa_priv *hdd_ipa = user_data;
2168
2169 if (unlikely(!hdd_ipa))
2170 return;
2171
2172 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2173 return;
2174
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302175 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002176
2177 switch (event) {
2178 case IPA_RM_RESOURCE_GRANTED:
2179 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2180 /* RM Notification comes with ISR context
2181 * it should be serialized into work queue to avoid
2182 * ISR sleep problem
2183 */
2184 hdd_ipa->uc_rm_work.event = event;
2185 schedule_work(&hdd_ipa->uc_rm_work.work);
2186 break;
2187 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302188 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002189 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302190 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002191 hdd_ipa->stats.num_rm_grant++;
2192 break;
2193
2194 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302195 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002196 hdd_ipa->resource_unloading = false;
2197 break;
2198
2199 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302200 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002201 break;
2202 }
2203}
2204
2205/**
2206 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2207 *
2208 * Callback function registered with IPA that is called when IPA wants
2209 * to release the WLAN consumer resource
2210 *
2211 * Return: 0 if the request is granted, negative errno otherwise
2212 */
2213static int hdd_ipa_rm_cons_release(void)
2214{
2215 return 0;
2216}
2217
2218/**
2219 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2220 *
2221 * Callback function registered with IPA that is called when IPA wants
2222 * to access the WLAN consumer resource
2223 *
2224 * Return: 0 if the request is granted, negative errno otherwise
2225 */
2226static int hdd_ipa_rm_cons_request(void)
2227{
Yun Park4d8b60a2015-10-22 13:59:32 -07002228 int ret = 0;
2229
2230 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302231 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002232 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002233 __func__);
2234 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002235 ret = -EINPROGRESS;
2236 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302237 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002238 "%s: IPA resource unloading in progress",
2239 __func__);
2240 ghdd_ipa->pending_cons_req = true;
2241 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002242 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002243
2244 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002245}
2246
2247/**
2248 * hdd_ipa_set_perf_level() - Set IPA performance level
2249 * @hdd_ctx: Global HDD context
2250 * @tx_packets: Number of packets transmitted in the last sample period
2251 * @rx_packets: Number of packets received in the last sample period
2252 *
2253 * Return: 0 on success, negative errno on error
2254 */
2255int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2256 uint64_t rx_packets)
2257{
2258 uint32_t next_cons_bw, next_prod_bw;
2259 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2260 struct ipa_rm_perf_profile profile;
2261 int ret;
2262
2263 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2264 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2265 return 0;
2266
2267 memset(&profile, 0, sizeof(profile));
2268
2269 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2270 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2271 else if (tx_packets >
2272 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2273 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2274 else
2275 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2276
2277 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2278 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2279 else if (rx_packets >
2280 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2281 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2282 else
2283 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2284
Yun Park8f289c82016-10-18 16:38:21 -07002285 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002286 "CONS perf curr: %d, next: %d",
2287 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Park8f289c82016-10-18 16:38:21 -07002288 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002289 "PROD perf curr: %d, next: %d",
2290 hdd_ipa->curr_prod_bw, next_prod_bw);
2291
2292 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302293 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002294 "Requesting CONS perf curr: %d, next: %d",
2295 hdd_ipa->curr_cons_bw, next_cons_bw);
2296 profile.max_supported_bandwidth_mbps = next_cons_bw;
2297 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2298 &profile);
2299 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302300 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002301 "RM CONS set perf profile failed: %d", ret);
2302
2303 return ret;
2304 }
2305 hdd_ipa->curr_cons_bw = next_cons_bw;
2306 hdd_ipa->stats.num_cons_perf_req++;
2307 }
2308
2309 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302310 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002311 "Requesting PROD perf curr: %d, next: %d",
2312 hdd_ipa->curr_prod_bw, next_prod_bw);
2313 profile.max_supported_bandwidth_mbps = next_prod_bw;
2314 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2315 &profile);
2316 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302317 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002318 "RM PROD set perf profile failed: %d", ret);
2319 return ret;
2320 }
2321 hdd_ipa->curr_prod_bw = next_prod_bw;
2322 hdd_ipa->stats.num_prod_perf_req++;
2323 }
2324
2325 return 0;
2326}
2327
2328/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002329 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2330 * @work: struct work_struct
2331 * @work_handler: work_handler
2332 *
2333 * Return: none
2334 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002335static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2336 work_func_t work_handler)
2337{
2338 INIT_WORK(work, work_handler);
2339}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002340
2341/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002342 * hdd_ipa_setup_rm() - Setup IPA resource management
2343 * @hdd_ipa: Global HDD IPA context
2344 *
2345 * Return: 0 on success, negative errno on error
2346 */
2347static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2348{
2349 struct ipa_rm_create_params create_params = { 0 };
2350 int ret;
2351
2352 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2353 return 0;
2354
Rajeev Kumar217f2172016-01-06 18:11:55 -08002355 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2356 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002357 memset(&create_params, 0, sizeof(create_params));
2358 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2359 create_params.reg_params.user_data = hdd_ipa;
2360 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2361 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2362
2363 ret = ipa_rm_create_resource(&create_params);
2364 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302365 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002366 "Create RM resource failed: %d", ret);
2367 goto setup_rm_fail;
2368 }
2369
2370 memset(&create_params, 0, sizeof(create_params));
2371 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2372 create_params.request_resource = hdd_ipa_rm_cons_request;
2373 create_params.release_resource = hdd_ipa_rm_cons_release;
2374 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2375
2376 ret = ipa_rm_create_resource(&create_params);
2377 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302378 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002379 "Create RM CONS resource failed: %d", ret);
2380 goto delete_prod;
2381 }
2382
2383 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2384 IPA_RM_RESOURCE_APPS_CONS);
2385
2386 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2387 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2388 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302389 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002390 ret);
2391 goto timer_init_failed;
2392 }
2393
2394 /* Set the lowest bandwidth to start with */
2395 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2396
2397 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302398 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002399 "Set perf level failed: %d", ret);
2400 goto set_perf_failed;
2401 }
2402
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302403 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2405 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302406 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002407 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2408 hdd_ipa->wake_lock_released = true;
2409 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2410
2411 return ret;
2412
2413set_perf_failed:
2414 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2415
2416timer_init_failed:
2417 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2418
2419delete_prod:
2420 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2421
2422setup_rm_fail:
2423 return ret;
2424}
2425
2426/**
2427 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2428 * @hdd_ipa: Global HDD IPA context
2429 *
2430 * Destroys all resources associated with the IPA resource manager
2431 *
2432 * Return: None
2433 */
2434static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2435{
2436 int ret;
2437
2438 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2439 return;
2440
2441 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302442 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002443
2444#ifdef WLAN_OPEN_SOURCE
2445 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2446#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302447 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002448
2449 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2450
2451 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2452 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302453 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002454 "RM PROD resource delete failed %d", ret);
2455
2456 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2457 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302458 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002459 "RM CONS resource delete failed %d", ret);
2460}
2461
2462/**
2463 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2464 * @skb: network buffer
2465 * @adapter: network adapter
2466 *
2467 * Called when a network buffer is received which should not be routed
2468 * to the IPA module.
2469 *
2470 * Return: None
2471 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302472static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002473 hdd_adapter_t *adapter)
2474{
2475 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2476 unsigned int cpu_index;
2477
2478 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302479 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002480 adapter);
2481 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002482 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002483 return;
2484 }
2485
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002486 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002487 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002488 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002489 return;
2490 }
2491
2492 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2493 skb->dev = adapter->dev;
2494 skb->protocol = eth_type_trans(skb, skb->dev);
2495 skb->ip_summed = CHECKSUM_NONE;
2496
2497 cpu_index = wlan_hdd_get_cpu();
2498
2499 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2500 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2501 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2502 else
2503 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2504
2505 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2506 adapter->dev->last_rx = jiffies;
2507}
2508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002509/**
Leo Chang69c39692016-10-12 20:11:12 -07002510 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2511 * @hdd_ipa: pointer to hdd ipa context
2512 * @adapter: network adapter
2513 * @skb: data pointer
2514 *
2515 * if exception packet has set forward bit, copied new packet should be
2516 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2517 * put into pm queue and tx procedure will be differed
2518 *
2519 * Return: None
2520 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002521static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2522 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002523{
2524 qdf_nbuf_t copy;
2525 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2526
2527 copy = qdf_nbuf_copy(skb);
2528 if (!copy) {
2529 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2530 return;
2531 }
2532
2533 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2534 /* WLAN subsystem is in suspend, put int queue */
2535 if (hdd_ipa->suspended) {
2536 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2537 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2538 "TX in SUSPEND PUT QUEUE");
2539 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2540 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2541 pm_tx_cb->exception = true;
2542 pm_tx_cb->adapter = adapter;
2543 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2544 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2545 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2546 hdd_ipa->stats.num_tx_queued++;
2547 } else {
2548 /* Resume, put packet into WLAN TX */
2549 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2550 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2551 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2552 "packet tx fail");
2553 } else {
2554 hdd_ipa->stats.num_tx_bcmc++;
2555 hdd_ipa->ipa_tx_forward++;
2556 }
2557 }
2558}
2559
2560/**
2561 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562 * @priv: pointer to private data registered with IPA (we register a
2563 * pointer to the global IPA context)
2564 * @evt: the IPA event which triggered the callback
2565 * @data: data associated with the event
2566 *
2567 * Return: None
2568 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002569static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002570 unsigned long data)
2571{
2572 struct hdd_ipa_priv *hdd_ipa = NULL;
2573 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302574 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002575 uint8_t iface_id;
2576 uint8_t session_id;
2577 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002579 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580
2581 hdd_ipa = (struct hdd_ipa_priv *)priv;
2582
2583 switch (evt) {
2584 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302585 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002586
2587 /*
2588 * When SSR is going on or driver is unloading,
2589 * just drop the packets.
2590 */
2591 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2592 if (0 != status) {
2593 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2594 "Invalid context: drop packet");
2595 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2596 kfree_skb(skb);
2597 return;
2598 }
2599
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002600 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2601 session_id = (uint8_t)skb->cb[0];
2602 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302603 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002604 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2605 session_id, iface_id);
2606 } else {
2607 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2608 }
2609
2610 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302611 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612 "IPA_RECEIVE: Invalid iface_id: %u",
2613 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302614 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615 "w2i -- skb", skb->data, 8);
2616 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002617 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002618 return;
2619 }
2620
2621 iface_context = &hdd_ipa->iface_context[iface_id];
2622 adapter = iface_context->adapter;
2623
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302624 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002625 "w2i -- skb", skb->data, 8);
2626 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2627 hdd_ipa->stats.num_rx_excep++;
2628 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2629 } else {
2630 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2631 }
2632
2633 iface_context->stats.num_rx_ipa_excep++;
2634
2635 /* Disable to forward Intra-BSS Rx packets when
2636 * ap_isolate=1 in hostapd.conf
2637 */
Yun Park046101c2016-09-02 15:32:14 -07002638 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002639 /*
2640 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2641 * all Rx packets to IPA uC, which need to be forwarded
2642 * to other interface.
2643 * And, IPA driver will send back to WLAN host driver
2644 * through exception pipe with fw_desc field set by FW.
2645 * Here we are checking fw_desc field for FORWARD bit
2646 * set, and forward to Tx. Then copy to kernel stack
2647 * only when DISCARD bit is not set.
2648 */
2649 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002650 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302651 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302652 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002653 "Forward packet to Tx (fw_desc=%d)",
2654 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002655 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002656 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002657 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002658 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2659 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002660 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002661 break;
2662 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002663 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302664 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665 "Intra-BSS FWD is disabled-skip forward to Tx");
2666 }
2667
2668 hdd_ipa_send_skb_to_network(skb, adapter);
2669 break;
2670
2671 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302672 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002673 "w2i cb wrong event: 0x%x", evt);
2674 return;
2675 }
2676}
2677
2678/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002679 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2680 * @priv: pointer to private data registered with IPA (we register a
2681 * pointer to the global IPA context)
2682 * @evt: the IPA event which triggered the callback
2683 * @data: data associated with the event
2684 *
2685 * Return: None
2686 */
2687static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2688 unsigned long data)
2689{
2690 cds_ssr_protect(__func__);
2691 __hdd_ipa_w2i_cb(priv, evt, data);
2692 cds_ssr_unprotect(__func__);
2693}
2694
2695/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002696 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2697 * @skb: packet buffer which was transmitted
2698 *
2699 * Return: None
2700 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302701void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002702{
2703 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2704
Govind Singhb6a89772016-08-12 11:23:35 +05302705 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302706 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002707 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302708 ipa_free_skb((struct ipa_rx_data *)
2709 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002710
2711 hdd_ipa->stats.num_tx_comp_cnt++;
2712
2713 atomic_dec(&hdd_ipa->tx_ref_cnt);
2714
2715 hdd_ipa_rm_try_release(hdd_ipa);
2716}
2717
2718/**
2719 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2720 * @iface_context: interface-specific IPA context
2721 * @ipa_tx_desc: packet data descriptor
2722 *
2723 * Return: None
2724 */
2725static void hdd_ipa_send_pkt_to_tl(
2726 struct hdd_ipa_iface_context *iface_context,
2727 struct ipa_rx_data *ipa_tx_desc)
2728{
2729 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2730 uint8_t interface_id;
2731 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302732 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002733
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302734 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002735 adapter = iface_context->adapter;
2736 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302737 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738 ipa_free_skb(ipa_tx_desc);
2739 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302740 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002741 hdd_ipa_rm_try_release(hdd_ipa);
2742 return;
2743 }
2744
2745 /*
2746 * During CAC period, data packets shouldn't be sent over the air so
2747 * drop all the packets here
2748 */
2749 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2750 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302751 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002752 iface_context->stats.num_tx_cac_drop++;
2753 hdd_ipa_rm_try_release(hdd_ipa);
2754 return;
2755 }
2756
2757 interface_id = adapter->sessionId;
2758 ++adapter->stats.tx_packets;
2759
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302760 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761
2762 skb = ipa_tx_desc->skb;
2763
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302764 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302765 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002766 /* FIXME: This is broken. No such field in cb any more:
2767 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002768 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302769 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002770 ipa_tx_desc->dma_addr
2771 + HDD_IPA_WLAN_FRAG_HEADER
2772 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002773 ipa_tx_desc->skb->len -=
2774 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2775 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302776 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002777
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002778 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302779 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002780
2781 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2782
2783 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2784 ipa_tx_desc->skb);
2785 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302786 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 ipa_free_skb(ipa_tx_desc);
2788 iface_context->stats.num_tx_err++;
2789 hdd_ipa_rm_try_release(hdd_ipa);
2790 return;
2791 }
2792
2793 atomic_inc(&hdd_ipa->tx_ref_cnt);
2794
2795 iface_context->stats.num_tx++;
2796
2797}
2798
2799/**
Leo Chang11545d62016-10-17 14:53:50 -07002800 * hdd_ipa_is_present() - get IPA hw status
2801 * @hdd_ctx: pointer to hdd context
2802 *
2803 * ipa_uc_reg_rdyCB is not directly designed to check
2804 * ipa hw status. This is an undocumented function which
2805 * has confirmed with IPA team.
2806 *
2807 * Return: true - ipa hw present
2808 * false - ipa hw not present
2809 */
2810bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2811{
2812 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002813 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002814 return true;
2815 else
2816 return false;
2817}
2818
2819/**
Leo Chang69c39692016-10-12 20:11:12 -07002820 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821 * @work: pointer to the scheduled work
2822 *
2823 * Called during PM resume to send packets to TL which were queued
2824 * while host was in the process of suspending.
2825 *
2826 * Return: None
2827 */
Leo Chang69c39692016-10-12 20:11:12 -07002828static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002829{
2830 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2831 struct hdd_ipa_priv,
2832 pm_work);
2833 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302834 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002835 uint32_t dequeued = 0;
2836
Leo Chang69c39692016-10-12 20:11:12 -07002837 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2838 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302839 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302840 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2841 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302842 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843
2844 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002846 if (pm_tx_cb->exception) {
2847 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2848 "FLUSH EXCEPTION");
2849 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2850 } else {
2851 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002853 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302854 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302856 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002857 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2858 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002859
2860 hdd_ipa->stats.num_tx_dequeued += dequeued;
2861 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2862 hdd_ipa->stats.num_max_pm_queue = dequeued;
2863}
2864
2865/**
2866 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2867 * @priv: pointer to private data registered with IPA (we register a
2868 * pointer to the interface-specific IPA context)
2869 * @evt: the IPA event which triggered the callback
2870 * @data: data associated with the event
2871 *
2872 * Return: None
2873 */
2874static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2875 unsigned long data)
2876{
2877 struct hdd_ipa_priv *hdd_ipa = NULL;
2878 struct ipa_rx_data *ipa_tx_desc;
2879 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302880 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302882 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002883
Mukul Sharma81661ae2015-10-30 20:26:02 +05302884 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002885 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302886 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002887 dev_kfree_skb_any(skb);
2888 iface_context->stats.num_tx_drop++;
2889 return;
2890 }
2891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892 ipa_tx_desc = (struct ipa_rx_data *)data;
2893
2894 hdd_ipa = iface_context->hdd_ipa;
2895
2896 /*
2897 * When SSR is going on or driver is unloading, just drop the packets.
2898 * During SSR, there is no use in queueing the packets as STA has to
2899 * connect back any way
2900 */
2901 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302902 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903 ipa_free_skb(ipa_tx_desc);
2904 iface_context->stats.num_tx_drop++;
2905 return;
2906 }
2907
2908 skb = ipa_tx_desc->skb;
2909
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302910 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911
2912 /*
2913 * If PROD resource is not requested here then there may be cases where
2914 * IPA hardware may be clocked down because of not having proper
2915 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2916 * workaround to request PROD resource while data is going over CONS
2917 * pipe to prevent the IPA hardware clockdown.
2918 */
2919 hdd_ipa_rm_request(hdd_ipa);
2920
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302921 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922 /*
2923 * If host is still suspended then queue the packets and these will be
2924 * drained later when resume completes. When packet is arrived here and
2925 * host is suspended, this means that there is already resume is in
2926 * progress.
2927 */
2928 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302929 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002930 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2931 pm_tx_cb->iface_context = iface_context;
2932 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302933 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934 hdd_ipa->stats.num_tx_queued++;
2935
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302936 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002937 return;
2938 }
2939
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302940 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941
2942 /*
2943 * If we are here means, host is not suspended, wait for the work queue
2944 * to finish.
2945 */
2946#ifdef WLAN_OPEN_SOURCE
2947 flush_work(&hdd_ipa->pm_work);
2948#endif
2949
2950 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2951}
2952
2953/**
2954 * hdd_ipa_suspend() - Suspend IPA
2955 * @hdd_ctx: Global HDD context
2956 *
2957 * Return: 0 on success, negativer errno on error
2958 */
2959int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2960{
2961 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2962
2963 if (!hdd_ipa_is_enabled(hdd_ctx))
2964 return 0;
2965
2966 /*
2967 * Check if IPA is ready for suspend, If we are here means, there is
2968 * high chance that suspend would go through but just to avoid any race
2969 * condition after suspend started, these checks are conducted before
2970 * allowing to suspend.
2971 */
2972 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2973 return -EAGAIN;
2974
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302975 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002976
2977 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302978 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002979 return -EAGAIN;
2980 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302981 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002982
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302983 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302985 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002986
2987 return 0;
2988}
2989
2990/**
2991 * hdd_ipa_resume() - Resume IPA following suspend
2992 * hdd_ctx: Global HDD context
2993 *
2994 * Return: 0 on success, negative errno on error
2995 */
2996int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2997{
2998 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2999
3000 if (!hdd_ipa_is_enabled(hdd_ctx))
3001 return 0;
3002
3003 schedule_work(&hdd_ipa->pm_work);
3004
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303005 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003006 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303007 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008
3009 return 0;
3010}
3011
3012/**
3013 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3014 * @hdd_ipa: Global HDD IPA context
3015 *
3016 * Return: 0 on success, negative errno on error
3017 */
3018static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3019{
3020 int i, ret = 0;
3021 struct ipa_sys_connect_params *ipa;
3022 uint32_t desc_fifo_sz;
3023
3024 /* The maximum number of descriptors that can be provided to a BAM at
3025 * once is one less than the total number of descriptors that the buffer
3026 * can contain.
3027 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3028 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3029 * be provided at once.
3030 * Because of above requirement, one extra descriptor will be added to
3031 * make sure hardware always has one descriptor.
3032 */
3033 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3034 + sizeof(struct sps_iovec);
3035
3036 /*setup TX pipes */
3037 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3038 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3039
3040 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3041 ipa->desc_fifo_sz = desc_fifo_sz;
3042 ipa->priv = &hdd_ipa->iface_context[i];
3043 ipa->notify = hdd_ipa_i2w_cb;
3044
3045 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3046 ipa->ipa_ep_cfg.hdr.hdr_len =
3047 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3048 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3049 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3050 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3051 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3052 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3053 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3054 } else {
3055 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3056 }
3057 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3058
3059 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3060 ipa->keep_ipa_awake = 1;
3061
3062 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3063 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303064 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003065 " ret: %d", i, ret);
3066 goto setup_sys_pipe_fail;
3067 }
3068 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3069 }
3070
3071 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3072 /*
3073 * Hard code it here, this can be extended if in case
3074 * PROD pipe is also per interface.
3075 * Right now there is no advantage of doing this.
3076 */
3077 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3078
3079 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3080
3081 ipa->client = hdd_ipa->prod_client;
3082
3083 ipa->desc_fifo_sz = desc_fifo_sz;
3084 ipa->priv = hdd_ipa;
3085 ipa->notify = hdd_ipa_w2i_cb;
3086
3087 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3088 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3089 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3090 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3091
3092 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3093 ipa->keep_ipa_awake = 1;
3094
3095 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3096 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303097 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003098 "Failed for RX pipe: %d", ret);
3099 goto setup_sys_pipe_fail;
3100 }
3101 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3102 }
3103
3104 return ret;
3105
3106setup_sys_pipe_fail:
3107
3108 while (--i >= 0) {
3109 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303110 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003111 sizeof(struct hdd_ipa_sys_pipe));
3112 }
3113
3114 return ret;
3115}
3116
3117/**
3118 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3119 * @hdd_ipa: Global HDD IPA context
3120 *
3121 * Return: None
3122 */
3123static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3124{
3125 int ret = 0, i;
3126 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3127 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3128 ret =
3129 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3130 conn_hdl);
3131 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303132 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 ret);
3134
3135 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3136 }
3137 }
3138}
3139
3140/**
3141 * hdd_ipa_register_interface() - register IPA interface
3142 * @hdd_ipa: Global IPA context
3143 * @iface_context: Per-interface IPA context
3144 *
3145 * Return: 0 on success, negative errno on error
3146 */
3147static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3148 struct hdd_ipa_iface_context
3149 *iface_context)
3150{
3151 struct ipa_tx_intf tx_intf;
3152 struct ipa_rx_intf rx_intf;
3153 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3154 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3155 char *ifname = iface_context->adapter->dev->name;
3156
3157 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3158 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3159
3160 int num_prop = 1;
3161 int ret = 0;
3162
3163 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3164 num_prop++;
3165
3166 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3167 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303168 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303170 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 goto register_interface_fail;
3172 }
3173
3174 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3175 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303176 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303178 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 goto register_interface_fail;
3180 }
3181
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303182 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3183 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184
3185 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3186 ifname, HDD_IPA_IPV4_NAME_EXT);
3187 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3188 ifname, HDD_IPA_IPV6_NAME_EXT);
3189
3190 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3191 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3192 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3193 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3194
3195 /*
3196 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3197 * mask to identify the interface in IPA hardware
3198 */
3199 rx_prop[IPA_IP_v4].attrib.meta_data =
3200 htonl(iface_context->adapter->sessionId << 16);
3201 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3202
3203 rx_intf.num_props++;
3204 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3205 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3206 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3207 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3208 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3209 rx_prop[IPA_IP_v4].attrib.meta_data =
3210 htonl(iface_context->adapter->sessionId << 16);
3211 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3212
3213 rx_intf.num_props++;
3214 }
3215
3216 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3217 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3218 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3219 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3220 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3221 IPA_RESOURCE_NAME_MAX);
3222 tx_intf.num_props++;
3223
3224 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3225 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3226 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3227 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3228 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3229 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3230 IPA_RESOURCE_NAME_MAX);
3231 tx_intf.num_props++;
3232 }
3233
3234 tx_intf.prop = tx_prop;
3235 rx_intf.prop = rx_prop;
3236
3237 /* Call the ipa api to register interface */
3238 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3239
3240register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303241 qdf_mem_free(tx_prop);
3242 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243 return ret;
3244}
3245
3246/**
3247 * hdd_remove_ipa_header() - Remove a specific header from IPA
3248 * @name: Name of the header to be removed
3249 *
3250 * Return: None
3251 */
3252static void hdd_ipa_remove_header(char *name)
3253{
3254 struct ipa_ioc_get_hdr hdrlookup;
3255 int ret = 0, len;
3256 struct ipa_ioc_del_hdr *ipa_hdr;
3257
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303258 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3260 ret = ipa_get_hdr(&hdrlookup);
3261 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303262 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263 name, ret);
3264 return;
3265 }
3266
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303267 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303269 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303271 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 return;
3273 }
3274 ipa_hdr->num_hdls = 1;
3275 ipa_hdr->commit = 0;
3276 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3277 ipa_hdr->hdl[0].status = -1;
3278 ret = ipa_del_hdr(ipa_hdr);
3279 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303280 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 ret);
3282
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303283 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284}
3285
3286/**
3287 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3288 * @hdd_ipa: Global HDD IPA context
3289 * @iface_context: Interface-specific HDD IPA context
3290 * @mac_addr: Interface MAC address
3291 *
3292 * Return: 0 on success, negativer errno value on error
3293 */
3294static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3295 struct hdd_ipa_iface_context *iface_context,
3296 uint8_t *mac_addr)
3297{
3298 hdd_adapter_t *adapter = iface_context->adapter;
3299 char *ifname;
3300 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3301 int ret = -EINVAL;
3302 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3303 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3304
3305 ifname = adapter->dev->name;
3306
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303307 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308 ifname, mac_addr);
3309
3310 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303311 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 + sizeof(struct ipa_hdr_add));
3313 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303314 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003315 "%s: ipa_hdr allocation failed", ifname);
3316 ret = -ENOMEM;
3317 goto end;
3318 }
3319
3320 ipa_hdr->commit = 0;
3321 ipa_hdr->num_hdrs = 1;
3322
3323 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3324 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3325 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3326 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3327 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303328 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329 "ifname=%s, vdev_id=%d",
3330 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3331 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3332 ifname, HDD_IPA_IPV4_NAME_EXT);
3333 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3334 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3335 ipa_hdr->hdr[0].is_partial = 1;
3336 ipa_hdr->hdr[0].hdr_hdl = 0;
3337 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3338 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3339
3340 ret = ipa_add_hdr(ipa_hdr);
3341 } else {
3342 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3343
3344 /* Set the Source MAC */
3345 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3346 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3347
3348 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3349 ifname, HDD_IPA_IPV4_NAME_EXT);
3350 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3351 ipa_hdr->hdr[0].is_partial = 1;
3352 ipa_hdr->hdr[0].hdr_hdl = 0;
3353 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3354 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3355
3356 /* Set the type to IPV4 in the header */
3357 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3358
3359 ret = ipa_add_hdr(ipa_hdr);
3360 }
3361 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303362 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 ifname, ret);
3364 goto end;
3365 }
3366
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303367 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3369
3370 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3371 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3372 ifname, HDD_IPA_IPV6_NAME_EXT);
3373
3374 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3375 uc_tx_hdr =
3376 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3377 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3378 } else {
3379 /* Set the type to IPV6 in the header */
3380 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3381 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3382 }
3383
3384 ret = ipa_add_hdr(ipa_hdr);
3385 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303386 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387 "%s: IPv6 add hdr failed: %d", ifname, ret);
3388 goto clean_ipv4_hdr;
3389 }
3390
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303391 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3393 }
3394
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303395 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396
3397 return ret;
3398
3399clean_ipv4_hdr:
3400 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3401 ifname, HDD_IPA_IPV4_NAME_EXT);
3402 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3403end:
3404 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303405 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406
3407 return ret;
3408}
3409
3410/**
3411 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3412 * @adapter: Adapter upon which IPA was previously configured
3413 *
3414 * Return: None
3415 */
3416static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3417{
3418 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3419 int ret;
3420 char name_ipa[IPA_RESOURCE_NAME_MAX];
3421
3422 /* Remove the headers */
3423 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3424 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3425 hdd_ipa_remove_header(name_ipa);
3426
3427 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3428 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3429 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3430 hdd_ipa_remove_header(name_ipa);
3431 }
3432 /* unregister the interface with IPA */
3433 ret = ipa_deregister_intf(adapter->dev->name);
3434 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303435 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 "%s: ipa_deregister_intf fail: %d",
3437 adapter->dev->name, ret);
3438}
3439
3440/**
3441 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3442 * @iface_context: interface-specific IPA context
3443 *
3444 * Return: None
3445 */
3446static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3447{
3448 if (iface_context == NULL)
3449 return;
3450
3451 hdd_ipa_clean_hdr(iface_context->adapter);
3452
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303453 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003454 iface_context->adapter->ipa_context = NULL;
3455 iface_context->adapter = NULL;
3456 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303457 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458 iface_context->ifa_address = 0;
3459 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303460 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303462 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 }
3464 iface_context->hdd_ipa->num_iface--;
3465}
3466
3467/**
3468 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3469 * @hdd_ipa: HDD IPA global context
3470 * @adapter: Interface upon which IPA is being setup
3471 * @sta_id: Station ID of the API instance
3472 *
3473 * Return: 0 on success, negative errno value on error
3474 */
3475static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3476 hdd_adapter_t *adapter, uint8_t sta_id)
3477{
3478 struct hdd_ipa_iface_context *iface_context = NULL;
3479 void *tl_context = NULL;
3480 int i, ret = 0;
3481
3482 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3483 * channel change indication. Since these indications are sent by lower
3484 * layer as SAP updates and IPA doesn't have to do anything for these
3485 * updates so ignoring!
3486 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003487 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 return 0;
3489
3490 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3491 if (hdd_ipa->iface_context[i].adapter == NULL) {
3492 iface_context = &(hdd_ipa->iface_context[i]);
3493 break;
3494 }
3495 }
3496
3497 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303498 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 "All the IPA interfaces are in use");
3500 ret = -ENOMEM;
3501 goto end;
3502 }
3503
3504 adapter->ipa_context = iface_context;
3505 iface_context->adapter = adapter;
3506 iface_context->sta_id = sta_id;
3507 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3508
3509 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303510 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511 "Not able to get TL context sta_id: %d", sta_id);
3512 ret = -EINVAL;
3513 goto end;
3514 }
3515
3516 iface_context->tl_context = tl_context;
3517
3518 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3519 adapter->dev->dev_addr);
3520
3521 if (ret)
3522 goto end;
3523
3524 /* Configure the TX and RX pipes filter rules */
3525 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3526 if (ret)
3527 goto cleanup_header;
3528
3529 hdd_ipa->num_iface++;
3530 return ret;
3531
3532cleanup_header:
3533
3534 hdd_ipa_clean_hdr(adapter);
3535end:
3536 if (iface_context)
3537 hdd_ipa_cleanup_iface(iface_context);
3538 return ret;
3539}
3540
3541/**
3542 * hdd_ipa_msg_free_fn() - Free an IPA message
3543 * @buff: pointer to the IPA message
3544 * @len: length of the IPA message
3545 * @type: type of IPA message
3546 *
3547 * Return: None
3548 */
3549static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3550{
3551 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3552 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303553 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554}
3555
Yun Parka27049a2016-10-11 12:30:49 -07003556#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557/**
3558 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3559 * @mcc_mode: 0=MCC/1=SCC
3560 *
3561 * Return: 0 on success, negative errno value on error
3562 */
3563int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3564{
3565 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303566 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567 hdd_adapter_t *pAdapter;
3568 struct ipa_msg_meta meta;
3569 struct ipa_wlan_msg *msg;
3570 int ret;
3571
3572 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3573 return -EINVAL;
3574
3575 if (!pHddCtx->mcc_mode) {
3576 /* Flush TxRx queue for each adapter before switch to SCC */
3577 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303578 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003580 if (pAdapter->device_mode == QDF_STA_MODE ||
3581 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303582 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003583 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3584 pAdapter->device_mode);
3585 hdd_deinit_tx_rx(pAdapter);
3586 }
3587 status = hdd_get_next_adapter(
3588 pHddCtx, adapter_node, &next);
3589 adapter_node = next;
3590 }
3591 }
3592
3593 /* Send SCC/MCC Switching event to IPA */
3594 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303595 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596 if (msg == NULL) {
3597 hddLog(LOGE, "msg allocation failed");
3598 return -ENOMEM;
3599 }
3600
3601 meta.msg_type = mcc_mode ?
3602 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3603 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3604
3605 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3606
3607 if (ret) {
3608 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3609 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303610 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611 }
3612
3613 return ret;
3614}
Yun Parka27049a2016-10-11 12:30:49 -07003615#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616
3617/**
3618 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3619 * @event: IPA WLAN event to be converted to a string
3620 *
3621 * Return: ASCII string representing the IPA WLAN event
3622 */
3623static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3624{
3625 switch (event) {
3626 case WLAN_CLIENT_CONNECT:
3627 return "WLAN_CLIENT_CONNECT";
3628 case WLAN_CLIENT_DISCONNECT:
3629 return "WLAN_CLIENT_DISCONNECT";
3630 case WLAN_CLIENT_POWER_SAVE_MODE:
3631 return "WLAN_CLIENT_POWER_SAVE_MODE";
3632 case WLAN_CLIENT_NORMAL_MODE:
3633 return "WLAN_CLIENT_NORMAL_MODE";
3634 case SW_ROUTING_ENABLE:
3635 return "SW_ROUTING_ENABLE";
3636 case SW_ROUTING_DISABLE:
3637 return "SW_ROUTING_DISABLE";
3638 case WLAN_AP_CONNECT:
3639 return "WLAN_AP_CONNECT";
3640 case WLAN_AP_DISCONNECT:
3641 return "WLAN_AP_DISCONNECT";
3642 case WLAN_STA_CONNECT:
3643 return "WLAN_STA_CONNECT";
3644 case WLAN_STA_DISCONNECT:
3645 return "WLAN_STA_DISCONNECT";
3646 case WLAN_CLIENT_CONNECT_EX:
3647 return "WLAN_CLIENT_CONNECT_EX";
3648
3649 case IPA_WLAN_EVENT_MAX:
3650 default:
3651 return "UNKNOWN";
3652 }
3653}
3654
3655/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003656 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3657 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3658 *
3659 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3660 */
3661static enum ipa_wlan_event
3662hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3663{
3664 enum ipa_wlan_event ipa_event;
3665
3666 switch (hdd_ipa_event_type) {
3667 case HDD_IPA_CLIENT_CONNECT:
3668 ipa_event = WLAN_CLIENT_CONNECT;
3669 break;
3670 case HDD_IPA_CLIENT_DISCONNECT:
3671 ipa_event = WLAN_CLIENT_DISCONNECT;
3672 break;
3673 case HDD_IPA_AP_CONNECT:
3674 ipa_event = WLAN_AP_CONNECT;
3675 break;
3676 case HDD_IPA_AP_DISCONNECT:
3677 ipa_event = WLAN_AP_DISCONNECT;
3678 break;
3679 case HDD_IPA_STA_CONNECT:
3680 ipa_event = WLAN_STA_CONNECT;
3681 break;
3682 case HDD_IPA_STA_DISCONNECT:
3683 ipa_event = WLAN_STA_DISCONNECT;
3684 break;
3685 case HDD_IPA_CLIENT_CONNECT_EX:
3686 ipa_event = WLAN_CLIENT_CONNECT_EX;
3687 break;
3688 case HDD_IPA_WLAN_EVENT_MAX:
3689 default:
3690 ipa_event = IPA_WLAN_EVENT_MAX;
3691 break;
3692 }
3693 return ipa_event;
3694
3695}
3696
3697/**
3698 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003699 * @adapter: adapter upon which the event was received
3700 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003701 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 * @mac_address: MAC address associated with the event
3703 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003704 * This function is meant to be called from within wlan_hdd_ipa.c
3705 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706 * Return: 0 on success, negative errno value on error
3707 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003708static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 enum ipa_wlan_event type, uint8_t *mac_addr)
3710{
3711 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3712 struct ipa_msg_meta meta;
3713 struct ipa_wlan_msg *msg;
3714 struct ipa_wlan_msg_ex *msg_ex = NULL;
3715 int ret;
3716
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303717 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003718 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3719 mac_addr, sta_id);
3720
3721 if (type >= IPA_WLAN_EVENT_MAX)
3722 return -EINVAL;
3723
3724 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3725 return -EINVAL;
3726
3727 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303728 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729 return -EINVAL;
3730 }
3731
3732 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3733 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003734 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003735 return 0;
3736 }
3737
3738 /*
3739 * During IPA UC resource loading/unloading new events can be issued.
3740 * Store the events separately and handle them later.
3741 */
3742 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3743 ((hdd_ipa->resource_loading) ||
3744 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003745 unsigned int pending_event_count;
3746 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747
Yun Parkf19e07d2015-11-20 11:34:27 -08003748 hdd_err("IPA resource %s inprogress",
3749 hdd_ipa->resource_loading ? "load":"unload");
3750
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303751 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003752
Anurag Chouhanffb21542016-02-17 14:33:03 +05303753 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003754 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3755 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303756 qdf_list_remove_front(&hdd_ipa->pending_event,
3757 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003758 } else {
3759 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303760 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003761 sizeof(struct ipa_uc_pending_event));
3762 }
3763
3764 if (!pending_event) {
3765 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303766 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767 return -ENOMEM;
3768 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003769
3770 pending_event->adapter = adapter;
3771 pending_event->sta_id = sta_id;
3772 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303773 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303775 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303776 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003777 &pending_event->node);
3778
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303779 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780 return 0;
3781 }
3782
3783 hdd_ipa->stats.event[type]++;
3784
Leo Chang3bc8fed2015-11-13 10:59:47 -08003785 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786 switch (type) {
3787 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003788 qdf_mutex_acquire(&hdd_ipa->event_lock);
3789
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003790 /* STA already connected and without disconnect, connect again
3791 * This is Roaming scenario
3792 */
3793 if (hdd_ipa->sta_connected)
3794 hdd_ipa_cleanup_iface(adapter->ipa_context);
3795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003796 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3797 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303798 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003799 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003800 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003801
Yun Park8f289c82016-10-18 16:38:21 -07003802 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3803 (hdd_ipa->sap_num_connected_sta > 0) &&
3804 !hdd_ipa->sta_connected) {
3805 qdf_mutex_release(&hdd_ipa->event_lock);
3806 hdd_ipa_uc_offload_enable_disable(adapter,
3807 SIR_STA_RX_DATA_OFFLOAD, 1);
3808 qdf_mutex_acquire(&hdd_ipa->event_lock);
3809 }
3810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811 vdev_to_iface[adapter->sessionId] =
3812 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003813 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003816
3817 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 break;
3819
3820 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003821 qdf_mutex_acquire(&hdd_ipa->event_lock);
3822
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823 /* For DFS channel we get two start_bss event (before and after
3824 * CAC). Also when ACS range includes both DFS and non DFS
3825 * channels, we could possibly change channel many times due to
3826 * RADAR detection and chosen channel may not be a DFS channels.
3827 * So dont return error here. Just discard the event.
3828 */
Yun Park8f289c82016-10-18 16:38:21 -07003829 if (adapter->ipa_context) {
3830 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003832 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3835 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303836 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837 "%s: Evt: %d, Interface setup failed",
3838 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303839 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003841 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842
Yun Park8f289c82016-10-18 16:38:21 -07003843 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3844 qdf_mutex_release(&hdd_ipa->event_lock);
3845 hdd_ipa_uc_offload_enable_disable(adapter,
3846 SIR_AP_RX_DATA_OFFLOAD, 1);
3847 qdf_mutex_acquire(&hdd_ipa->event_lock);
3848 }
3849
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850 vdev_to_iface[adapter->sessionId] =
3851 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003852 (adapter->ipa_context))->iface_id;
3853
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303854 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 break;
3856
3857 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303858 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859
3860 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303861 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 "%s: Evt: %d, STA already disconnected",
3863 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303864 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003865 return -EINVAL;
3866 }
Yun Parka37592b2016-06-11 17:10:28 -07003867
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003868 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003869
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303871 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 "%s: IPA UC OFFLOAD NOT ENABLED",
3873 msg_ex->name);
3874 } else {
3875 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003876 if (!hdd_ipa->num_iface &&
3877 (HDD_IPA_UC_NUM_WDI_PIPE ==
3878 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880 }
3881
Yun Park74127cf2016-09-18 11:22:41 -07003882 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3883 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07003884 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 hdd_ipa_uc_offload_enable_disable(adapter,
3886 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003887 qdf_mutex_acquire(&hdd_ipa->event_lock);
3888 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 }
3890
Yun Park8f289c82016-10-18 16:38:21 -07003891 hdd_ipa_cleanup_iface(adapter->ipa_context);
3892
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303893 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003894 break;
3895
3896 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003897 qdf_mutex_acquire(&hdd_ipa->event_lock);
3898
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303900 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003901 "%s: Evt: %d, SAP already disconnected",
3902 msg_ex->name, meta.msg_type);
Yun Park8f289c82016-10-18 16:38:21 -07003903 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 return -EINVAL;
3905 }
3906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 if ((!hdd_ipa->num_iface) &&
3908 (HDD_IPA_UC_NUM_WDI_PIPE ==
3909 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003910 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 /*
3912 * We disable WDI pipes directly here since
3913 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3914 * processed when unloading WLAN driver is in
3915 * progress
3916 */
3917 hdd_ipa_uc_disable_pipes(hdd_ipa);
3918 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303919 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 "NO INTF left but still pipe clean up");
3921 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3922 }
3923 }
3924
3925 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07003926 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927 hdd_ipa_uc_offload_enable_disable(adapter,
3928 SIR_AP_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003929 qdf_mutex_acquire(&hdd_ipa->event_lock);
3930 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 }
Yun Parka37592b2016-06-11 17:10:28 -07003932
Yun Park8f289c82016-10-18 16:38:21 -07003933 hdd_ipa_cleanup_iface(adapter->ipa_context);
3934
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303935 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 break;
3937
3938 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303940 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003941 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3942 adapter->dev->name, meta.msg_type);
3943 return 0;
3944 }
3945
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303946 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3948 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07003949 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303950 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003951 "%s: STA ID %d found, not valid",
3952 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 return 0;
3954 }
Yun Park312f71a2015-12-08 10:22:42 -08003955
3956 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07003957 if (0 == hdd_ipa->sap_num_connected_sta) {
3958 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07003959 hdd_ipa->sta_connected) {
3960 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003961 hdd_ipa_uc_offload_enable_disable(
3962 hdd_get_adapter(hdd_ipa->hdd_ctx,
3963 QDF_STA_MODE),
3964 SIR_STA_RX_DATA_OFFLOAD, 1);
Yun Park8f289c82016-10-18 16:38:21 -07003965 qdf_mutex_acquire(&hdd_ipa->event_lock);
3966 }
Yun Parka37592b2016-06-11 17:10:28 -07003967
Yun Park312f71a2015-12-08 10:22:42 -08003968 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3969 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303970 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003971 "%s: handle 1st con ret %d",
3972 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07003973
3974 if (hdd_ipa_uc_sta_is_enabled(
3975 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07003976 hdd_ipa->sta_connected) {
3977 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003978 hdd_ipa_uc_offload_enable_disable(
3979 hdd_get_adapter(
3980 hdd_ipa->hdd_ctx,
3981 QDF_STA_MODE),
3982 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003983 } else {
3984 qdf_mutex_release(&hdd_ipa->event_lock);
3985 }
Yun Parka37592b2016-06-11 17:10:28 -07003986
Yun Park312f71a2015-12-08 10:22:42 -08003987 return ret;
3988 }
3989 }
3990
3991 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003992
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303993 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994
3995 meta.msg_type = type;
3996 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3997 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303998 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999
4000 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304001 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004002 "msg_ex allocation failed");
4003 return -ENOMEM;
4004 }
4005 strlcpy(msg_ex->name, adapter->dev->name,
4006 IPA_RESOURCE_NAME_MAX);
4007 msg_ex->num_of_attribs = 1;
4008 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4009 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4010 msg_ex->attribs[0].offset =
4011 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4012 } else {
4013 msg_ex->attribs[0].offset =
4014 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4015 }
4016 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4017 IPA_MAC_ADDR_SIZE);
4018
4019 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4020
4021 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304022 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304024 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 return ret;
4026 }
4027 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 return ret;
4029
4030 case WLAN_CLIENT_DISCONNECT:
4031 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304032 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 "%s: IPA UC OFFLOAD NOT ENABLED",
4034 msg_ex->name);
4035 return 0;
4036 }
4037
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304038 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304040 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 "%s: STA ID %d NOT found, not valid",
4042 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304043 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 return 0;
4045 }
4046 hdd_ipa->sap_num_connected_sta--;
4047 /* Disable IPA UC TX PIPE when last STA disconnected */
4048 if (!hdd_ipa->sap_num_connected_sta
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 && (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);
Yun Parka37592b2016-06-11 17:10:28 -07004053
4054 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004055 hdd_ipa->sta_connected) {
4056 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004057 hdd_ipa_uc_offload_enable_disable(
4058 hdd_get_adapter(hdd_ipa->hdd_ctx,
4059 QDF_STA_MODE),
4060 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004061 } else {
4062 qdf_mutex_release(&hdd_ipa->event_lock);
4063 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 break;
4065
4066 default:
4067 return 0;
4068 }
4069
4070 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304071 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304073 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004074 return -ENOMEM;
4075 }
4076
4077 meta.msg_type = type;
4078 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4079 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4080
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304081 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 msg->name, meta.msg_type);
4083
4084 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4085
4086 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304087 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004088 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304089 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 return ret;
4091 }
4092
4093 hdd_ipa->stats.num_send_msg++;
4094
4095end:
4096 return ret;
4097}
4098
4099/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004100 * hdd_ipa_wlan_evt() - IPA event handler
4101 * @adapter: adapter upon which the event was received
4102 * @sta_id: station id for the event
4103 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4104 * @mac_address: MAC address associated with the event
4105 *
4106 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4107 *
4108 * Return: 0 on success, negative errno value on error
4109 */
4110int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4111 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4112{
4113 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4114
Leo Changa202b522016-10-14 16:13:50 -07004115 /* Data path offload only support for STA and SAP mode */
4116 if ((QDF_STA_MODE == adapter->device_mode) ||
4117 (QDF_SAP_MODE == adapter->device_mode))
4118 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4119
4120 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004121}
4122
4123/**
4124 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4125 * @hdd_ipa: Global HDD IPA context
4126 *
4127 * Return: None
4128 */
4129static void
4130hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4131{
4132 unsigned int pending_event_count;
4133 struct ipa_uc_pending_event *pending_event = NULL;
4134
4135 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4136 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4137 "%s, Pending Event Count %d", __func__, pending_event_count);
4138 if (!pending_event_count) {
4139 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4140 "%s, No Pending Event", __func__);
4141 return;
4142 }
4143
4144 qdf_list_remove_front(&hdd_ipa->pending_event,
4145 (qdf_list_node_t **)&pending_event);
4146 while (pending_event != NULL) {
4147 __hdd_ipa_wlan_evt(pending_event->adapter,
4148 pending_event->type,
4149 pending_event->sta_id,
4150 pending_event->mac_addr);
4151 qdf_mem_free(pending_event);
4152 pending_event = NULL;
4153 qdf_list_remove_front(&hdd_ipa->pending_event,
4154 (qdf_list_node_t **)&pending_event);
4155 }
4156}
4157
4158/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4160 * @state: IPA RM state value
4161 *
4162 * Return: ASCII string representing the IPA RM state
4163 */
4164static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4165{
4166 switch (state) {
4167 case HDD_IPA_RM_RELEASED:
4168 return "RELEASED";
4169 case HDD_IPA_RM_GRANT_PENDING:
4170 return "GRANT_PENDING";
4171 case HDD_IPA_RM_GRANTED:
4172 return "GRANTED";
4173 }
4174
4175 return "UNKNOWN";
4176}
4177
4178/**
4179 * hdd_ipa_init() - IPA initialization function
4180 * @hdd_ctx: HDD global context
4181 *
4182 * Allocate hdd_ipa resources, ipa pipe resource and register
4183 * wlan interface with IPA module.
4184 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304185 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304187QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188{
4189 struct hdd_ipa_priv *hdd_ipa = NULL;
4190 int ret, i;
4191 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004192 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193
4194 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304195 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196
Yun Park7f171ab2016-07-29 15:44:22 -07004197 if (!pdev) {
4198 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4199 goto fail_return;
4200 }
4201
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304202 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304204 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004205 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 }
4207
4208 hdd_ctx->hdd_ipa = hdd_ipa;
4209 ghdd_ipa = hdd_ipa;
4210 hdd_ipa->hdd_ctx = hdd_ctx;
4211 hdd_ipa->num_iface = 0;
Yun Park7f171ab2016-07-29 15:44:22 -07004212 ol_txrx_ipa_uc_get_resource(pdev, &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004213 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4214 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4215 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4216 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304217 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004218 "IPA UC resource alloc fail");
4219 goto fail_get_resource;
4220 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221
4222 /* Create the interface context */
4223 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4224 iface_context = &hdd_ipa->iface_context[i];
4225 iface_context->hdd_ipa = hdd_ipa;
4226 iface_context->cons_client =
4227 hdd_ipa_adapter_2_client[i].cons_client;
4228 iface_context->prod_client =
4229 hdd_ipa_adapter_2_client[i].prod_client;
4230 iface_context->iface_id = i;
4231 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004232 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304233 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park8f289c82016-10-18 16:38:21 -07004234 vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 }
4236
Leo Chang69c39692016-10-12 20:11:12 -07004237 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304238 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304239 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240
4241 ret = hdd_ipa_setup_rm(hdd_ipa);
4242 if (ret)
4243 goto fail_setup_rm;
4244
4245 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4246 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304247 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 hdd_ipa->sap_num_connected_sta = 0;
4249 hdd_ipa->ipa_tx_packets_diff = 0;
4250 hdd_ipa->ipa_rx_packets_diff = 0;
4251 hdd_ipa->ipa_p_tx_packets = 0;
4252 hdd_ipa->ipa_p_rx_packets = 0;
4253 hdd_ipa->resource_loading = false;
4254 hdd_ipa->resource_unloading = false;
4255 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004256 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 /* Setup IPA sys_pipe for MCC */
4258 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4259 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4260 if (ret)
4261 goto fail_create_sys_pipe;
4262 }
4263 hdd_ipa_uc_ol_init(hdd_ctx);
4264 } else {
4265 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4266 if (ret)
4267 goto fail_create_sys_pipe;
4268 }
4269
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304270 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271
4272fail_create_sys_pipe:
4273 hdd_ipa_destroy_rm_resource(hdd_ipa);
4274fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304275 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004276fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304277 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004278 hdd_ctx->hdd_ipa = NULL;
4279 ghdd_ipa = NULL;
4280fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304281 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282}
4283
4284/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004285 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4286 * @hdd_ipa: pointer to HDD IPA struct
4287 *
4288 * Return: none
4289 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004290static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004291{
4292 struct ipa_uc_pending_event *pending_event = NULL;
4293
Anurag Chouhanffb21542016-02-17 14:33:03 +05304294 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4295 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304296 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004297 }
4298
Anurag Chouhanffb21542016-02-17 14:33:03 +05304299 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004300}
4301
4302/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303 * hdd_ipa_cleanup - IPA cleanup function
4304 * @hdd_ctx: HDD global context
4305 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304306 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304308QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309{
4310 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4311 int i;
4312 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304313 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4315
4316 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304317 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318
4319 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4320 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4321 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4322 }
4323
4324 /* Teardown IPA sys_pipe for MCC */
4325 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4326 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4327
4328 hdd_ipa_destroy_rm_resource(hdd_ipa);
4329
4330#ifdef WLAN_OPEN_SOURCE
4331 cancel_work_sync(&hdd_ipa->pm_work);
4332#endif
4333
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304334 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335
Nirav Shahcbc6d722016-03-01 16:24:53 +05304336 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4337 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304338 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339
4340 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4341 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4342
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304343 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004344 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304345 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304347 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348
4349 /* destory the interface lock */
4350 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4351 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304352 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353 }
4354
4355 /* This should never hit but still make sure that there are no pending
4356 * descriptor in IPA hardware
4357 */
4358 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304359 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360 "IPA Pending write done: %d Waiting!",
4361 hdd_ipa->pending_hw_desc_cnt);
4362
4363 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4364 usleep_range(100, 100);
4365 }
4366
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304367 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368 "IPA Pending write done: desc: %d %s(%d)!",
4369 hdd_ipa->pending_hw_desc_cnt,
4370 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4371 : "leak", i);
4372 }
4373 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4374 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304375 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304376 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4377 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004378 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
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 RX PIPE rx_pipe_handle=0x%x",
4381 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304383 qdf_mutex_destroy(&hdd_ipa->event_lock);
4384 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004385 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386
4387#ifdef WLAN_OPEN_SOURCE
4388 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4389 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4390 hdd_ipa->uc_op_work[i].msg = NULL;
4391 }
4392#endif
4393 }
4394
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304395 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 hdd_ctx->hdd_ipa = NULL;
4397
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304398 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399}
4400#endif /* IPA_OFFLOAD */