blob: a9f4c06e29fcc463ce2ec765f7982adfcbdb5c86 [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 {
205 struct hdd_ipa_iface_context *iface_context;
206 struct ipa_rx_data *ipa_tx_desc;
207};
208
209struct hdd_ipa_uc_rx_hdr {
210 struct ethhdr eth;
211} __packed;
212
213struct hdd_ipa_sys_pipe {
214 uint32_t conn_hdl;
215 uint8_t conn_hdl_valid;
216 struct ipa_sys_connect_params ipa_sys_params;
217};
218
219struct hdd_ipa_iface_stats {
220 uint64_t num_tx;
221 uint64_t num_tx_drop;
222 uint64_t num_tx_err;
223 uint64_t num_tx_cac_drop;
224 uint64_t num_rx_prefilter;
225 uint64_t num_rx_ipa_excep;
226 uint64_t num_rx_recv;
227 uint64_t num_rx_recv_mul;
228 uint64_t num_rx_send_desc_err;
229 uint64_t max_rx_mul;
230};
231
232struct hdd_ipa_priv;
233
234struct hdd_ipa_iface_context {
235 struct hdd_ipa_priv *hdd_ipa;
236 hdd_adapter_t *adapter;
237 void *tl_context;
238
239 enum ipa_client_type cons_client;
240 enum ipa_client_type prod_client;
241
242 uint8_t iface_id; /* This iface ID */
243 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530244 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800245 uint32_t ifa_address;
246 struct hdd_ipa_iface_stats stats;
247};
248
249struct hdd_ipa_stats {
250 uint32_t event[IPA_WLAN_EVENT_MAX];
251 uint64_t num_send_msg;
252 uint64_t num_free_msg;
253
254 uint64_t num_rm_grant;
255 uint64_t num_rm_release;
256 uint64_t num_rm_grant_imm;
257 uint64_t num_cons_perf_req;
258 uint64_t num_prod_perf_req;
259
260 uint64_t num_rx_drop;
261 uint64_t num_rx_ipa_tx_dp;
262 uint64_t num_rx_ipa_splice;
263 uint64_t num_rx_ipa_loop;
264 uint64_t num_rx_ipa_tx_dp_err;
265 uint64_t num_rx_ipa_write_done;
266 uint64_t num_max_ipa_tx_mul;
267 uint64_t num_rx_ipa_hw_maxed_out;
268 uint64_t max_pend_q_cnt;
269
270 uint64_t num_tx_comp_cnt;
271 uint64_t num_tx_queued;
272 uint64_t num_tx_dequeued;
273 uint64_t num_max_pm_queue;
274
275 uint64_t num_freeq_empty;
276 uint64_t num_pri_freeq_empty;
277 uint64_t num_rx_excep;
278 uint64_t num_tx_bcmc;
279 uint64_t num_tx_bcmc_err;
280};
281
282struct ipa_uc_stas_map {
283 bool is_reserved;
284 uint8_t sta_id;
285};
286struct op_msg_type {
287 uint8_t msg_t;
288 uint8_t rsvd;
289 uint16_t op_code;
290 uint16_t len;
291 uint16_t rsvd_snd;
292};
293
294struct ipa_uc_fw_stats {
295 uint32_t tx_comp_ring_base;
296 uint32_t tx_comp_ring_size;
297 uint32_t tx_comp_ring_dbell_addr;
298 uint32_t tx_comp_ring_dbell_ind_val;
299 uint32_t tx_comp_ring_dbell_cached_val;
300 uint32_t tx_pkts_enqueued;
301 uint32_t tx_pkts_completed;
302 uint32_t tx_is_suspend;
303 uint32_t tx_reserved;
304 uint32_t rx_ind_ring_base;
305 uint32_t rx_ind_ring_size;
306 uint32_t rx_ind_ring_dbell_addr;
307 uint32_t rx_ind_ring_dbell_ind_val;
308 uint32_t rx_ind_ring_dbell_ind_cached_val;
309 uint32_t rx_ind_ring_rdidx_addr;
310 uint32_t rx_ind_ring_rd_idx_cached_val;
311 uint32_t rx_refill_idx;
312 uint32_t rx_num_pkts_indicated;
313 uint32_t rx_buf_refilled;
314 uint32_t rx_num_ind_drop_no_space;
315 uint32_t rx_num_ind_drop_no_buf;
316 uint32_t rx_is_suspend;
317 uint32_t rx_reserved;
318};
319
320struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530321 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322 hdd_adapter_t *adapter;
323 enum ipa_wlan_event type;
324 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530325 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326};
327
328/**
329 * struct uc_rm_work_struct
330 * @work: uC RM work
331 * @event: IPA RM event
332 */
333struct uc_rm_work_struct {
334 struct work_struct work;
335 enum ipa_rm_event event;
336};
337
338/**
339 * struct uc_op_work_struct
340 * @work: uC OP work
341 * @msg: OP message
342 */
343struct uc_op_work_struct {
344 struct work_struct work;
345 struct op_msg_type *msg;
346};
347static uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
348
349/**
350 * struct uc_rt_debug_info
351 * @time: system time
352 * @ipa_excep_count: IPA exception packet count
353 * @rx_drop_count: IPA Rx drop packet count
354 * @net_sent_count: IPA Rx packet sent to network stack count
355 * @rx_discard_count: IPA Rx discard packet count
356 * @rx_mcbc_count: IPA Rx BCMC packet count
357 * @tx_mcbc_count: IPA Tx BCMC packet countt
358 * @tx_fwd_count: IPA Tx forward packet count
359 * @rx_destructor_call: IPA Rx packet destructor count
360 */
361struct uc_rt_debug_info {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530362 unsigned long time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 uint64_t ipa_excep_count;
364 uint64_t rx_drop_count;
365 uint64_t net_sent_count;
366 uint64_t rx_discard_count;
367 uint64_t rx_mcbc_count;
368 uint64_t tx_mcbc_count;
369 uint64_t tx_fwd_count;
370 uint64_t rx_destructor_call;
371};
372
373struct hdd_ipa_priv {
374 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
375 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
376 uint8_t num_iface;
377 enum hdd_ipa_rm_state rm_state;
378 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530379 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 * APIs as it is taken care gracefully. Without this, kernel would throw
381 * an warning if spin_lock_bh is used while IRQ is disabled
382 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530383 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800384 struct uc_rm_work_struct uc_rm_work;
385 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530386 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 struct delayed_work wake_lock_work;
388 bool wake_lock_released;
389
390 enum ipa_client_type prod_client;
391
392 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530393 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800394 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530395 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396 bool suspended;
397
398 uint32_t pending_hw_desc_cnt;
399 uint32_t hw_desc_cnt;
400 spinlock_t q_lock;
401 uint32_t freeq_cnt;
402 struct list_head free_desc_head;
403
404 uint32_t pend_q_cnt;
405 struct list_head pend_desc_head;
406
407 hdd_context_t *hdd_ctx;
408
409 struct dentry *debugfs_dir;
410 struct hdd_ipa_stats stats;
411
412 struct notifier_block ipv4_notifier;
413 uint32_t curr_prod_bw;
414 uint32_t curr_cons_bw;
415
416 uint8_t activated_fw_pipe;
417 uint8_t sap_num_connected_sta;
418 uint8_t sta_connected;
419 uint32_t tx_pipe_handle;
420 uint32_t rx_pipe_handle;
421 bool resource_loading;
422 bool resource_unloading;
423 bool pending_cons_req;
424 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530425 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530426 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700427 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800428 uint32_t ipa_tx_packets_diff;
429 uint32_t ipa_rx_packets_diff;
430 uint32_t ipa_p_tx_packets;
431 uint32_t ipa_p_rx_packets;
432 uint32_t stat_req_reason;
433 uint64_t ipa_tx_forward;
434 uint64_t ipa_rx_discard;
435 uint64_t ipa_rx_net_send_count;
436 uint64_t ipa_rx_internel_drop_count;
437 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530438 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800439 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
440 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530441 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530442 qdf_mutex_t rt_debug_lock;
443 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800444 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800445 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530446 qdf_dma_addr_t tx_comp_doorbell_paddr;
447 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448};
449
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800450/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800451 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800452 * They will be implemented fully by another update.
453 * The stubs will let the compile go ahead, and functionality
454 * is broken.
455 * This should be OK and IPA is not enabled yet
456 */
457void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
458{
459 void *vaddr;
460 uint32_t ipa_priv = priv;
461
462 vaddr = &ipa_priv; /* just to use the var */
463 vaddr = NULL;
464 return vaddr;
465}
466
467uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
468{
469 uint32_t ipa_priv = 0;
470
471 BUG_ON(ptr == NULL);
472 return ipa_priv;
473}
Leo Changcc923e22016-06-16 15:29:03 -0700474
475#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
476#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
478#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
479#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
480#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
481#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
482#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700483#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
484 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800485
Leo Chang3bc8fed2015-11-13 10:59:47 -0800486#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
487#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489#define HDD_IPA_GET_IFACE_ID(_data) \
490 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
491
492#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530493 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800494 "%s:%d: "fmt, __func__, __LINE__, ## args)
495
Govind Singhb6a89772016-08-12 11:23:35 +0530496#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
497 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
498 "%s:%d: "fmt, __func__, __LINE__, ## args)
499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
501 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530502 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
503 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800504 } while (0)
505
506#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
507 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
508
509#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
510 do { \
511 hdd_ipa->ipa_rx_internel_drop_count++; \
512 } while (0)
513#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
514 do { \
515 hdd_ipa->ipa_rx_net_send_count++; \
516 } while (0)
517#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
518
Leo Chang07b28f62016-05-11 12:29:22 -0700519#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800520#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
521do { \
522 pipe_in.u.ul.rdy_ring_rp_va = \
523 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
524 pipe_in.u.ul.rdy_comp_ring_base_pa = \
525 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
526 pipe_in.u.ul.rdy_comp_ring_size = \
527 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
528 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
529 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
530 pipe_in.u.ul.rdy_comp_ring_wp_va = \
531 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800532} while (0)
533#else
534/* Do nothing */
535#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang07b28f62016-05-11 12:29:22 -0700536#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800538static struct hdd_ipa_adapter_2_client {
539 enum ipa_client_type cons_client;
540 enum ipa_client_type prod_client;
541} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
542 {
543 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
544 }, {
545 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
546 }, {
547 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
548 },
549};
550
551/* For Tx pipes, use Ethernet-II Header format */
552struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
553 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800554 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555 0x00000000,
556 0x00000000
557 },
558 {
559 0x00000000
560 },
561 {
562 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
563 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
564 0x0008
565 }
566};
567
568/* For Tx pipes, use 802.3 Header format */
569static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
570 {
571 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
572 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
573 0x00 /* length can be zero */
574 },
575 {
576 /* LLC SNAP header 8 bytes */
577 0xaa, 0xaa,
578 {0x03, 0x00, 0x00, 0x00},
579 0x0008 /* type value(2 bytes) ,filled by wlan */
580 /* 0x0800 - IPV4, 0x86dd - IPV6 */
581 }
582};
583
584static const char *op_string[] = {
585 "TX_SUSPEND",
586 "TX_RESUME",
587 "RX_SUSPEND",
588 "RX_RESUME",
589 "STATS",
590};
591
592static struct hdd_ipa_priv *ghdd_ipa;
593
594/* Local Function Prototypes */
595static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
596 unsigned long data);
597static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
598 unsigned long data);
599
600static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700601static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800602
603/**
604 * hdd_ipa_is_enabled() - Is IPA enabled?
605 * @hdd_ctx: Global HDD context
606 *
607 * Return: true if IPA is enabled, false otherwise
608 */
609bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
610{
611 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
612}
613
614/**
615 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
616 * @hdd_ctx: Global HDD context
617 *
618 * Return: true if IPA uC offload is enabled, false otherwise
619 */
620bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
621{
622 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
623}
624
625/**
626 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
627 * @hdd_ctx: Global HDD context
628 *
629 * Return: true if STA mode IPA uC offload is enabled, false otherwise
630 */
631static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
632{
633 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
634}
635
636/**
637 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
638 * @hdd_ipa: Global HDD IPA context
639 *
640 * Return: true if pre-filter is enabled, otherwise false
641 */
642static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
643{
644 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
645 HDD_IPA_PRE_FILTER_ENABLE_MASK);
646}
647
648/**
649 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
650 * @hdd_ipa: Global HDD IPA context
651 *
652 * Return: true if IPv6 is enabled, otherwise false
653 */
654static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
655{
656 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
657}
658
659/**
660 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
661 * @hdd_ipa: Global HDD IPA context
662 *
663 * Return: true if resource manager is enabled, otherwise false
664 */
665static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
666{
667 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
668}
669
670/**
671 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
672 * @hdd_ipa: Global HDD IPA context
673 *
674 * Return: true if resource manager is enabled, otherwise false
675 */
676static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
677{
678 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
679}
680
681/**
682 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
683 * @hdd_ipa: Global HDD IPA context
684 *
685 * Return: true if clock scaling is enabled, otherwise false
686 */
687static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
688{
689 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
690 HDD_IPA_CLK_SCALING_ENABLE_MASK |
691 HDD_IPA_RM_ENABLE_MASK);
692}
693
694/**
695 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
696 * @ctext: pointer to hdd context.
697 *
698 * If rt debug enabled, periodically called, and fill debug buffer
699 *
700 * Return: none
701 */
702static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
703{
704 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
705 struct hdd_ipa_priv *hdd_ipa;
706 struct uc_rt_debug_info *dump_info = NULL;
707
708 if (wlan_hdd_validate_context(hdd_ctx))
709 return;
710
711 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530712 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713 "%s: IPA UC is not enabled", __func__);
714 return;
715 }
716
717 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
718
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530719 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800720 dump_info = &hdd_ipa->rt_bug_buffer[
721 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
722
Anurag Chouhan210db072016-02-22 18:42:15 +0530723 dump_info->time = qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
725 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
726 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
727 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
728 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
729 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
730 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
731 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530732 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733
Anurag Chouhan210db072016-02-22 18:42:15 +0530734 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
736}
737
738/**
739 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
740 * @hdd_ctx: pointer to hdd context.
741 *
742 * If rt debug enabled, dump debug buffer contents based on requirement
743 *
744 * Return: none
745 */
746void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
747{
748 struct hdd_ipa_priv *hdd_ipa;
749 unsigned int dump_count;
750 unsigned int dump_index;
751 struct uc_rt_debug_info *dump_info = NULL;
752
753 if (wlan_hdd_validate_context(hdd_ctx))
754 return;
755
756 hdd_ipa = hdd_ctx->hdd_ipa;
757 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530758 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 "%s: IPA UC is not enabled", __func__);
760 return;
761 }
762
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530763 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530765 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800766 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
767
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530768 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 for (dump_count = 0;
770 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
771 dump_count++) {
772 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
773 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
774 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530775 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800776 "%12lu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
777 dump_info->time, dump_info->ipa_excep_count,
778 dump_info->rx_drop_count, dump_info->net_sent_count,
779 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
780 dump_info->rx_destructor_call,
781 dump_info->rx_discard_count);
782 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530783 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530784 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
786}
787
788/**
789 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
790 * @ctext: pointer to hdd context.
791 *
792 * periodically called by timer expire
793 * will try to alloc dummy memory and detect out of memory condition
794 * if out of memory detected, dump wlan-ipa stats
795 *
796 * Return: none
797 */
798static void hdd_ipa_uc_rt_debug_handler(void *ctext)
799{
800 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
801 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
802 void *dummy_ptr = NULL;
803
804 if (wlan_hdd_validate_context(hdd_ctx))
805 return;
806
807 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530808 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809 "%s: IPA RT debug is not enabled", __func__);
810 return;
811 }
812
813 /* Allocate dummy buffer periodically and free immediately. this will
814 * proactively detect OOM and if allocation fails dump ipa stats
815 */
816 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
817 GFP_KERNEL | GFP_ATOMIC);
818 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530819 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 "%s: Dummy alloc fail", __func__);
821 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
822 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800823 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 } else {
825 kfree(dummy_ptr);
826 }
827
Anurag Chouhan210db072016-02-22 18:42:15 +0530828 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 HDD_IPA_UC_RT_DEBUG_PERIOD);
830}
831
832/**
833 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
834 * @skb: packet pinter
835 *
836 * when free data packet, will be invoked by wlan client and will increase
837 * free counter
838 *
839 * Return: none
840 */
841void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
842{
843 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530844 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 "%s: invalid hdd context", __func__);
846 return;
847 }
848
849 ghdd_ipa->ipa_rx_destructor_count++;
850}
851
852/**
853 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
854 * @hdd_ctx: hdd main context
855 *
856 * free all rt debugging resources
857 *
858 * Return: none
859 */
860static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
861{
862 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
863
Anurag Chouhan210db072016-02-22 18:42:15 +0530864 if (QDF_TIMER_STATE_STOPPED !=
865 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
866 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530868 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530869 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870
871 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530872 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 "%s: IPA RT debug is not enabled", __func__);
874 return;
875 }
876
Anurag Chouhan210db072016-02-22 18:42:15 +0530877 if (QDF_TIMER_STATE_STOPPED !=
878 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
879 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530881 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800882}
883
884/**
885 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
886 * @hdd_ctx: hdd main context
887 *
888 * alloc and initialize all rt debugging resources
889 *
890 * Return: none
891 */
892static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
893{
894 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
895
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530896 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530897 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
899 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530900 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 sizeof(struct uc_rt_debug_info) *
902 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
903 hdd_ipa->ipa_tx_forward = 0;
904 hdd_ipa->ipa_rx_discard = 0;
905 hdd_ipa->ipa_rx_net_send_count = 0;
906 hdd_ipa->ipa_rx_internel_drop_count = 0;
907 hdd_ipa->ipa_rx_destructor_count = 0;
908
Anurag Chouhan210db072016-02-22 18:42:15 +0530909 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800910 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
911
912 /* Reatime debug enable on feature enable */
913 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530914 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 "%s: IPA RT debug is not enabled", __func__);
916 return;
917 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530918 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530920 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 HDD_IPA_UC_RT_DEBUG_PERIOD);
922
923}
924
925/**
926 * hdd_ipa_uc_stat_query() - Query the IPA stats
927 * @hdd_ctx: Global HDD context
928 * @ipa_tx_diff: tx packet count diff from previous
929 * tx packet count
930 * @ipa_rx_diff: rx packet count diff from previous
931 * rx packet count
932 *
933 * Return: true if IPA is enabled, false otherwise
934 */
935void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
936 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
937{
938 struct hdd_ipa_priv *hdd_ipa;
939
940 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
941 *ipa_tx_diff = 0;
942 *ipa_rx_diff = 0;
943
944 if (!hdd_ipa_is_enabled(pHddCtx) ||
945 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
946 return;
947 }
948
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530949 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
951 (false == hdd_ipa->resource_loading)) {
952 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
953 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
954 HDD_IPA_LOG(LOG1, "STAT Query TX DIFF %d, RX DIFF %d",
955 *ipa_tx_diff, *ipa_rx_diff);
956 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530957 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 return;
959}
960
961/**
962 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
963 * @adapter: network adapter
964 * @reason: STAT REQ Reason
965 *
966 * Return: None
967 */
968void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
969{
970 hdd_context_t *pHddCtx;
971 struct hdd_ipa_priv *hdd_ipa;
972
973 if (!adapter) {
974 return;
975 }
976
977 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
978 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
979 if (!hdd_ipa_is_enabled(pHddCtx) ||
980 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
981 return;
982 }
983
984 HDD_IPA_LOG(LOG1, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530985 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
987 (false == hdd_ipa->resource_loading)) {
988 hdd_ipa->stat_req_reason = reason;
989 wma_cli_set_command(
990 (int)adapter->sessionId,
991 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
992 0, VDEV_CMD);
993 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530994 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995}
996
997/**
998 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
999 * @hdd_ipa: Global HDD IPA context
1000 * @sta_add: Should station be added
1001 * @sta_id: ID of the station being queried
1002 *
1003 * Return: true if the station was found
1004 */
1005static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1006 bool sta_add, uint8_t sta_id)
1007{
1008 bool sta_found = false;
1009 uint8_t idx;
1010 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1011 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1012 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1013 sta_found = true;
1014 break;
1015 }
1016 }
1017 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301018 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 "%s: STA ID %d already exist, cannot add",
1020 __func__, sta_id);
1021 return sta_found;
1022 }
1023 if (sta_add) {
1024 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1025 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1026 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1027 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1028 return sta_found;
1029 }
1030 }
1031 }
1032 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301033 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 "%s: STA ID %d does not exist, cannot delete",
1035 __func__, sta_id);
1036 return sta_found;
1037 }
1038 if (!sta_add) {
1039 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1040 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1041 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1042 hdd_ipa->assoc_stas_map[idx].is_reserved =
1043 false;
1044 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1045 return sta_found;
1046 }
1047 }
1048 }
1049 return sta_found;
1050}
1051
1052/**
1053 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1054 * @hdd_ipa: Global HDD IPA context
1055 *
1056 * Return: 0 on success, negative errno if error
1057 */
1058static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1059{
1060 int result;
1061 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1062
1063 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301064 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001065 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1066 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1068 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301069 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 "%s: Enable TX PIPE fail, code %d",
1071 __func__, result);
1072 return result;
1073 }
1074 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1075 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301076 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077 "%s: Resume TX PIPE fail, code %d",
1078 __func__, result);
1079 return result;
1080 }
1081 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1082
1083 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301084 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001085 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1086 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001087 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1088 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301089 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090 "%s: Enable RX PIPE fail, code %d",
1091 __func__, result);
1092 return result;
1093 }
1094 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1095 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301096 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 "%s: Resume RX PIPE fail, code %d",
1098 __func__, result);
1099 return result;
1100 }
1101 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001102 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 return 0;
1104}
1105
1106/**
1107 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1108 * @hdd_ipa: Global HDD IPA context
1109 *
1110 * Return: 0 on success, negative errno if error
1111 */
1112static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1113{
1114 int result;
1115
Leo Change3e49442015-10-26 20:07:13 -07001116 hdd_ipa->ipa_pipes_down = true;
1117
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301118 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001119 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1120 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301121 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 "%s: Suspend RX PIPE fail, code %d",
1123 __func__, result);
1124 return result;
1125 }
1126 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1127 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301128 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 "%s: Disable RX PIPE fail, code %d",
1130 __func__, result);
1131 return result;
1132 }
1133
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301134 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1136 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301137 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 "%s: Suspend TX PIPE fail, code %d",
1139 __func__, result);
1140 return result;
1141 }
1142 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1143 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301144 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145 "%s: Disable TX PIPE fail, code %d",
1146 __func__, result);
1147 return result;
1148 }
1149
1150 return 0;
1151}
1152
1153/**
1154 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1155 * @hdd_ipa: Global HDD IPA context
1156 *
1157 * Return: 0 on success, negative errno if error
1158 */
1159static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1160{
1161 hdd_ipa->activated_fw_pipe = 0;
1162 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001163
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001164 /* If RM feature enabled
1165 * Request PROD Resource first
1166 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001167 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1168 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1169 /* RM PROD request sync return
1170 * enable pipe immediately
1171 */
1172 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301173 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001174 "%s: IPA WDI Pipe activation failed",
1175 __func__);
1176 hdd_ipa->resource_loading = false;
1177 return -EBUSY;
1178 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179 }
1180 } else {
1181 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001182 * Just enabled all the PIPEs
1183 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001184 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301185 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001186 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 __func__);
1188 hdd_ipa->resource_loading = false;
1189 return -EBUSY;
1190 }
1191 hdd_ipa->resource_loading = false;
1192 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001193
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301194 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001195 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001196 return 0;
1197}
1198
1199/**
1200 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1201 * @hdd_ipa: Global HDD IPA context
1202 *
1203 * Return: None
1204 */
1205static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1206{
1207 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1208
1209 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301210 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001211 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301212 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1214}
1215
1216/**
1217 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1218 * @context: User context registered with TL (the IPA Global context is
1219 * registered
1220 * @rxpkt: Packet containing the notification
1221 * @staid: ID of the station associated with the packet
1222 *
1223 * Return: None
1224 */
1225static void
1226hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1227{
1228 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301229 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230
1231 /*
1232 * When SSR is going on or driver is unloading, just return.
1233 */
1234 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301235 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237
1238 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1239 return;
1240
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301241 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 __func__, event);
1243
1244 switch (event) {
1245 case IPA_RM_RESOURCE_GRANTED:
1246 /* Differed RM Granted */
1247 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301248 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001249 if ((false == hdd_ipa->resource_unloading) &&
1250 (!hdd_ipa->activated_fw_pipe)) {
1251 hdd_ipa_uc_enable_pipes(hdd_ipa);
1252 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301253 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 break;
1255
1256 case IPA_RM_RESOURCE_RELEASED:
1257 /* Differed RM Released */
1258 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259 break;
1260
1261 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301262 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001263 "%s, invalid event code %d", __func__, event);
1264 break;
1265 }
1266}
1267
1268/**
1269 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1270 * @hdd_ipa: Global HDD IPA context
1271 * @event: IPA resource manager event to be deferred
1272 *
1273 * This function is called when a resource manager event is received
1274 * from firmware in interrupt context. This function will defer the
1275 * handling to the OL RX thread
1276 *
1277 * Return: None
1278 */
1279static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1280{
1281 enum ipa_rm_event event;
1282 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1283 struct uc_rm_work_struct, work);
1284 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1285 struct hdd_ipa_priv, uc_rm_work);
1286
1287 cds_ssr_protect(__func__);
1288 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301289 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001290 "%s, posted event %d", __func__, event);
1291
1292 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1293 cds_ssr_unprotect(__func__);
1294
1295 return;
1296}
1297
1298/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001299 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1300 * @op_msg: operation message received from firmware
1301 * @usr_ctxt: user context registered with TL (we register the HDD Global
1302 * context)
1303 *
1304 * Return: None
1305 */
1306static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1307{
1308 struct op_msg_type *msg = op_msg;
1309 struct ipa_uc_fw_stats *uc_fw_stat;
1310 struct IpaHwStatsWDIInfoData_t ipa_stat;
1311 struct hdd_ipa_priv *hdd_ipa;
1312 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301313 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314
1315 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301316 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001317 return;
1318 }
1319
1320 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301321 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1323 return;
1324 }
1325
1326 hdd_ctx = (hdd_context_t *) usr_ctxt;
1327
1328 /*
1329 * When SSR is going on or driver is unloading, just return.
1330 */
1331 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301332 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301333 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001334 return;
1335 }
1336
1337 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1338
Govind Singhb6a89772016-08-12 11:23:35 +05301339 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1341
1342 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1343 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301344 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345 hdd_ipa->activated_fw_pipe++;
1346 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1347 hdd_ipa->resource_loading = false;
1348 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001349 if (hdd_ipa->pending_cons_req)
1350 ipa_rm_notify_completion(
1351 IPA_RM_RESOURCE_GRANTED,
1352 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001353 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301355 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001356 }
1357
1358 if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
1359 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301360 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 hdd_ipa->activated_fw_pipe--;
1362 if (!hdd_ipa->activated_fw_pipe) {
1363 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001364 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1365 ipa_rm_release_resource(
1366 IPA_RM_RESOURCE_WLAN_PROD);
1367 /* Sync return success from IPA
1368 * Enable/resume all the PIPEs */
1369 hdd_ipa->resource_unloading = false;
1370 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1371 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301373 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374 }
1375
1376 if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1377 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001378 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301380 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001382 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 "CE RING SIZE: %d\n"
1384 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001385 (unsigned long long)res->ce_sr_base_paddr,
1386 res->ce_sr_ring_size,
1387 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301388 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001389 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001390 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 "COMP RING SIZE: %d\n"
1392 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001393 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001394 (unsigned long long)res->tx_comp_ring_base_paddr,
1395 res->tx_comp_ring_size,
1396 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001397 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301398 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001400 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001402 "IND RING DBELL : 0x%llx\n"
1403 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 "NUM EXCP PKT : %llu\n"
1405 "NUM TX BCMC : %llu\n"
1406 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001407 (unsigned long long)res->rx_rdy_ring_base_paddr,
1408 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001409 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001410 (unsigned long long)hdd_ipa->ipa_resource.
1411 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001412 hdd_ipa->stats.num_rx_excep,
1413 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001414 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301415 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001416 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1417 "SAP NUM STAs: %d\n"
1418 "STA CONNECTED: %d\n"
1419 "TX PIPE HDL: %d\n"
1420 "RX PIPE HDL : %d\n"
1421 "RSC LOADING : %d\n"
1422 "RSC UNLOADING : %d\n"
1423 "PNDNG CNS RQT : %d",
1424 hdd_ipa->sap_num_connected_sta,
1425 hdd_ipa->sta_connected,
1426 hdd_ipa->tx_pipe_handle,
1427 hdd_ipa->rx_pipe_handle,
1428 (unsigned int)hdd_ipa->resource_loading,
1429 (unsigned int)hdd_ipa->resource_unloading,
1430 (unsigned int)hdd_ipa->pending_cons_req);
1431
1432 /* STATs from FW */
1433 uc_fw_stat = (struct ipa_uc_fw_stats *)
1434 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301435 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 "==== IPA_UC WLAN_FW TX ====\n"
1437 "COMP RING BASE: 0x%x\n"
1438 "COMP RING SIZE: %d\n"
1439 "COMP RING DBELL : 0x%x\n"
1440 "COMP RING DBELL IND VAL : %d\n"
1441 "COMP RING DBELL CACHED VAL : %d\n"
1442 "COMP RING DBELL CACHED VAL : %d\n"
1443 "PKTS ENQ : %d\n"
1444 "PKTS COMP : %d\n"
1445 "IS SUSPEND : %d\n"
1446 "RSVD : 0x%x",
1447 uc_fw_stat->tx_comp_ring_base,
1448 uc_fw_stat->tx_comp_ring_size,
1449 uc_fw_stat->tx_comp_ring_dbell_addr,
1450 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1451 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1452 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1453 uc_fw_stat->tx_pkts_enqueued,
1454 uc_fw_stat->tx_pkts_completed,
1455 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301456 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 "==== IPA_UC WLAN_FW RX ====\n"
1458 "IND RING BASE: 0x%x\n"
1459 "IND RING SIZE: %d\n"
1460 "IND RING DBELL : 0x%x\n"
1461 "IND RING DBELL IND VAL : %d\n"
1462 "IND RING DBELL CACHED VAL : %d\n"
1463 "RDY IND ADDR : 0x%x\n"
1464 "RDY IND CACHE VAL : %d\n"
1465 "RFIL IND : %d\n"
1466 "NUM PKT INDICAT : %d\n"
1467 "BUF REFIL : %d\n"
1468 "NUM DROP NO SPC : %d\n"
1469 "NUM DROP NO BUF : %d\n"
1470 "IS SUSPND : %d\n"
1471 "RSVD : 0x%x\n",
1472 uc_fw_stat->rx_ind_ring_base,
1473 uc_fw_stat->rx_ind_ring_size,
1474 uc_fw_stat->rx_ind_ring_dbell_addr,
1475 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1476 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1477 uc_fw_stat->rx_ind_ring_rdidx_addr,
1478 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1479 uc_fw_stat->rx_refill_idx,
1480 uc_fw_stat->rx_num_pkts_indicated,
1481 uc_fw_stat->rx_buf_refilled,
1482 uc_fw_stat->rx_num_ind_drop_no_space,
1483 uc_fw_stat->rx_num_ind_drop_no_buf,
1484 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1485 /* STATs from IPA */
1486 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301487 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 "==== IPA_UC IPA TX ====\n"
1489 "NUM PROCD : %d\n"
1490 "CE DBELL : 0x%x\n"
1491 "NUM DBELL FIRED : %d\n"
1492 "COMP RNG FULL : %d\n"
1493 "COMP RNG EMPT : %d\n"
1494 "COMP RNG USE HGH : %d\n"
1495 "COMP RNG USE LOW : %d\n"
1496 "BAM FIFO FULL : %d\n"
1497 "BAM FIFO EMPT : %d\n"
1498 "BAM FIFO USE HGH : %d\n"
1499 "BAM FIFO USE LOW : %d\n"
1500 "NUM DBELL : %d\n"
1501 "NUM UNEXP DBELL : %d\n"
1502 "NUM BAM INT HDL : 0x%x\n"
1503 "NUM BAM INT NON-RUN : 0x%x\n"
1504 "NUM QMB INT HDL : 0x%x",
1505 ipa_stat.tx_ch_stats.num_pkts_processed,
1506 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1507 ipa_stat.tx_ch_stats.num_db_fired,
1508 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1509 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1510 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1511 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1512 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1513 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1514 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1515 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1516 ipa_stat.tx_ch_stats.num_db,
1517 ipa_stat.tx_ch_stats.num_unexpected_db,
1518 ipa_stat.tx_ch_stats.num_bam_int_handled,
1519 ipa_stat.tx_ch_stats.
1520 num_bam_int_in_non_runnning_state,
1521 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1522
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301523 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524 "==== IPA_UC IPA RX ====\n"
1525 "MAX OST PKT : %d\n"
1526 "NUM PKT PRCSD : %d\n"
1527 "RNG RP : 0x%x\n"
1528 "COMP RNG FULL : %d\n"
1529 "COMP RNG EMPT : %d\n"
1530 "COMP RNG USE HGH : %d\n"
1531 "COMP RNG USE LOW : %d\n"
1532 "BAM FIFO FULL : %d\n"
1533 "BAM FIFO EMPT : %d\n"
1534 "BAM FIFO USE HGH : %d\n"
1535 "BAM FIFO USE LOW : %d\n"
1536 "NUM DB : %d\n"
1537 "NUM UNEXP DB : %d\n"
1538 "NUM BAM INT HNDL : 0x%x\n",
1539 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1540 ipa_stat.rx_ch_stats.num_pkts_processed,
1541 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1542 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1543 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1544 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1545 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1546 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1547 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1548 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1549 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1550 ipa_stat.rx_ch_stats.num_db,
1551 ipa_stat.rx_ch_stats.num_unexpected_db,
1552 ipa_stat.rx_ch_stats.num_bam_int_handled);
1553 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1554 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1555 /* STATs from FW */
1556 uc_fw_stat = (struct ipa_uc_fw_stats *)
1557 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301558 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001559 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1560 uc_fw_stat->tx_pkts_completed,
1561 hdd_ipa->ipa_p_tx_packets);
1562 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1563 (uc_fw_stat->rx_num_ind_drop_no_space +
1564 uc_fw_stat->rx_num_ind_drop_no_buf +
1565 uc_fw_stat->rx_num_pkts_indicated),
1566 hdd_ipa->ipa_p_rx_packets);
1567
1568 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1569 hdd_ipa->ipa_p_rx_packets =
1570 (uc_fw_stat->rx_num_ind_drop_no_space +
1571 uc_fw_stat->rx_num_ind_drop_no_buf +
1572 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301573 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574 } else {
1575 HDD_IPA_LOG(LOGE, "INVALID REASON %d",
1576 hdd_ipa->stat_req_reason);
1577 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301578 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579}
1580
1581
1582/**
1583 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1584 * @adapter: device adapter instance
1585 * @offload_type: MCC or SCC
1586 * @enable: TX offload enable or disable
1587 *
1588 * Return: none
1589 */
1590static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1591 uint32_t offload_type, uint32_t enable)
1592{
1593 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
1594
Yun Parka37592b2016-06-11 17:10:28 -07001595 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 return;
1597
1598 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1599 * channel change indication. Since these indications are sent by lower
1600 * layer as SAP updates and IPA doesn't have to do anything for these
1601 * updates so ignoring!
Yun Parka37592b2016-06-11 17:10:28 -07001602 */
1603 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 return;
1605
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301606 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 sizeof(ipa_offload_enable_disable));
1608 ipa_offload_enable_disable.offload_type = offload_type;
1609 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1610 ipa_offload_enable_disable.enable = enable;
1611
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301612 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613 "%s: offload_type=%d, vdev_id=%d, enable=%d", __func__,
1614 ipa_offload_enable_disable.offload_type,
1615 ipa_offload_enable_disable.vdev_id,
1616 ipa_offload_enable_disable.enable);
1617
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301618 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1620 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301621 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 "%s: Failure to enable IPA offload \
1623 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1624 ipa_offload_enable_disable.offload_type,
1625 ipa_offload_enable_disable.vdev_id,
1626 ipa_offload_enable_disable.enable);
1627 }
1628}
1629
1630/**
1631 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1632 * @work: uC OP work
1633 *
1634 * Return: None
1635 */
1636static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1637{
1638 struct op_msg_type *msg;
1639 struct uc_op_work_struct *uc_op_work = container_of(work,
1640 struct uc_op_work_struct, work);
1641 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1642
1643 cds_ssr_protect(__func__);
1644
1645 msg = uc_op_work->msg;
1646 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301647 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648 "%s, posted msg %d", __func__, msg->op_code);
1649
1650 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1651
1652 cds_ssr_unprotect(__func__);
1653
1654 return;
1655}
1656
1657/**
1658 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1659 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1660 * @op_msg: operation message received from firmware
1661 * @hdd_ctx: Global HDD context
1662 *
1663 * Return: None
1664 */
1665static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1666{
1667 struct hdd_ipa_priv *hdd_ipa;
1668 struct op_msg_type *msg;
1669 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301670 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671
1672 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301673 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001675
1676 msg = (struct op_msg_type *)op_msg;
1677 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1678
1679 if (unlikely(!hdd_ipa))
1680 goto end;
1681
1682 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301683 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 __func__, msg->op_code);
1685 goto end;
1686 }
1687
1688 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1689 if (uc_op_work->msg)
1690 /* When the same uC OPCODE is already pended, just return */
1691 goto end;
1692
1693 uc_op_work->msg = msg;
1694 schedule_work(&uc_op_work->work);
1695 return;
1696
1697end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301698 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001699}
1700
1701/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001702 * hdd_ipa_init_uc_op_work - init ipa uc op work
1703 * @work: struct work_struct
1704 * @work_handler: work_handler
1705 *
1706 * Return: none
1707 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001708static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1709 work_func_t work_handler)
1710{
1711 INIT_WORK(work, work_handler);
1712}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001713
1714
1715/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1717 * @hdd_ctx: Global HDD context
1718 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301719 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001720 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301721static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722{
1723 struct ipa_wdi_in_params pipe_in;
1724 struct ipa_wdi_out_params pipe_out;
1725 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1726 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1727 uint8_t i;
1728
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301729 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1730 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731
Anurag Chouhanffb21542016-02-17 14:33:03 +05301732 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301733 qdf_mutex_create(&ipa_ctxt->event_lock);
1734 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001735
1736 /* TX PIPE */
1737 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1738 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1739 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1740 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1741 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1742 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1743 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1744 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1745 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1746 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1747 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1748 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1749 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301750 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001751 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1752 pipe_in.sys.keep_ipa_awake = true;
1753 }
1754
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001755 pipe_in.u.dl.comp_ring_base_pa =
1756 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001757 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001758 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1759 sizeof(qdf_dma_addr_t);
1760 pipe_in.u.dl.ce_ring_base_pa =
1761 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1762 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1763 pipe_in.u.dl.ce_ring_size =
1764 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1765 pipe_in.u.dl.num_tx_buffers =
1766 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767
1768 /* Connect WDI IPA PIPE */
1769 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1770 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301771 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1772 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1773 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1774 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001775 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776 /* WLAN TX PIPE Handle */
1777 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301778 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001779 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1780 " CERZ %d, NB %d, CDBPAD 0x%x",
1781 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1782 pipe_in.u.dl.comp_ring_size,
1783 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1784 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1785 pipe_in.u.dl.ce_ring_size,
1786 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001787 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788
1789 /* RX PIPE */
1790 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1791 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1792 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1793 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1794 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1795 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1796 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1797 sizeof(struct sps_iovec);
1798 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1799 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301800 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1802 pipe_in.sys.keep_ipa_awake = true;
1803 }
1804
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001805 pipe_in.u.ul.rdy_ring_base_pa =
1806 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1807 pipe_in.u.ul.rdy_ring_size =
1808 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1809 pipe_in.u.ul.rdy_ring_rp_pa =
1810 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001811 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001812 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001813 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001814 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301815 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001816 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1817 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1818 pipe_in.u.ul.rdy_ring_size,
1819 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001820 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821
1822 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001823 ipa_ctxt->tx_comp_doorbell_paddr,
1824 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825
1826 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1827 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1828
1829 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001830 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831 hdd_ipa_uc_fw_op_event_handler);
1832 ipa_ctxt->uc_op_work[i].msg = NULL;
1833 }
1834
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301835 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001836}
1837
Leo Change3e49442015-10-26 20:07:13 -07001838/**
1839 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1840 * @hdd_ctx: hdd main context
1841 *
1842 * Force shutdown IPA pipe
1843 * Independent of FW pipe status, IPA pipe shutdonw progress
1844 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1845 * independent from FW pipe status
1846 *
1847 * Return: NONE
1848 */
1849void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1850{
1851 struct hdd_ipa_priv *hdd_ipa;
1852
1853 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1854 return;
1855
1856 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1857 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301858 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001859 "IPA pipes are not down yet, force shutdown");
1860 hdd_ipa_uc_disable_pipes(hdd_ipa);
1861 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301862 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001863 "IPA pipes are down, do nothing");
1864 }
1865
1866 return;
1867}
1868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869/**
1870 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1871 *
1872 * Deinit basic IPA UC host side to be in sync reloaded FW during
1873 * SSR
1874 *
1875 * Return: 0 - Success
1876 */
1877int hdd_ipa_uc_ssr_deinit(void)
1878{
1879 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1880 int idx;
1881 struct hdd_ipa_iface_context *iface_context;
1882
Leo Chang3bc8fed2015-11-13 10:59:47 -08001883 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884 return 0;
1885
1886 /* Clean up HDD IPA interfaces */
1887 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1888 (idx < HDD_IPA_MAX_IFACE); idx++) {
1889 iface_context = &hdd_ipa->iface_context[idx];
1890 if (iface_context && iface_context->adapter)
1891 hdd_ipa_cleanup_iface(iface_context);
1892 }
1893
1894 /* After SSR, wlan driver reloads FW again. But we need to protect
1895 * IPA submodule during SSR transient state. So deinit basic IPA
1896 * UC host side to be in sync with reloaded FW during SSR
1897 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001898 if (!hdd_ipa->ipa_pipes_down)
1899 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301901 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001902 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1903 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1904 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1905 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301906 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907
1908 /* Full IPA driver cleanup not required since wlan driver is now
1909 * unloaded and reloaded after SSR.
1910 */
1911 return 0;
1912}
1913
1914/**
1915 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1916 *
1917 * Init basic IPA UC host side to be in sync with reloaded FW after
1918 * SSR to resume IPA UC operations
1919 *
1920 * Return: 0 - Success
1921 */
1922int hdd_ipa_uc_ssr_reinit(void)
1923{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001924
1925 /* After SSR is complete, IPA UC can resume operation. But now wlan
1926 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1927 * and initialization. This is a placeholder func if IPA has to resume
1928 * operations without driver reload.
1929 */
1930 return 0;
1931}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001932
1933/**
1934 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1935 * @hdd_ctx: Global HDD context
1936 * @skb: skb sent to IPA
1937 * @session_id: send packet instance session id
1938 *
1939 * Send TX packet which generated by system to IPA.
1940 * This routine only will be used for function verification
1941 *
1942 * Return: NULL packet sent to IPA properly
1943 * NULL invalid packet drop
1944 * skb packet not sent to IPA. legacy data path should handle
1945 */
1946struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1947 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001948{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001949 struct ipa_header *ipa_header;
1950 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07001951 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001952
1953 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1954 return skb;
1955
Leo Chang07b28f62016-05-11 12:29:22 -07001956 if (!hdd_ipa)
1957 return skb;
1958
1959 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
1960 return skb;
1961
Leo Changcc923e22016-06-16 15:29:03 -07001962 if (skb_headroom(skb) <
1963 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07001964 return skb;
1965
Leo Chang3bc8fed2015-11-13 10:59:47 -08001966 ipa_header = (struct ipa_header *) skb_push(skb,
1967 sizeof(struct ipa_header));
1968 if (!ipa_header) {
1969 /* No headroom, legacy */
1970 return skb;
1971 }
1972 memset(ipa_header, 0, sizeof(*ipa_header));
1973 ipa_header->vdev_id = 0;
1974
1975 frag_header = (struct frag_header *) skb_push(skb,
1976 sizeof(struct frag_header));
1977 if (!frag_header) {
1978 /* No headroom, drop */
1979 kfree_skb(skb);
1980 return NULL;
1981 }
1982 memset(frag_header, 0, sizeof(*frag_header));
1983 frag_header->length = skb->len - sizeof(struct frag_header)
1984 - sizeof(struct ipa_header);
1985
1986 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
1987 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07001988}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989
1990/**
1991 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
1992 * @work: scheduled work
1993 *
1994 * When IPA resources are released in hdd_ipa_rm_try_release() we do
1995 * not want to immediately release the wake lock since the system
1996 * would then potentially try to suspend when there is a healthy data
1997 * rate. Deferred work is scheduled and this function handles the
1998 * work. When this function is called, if the IPA resource is still
1999 * released then we release the wake lock.
2000 *
2001 * Return: None
2002 */
2003static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2004{
2005 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2006 struct hdd_ipa_priv,
2007 wake_lock_work);
2008
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302009 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002010
2011 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2012 goto end;
2013
2014 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302015 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016 WIFI_POWER_EVENT_WAKELOCK_IPA);
2017
2018end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302019 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020}
2021
2022/**
2023 * hdd_ipa_rm_request() - Request resource from IPA
2024 * @hdd_ipa: Global HDD IPA context
2025 *
2026 * Return: 0 on success, negative errno on error
2027 */
2028static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2029{
2030 int ret = 0;
2031
2032 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2033 return 0;
2034
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302035 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002036
2037 switch (hdd_ipa->rm_state) {
2038 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302039 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002040 return 0;
2041 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302042 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002043 return -EINPROGRESS;
2044 case HDD_IPA_RM_RELEASED:
2045 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2046 break;
2047 }
2048
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302049 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050
2051 ret = ipa_rm_inactivity_timer_request_resource(
2052 IPA_RM_RESOURCE_WLAN_PROD);
2053
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302054 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002055 if (ret == 0) {
2056 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2057 hdd_ipa->stats.num_rm_grant_imm++;
2058 }
2059
2060 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2061 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302062 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063 WIFI_POWER_EVENT_WAKELOCK_IPA);
2064 hdd_ipa->wake_lock_released = false;
2065 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302066 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002067
2068 return ret;
2069}
2070
2071/**
2072 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2073 * @hdd_ipa: Global HDD IPA context
2074 *
2075 * Return: 0 if resources released, negative errno otherwise
2076 */
2077static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2078{
2079 int ret = 0;
2080
2081 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2082 return 0;
2083
2084 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2085 return -EAGAIN;
2086
2087 spin_lock_bh(&hdd_ipa->q_lock);
2088 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2089 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2090 spin_unlock_bh(&hdd_ipa->q_lock);
2091 return -EAGAIN;
2092 }
2093 spin_unlock_bh(&hdd_ipa->q_lock);
2094
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302095 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096
Nirav Shahcbc6d722016-03-01 16:24:53 +05302097 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302098 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002099 return -EAGAIN;
2100 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302101 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002102
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302103 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104 switch (hdd_ipa->rm_state) {
2105 case HDD_IPA_RM_GRANTED:
2106 break;
2107 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302108 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002109 return -EINPROGRESS;
2110 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302111 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112 return 0;
2113 }
2114
2115 /* IPA driver returns immediately so set the state here to avoid any
2116 * race condition.
2117 */
2118 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2119 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302120 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121
2122 ret =
2123 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2124
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302125 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126 if (unlikely(ret != 0)) {
2127 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2128 WARN_ON(1);
2129 }
2130
2131 /*
2132 * If wake_lock is released immediately, kernel would try to suspend
2133 * immediately as well, Just avoid ping-pong between suspend-resume
2134 * while there is healthy amount of data transfer going on by
2135 * releasing the wake_lock after some delay.
2136 */
2137 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2138 msecs_to_jiffies
2139 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2140
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302141 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002142
2143 return ret;
2144}
2145
2146/**
2147 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2148 * @user_data: user data registered with IPA
2149 * @event: the IPA resource manager event that occurred
2150 * @data: the data associated with the event
2151 *
2152 * Return: None
2153 */
2154static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2155 unsigned long data)
2156{
2157 struct hdd_ipa_priv *hdd_ipa = user_data;
2158
2159 if (unlikely(!hdd_ipa))
2160 return;
2161
2162 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2163 return;
2164
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302165 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166
2167 switch (event) {
2168 case IPA_RM_RESOURCE_GRANTED:
2169 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2170 /* RM Notification comes with ISR context
2171 * it should be serialized into work queue to avoid
2172 * ISR sleep problem
2173 */
2174 hdd_ipa->uc_rm_work.event = event;
2175 schedule_work(&hdd_ipa->uc_rm_work.work);
2176 break;
2177 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302178 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302180 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002181 hdd_ipa->stats.num_rm_grant++;
2182 break;
2183
2184 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302185 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002186 hdd_ipa->resource_unloading = false;
2187 break;
2188
2189 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302190 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002191 break;
2192 }
2193}
2194
2195/**
2196 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2197 *
2198 * Callback function registered with IPA that is called when IPA wants
2199 * to release the WLAN consumer resource
2200 *
2201 * Return: 0 if the request is granted, negative errno otherwise
2202 */
2203static int hdd_ipa_rm_cons_release(void)
2204{
2205 return 0;
2206}
2207
2208/**
2209 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2210 *
2211 * Callback function registered with IPA that is called when IPA wants
2212 * to access the WLAN consumer resource
2213 *
2214 * Return: 0 if the request is granted, negative errno otherwise
2215 */
2216static int hdd_ipa_rm_cons_request(void)
2217{
Yun Park4d8b60a2015-10-22 13:59:32 -07002218 int ret = 0;
2219
2220 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302221 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002222 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002223 __func__);
2224 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002225 ret = -EINPROGRESS;
2226 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302227 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002228 "%s: IPA resource unloading in progress",
2229 __func__);
2230 ghdd_ipa->pending_cons_req = true;
2231 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002233
2234 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002235}
2236
2237/**
2238 * hdd_ipa_set_perf_level() - Set IPA performance level
2239 * @hdd_ctx: Global HDD context
2240 * @tx_packets: Number of packets transmitted in the last sample period
2241 * @rx_packets: Number of packets received in the last sample period
2242 *
2243 * Return: 0 on success, negative errno on error
2244 */
2245int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2246 uint64_t rx_packets)
2247{
2248 uint32_t next_cons_bw, next_prod_bw;
2249 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2250 struct ipa_rm_perf_profile profile;
2251 int ret;
2252
2253 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2254 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2255 return 0;
2256
2257 memset(&profile, 0, sizeof(profile));
2258
2259 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2260 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2261 else if (tx_packets >
2262 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2263 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2264 else
2265 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2266
2267 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2268 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2269 else if (rx_packets >
2270 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2271 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2272 else
2273 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2274
2275 HDD_IPA_LOG(LOG1,
2276 "CONS perf curr: %d, next: %d",
2277 hdd_ipa->curr_cons_bw, next_cons_bw);
2278 HDD_IPA_LOG(LOG1,
2279 "PROD perf curr: %d, next: %d",
2280 hdd_ipa->curr_prod_bw, next_prod_bw);
2281
2282 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302283 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002284 "Requesting CONS perf curr: %d, next: %d",
2285 hdd_ipa->curr_cons_bw, next_cons_bw);
2286 profile.max_supported_bandwidth_mbps = next_cons_bw;
2287 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2288 &profile);
2289 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302290 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002291 "RM CONS set perf profile failed: %d", ret);
2292
2293 return ret;
2294 }
2295 hdd_ipa->curr_cons_bw = next_cons_bw;
2296 hdd_ipa->stats.num_cons_perf_req++;
2297 }
2298
2299 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302300 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002301 "Requesting PROD perf curr: %d, next: %d",
2302 hdd_ipa->curr_prod_bw, next_prod_bw);
2303 profile.max_supported_bandwidth_mbps = next_prod_bw;
2304 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2305 &profile);
2306 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302307 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002308 "RM PROD set perf profile failed: %d", ret);
2309 return ret;
2310 }
2311 hdd_ipa->curr_prod_bw = next_prod_bw;
2312 hdd_ipa->stats.num_prod_perf_req++;
2313 }
2314
2315 return 0;
2316}
2317
2318/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002319 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2320 * @work: struct work_struct
2321 * @work_handler: work_handler
2322 *
2323 * Return: none
2324 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002325static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2326 work_func_t work_handler)
2327{
2328 INIT_WORK(work, work_handler);
2329}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002330
2331/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002332 * hdd_ipa_setup_rm() - Setup IPA resource management
2333 * @hdd_ipa: Global HDD IPA context
2334 *
2335 * Return: 0 on success, negative errno on error
2336 */
2337static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2338{
2339 struct ipa_rm_create_params create_params = { 0 };
2340 int ret;
2341
2342 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2343 return 0;
2344
Rajeev Kumar217f2172016-01-06 18:11:55 -08002345 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2346 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002347 memset(&create_params, 0, sizeof(create_params));
2348 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2349 create_params.reg_params.user_data = hdd_ipa;
2350 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2351 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2352
2353 ret = ipa_rm_create_resource(&create_params);
2354 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302355 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002356 "Create RM resource failed: %d", ret);
2357 goto setup_rm_fail;
2358 }
2359
2360 memset(&create_params, 0, sizeof(create_params));
2361 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2362 create_params.request_resource = hdd_ipa_rm_cons_request;
2363 create_params.release_resource = hdd_ipa_rm_cons_release;
2364 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2365
2366 ret = ipa_rm_create_resource(&create_params);
2367 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302368 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002369 "Create RM CONS resource failed: %d", ret);
2370 goto delete_prod;
2371 }
2372
2373 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2374 IPA_RM_RESOURCE_APPS_CONS);
2375
2376 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2377 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2378 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302379 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002380 ret);
2381 goto timer_init_failed;
2382 }
2383
2384 /* Set the lowest bandwidth to start with */
2385 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2386
2387 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302388 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002389 "Set perf level failed: %d", ret);
2390 goto set_perf_failed;
2391 }
2392
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302393 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002394 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2395 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302396 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002397 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2398 hdd_ipa->wake_lock_released = true;
2399 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2400
2401 return ret;
2402
2403set_perf_failed:
2404 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2405
2406timer_init_failed:
2407 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2408
2409delete_prod:
2410 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2411
2412setup_rm_fail:
2413 return ret;
2414}
2415
2416/**
2417 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2418 * @hdd_ipa: Global HDD IPA context
2419 *
2420 * Destroys all resources associated with the IPA resource manager
2421 *
2422 * Return: None
2423 */
2424static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2425{
2426 int ret;
2427
2428 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2429 return;
2430
2431 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302432 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433
2434#ifdef WLAN_OPEN_SOURCE
2435 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2436#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302437 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002438
2439 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2440
2441 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2442 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302443 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002444 "RM PROD resource delete failed %d", ret);
2445
2446 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2447 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302448 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002449 "RM CONS resource delete failed %d", ret);
2450}
2451
2452/**
2453 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2454 * @skb: network buffer
2455 * @adapter: network adapter
2456 *
2457 * Called when a network buffer is received which should not be routed
2458 * to the IPA module.
2459 *
2460 * Return: None
2461 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302462static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002463 hdd_adapter_t *adapter)
2464{
2465 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2466 unsigned int cpu_index;
2467
2468 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302469 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002470 adapter);
2471 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302472 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002473 return;
2474 }
2475
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002476 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002477 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302478 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002479 return;
2480 }
2481
2482 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2483 skb->dev = adapter->dev;
2484 skb->protocol = eth_type_trans(skb, skb->dev);
2485 skb->ip_summed = CHECKSUM_NONE;
2486
2487 cpu_index = wlan_hdd_get_cpu();
2488
2489 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2490 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2491 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2492 else
2493 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2494
2495 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2496 adapter->dev->last_rx = jiffies;
2497}
2498
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002499/**
2500 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
2501 * @priv: pointer to private data registered with IPA (we register a
2502 * pointer to the global IPA context)
2503 * @evt: the IPA event which triggered the callback
2504 * @data: data associated with the event
2505 *
2506 * Return: None
2507 */
2508static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2509 unsigned long data)
2510{
2511 struct hdd_ipa_priv *hdd_ipa = NULL;
2512 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302513 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002514 uint8_t iface_id;
2515 uint8_t session_id;
2516 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302517 qdf_nbuf_t copy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002518 uint8_t fw_desc;
2519 int ret;
2520
2521 hdd_ipa = (struct hdd_ipa_priv *)priv;
2522
2523 switch (evt) {
2524 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302525 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002526 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2527 session_id = (uint8_t)skb->cb[0];
2528 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302529 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2531 session_id, iface_id);
2532 } else {
2533 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2534 }
2535
2536 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302537 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002538 "IPA_RECEIVE: Invalid iface_id: %u",
2539 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302540 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002541 "w2i -- skb", skb->data, 8);
2542 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302543 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002544 return;
2545 }
2546
2547 iface_context = &hdd_ipa->iface_context[iface_id];
2548 adapter = iface_context->adapter;
2549
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302550 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551 "w2i -- skb", skb->data, 8);
2552 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2553 hdd_ipa->stats.num_rx_excep++;
2554 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2555 } else {
2556 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2557 }
2558
2559 iface_context->stats.num_rx_ipa_excep++;
2560
2561 /* Disable to forward Intra-BSS Rx packets when
2562 * ap_isolate=1 in hostapd.conf
2563 */
Yun Park046101c2016-09-02 15:32:14 -07002564 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002565 /*
2566 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2567 * all Rx packets to IPA uC, which need to be forwarded
2568 * to other interface.
2569 * And, IPA driver will send back to WLAN host driver
2570 * through exception pipe with fw_desc field set by FW.
2571 * Here we are checking fw_desc field for FORWARD bit
2572 * set, and forward to Tx. Then copy to kernel stack
2573 * only when DISCARD bit is not set.
2574 */
2575 fw_desc = (uint8_t)skb->cb[1];
2576
Leo Chang3bc8fed2015-11-13 10:59:47 -08002577 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302578 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302579 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 "Forward packet to Tx (fw_desc=%d)",
2581 fw_desc);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302582 copy = qdf_nbuf_copy(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 if (copy) {
2584 hdd_ipa->ipa_tx_forward++;
2585 ret = hdd_softap_hard_start_xmit(
2586 (struct sk_buff *)copy,
2587 adapter->dev);
2588 if (ret) {
2589 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302590 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002591 "Forward packet tx fail");
2592 hdd_ipa->stats.
2593 num_tx_bcmc_err++;
2594 } else {
2595 hdd_ipa->stats.num_tx_bcmc++;
2596 }
2597 }
2598 }
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002599
Leo Chang3bc8fed2015-11-13 10:59:47 -08002600 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002601 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2602 hdd_ipa->ipa_rx_discard++;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302603 qdf_nbuf_free(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002604 break;
2605 }
2606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002607 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302608 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 "Intra-BSS FWD is disabled-skip forward to Tx");
2610 }
2611
2612 hdd_ipa_send_skb_to_network(skb, adapter);
2613 break;
2614
2615 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302616 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617 "w2i cb wrong event: 0x%x", evt);
2618 return;
2619 }
2620}
2621
2622/**
2623 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2624 * @skb: packet buffer which was transmitted
2625 *
2626 * Return: None
2627 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302628void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002629{
2630 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2631
Govind Singhb6a89772016-08-12 11:23:35 +05302632 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302633 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002634 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302635 ipa_free_skb((struct ipa_rx_data *)
2636 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637
2638 hdd_ipa->stats.num_tx_comp_cnt++;
2639
2640 atomic_dec(&hdd_ipa->tx_ref_cnt);
2641
2642 hdd_ipa_rm_try_release(hdd_ipa);
2643}
2644
2645/**
2646 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2647 * @iface_context: interface-specific IPA context
2648 * @ipa_tx_desc: packet data descriptor
2649 *
2650 * Return: None
2651 */
2652static void hdd_ipa_send_pkt_to_tl(
2653 struct hdd_ipa_iface_context *iface_context,
2654 struct ipa_rx_data *ipa_tx_desc)
2655{
2656 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2657 uint8_t interface_id;
2658 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302659 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302661 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002662 adapter = iface_context->adapter;
2663 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302664 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665 ipa_free_skb(ipa_tx_desc);
2666 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302667 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002668 hdd_ipa_rm_try_release(hdd_ipa);
2669 return;
2670 }
2671
2672 /*
2673 * During CAC period, data packets shouldn't be sent over the air so
2674 * drop all the packets here
2675 */
2676 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2677 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302678 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002679 iface_context->stats.num_tx_cac_drop++;
2680 hdd_ipa_rm_try_release(hdd_ipa);
2681 return;
2682 }
2683
2684 interface_id = adapter->sessionId;
2685 ++adapter->stats.tx_packets;
2686
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302687 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002688
2689 skb = ipa_tx_desc->skb;
2690
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302691 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302692 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002693 /* FIXME: This is broken. No such field in cb any more:
2694 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302696 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002697 ipa_tx_desc->dma_addr
2698 + HDD_IPA_WLAN_FRAG_HEADER
2699 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002700 ipa_tx_desc->skb->len -=
2701 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2702 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302703 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002705 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302706 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707
2708 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2709
2710 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2711 ipa_tx_desc->skb);
2712 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302713 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714 ipa_free_skb(ipa_tx_desc);
2715 iface_context->stats.num_tx_err++;
2716 hdd_ipa_rm_try_release(hdd_ipa);
2717 return;
2718 }
2719
2720 atomic_inc(&hdd_ipa->tx_ref_cnt);
2721
2722 iface_context->stats.num_tx++;
2723
2724}
2725
2726/**
2727 * hdd_ipa_pm_send_pkt_to_tl() - Send queued packets to TL
2728 * @work: pointer to the scheduled work
2729 *
2730 * Called during PM resume to send packets to TL which were queued
2731 * while host was in the process of suspending.
2732 *
2733 * Return: None
2734 */
2735static void hdd_ipa_pm_send_pkt_to_tl(struct work_struct *work)
2736{
2737 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2738 struct hdd_ipa_priv,
2739 pm_work);
2740 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302741 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002742 uint32_t dequeued = 0;
2743
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302744 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002745
Nirav Shahcbc6d722016-03-01 16:24:53 +05302746 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2747 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302748 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002749
2750 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2751
2752 dequeued++;
2753
2754 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
2755 pm_tx_cb->ipa_tx_desc);
2756
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302757 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002758 }
2759
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302760 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761
2762 hdd_ipa->stats.num_tx_dequeued += dequeued;
2763 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2764 hdd_ipa->stats.num_max_pm_queue = dequeued;
2765}
2766
2767/**
2768 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2769 * @priv: pointer to private data registered with IPA (we register a
2770 * pointer to the interface-specific IPA context)
2771 * @evt: the IPA event which triggered the callback
2772 * @data: data associated with the event
2773 *
2774 * Return: None
2775 */
2776static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2777 unsigned long data)
2778{
2779 struct hdd_ipa_priv *hdd_ipa = NULL;
2780 struct ipa_rx_data *ipa_tx_desc;
2781 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302782 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002783 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302784 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785
Mukul Sharma81661ae2015-10-30 20:26:02 +05302786 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302788 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002789 dev_kfree_skb_any(skb);
2790 iface_context->stats.num_tx_drop++;
2791 return;
2792 }
2793
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002794 ipa_tx_desc = (struct ipa_rx_data *)data;
2795
2796 hdd_ipa = iface_context->hdd_ipa;
2797
2798 /*
2799 * When SSR is going on or driver is unloading, just drop the packets.
2800 * During SSR, there is no use in queueing the packets as STA has to
2801 * connect back any way
2802 */
2803 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302804 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002805 ipa_free_skb(ipa_tx_desc);
2806 iface_context->stats.num_tx_drop++;
2807 return;
2808 }
2809
2810 skb = ipa_tx_desc->skb;
2811
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302812 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002813
2814 /*
2815 * If PROD resource is not requested here then there may be cases where
2816 * IPA hardware may be clocked down because of not having proper
2817 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2818 * workaround to request PROD resource while data is going over CONS
2819 * pipe to prevent the IPA hardware clockdown.
2820 */
2821 hdd_ipa_rm_request(hdd_ipa);
2822
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302823 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824 /*
2825 * If host is still suspended then queue the packets and these will be
2826 * drained later when resume completes. When packet is arrived here and
2827 * host is suspended, this means that there is already resume is in
2828 * progress.
2829 */
2830 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302831 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2833 pm_tx_cb->iface_context = iface_context;
2834 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302835 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002836 hdd_ipa->stats.num_tx_queued++;
2837
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302838 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002839 return;
2840 }
2841
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 /*
2845 * If we are here means, host is not suspended, wait for the work queue
2846 * to finish.
2847 */
2848#ifdef WLAN_OPEN_SOURCE
2849 flush_work(&hdd_ipa->pm_work);
2850#endif
2851
2852 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2853}
2854
2855/**
2856 * hdd_ipa_suspend() - Suspend IPA
2857 * @hdd_ctx: Global HDD context
2858 *
2859 * Return: 0 on success, negativer errno on error
2860 */
2861int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2862{
2863 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2864
2865 if (!hdd_ipa_is_enabled(hdd_ctx))
2866 return 0;
2867
2868 /*
2869 * Check if IPA is ready for suspend, If we are here means, there is
2870 * high chance that suspend would go through but just to avoid any race
2871 * condition after suspend started, these checks are conducted before
2872 * allowing to suspend.
2873 */
2874 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2875 return -EAGAIN;
2876
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302877 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878
2879 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302880 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002881 return -EAGAIN;
2882 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302883 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002884
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302885 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302887 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002888
2889 return 0;
2890}
2891
2892/**
2893 * hdd_ipa_resume() - Resume IPA following suspend
2894 * hdd_ctx: Global HDD context
2895 *
2896 * Return: 0 on success, negative errno on error
2897 */
2898int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2899{
2900 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2901
2902 if (!hdd_ipa_is_enabled(hdd_ctx))
2903 return 0;
2904
2905 schedule_work(&hdd_ipa->pm_work);
2906
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302907 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302909 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002910
2911 return 0;
2912}
2913
2914/**
2915 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
2916 * @hdd_ipa: Global HDD IPA context
2917 *
2918 * Return: 0 on success, negative errno on error
2919 */
2920static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
2921{
2922 int i, ret = 0;
2923 struct ipa_sys_connect_params *ipa;
2924 uint32_t desc_fifo_sz;
2925
2926 /* The maximum number of descriptors that can be provided to a BAM at
2927 * once is one less than the total number of descriptors that the buffer
2928 * can contain.
2929 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2930 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2931 * be provided at once.
2932 * Because of above requirement, one extra descriptor will be added to
2933 * make sure hardware always has one descriptor.
2934 */
2935 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
2936 + sizeof(struct sps_iovec);
2937
2938 /*setup TX pipes */
2939 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2940 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
2941
2942 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
2943 ipa->desc_fifo_sz = desc_fifo_sz;
2944 ipa->priv = &hdd_ipa->iface_context[i];
2945 ipa->notify = hdd_ipa_i2w_cb;
2946
2947 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2948 ipa->ipa_ep_cfg.hdr.hdr_len =
2949 HDD_IPA_UC_WLAN_TX_HDR_LEN;
2950 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2951 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2952 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2953 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
2954 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2955 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2956 } else {
2957 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
2958 }
2959 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
2960
2961 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2962 ipa->keep_ipa_awake = 1;
2963
2964 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
2965 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302966 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967 " ret: %d", i, ret);
2968 goto setup_sys_pipe_fail;
2969 }
2970 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
2971 }
2972
2973 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2974 /*
2975 * Hard code it here, this can be extended if in case
2976 * PROD pipe is also per interface.
2977 * Right now there is no advantage of doing this.
2978 */
2979 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
2980
2981 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
2982
2983 ipa->client = hdd_ipa->prod_client;
2984
2985 ipa->desc_fifo_sz = desc_fifo_sz;
2986 ipa->priv = hdd_ipa;
2987 ipa->notify = hdd_ipa_w2i_cb;
2988
2989 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2990 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
2991 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
2992 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
2993
2994 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2995 ipa->keep_ipa_awake = 1;
2996
2997 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
2998 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302999 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003000 "Failed for RX pipe: %d", ret);
3001 goto setup_sys_pipe_fail;
3002 }
3003 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3004 }
3005
3006 return ret;
3007
3008setup_sys_pipe_fail:
3009
3010 while (--i >= 0) {
3011 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303012 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013 sizeof(struct hdd_ipa_sys_pipe));
3014 }
3015
3016 return ret;
3017}
3018
3019/**
3020 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3021 * @hdd_ipa: Global HDD IPA context
3022 *
3023 * Return: None
3024 */
3025static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3026{
3027 int ret = 0, i;
3028 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3029 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3030 ret =
3031 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3032 conn_hdl);
3033 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303034 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003035 ret);
3036
3037 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3038 }
3039 }
3040}
3041
3042/**
3043 * hdd_ipa_register_interface() - register IPA interface
3044 * @hdd_ipa: Global IPA context
3045 * @iface_context: Per-interface IPA context
3046 *
3047 * Return: 0 on success, negative errno on error
3048 */
3049static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3050 struct hdd_ipa_iface_context
3051 *iface_context)
3052{
3053 struct ipa_tx_intf tx_intf;
3054 struct ipa_rx_intf rx_intf;
3055 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3056 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3057 char *ifname = iface_context->adapter->dev->name;
3058
3059 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3060 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3061
3062 int num_prop = 1;
3063 int ret = 0;
3064
3065 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3066 num_prop++;
3067
3068 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3069 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303070 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303072 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073 goto register_interface_fail;
3074 }
3075
3076 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3077 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303078 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003079 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303080 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003081 goto register_interface_fail;
3082 }
3083
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303084 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3085 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086
3087 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3088 ifname, HDD_IPA_IPV4_NAME_EXT);
3089 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3090 ifname, HDD_IPA_IPV6_NAME_EXT);
3091
3092 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3093 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3094 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3095 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3096
3097 /*
3098 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3099 * mask to identify the interface in IPA hardware
3100 */
3101 rx_prop[IPA_IP_v4].attrib.meta_data =
3102 htonl(iface_context->adapter->sessionId << 16);
3103 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3104
3105 rx_intf.num_props++;
3106 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3107 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3108 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3109 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3110 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3111 rx_prop[IPA_IP_v4].attrib.meta_data =
3112 htonl(iface_context->adapter->sessionId << 16);
3113 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3114
3115 rx_intf.num_props++;
3116 }
3117
3118 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3119 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3120 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3121 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3122 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3123 IPA_RESOURCE_NAME_MAX);
3124 tx_intf.num_props++;
3125
3126 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3127 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3128 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3129 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3130 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3131 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3132 IPA_RESOURCE_NAME_MAX);
3133 tx_intf.num_props++;
3134 }
3135
3136 tx_intf.prop = tx_prop;
3137 rx_intf.prop = rx_prop;
3138
3139 /* Call the ipa api to register interface */
3140 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3141
3142register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303143 qdf_mem_free(tx_prop);
3144 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003145 return ret;
3146}
3147
3148/**
3149 * hdd_remove_ipa_header() - Remove a specific header from IPA
3150 * @name: Name of the header to be removed
3151 *
3152 * Return: None
3153 */
3154static void hdd_ipa_remove_header(char *name)
3155{
3156 struct ipa_ioc_get_hdr hdrlookup;
3157 int ret = 0, len;
3158 struct ipa_ioc_del_hdr *ipa_hdr;
3159
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303160 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003161 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3162 ret = ipa_get_hdr(&hdrlookup);
3163 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303164 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165 name, ret);
3166 return;
3167 }
3168
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303169 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303171 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303173 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174 return;
3175 }
3176 ipa_hdr->num_hdls = 1;
3177 ipa_hdr->commit = 0;
3178 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3179 ipa_hdr->hdl[0].status = -1;
3180 ret = ipa_del_hdr(ipa_hdr);
3181 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303182 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183 ret);
3184
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303185 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186}
3187
3188/**
3189 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3190 * @hdd_ipa: Global HDD IPA context
3191 * @iface_context: Interface-specific HDD IPA context
3192 * @mac_addr: Interface MAC address
3193 *
3194 * Return: 0 on success, negativer errno value on error
3195 */
3196static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3197 struct hdd_ipa_iface_context *iface_context,
3198 uint8_t *mac_addr)
3199{
3200 hdd_adapter_t *adapter = iface_context->adapter;
3201 char *ifname;
3202 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3203 int ret = -EINVAL;
3204 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3205 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3206
3207 ifname = adapter->dev->name;
3208
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303209 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003210 ifname, mac_addr);
3211
3212 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303213 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214 + sizeof(struct ipa_hdr_add));
3215 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303216 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 "%s: ipa_hdr allocation failed", ifname);
3218 ret = -ENOMEM;
3219 goto end;
3220 }
3221
3222 ipa_hdr->commit = 0;
3223 ipa_hdr->num_hdrs = 1;
3224
3225 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3226 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3227 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3228 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3229 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303230 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003231 "ifname=%s, vdev_id=%d",
3232 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3233 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3234 ifname, HDD_IPA_IPV4_NAME_EXT);
3235 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3236 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3237 ipa_hdr->hdr[0].is_partial = 1;
3238 ipa_hdr->hdr[0].hdr_hdl = 0;
3239 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3240 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3241
3242 ret = ipa_add_hdr(ipa_hdr);
3243 } else {
3244 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3245
3246 /* Set the Source MAC */
3247 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3248 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3249
3250 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3251 ifname, HDD_IPA_IPV4_NAME_EXT);
3252 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3253 ipa_hdr->hdr[0].is_partial = 1;
3254 ipa_hdr->hdr[0].hdr_hdl = 0;
3255 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3256 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3257
3258 /* Set the type to IPV4 in the header */
3259 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3260
3261 ret = ipa_add_hdr(ipa_hdr);
3262 }
3263 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303264 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265 ifname, ret);
3266 goto end;
3267 }
3268
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303269 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003270 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3271
3272 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3273 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3274 ifname, HDD_IPA_IPV6_NAME_EXT);
3275
3276 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3277 uc_tx_hdr =
3278 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3279 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3280 } else {
3281 /* Set the type to IPV6 in the header */
3282 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3283 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3284 }
3285
3286 ret = ipa_add_hdr(ipa_hdr);
3287 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303288 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289 "%s: IPv6 add hdr failed: %d", ifname, ret);
3290 goto clean_ipv4_hdr;
3291 }
3292
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303293 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3295 }
3296
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303297 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298
3299 return ret;
3300
3301clean_ipv4_hdr:
3302 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3303 ifname, HDD_IPA_IPV4_NAME_EXT);
3304 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3305end:
3306 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303307 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308
3309 return ret;
3310}
3311
3312/**
3313 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3314 * @adapter: Adapter upon which IPA was previously configured
3315 *
3316 * Return: None
3317 */
3318static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3319{
3320 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3321 int ret;
3322 char name_ipa[IPA_RESOURCE_NAME_MAX];
3323
3324 /* Remove the headers */
3325 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3326 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3327 hdd_ipa_remove_header(name_ipa);
3328
3329 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3330 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3331 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3332 hdd_ipa_remove_header(name_ipa);
3333 }
3334 /* unregister the interface with IPA */
3335 ret = ipa_deregister_intf(adapter->dev->name);
3336 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303337 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338 "%s: ipa_deregister_intf fail: %d",
3339 adapter->dev->name, ret);
3340}
3341
3342/**
3343 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3344 * @iface_context: interface-specific IPA context
3345 *
3346 * Return: None
3347 */
3348static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3349{
3350 if (iface_context == NULL)
3351 return;
3352
3353 hdd_ipa_clean_hdr(iface_context->adapter);
3354
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303355 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356 iface_context->adapter->ipa_context = NULL;
3357 iface_context->adapter = NULL;
3358 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303359 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 iface_context->ifa_address = 0;
3361 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303362 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303364 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 }
3366 iface_context->hdd_ipa->num_iface--;
3367}
3368
3369/**
3370 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3371 * @hdd_ipa: HDD IPA global context
3372 * @adapter: Interface upon which IPA is being setup
3373 * @sta_id: Station ID of the API instance
3374 *
3375 * Return: 0 on success, negative errno value on error
3376 */
3377static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3378 hdd_adapter_t *adapter, uint8_t sta_id)
3379{
3380 struct hdd_ipa_iface_context *iface_context = NULL;
3381 void *tl_context = NULL;
3382 int i, ret = 0;
3383
3384 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3385 * channel change indication. Since these indications are sent by lower
3386 * layer as SAP updates and IPA doesn't have to do anything for these
3387 * updates so ignoring!
3388 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003389 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003390 return 0;
3391
3392 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3393 if (hdd_ipa->iface_context[i].adapter == NULL) {
3394 iface_context = &(hdd_ipa->iface_context[i]);
3395 break;
3396 }
3397 }
3398
3399 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303400 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401 "All the IPA interfaces are in use");
3402 ret = -ENOMEM;
3403 goto end;
3404 }
3405
3406 adapter->ipa_context = iface_context;
3407 iface_context->adapter = adapter;
3408 iface_context->sta_id = sta_id;
3409 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3410
3411 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303412 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 "Not able to get TL context sta_id: %d", sta_id);
3414 ret = -EINVAL;
3415 goto end;
3416 }
3417
3418 iface_context->tl_context = tl_context;
3419
3420 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3421 adapter->dev->dev_addr);
3422
3423 if (ret)
3424 goto end;
3425
3426 /* Configure the TX and RX pipes filter rules */
3427 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3428 if (ret)
3429 goto cleanup_header;
3430
3431 hdd_ipa->num_iface++;
3432 return ret;
3433
3434cleanup_header:
3435
3436 hdd_ipa_clean_hdr(adapter);
3437end:
3438 if (iface_context)
3439 hdd_ipa_cleanup_iface(iface_context);
3440 return ret;
3441}
3442
3443/**
3444 * hdd_ipa_msg_free_fn() - Free an IPA message
3445 * @buff: pointer to the IPA message
3446 * @len: length of the IPA message
3447 * @type: type of IPA message
3448 *
3449 * Return: None
3450 */
3451static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3452{
3453 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3454 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303455 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456}
3457
3458/**
3459 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3460 * @mcc_mode: 0=MCC/1=SCC
3461 *
3462 * Return: 0 on success, negative errno value on error
3463 */
3464int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3465{
3466 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303467 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 hdd_adapter_t *pAdapter;
3469 struct ipa_msg_meta meta;
3470 struct ipa_wlan_msg *msg;
3471 int ret;
3472
3473 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3474 return -EINVAL;
3475
3476 if (!pHddCtx->mcc_mode) {
3477 /* Flush TxRx queue for each adapter before switch to SCC */
3478 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303479 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003481 if (pAdapter->device_mode == QDF_STA_MODE ||
3482 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303483 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3485 pAdapter->device_mode);
3486 hdd_deinit_tx_rx(pAdapter);
3487 }
3488 status = hdd_get_next_adapter(
3489 pHddCtx, adapter_node, &next);
3490 adapter_node = next;
3491 }
3492 }
3493
3494 /* Send SCC/MCC Switching event to IPA */
3495 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303496 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497 if (msg == NULL) {
3498 hddLog(LOGE, "msg allocation failed");
3499 return -ENOMEM;
3500 }
3501
3502 meta.msg_type = mcc_mode ?
3503 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3504 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3505
3506 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3507
3508 if (ret) {
3509 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3510 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303511 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 }
3513
3514 return ret;
3515}
3516
3517/**
3518 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3519 * @event: IPA WLAN event to be converted to a string
3520 *
3521 * Return: ASCII string representing the IPA WLAN event
3522 */
3523static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3524{
3525 switch (event) {
3526 case WLAN_CLIENT_CONNECT:
3527 return "WLAN_CLIENT_CONNECT";
3528 case WLAN_CLIENT_DISCONNECT:
3529 return "WLAN_CLIENT_DISCONNECT";
3530 case WLAN_CLIENT_POWER_SAVE_MODE:
3531 return "WLAN_CLIENT_POWER_SAVE_MODE";
3532 case WLAN_CLIENT_NORMAL_MODE:
3533 return "WLAN_CLIENT_NORMAL_MODE";
3534 case SW_ROUTING_ENABLE:
3535 return "SW_ROUTING_ENABLE";
3536 case SW_ROUTING_DISABLE:
3537 return "SW_ROUTING_DISABLE";
3538 case WLAN_AP_CONNECT:
3539 return "WLAN_AP_CONNECT";
3540 case WLAN_AP_DISCONNECT:
3541 return "WLAN_AP_DISCONNECT";
3542 case WLAN_STA_CONNECT:
3543 return "WLAN_STA_CONNECT";
3544 case WLAN_STA_DISCONNECT:
3545 return "WLAN_STA_DISCONNECT";
3546 case WLAN_CLIENT_CONNECT_EX:
3547 return "WLAN_CLIENT_CONNECT_EX";
3548
3549 case IPA_WLAN_EVENT_MAX:
3550 default:
3551 return "UNKNOWN";
3552 }
3553}
3554
3555/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003556 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3557 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3558 *
3559 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3560 */
3561static enum ipa_wlan_event
3562hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3563{
3564 enum ipa_wlan_event ipa_event;
3565
3566 switch (hdd_ipa_event_type) {
3567 case HDD_IPA_CLIENT_CONNECT:
3568 ipa_event = WLAN_CLIENT_CONNECT;
3569 break;
3570 case HDD_IPA_CLIENT_DISCONNECT:
3571 ipa_event = WLAN_CLIENT_DISCONNECT;
3572 break;
3573 case HDD_IPA_AP_CONNECT:
3574 ipa_event = WLAN_AP_CONNECT;
3575 break;
3576 case HDD_IPA_AP_DISCONNECT:
3577 ipa_event = WLAN_AP_DISCONNECT;
3578 break;
3579 case HDD_IPA_STA_CONNECT:
3580 ipa_event = WLAN_STA_CONNECT;
3581 break;
3582 case HDD_IPA_STA_DISCONNECT:
3583 ipa_event = WLAN_STA_DISCONNECT;
3584 break;
3585 case HDD_IPA_CLIENT_CONNECT_EX:
3586 ipa_event = WLAN_CLIENT_CONNECT_EX;
3587 break;
3588 case HDD_IPA_WLAN_EVENT_MAX:
3589 default:
3590 ipa_event = IPA_WLAN_EVENT_MAX;
3591 break;
3592 }
3593 return ipa_event;
3594
3595}
3596
3597/**
3598 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 * @adapter: adapter upon which the event was received
3600 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003601 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 * @mac_address: MAC address associated with the event
3603 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003604 * This function is meant to be called from within wlan_hdd_ipa.c
3605 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003606 * Return: 0 on success, negative errno value on error
3607 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003608static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 enum ipa_wlan_event type, uint8_t *mac_addr)
3610{
3611 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3612 struct ipa_msg_meta meta;
3613 struct ipa_wlan_msg *msg;
3614 struct ipa_wlan_msg_ex *msg_ex = NULL;
3615 int ret;
3616
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303617 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3619 mac_addr, sta_id);
3620
3621 if (type >= IPA_WLAN_EVENT_MAX)
3622 return -EINVAL;
3623
3624 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3625 return -EINVAL;
3626
3627 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303628 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 return -EINVAL;
3630 }
3631
3632 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3633 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003634 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 return 0;
3636 }
3637
3638 /*
3639 * During IPA UC resource loading/unloading new events can be issued.
3640 * Store the events separately and handle them later.
3641 */
3642 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3643 ((hdd_ipa->resource_loading) ||
3644 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003645 unsigned int pending_event_count;
3646 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647
Yun Parkf19e07d2015-11-20 11:34:27 -08003648 hdd_err("IPA resource %s inprogress",
3649 hdd_ipa->resource_loading ? "load":"unload");
3650
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303651 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003652
Anurag Chouhanffb21542016-02-17 14:33:03 +05303653 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003654 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3655 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303656 qdf_list_remove_front(&hdd_ipa->pending_event,
3657 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003658 } else {
3659 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303660 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003661 sizeof(struct ipa_uc_pending_event));
3662 }
3663
3664 if (!pending_event) {
3665 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303666 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 return -ENOMEM;
3668 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003669
3670 pending_event->adapter = adapter;
3671 pending_event->sta_id = sta_id;
3672 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303673 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303675 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303676 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003677 &pending_event->node);
3678
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303679 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 return 0;
3681 }
3682
3683 hdd_ipa->stats.event[type]++;
3684
Leo Chang3bc8fed2015-11-13 10:59:47 -08003685 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686 switch (type) {
3687 case WLAN_STA_CONNECT:
3688 /* STA already connected and without disconnect, connect again
3689 * This is Roaming scenario
3690 */
3691 if (hdd_ipa->sta_connected)
3692 hdd_ipa_cleanup_iface(adapter->ipa_context);
3693
Yun Parka37592b2016-06-11 17:10:28 -07003694 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3695 (hdd_ipa->sap_num_connected_sta > 0) &&
3696 !hdd_ipa->sta_connected)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 hdd_ipa_uc_offload_enable_disable(adapter,
3698 SIR_STA_RX_DATA_OFFLOAD, 1);
3699
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303700 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3703 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303704 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003705 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3706 (hdd_ipa->sap_num_connected_sta > 0) &&
3707 !hdd_ipa->sta_connected)
3708 hdd_ipa_uc_offload_enable_disable(adapter,
3709 SIR_STA_RX_DATA_OFFLOAD, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003711 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713 vdev_to_iface[adapter->sessionId] =
3714 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003715 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303717 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003718
3719 hdd_ipa->sta_connected = 1;
3720 break;
3721
3722 case WLAN_AP_CONNECT:
3723 /* For DFS channel we get two start_bss event (before and after
3724 * CAC). Also when ACS range includes both DFS and non DFS
3725 * channels, we could possibly change channel many times due to
3726 * RADAR detection and chosen channel may not be a DFS channels.
3727 * So dont return error here. Just discard the event.
3728 */
3729 if (adapter->ipa_context)
3730 return 0;
3731
Yun Parka37592b2016-06-11 17:10:28 -07003732 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733 hdd_ipa_uc_offload_enable_disable(adapter,
3734 SIR_AP_RX_DATA_OFFLOAD, 1);
Yun Parka37592b2016-06-11 17:10:28 -07003735
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303736 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3738 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303739 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 "%s: Evt: %d, Interface setup failed",
3741 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303742 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003743 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003744 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746 vdev_to_iface[adapter->sessionId] =
3747 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003748 (adapter->ipa_context))->iface_id;
3749
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303750 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 break;
3752
3753 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303754 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755 hdd_ipa_cleanup_iface(adapter->ipa_context);
3756
3757 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303758 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 "%s: Evt: %d, STA already disconnected",
3760 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303761 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762 return -EINVAL;
3763 }
Yun Parka37592b2016-06-11 17:10:28 -07003764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303768 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769 "%s: IPA UC OFFLOAD NOT ENABLED",
3770 msg_ex->name);
3771 } else {
3772 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003773 if (!hdd_ipa->num_iface &&
3774 (HDD_IPA_UC_NUM_WDI_PIPE ==
3775 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003777 }
3778
3779 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3780 hdd_ipa_uc_offload_enable_disable(adapter,
3781 SIR_STA_RX_DATA_OFFLOAD, 0);
3782 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3783 }
3784
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303785 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786 break;
3787
3788 case WLAN_AP_DISCONNECT:
3789 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303790 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791 "%s: Evt: %d, SAP already disconnected",
3792 msg_ex->name, meta.msg_type);
3793 return -EINVAL;
3794 }
3795
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303796 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003797 hdd_ipa_cleanup_iface(adapter->ipa_context);
3798 if ((!hdd_ipa->num_iface) &&
3799 (HDD_IPA_UC_NUM_WDI_PIPE ==
3800 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003801 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802 /*
3803 * We disable WDI pipes directly here since
3804 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3805 * processed when unloading WLAN driver is in
3806 * progress
3807 */
3808 hdd_ipa_uc_disable_pipes(hdd_ipa);
3809 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303810 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811 "NO INTF left but still pipe clean up");
3812 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3813 }
3814 }
3815
3816 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3817 hdd_ipa_uc_offload_enable_disable(adapter,
3818 SIR_AP_RX_DATA_OFFLOAD, 0);
3819 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3820 }
Yun Parka37592b2016-06-11 17:10:28 -07003821
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303822 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823 break;
3824
3825 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303826 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 adapter->dev->ifindex, sta_id);
3828
3829 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303830 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3832 adapter->dev->name, meta.msg_type);
3833 return 0;
3834 }
3835
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303836 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3838 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303839 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840 "%s: STA ID %d found, not valid",
3841 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303842 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843 return 0;
3844 }
Yun Park312f71a2015-12-08 10:22:42 -08003845
3846 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07003847 if (0 == hdd_ipa->sap_num_connected_sta) {
3848 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3849 hdd_ipa->sta_connected)
3850 hdd_ipa_uc_offload_enable_disable(
3851 hdd_get_adapter(hdd_ipa->hdd_ctx,
3852 QDF_STA_MODE),
3853 SIR_STA_RX_DATA_OFFLOAD, 1);
3854
Yun Park312f71a2015-12-08 10:22:42 -08003855 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3856 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303857 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303858 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003859 "%s: handle 1st con ret %d",
3860 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07003861
3862 if (hdd_ipa_uc_sta_is_enabled(
3863 hdd_ipa->hdd_ctx) &&
3864 hdd_ipa->sta_connected)
3865 hdd_ipa_uc_offload_enable_disable(
3866 hdd_get_adapter(
3867 hdd_ipa->hdd_ctx,
3868 QDF_STA_MODE),
3869 SIR_STA_RX_DATA_OFFLOAD, 0);
3870
Yun Park312f71a2015-12-08 10:22:42 -08003871 return ret;
3872 }
3873 }
3874
3875 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003876
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303877 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
3879 meta.msg_type = type;
3880 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3881 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303882 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883
3884 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303885 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 "msg_ex allocation failed");
3887 return -ENOMEM;
3888 }
3889 strlcpy(msg_ex->name, adapter->dev->name,
3890 IPA_RESOURCE_NAME_MAX);
3891 msg_ex->num_of_attribs = 1;
3892 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
3893 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3894 msg_ex->attribs[0].offset =
3895 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3896 } else {
3897 msg_ex->attribs[0].offset =
3898 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3899 }
3900 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
3901 IPA_MAC_ADDR_SIZE);
3902
3903 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
3904
3905 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303906 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003907 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303908 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 return ret;
3910 }
3911 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912 return ret;
3913
3914 case WLAN_CLIENT_DISCONNECT:
3915 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303916 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 "%s: IPA UC OFFLOAD NOT ENABLED",
3918 msg_ex->name);
3919 return 0;
3920 }
3921
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303922 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303924 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 "%s: STA ID %d NOT found, not valid",
3926 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303927 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 return 0;
3929 }
3930 hdd_ipa->sap_num_connected_sta--;
3931 /* Disable IPA UC TX PIPE when last STA disconnected */
3932 if (!hdd_ipa->sap_num_connected_sta
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 && (false == hdd_ipa->resource_unloading)
3934 && (HDD_IPA_UC_NUM_WDI_PIPE ==
3935 hdd_ipa->activated_fw_pipe))
3936 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Yun Parka37592b2016-06-11 17:10:28 -07003937
3938 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3939 hdd_ipa->sta_connected)
3940 hdd_ipa_uc_offload_enable_disable(
3941 hdd_get_adapter(hdd_ipa->hdd_ctx,
3942 QDF_STA_MODE),
3943 SIR_STA_RX_DATA_OFFLOAD, 0);
3944
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303945 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 break;
3947
3948 default:
3949 return 0;
3950 }
3951
3952 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303953 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303955 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 return -ENOMEM;
3957 }
3958
3959 meta.msg_type = type;
3960 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
3961 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
3962
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303963 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 msg->name, meta.msg_type);
3965
3966 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3967
3968 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303969 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303971 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 return ret;
3973 }
3974
3975 hdd_ipa->stats.num_send_msg++;
3976
3977end:
3978 return ret;
3979}
3980
3981/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003982 * hdd_ipa_wlan_evt() - IPA event handler
3983 * @adapter: adapter upon which the event was received
3984 * @sta_id: station id for the event
3985 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
3986 * @mac_address: MAC address associated with the event
3987 *
3988 * This function is meant to be called from outside of wlan_hdd_ipa.c.
3989 *
3990 * Return: 0 on success, negative errno value on error
3991 */
3992int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
3993 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
3994{
3995 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
3996
3997 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
3998}
3999
4000/**
4001 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4002 * @hdd_ipa: Global HDD IPA context
4003 *
4004 * Return: None
4005 */
4006static void
4007hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4008{
4009 unsigned int pending_event_count;
4010 struct ipa_uc_pending_event *pending_event = NULL;
4011
4012 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4013 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4014 "%s, Pending Event Count %d", __func__, pending_event_count);
4015 if (!pending_event_count) {
4016 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4017 "%s, No Pending Event", __func__);
4018 return;
4019 }
4020
4021 qdf_list_remove_front(&hdd_ipa->pending_event,
4022 (qdf_list_node_t **)&pending_event);
4023 while (pending_event != NULL) {
4024 __hdd_ipa_wlan_evt(pending_event->adapter,
4025 pending_event->type,
4026 pending_event->sta_id,
4027 pending_event->mac_addr);
4028 qdf_mem_free(pending_event);
4029 pending_event = NULL;
4030 qdf_list_remove_front(&hdd_ipa->pending_event,
4031 (qdf_list_node_t **)&pending_event);
4032 }
4033}
4034
4035/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4037 * @state: IPA RM state value
4038 *
4039 * Return: ASCII string representing the IPA RM state
4040 */
4041static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4042{
4043 switch (state) {
4044 case HDD_IPA_RM_RELEASED:
4045 return "RELEASED";
4046 case HDD_IPA_RM_GRANT_PENDING:
4047 return "GRANT_PENDING";
4048 case HDD_IPA_RM_GRANTED:
4049 return "GRANTED";
4050 }
4051
4052 return "UNKNOWN";
4053}
4054
4055/**
4056 * hdd_ipa_init() - IPA initialization function
4057 * @hdd_ctx: HDD global context
4058 *
4059 * Allocate hdd_ipa resources, ipa pipe resource and register
4060 * wlan interface with IPA module.
4061 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304062 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304064QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004065{
4066 struct hdd_ipa_priv *hdd_ipa = NULL;
4067 int ret, i;
4068 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004069 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004070
4071 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304072 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073
Yun Park7f171ab2016-07-29 15:44:22 -07004074 if (!pdev) {
4075 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4076 goto fail_return;
4077 }
4078
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304079 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304081 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004082 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 }
4084
4085 hdd_ctx->hdd_ipa = hdd_ipa;
4086 ghdd_ipa = hdd_ipa;
4087 hdd_ipa->hdd_ctx = hdd_ctx;
4088 hdd_ipa->num_iface = 0;
Yun Park7f171ab2016-07-29 15:44:22 -07004089 ol_txrx_ipa_uc_get_resource(pdev, &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004090 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4091 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4092 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4093 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304094 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004095 "IPA UC resource alloc fail");
4096 goto fail_get_resource;
4097 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098
4099 /* Create the interface context */
4100 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4101 iface_context = &hdd_ipa->iface_context[i];
4102 iface_context->hdd_ipa = hdd_ipa;
4103 iface_context->cons_client =
4104 hdd_ipa_adapter_2_client[i].cons_client;
4105 iface_context->prod_client =
4106 hdd_ipa_adapter_2_client[i].prod_client;
4107 iface_context->iface_id = i;
4108 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304109 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 }
4111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304113 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304114 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115
4116 ret = hdd_ipa_setup_rm(hdd_ipa);
4117 if (ret)
4118 goto fail_setup_rm;
4119
4120 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4121 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304122 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 hdd_ipa->sap_num_connected_sta = 0;
4124 hdd_ipa->ipa_tx_packets_diff = 0;
4125 hdd_ipa->ipa_rx_packets_diff = 0;
4126 hdd_ipa->ipa_p_tx_packets = 0;
4127 hdd_ipa->ipa_p_rx_packets = 0;
4128 hdd_ipa->resource_loading = false;
4129 hdd_ipa->resource_unloading = false;
4130 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004131 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132 /* Setup IPA sys_pipe for MCC */
4133 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4134 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4135 if (ret)
4136 goto fail_create_sys_pipe;
4137 }
4138 hdd_ipa_uc_ol_init(hdd_ctx);
4139 } else {
4140 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4141 if (ret)
4142 goto fail_create_sys_pipe;
4143 }
4144
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304145 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146
4147fail_create_sys_pipe:
4148 hdd_ipa_destroy_rm_resource(hdd_ipa);
4149fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304150 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004151fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304152 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004153 hdd_ctx->hdd_ipa = NULL;
4154 ghdd_ipa = NULL;
4155fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304156 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004157}
4158
4159/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004160 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4161 * @hdd_ipa: pointer to HDD IPA struct
4162 *
4163 * Return: none
4164 */
4165void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
4166{
4167 struct ipa_uc_pending_event *pending_event = NULL;
4168
Anurag Chouhanffb21542016-02-17 14:33:03 +05304169 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4170 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304171 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004172 }
4173
Anurag Chouhanffb21542016-02-17 14:33:03 +05304174 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004175}
4176
4177/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 * hdd_ipa_cleanup - IPA cleanup function
4179 * @hdd_ctx: HDD global context
4180 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304181 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004182 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304183QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184{
4185 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4186 int i;
4187 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304188 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004189 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4190
4191 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304192 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193
4194 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4195 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4196 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4197 }
4198
4199 /* Teardown IPA sys_pipe for MCC */
4200 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4201 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4202
4203 hdd_ipa_destroy_rm_resource(hdd_ipa);
4204
4205#ifdef WLAN_OPEN_SOURCE
4206 cancel_work_sync(&hdd_ipa->pm_work);
4207#endif
4208
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304209 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210
Nirav Shahcbc6d722016-03-01 16:24:53 +05304211 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4212 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304213 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214
4215 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4216 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4217
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304218 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304220 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304222 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004223
4224 /* destory the interface lock */
4225 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4226 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304227 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004228 }
4229
4230 /* This should never hit but still make sure that there are no pending
4231 * descriptor in IPA hardware
4232 */
4233 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304234 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 "IPA Pending write done: %d Waiting!",
4236 hdd_ipa->pending_hw_desc_cnt);
4237
4238 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4239 usleep_range(100, 100);
4240 }
4241
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304242 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 "IPA Pending write done: desc: %d %s(%d)!",
4244 hdd_ipa->pending_hw_desc_cnt,
4245 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4246 : "leak", i);
4247 }
4248 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4249 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304250 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304251 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4252 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304254 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304255 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4256 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304258 qdf_mutex_destroy(&hdd_ipa->event_lock);
4259 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004260 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261
4262#ifdef WLAN_OPEN_SOURCE
4263 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4264 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4265 hdd_ipa->uc_op_work[i].msg = NULL;
4266 }
4267#endif
4268 }
4269
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304270 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271 hdd_ctx->hdd_ipa = NULL;
4272
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304273 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274}
4275#endif /* IPA_OFFLOAD */