blob: 66ee27f6cc8f6fc4b0ac9b42036538dee4cc686f [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
Mohit Khannafa99aea2016-05-12 21:43:13 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
51#include <ol_txrx_osif_api.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070052#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053
54#include "cds_sched.h"
55
56#include "wma.h"
57#include "wma_api.h"
58
Dhanashri Atreb08959a2016-03-01 17:28:03 -080059#include "cdp_txrx_ipa.h"
60
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061#define HDD_IPA_DESC_BUFFER_RATIO 4
62#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
63#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
64
65#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
67/* WDI TX and RX PIPE */
68#define HDD_IPA_UC_NUM_WDI_PIPE 2
69#define HDD_IPA_UC_MAX_PENDING_EVENT 33
70
71#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
72#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
73#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
74#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
75
76#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
77#define HDD_IPA_MAX_IFACE 3
78#define HDD_IPA_MAX_SYSBAM_PIPE 4
79#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
80#define HDD_IPA_ENABLE_MASK BIT(0)
81#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
82#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
83#define HDD_IPA_RM_ENABLE_MASK BIT(3)
84#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
85#define HDD_IPA_UC_ENABLE_MASK BIT(5)
86#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
87#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
88
Yun Parkf19e07d2015-11-20 11:34:27 -080089#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
90
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091typedef enum {
92 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
93 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
94 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
95 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
96 HDD_IPA_UC_OPCODE_STATS = 4,
97 /* keep this last */
98 HDD_IPA_UC_OPCODE_MAX
99} hdd_ipa_uc_op_code;
100
101/**
102 * enum - Reason codes for stat query
103 *
104 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
105 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
106 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
107 */
108enum {
109 HDD_IPA_UC_STAT_REASON_NONE,
110 HDD_IPA_UC_STAT_REASON_DEBUG,
111 HDD_IPA_UC_STAT_REASON_BW_CAL
112};
113
114/**
115 * enum hdd_ipa_rm_state - IPA resource manager state
116 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
117 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
118 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
119 */
120enum hdd_ipa_rm_state {
121 HDD_IPA_RM_RELEASED,
122 HDD_IPA_RM_GRANT_PENDING,
123 HDD_IPA_RM_GRANTED,
124};
125
126struct llc_snap_hdr {
127 uint8_t dsap;
128 uint8_t ssap;
129 uint8_t resv[4];
130 __be16 eth_type;
131} __packed;
132
Leo Chang3bc8fed2015-11-13 10:59:47 -0800133/**
134 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
135 * @eth: ether II header
136 * @llc_snap: LLC snap header
137 *
138 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139struct hdd_ipa_tx_hdr {
140 struct ethhdr eth;
141 struct llc_snap_hdr llc_snap;
142} __packed;
143
Leo Chang3bc8fed2015-11-13 10:59:47 -0800144/**
145 * struct frag_header - fragment header type registered to IPA hardware
146 * @length: fragment length
147 * @reserved1: Reserved not used
148 * @reserved2: Reserved not used
149 *
150 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800152 uint16_t length;
153 uint32_t reserved1;
154 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155} __packed;
156
Leo Chang3bc8fed2015-11-13 10:59:47 -0800157/**
158 * struct ipa_header - ipa header type registered to IPA hardware
159 * @vdev_id: vdev id
160 * @reserved: Reserved not used
161 *
162 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800163struct ipa_header {
164 uint32_t
165 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
166 reserved:24;
167} __packed;
168
Leo Chang3bc8fed2015-11-13 10:59:47 -0800169/**
170 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
171 * @frag_hd: fragment header
172 * @ipa_hd: ipa header
173 * @eth: ether II header
174 *
175 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176struct hdd_ipa_uc_tx_hdr {
177 struct frag_header frag_hd;
178 struct ipa_header ipa_hd;
179 struct ethhdr eth;
180} __packed;
181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182/**
183 * struct hdd_ipa_cld_hdr - IPA CLD Header
184 * @reserved: reserved fields
185 * @iface_id: interface ID
186 * @sta_id: Station ID
187 *
188 * Packed 32-bit structure
189 * +----------+----------+--------------+--------+
190 * | Reserved | QCMAP ID | interface id | STA ID |
191 * +----------+----------+--------------+--------+
192 */
193struct hdd_ipa_cld_hdr {
194 uint8_t reserved[2];
195 uint8_t iface_id;
196 uint8_t sta_id;
197} __packed;
198
199struct hdd_ipa_rx_hdr {
200 struct hdd_ipa_cld_hdr cld_hdr;
201 struct ethhdr eth;
202} __packed;
203
204struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700205 bool exception;
206 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207 struct hdd_ipa_iface_context *iface_context;
208 struct ipa_rx_data *ipa_tx_desc;
209};
210
211struct hdd_ipa_uc_rx_hdr {
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_sys_pipe {
216 uint32_t conn_hdl;
217 uint8_t conn_hdl_valid;
218 struct ipa_sys_connect_params ipa_sys_params;
219};
220
221struct hdd_ipa_iface_stats {
222 uint64_t num_tx;
223 uint64_t num_tx_drop;
224 uint64_t num_tx_err;
225 uint64_t num_tx_cac_drop;
226 uint64_t num_rx_prefilter;
227 uint64_t num_rx_ipa_excep;
228 uint64_t num_rx_recv;
229 uint64_t num_rx_recv_mul;
230 uint64_t num_rx_send_desc_err;
231 uint64_t max_rx_mul;
232};
233
234struct hdd_ipa_priv;
235
236struct hdd_ipa_iface_context {
237 struct hdd_ipa_priv *hdd_ipa;
238 hdd_adapter_t *adapter;
239 void *tl_context;
240
241 enum ipa_client_type cons_client;
242 enum ipa_client_type prod_client;
243
244 uint8_t iface_id; /* This iface ID */
245 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530246 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 uint32_t ifa_address;
248 struct hdd_ipa_iface_stats stats;
Yun Park8292dcb2016-10-07 16:46:06 -0700249 uint32_t offload_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800250};
251
252struct hdd_ipa_stats {
253 uint32_t event[IPA_WLAN_EVENT_MAX];
254 uint64_t num_send_msg;
255 uint64_t num_free_msg;
256
257 uint64_t num_rm_grant;
258 uint64_t num_rm_release;
259 uint64_t num_rm_grant_imm;
260 uint64_t num_cons_perf_req;
261 uint64_t num_prod_perf_req;
262
263 uint64_t num_rx_drop;
264 uint64_t num_rx_ipa_tx_dp;
265 uint64_t num_rx_ipa_splice;
266 uint64_t num_rx_ipa_loop;
267 uint64_t num_rx_ipa_tx_dp_err;
268 uint64_t num_rx_ipa_write_done;
269 uint64_t num_max_ipa_tx_mul;
270 uint64_t num_rx_ipa_hw_maxed_out;
271 uint64_t max_pend_q_cnt;
272
273 uint64_t num_tx_comp_cnt;
274 uint64_t num_tx_queued;
275 uint64_t num_tx_dequeued;
276 uint64_t num_max_pm_queue;
277
278 uint64_t num_freeq_empty;
279 uint64_t num_pri_freeq_empty;
280 uint64_t num_rx_excep;
281 uint64_t num_tx_bcmc;
282 uint64_t num_tx_bcmc_err;
283};
284
285struct ipa_uc_stas_map {
286 bool is_reserved;
287 uint8_t sta_id;
288};
289struct op_msg_type {
290 uint8_t msg_t;
291 uint8_t rsvd;
292 uint16_t op_code;
293 uint16_t len;
294 uint16_t rsvd_snd;
295};
296
297struct ipa_uc_fw_stats {
298 uint32_t tx_comp_ring_base;
299 uint32_t tx_comp_ring_size;
300 uint32_t tx_comp_ring_dbell_addr;
301 uint32_t tx_comp_ring_dbell_ind_val;
302 uint32_t tx_comp_ring_dbell_cached_val;
303 uint32_t tx_pkts_enqueued;
304 uint32_t tx_pkts_completed;
305 uint32_t tx_is_suspend;
306 uint32_t tx_reserved;
307 uint32_t rx_ind_ring_base;
308 uint32_t rx_ind_ring_size;
309 uint32_t rx_ind_ring_dbell_addr;
310 uint32_t rx_ind_ring_dbell_ind_val;
311 uint32_t rx_ind_ring_dbell_ind_cached_val;
312 uint32_t rx_ind_ring_rdidx_addr;
313 uint32_t rx_ind_ring_rd_idx_cached_val;
314 uint32_t rx_refill_idx;
315 uint32_t rx_num_pkts_indicated;
316 uint32_t rx_buf_refilled;
317 uint32_t rx_num_ind_drop_no_space;
318 uint32_t rx_num_ind_drop_no_buf;
319 uint32_t rx_is_suspend;
320 uint32_t rx_reserved;
321};
322
323struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530324 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325 hdd_adapter_t *adapter;
326 enum ipa_wlan_event type;
327 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530328 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329};
330
331/**
332 * struct uc_rm_work_struct
333 * @work: uC RM work
334 * @event: IPA RM event
335 */
336struct uc_rm_work_struct {
337 struct work_struct work;
338 enum ipa_rm_event event;
339};
340
341/**
342 * struct uc_op_work_struct
343 * @work: uC OP work
344 * @msg: OP message
345 */
346struct uc_op_work_struct {
347 struct work_struct work;
348 struct op_msg_type *msg;
349};
350static uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
351
352/**
353 * struct uc_rt_debug_info
354 * @time: system time
355 * @ipa_excep_count: IPA exception packet count
356 * @rx_drop_count: IPA Rx drop packet count
357 * @net_sent_count: IPA Rx packet sent to network stack count
358 * @rx_discard_count: IPA Rx discard packet count
359 * @rx_mcbc_count: IPA Rx BCMC packet count
360 * @tx_mcbc_count: IPA Tx BCMC packet countt
361 * @tx_fwd_count: IPA Tx forward packet count
362 * @rx_destructor_call: IPA Rx packet destructor count
363 */
364struct uc_rt_debug_info {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530365 unsigned long time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800366 uint64_t ipa_excep_count;
367 uint64_t rx_drop_count;
368 uint64_t net_sent_count;
369 uint64_t rx_discard_count;
370 uint64_t rx_mcbc_count;
371 uint64_t tx_mcbc_count;
372 uint64_t tx_fwd_count;
373 uint64_t rx_destructor_call;
374};
375
376struct hdd_ipa_priv {
377 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
378 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
379 uint8_t num_iface;
380 enum hdd_ipa_rm_state rm_state;
381 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530382 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 * APIs as it is taken care gracefully. Without this, kernel would throw
384 * an warning if spin_lock_bh is used while IRQ is disabled
385 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530386 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 struct uc_rm_work_struct uc_rm_work;
388 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530389 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800390 struct delayed_work wake_lock_work;
391 bool wake_lock_released;
392
393 enum ipa_client_type prod_client;
394
395 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530396 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800397 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530398 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399 bool suspended;
400
401 uint32_t pending_hw_desc_cnt;
402 uint32_t hw_desc_cnt;
403 spinlock_t q_lock;
404 uint32_t freeq_cnt;
405 struct list_head free_desc_head;
406
407 uint32_t pend_q_cnt;
408 struct list_head pend_desc_head;
409
410 hdd_context_t *hdd_ctx;
411
412 struct dentry *debugfs_dir;
413 struct hdd_ipa_stats stats;
414
415 struct notifier_block ipv4_notifier;
416 uint32_t curr_prod_bw;
417 uint32_t curr_cons_bw;
418
419 uint8_t activated_fw_pipe;
420 uint8_t sap_num_connected_sta;
421 uint8_t sta_connected;
422 uint32_t tx_pipe_handle;
423 uint32_t rx_pipe_handle;
424 bool resource_loading;
425 bool resource_unloading;
426 bool pending_cons_req;
427 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530428 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530429 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700430 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800431 uint32_t ipa_tx_packets_diff;
432 uint32_t ipa_rx_packets_diff;
433 uint32_t ipa_p_tx_packets;
434 uint32_t ipa_p_rx_packets;
435 uint32_t stat_req_reason;
436 uint64_t ipa_tx_forward;
437 uint64_t ipa_rx_discard;
438 uint64_t ipa_rx_net_send_count;
439 uint64_t ipa_rx_internel_drop_count;
440 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530441 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
443 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530444 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530445 qdf_mutex_t rt_debug_lock;
446 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800447 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800448 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530449 qdf_dma_addr_t tx_comp_doorbell_paddr;
450 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451};
452
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800453/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800454 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800455 * They will be implemented fully by another update.
456 * The stubs will let the compile go ahead, and functionality
457 * is broken.
458 * This should be OK and IPA is not enabled yet
459 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700460static void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800461{
462 void *vaddr;
463 uint32_t ipa_priv = priv;
464
465 vaddr = &ipa_priv; /* just to use the var */
466 vaddr = NULL;
467 return vaddr;
468}
469
Jeff Johnsond7720632016-10-05 16:04:32 -0700470static uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800471{
472 uint32_t ipa_priv = 0;
473
474 BUG_ON(ptr == NULL);
475 return ipa_priv;
476}
Leo Changcc923e22016-06-16 15:29:03 -0700477
478#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
479#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
481#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
482#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
483#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
484#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
485#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700486#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
487 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488
Leo Chang3bc8fed2015-11-13 10:59:47 -0800489#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
490#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492#define HDD_IPA_GET_IFACE_ID(_data) \
493 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
494
495#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530496 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 "%s:%d: "fmt, __func__, __LINE__, ## args)
498
Govind Singhb6a89772016-08-12 11:23:35 +0530499#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
500 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
501 "%s:%d: "fmt, __func__, __LINE__, ## args)
502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
504 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530505 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
506 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507 } while (0)
508
509#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
510 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
511
512#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
513 do { \
514 hdd_ipa->ipa_rx_internel_drop_count++; \
515 } while (0)
516#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
517 do { \
518 hdd_ipa->ipa_rx_net_send_count++; \
519 } while (0)
520#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
521
Leo Chang07b28f62016-05-11 12:29:22 -0700522#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800523#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
524do { \
525 pipe_in.u.ul.rdy_ring_rp_va = \
526 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
527 pipe_in.u.ul.rdy_comp_ring_base_pa = \
528 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
529 pipe_in.u.ul.rdy_comp_ring_size = \
530 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
531 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
532 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
533 pipe_in.u.ul.rdy_comp_ring_wp_va = \
534 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800535} while (0)
536#else
537/* Do nothing */
538#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang07b28f62016-05-11 12:29:22 -0700539#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800540
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800541static struct hdd_ipa_adapter_2_client {
542 enum ipa_client_type cons_client;
543 enum ipa_client_type prod_client;
544} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
545 {
546 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
547 }, {
548 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
549 }, {
550 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
551 },
552};
553
554/* For Tx pipes, use Ethernet-II Header format */
555struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
556 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800557 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558 0x00000000,
559 0x00000000
560 },
561 {
562 0x00000000
563 },
564 {
565 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
566 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
567 0x0008
568 }
569};
570
571/* For Tx pipes, use 802.3 Header format */
572static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
573 {
574 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
575 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
576 0x00 /* length can be zero */
577 },
578 {
579 /* LLC SNAP header 8 bytes */
580 0xaa, 0xaa,
581 {0x03, 0x00, 0x00, 0x00},
582 0x0008 /* type value(2 bytes) ,filled by wlan */
583 /* 0x0800 - IPV4, 0x86dd - IPV6 */
584 }
585};
586
587static const char *op_string[] = {
588 "TX_SUSPEND",
589 "TX_RESUME",
590 "RX_SUSPEND",
591 "RX_RESUME",
592 "STATS",
593};
594
595static struct hdd_ipa_priv *ghdd_ipa;
596
597/* Local Function Prototypes */
598static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
599 unsigned long data);
600static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
601 unsigned long data);
602
603static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700604static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605
606/**
607 * hdd_ipa_is_enabled() - Is IPA enabled?
608 * @hdd_ctx: Global HDD context
609 *
610 * Return: true if IPA is enabled, false otherwise
611 */
612bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
613{
614 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
615}
616
617/**
618 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
619 * @hdd_ctx: Global HDD context
620 *
621 * Return: true if IPA uC offload is enabled, false otherwise
622 */
623bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
624{
625 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
626}
627
628/**
629 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
630 * @hdd_ctx: Global HDD context
631 *
632 * Return: true if STA mode IPA uC offload is enabled, false otherwise
633 */
634static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
635{
636 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
637}
638
639/**
640 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
641 * @hdd_ipa: Global HDD IPA context
642 *
643 * Return: true if pre-filter is enabled, otherwise false
644 */
645static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
646{
647 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
648 HDD_IPA_PRE_FILTER_ENABLE_MASK);
649}
650
651/**
652 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
653 * @hdd_ipa: Global HDD IPA context
654 *
655 * Return: true if IPv6 is enabled, otherwise false
656 */
657static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
658{
659 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
660}
661
662/**
663 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
664 * @hdd_ipa: Global HDD IPA context
665 *
666 * Return: true if resource manager is enabled, otherwise false
667 */
668static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
669{
670 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
671}
672
673/**
674 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
675 * @hdd_ipa: Global HDD IPA context
676 *
677 * Return: true if resource manager is enabled, otherwise false
678 */
679static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
680{
681 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
682}
683
684/**
685 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
686 * @hdd_ipa: Global HDD IPA context
687 *
688 * Return: true if clock scaling is enabled, otherwise false
689 */
690static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
691{
692 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
693 HDD_IPA_CLK_SCALING_ENABLE_MASK |
694 HDD_IPA_RM_ENABLE_MASK);
695}
696
697/**
698 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
699 * @ctext: pointer to hdd context.
700 *
701 * If rt debug enabled, periodically called, and fill debug buffer
702 *
703 * Return: none
704 */
705static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
706{
707 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
708 struct hdd_ipa_priv *hdd_ipa;
709 struct uc_rt_debug_info *dump_info = NULL;
710
711 if (wlan_hdd_validate_context(hdd_ctx))
712 return;
713
714 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530715 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800716 "%s: IPA UC is not enabled", __func__);
717 return;
718 }
719
720 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
721
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530722 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800723 dump_info = &hdd_ipa->rt_bug_buffer[
724 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
725
Anurag Chouhan210db072016-02-22 18:42:15 +0530726 dump_info->time = qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
728 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
729 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
730 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
731 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
732 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
733 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
734 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530735 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736
Anurag Chouhan210db072016-02-22 18:42:15 +0530737 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
739}
740
741/**
742 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
743 * @hdd_ctx: pointer to hdd context.
744 *
745 * If rt debug enabled, dump debug buffer contents based on requirement
746 *
747 * Return: none
748 */
749void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
750{
751 struct hdd_ipa_priv *hdd_ipa;
752 unsigned int dump_count;
753 unsigned int dump_index;
754 struct uc_rt_debug_info *dump_info = NULL;
755
756 if (wlan_hdd_validate_context(hdd_ctx))
757 return;
758
759 hdd_ipa = hdd_ctx->hdd_ipa;
760 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530761 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 "%s: IPA UC is not enabled", __func__);
763 return;
764 }
765
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530766 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530768 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
770
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530771 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772 for (dump_count = 0;
773 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
774 dump_count++) {
775 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
776 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
777 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530778 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800779 "%12lu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
780 dump_info->time, dump_info->ipa_excep_count,
781 dump_info->rx_drop_count, dump_info->net_sent_count,
782 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
783 dump_info->rx_destructor_call,
784 dump_info->rx_discard_count);
785 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530786 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530787 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
789}
790
791/**
792 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
793 * @ctext: pointer to hdd context.
794 *
795 * periodically called by timer expire
796 * will try to alloc dummy memory and detect out of memory condition
797 * if out of memory detected, dump wlan-ipa stats
798 *
799 * Return: none
800 */
801static void hdd_ipa_uc_rt_debug_handler(void *ctext)
802{
803 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
804 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
805 void *dummy_ptr = NULL;
806
807 if (wlan_hdd_validate_context(hdd_ctx))
808 return;
809
810 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530811 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 "%s: IPA RT debug is not enabled", __func__);
813 return;
814 }
815
816 /* Allocate dummy buffer periodically and free immediately. this will
817 * proactively detect OOM and if allocation fails dump ipa stats
818 */
819 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
820 GFP_KERNEL | GFP_ATOMIC);
821 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530822 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 "%s: Dummy alloc fail", __func__);
824 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
825 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800826 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800827 } else {
828 kfree(dummy_ptr);
829 }
830
Anurag Chouhan210db072016-02-22 18:42:15 +0530831 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800832 HDD_IPA_UC_RT_DEBUG_PERIOD);
833}
834
835/**
836 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
837 * @skb: packet pinter
838 *
839 * when free data packet, will be invoked by wlan client and will increase
840 * free counter
841 *
842 * Return: none
843 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700844static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845{
846 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530847 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848 "%s: invalid hdd context", __func__);
849 return;
850 }
851
852 ghdd_ipa->ipa_rx_destructor_count++;
853}
854
855/**
856 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
857 * @hdd_ctx: hdd main context
858 *
859 * free all rt debugging resources
860 *
861 * Return: none
862 */
863static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
864{
865 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
866
Anurag Chouhan210db072016-02-22 18:42:15 +0530867 if (QDF_TIMER_STATE_STOPPED !=
868 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
869 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530871 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530872 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873
874 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530875 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876 "%s: IPA RT debug is not enabled", __func__);
877 return;
878 }
879
Anurag Chouhan210db072016-02-22 18:42:15 +0530880 if (QDF_TIMER_STATE_STOPPED !=
881 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
882 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800883 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530884 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885}
886
887/**
888 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
889 * @hdd_ctx: hdd main context
890 *
891 * alloc and initialize all rt debugging resources
892 *
893 * Return: none
894 */
895static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
896{
897 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
898
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530899 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530900 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
902 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530903 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 sizeof(struct uc_rt_debug_info) *
905 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
906 hdd_ipa->ipa_tx_forward = 0;
907 hdd_ipa->ipa_rx_discard = 0;
908 hdd_ipa->ipa_rx_net_send_count = 0;
909 hdd_ipa->ipa_rx_internel_drop_count = 0;
910 hdd_ipa->ipa_rx_destructor_count = 0;
911
Anurag Chouhan210db072016-02-22 18:42:15 +0530912 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800913 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
914
915 /* Reatime debug enable on feature enable */
916 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530917 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918 "%s: IPA RT debug is not enabled", __func__);
919 return;
920 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530921 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800922 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530923 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 HDD_IPA_UC_RT_DEBUG_PERIOD);
925
926}
927
928/**
929 * hdd_ipa_uc_stat_query() - Query the IPA stats
930 * @hdd_ctx: Global HDD context
931 * @ipa_tx_diff: tx packet count diff from previous
932 * tx packet count
933 * @ipa_rx_diff: rx packet count diff from previous
934 * rx packet count
935 *
936 * Return: true if IPA is enabled, false otherwise
937 */
938void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
939 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
940{
941 struct hdd_ipa_priv *hdd_ipa;
942
943 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
944 *ipa_tx_diff = 0;
945 *ipa_rx_diff = 0;
946
947 if (!hdd_ipa_is_enabled(pHddCtx) ||
948 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
949 return;
950 }
951
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530952 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
954 (false == hdd_ipa->resource_loading)) {
955 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
956 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkf8d6a122016-10-11 15:49:43 -0700957 HDD_IPA_LOG(LOGOFF, "STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 *ipa_tx_diff, *ipa_rx_diff);
959 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530960 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 return;
962}
963
964/**
965 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
966 * @adapter: network adapter
967 * @reason: STAT REQ Reason
968 *
969 * Return: None
970 */
971void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
972{
973 hdd_context_t *pHddCtx;
974 struct hdd_ipa_priv *hdd_ipa;
975
976 if (!adapter) {
977 return;
978 }
979
980 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
981 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
982 if (!hdd_ipa_is_enabled(pHddCtx) ||
983 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
984 return;
985 }
986
987 HDD_IPA_LOG(LOG1, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530988 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
990 (false == hdd_ipa->resource_loading)) {
991 hdd_ipa->stat_req_reason = reason;
992 wma_cli_set_command(
993 (int)adapter->sessionId,
994 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
995 0, VDEV_CMD);
996 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530997 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998}
999
1000/**
1001 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1002 * @hdd_ipa: Global HDD IPA context
1003 * @sta_add: Should station be added
1004 * @sta_id: ID of the station being queried
1005 *
1006 * Return: true if the station was found
1007 */
1008static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1009 bool sta_add, uint8_t sta_id)
1010{
1011 bool sta_found = false;
1012 uint8_t idx;
1013 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1014 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1015 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1016 sta_found = true;
1017 break;
1018 }
1019 }
1020 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301021 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 "%s: STA ID %d already exist, cannot add",
1023 __func__, sta_id);
1024 return sta_found;
1025 }
1026 if (sta_add) {
1027 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1028 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1029 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1030 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1031 return sta_found;
1032 }
1033 }
1034 }
1035 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301036 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 "%s: STA ID %d does not exist, cannot delete",
1038 __func__, sta_id);
1039 return sta_found;
1040 }
1041 if (!sta_add) {
1042 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1043 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1044 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1045 hdd_ipa->assoc_stas_map[idx].is_reserved =
1046 false;
1047 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1048 return sta_found;
1049 }
1050 }
1051 }
1052 return sta_found;
1053}
1054
1055/**
1056 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1057 * @hdd_ipa: Global HDD IPA context
1058 *
1059 * Return: 0 on success, negative errno if error
1060 */
1061static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1062{
1063 int result;
1064 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1065
1066 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301067 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001068 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1069 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1071 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301072 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 "%s: Enable TX PIPE fail, code %d",
1074 __func__, result);
1075 return result;
1076 }
1077 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1078 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301079 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 "%s: Resume TX PIPE fail, code %d",
1081 __func__, result);
1082 return result;
1083 }
1084 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1085
1086 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301087 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001088 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1089 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1091 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301092 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 "%s: Enable RX PIPE fail, code %d",
1094 __func__, result);
1095 return result;
1096 }
1097 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1098 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301099 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001100 "%s: Resume RX PIPE fail, code %d",
1101 __func__, result);
1102 return result;
1103 }
1104 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001105 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001106 return 0;
1107}
1108
1109/**
1110 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1111 * @hdd_ipa: Global HDD IPA context
1112 *
1113 * Return: 0 on success, negative errno if error
1114 */
1115static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1116{
1117 int result;
1118
Leo Change3e49442015-10-26 20:07:13 -07001119 hdd_ipa->ipa_pipes_down = true;
1120
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301121 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1123 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301124 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 "%s: Suspend RX PIPE fail, code %d",
1126 __func__, result);
1127 return result;
1128 }
1129 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1130 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301131 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001132 "%s: Disable RX PIPE fail, code %d",
1133 __func__, result);
1134 return result;
1135 }
1136
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301137 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1139 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301140 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 "%s: Suspend TX PIPE fail, code %d",
1142 __func__, result);
1143 return result;
1144 }
1145 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1146 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301147 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 "%s: Disable TX PIPE fail, code %d",
1149 __func__, result);
1150 return result;
1151 }
1152
1153 return 0;
1154}
1155
1156/**
1157 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1158 * @hdd_ipa: Global HDD IPA context
1159 *
1160 * Return: 0 on success, negative errno if error
1161 */
1162static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1163{
1164 hdd_ipa->activated_fw_pipe = 0;
1165 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001166
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001167 /* If RM feature enabled
1168 * Request PROD Resource first
1169 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001170 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1171 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1172 /* RM PROD request sync return
1173 * enable pipe immediately
1174 */
1175 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301176 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001177 "%s: IPA WDI Pipe activation failed",
1178 __func__);
1179 hdd_ipa->resource_loading = false;
1180 return -EBUSY;
1181 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182 }
1183 } else {
1184 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001185 * Just enabled all the PIPEs
1186 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301188 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001189 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 __func__);
1191 hdd_ipa->resource_loading = false;
1192 return -EBUSY;
1193 }
1194 hdd_ipa->resource_loading = false;
1195 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001196
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301197 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001198 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199 return 0;
1200}
1201
1202/**
1203 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1204 * @hdd_ipa: Global HDD IPA context
1205 *
1206 * Return: None
1207 */
1208static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1209{
1210 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1211
1212 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301213 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301215 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001216 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1217}
1218
1219/**
1220 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1221 * @context: User context registered with TL (the IPA Global context is
1222 * registered
1223 * @rxpkt: Packet containing the notification
1224 * @staid: ID of the station associated with the packet
1225 *
1226 * Return: None
1227 */
1228static void
1229hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1230{
1231 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301232 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233
1234 /*
1235 * When SSR is going on or driver is unloading, just return.
1236 */
1237 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301238 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001240
1241 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1242 return;
1243
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301244 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 __func__, event);
1246
1247 switch (event) {
1248 case IPA_RM_RESOURCE_GRANTED:
1249 /* Differed RM Granted */
1250 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301251 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 if ((false == hdd_ipa->resource_unloading) &&
1253 (!hdd_ipa->activated_fw_pipe)) {
1254 hdd_ipa_uc_enable_pipes(hdd_ipa);
1255 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301256 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257 break;
1258
1259 case IPA_RM_RESOURCE_RELEASED:
1260 /* Differed RM Released */
1261 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262 break;
1263
1264 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301265 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266 "%s, invalid event code %d", __func__, event);
1267 break;
1268 }
1269}
1270
1271/**
1272 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1273 * @hdd_ipa: Global HDD IPA context
1274 * @event: IPA resource manager event to be deferred
1275 *
1276 * This function is called when a resource manager event is received
1277 * from firmware in interrupt context. This function will defer the
1278 * handling to the OL RX thread
1279 *
1280 * Return: None
1281 */
1282static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1283{
1284 enum ipa_rm_event event;
1285 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1286 struct uc_rm_work_struct, work);
1287 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1288 struct hdd_ipa_priv, uc_rm_work);
1289
1290 cds_ssr_protect(__func__);
1291 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301292 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001293 "%s, posted event %d", __func__, event);
1294
1295 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1296 cds_ssr_unprotect(__func__);
1297
1298 return;
1299}
1300
1301/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1303 * @op_msg: operation message received from firmware
1304 * @usr_ctxt: user context registered with TL (we register the HDD Global
1305 * context)
1306 *
1307 * Return: None
1308 */
1309static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1310{
1311 struct op_msg_type *msg = op_msg;
1312 struct ipa_uc_fw_stats *uc_fw_stat;
1313 struct IpaHwStatsWDIInfoData_t ipa_stat;
1314 struct hdd_ipa_priv *hdd_ipa;
1315 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301316 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001317
1318 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301319 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320 return;
1321 }
1322
1323 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301324 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1326 return;
1327 }
1328
1329 hdd_ctx = (hdd_context_t *) usr_ctxt;
1330
1331 /*
1332 * When SSR is going on or driver is unloading, just return.
1333 */
1334 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301335 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301336 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 return;
1338 }
1339
1340 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1341
Govind Singhb6a89772016-08-12 11:23:35 +05301342 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1344
1345 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1346 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301347 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 hdd_ipa->activated_fw_pipe++;
1349 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1350 hdd_ipa->resource_loading = false;
1351 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001352 if (hdd_ipa->pending_cons_req)
1353 ipa_rm_notify_completion(
1354 IPA_RM_RESOURCE_GRANTED,
1355 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001356 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301358 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001359 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301361 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 hdd_ipa->activated_fw_pipe--;
1363 if (!hdd_ipa->activated_fw_pipe) {
1364 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001365 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1366 ipa_rm_release_resource(
1367 IPA_RM_RESOURCE_WLAN_PROD);
1368 /* Sync return success from IPA
1369 * Enable/resume all the PIPEs */
1370 hdd_ipa->resource_unloading = false;
1371 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1372 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301374 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001375 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001377 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301379 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001381 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 "CE RING SIZE: %d\n"
1383 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001384 (unsigned long long)res->ce_sr_base_paddr,
1385 res->ce_sr_ring_size,
1386 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301387 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001388 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001389 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 "COMP RING SIZE: %d\n"
1391 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001392 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001393 (unsigned long long)res->tx_comp_ring_base_paddr,
1394 res->tx_comp_ring_size,
1395 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001396 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301397 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001399 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001401 "IND RING DBELL : 0x%llx\n"
1402 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 "NUM EXCP PKT : %llu\n"
1404 "NUM TX BCMC : %llu\n"
1405 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001406 (unsigned long long)res->rx_rdy_ring_base_paddr,
1407 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001408 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001409 (unsigned long long)hdd_ipa->ipa_resource.
1410 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 hdd_ipa->stats.num_rx_excep,
1412 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001413 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301414 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1416 "SAP NUM STAs: %d\n"
1417 "STA CONNECTED: %d\n"
1418 "TX PIPE HDL: %d\n"
1419 "RX PIPE HDL : %d\n"
1420 "RSC LOADING : %d\n"
1421 "RSC UNLOADING : %d\n"
1422 "PNDNG CNS RQT : %d",
1423 hdd_ipa->sap_num_connected_sta,
1424 hdd_ipa->sta_connected,
1425 hdd_ipa->tx_pipe_handle,
1426 hdd_ipa->rx_pipe_handle,
1427 (unsigned int)hdd_ipa->resource_loading,
1428 (unsigned int)hdd_ipa->resource_unloading,
1429 (unsigned int)hdd_ipa->pending_cons_req);
1430
1431 /* STATs from FW */
1432 uc_fw_stat = (struct ipa_uc_fw_stats *)
1433 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301434 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435 "==== IPA_UC WLAN_FW TX ====\n"
1436 "COMP RING BASE: 0x%x\n"
1437 "COMP RING SIZE: %d\n"
1438 "COMP RING DBELL : 0x%x\n"
1439 "COMP RING DBELL IND VAL : %d\n"
1440 "COMP RING DBELL CACHED VAL : %d\n"
1441 "COMP RING DBELL CACHED VAL : %d\n"
1442 "PKTS ENQ : %d\n"
1443 "PKTS COMP : %d\n"
1444 "IS SUSPEND : %d\n"
1445 "RSVD : 0x%x",
1446 uc_fw_stat->tx_comp_ring_base,
1447 uc_fw_stat->tx_comp_ring_size,
1448 uc_fw_stat->tx_comp_ring_dbell_addr,
1449 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1450 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1451 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1452 uc_fw_stat->tx_pkts_enqueued,
1453 uc_fw_stat->tx_pkts_completed,
1454 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301455 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 "==== IPA_UC WLAN_FW RX ====\n"
1457 "IND RING BASE: 0x%x\n"
1458 "IND RING SIZE: %d\n"
1459 "IND RING DBELL : 0x%x\n"
1460 "IND RING DBELL IND VAL : %d\n"
1461 "IND RING DBELL CACHED VAL : %d\n"
1462 "RDY IND ADDR : 0x%x\n"
1463 "RDY IND CACHE VAL : %d\n"
1464 "RFIL IND : %d\n"
1465 "NUM PKT INDICAT : %d\n"
1466 "BUF REFIL : %d\n"
1467 "NUM DROP NO SPC : %d\n"
1468 "NUM DROP NO BUF : %d\n"
1469 "IS SUSPND : %d\n"
1470 "RSVD : 0x%x\n",
1471 uc_fw_stat->rx_ind_ring_base,
1472 uc_fw_stat->rx_ind_ring_size,
1473 uc_fw_stat->rx_ind_ring_dbell_addr,
1474 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1475 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1476 uc_fw_stat->rx_ind_ring_rdidx_addr,
1477 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1478 uc_fw_stat->rx_refill_idx,
1479 uc_fw_stat->rx_num_pkts_indicated,
1480 uc_fw_stat->rx_buf_refilled,
1481 uc_fw_stat->rx_num_ind_drop_no_space,
1482 uc_fw_stat->rx_num_ind_drop_no_buf,
1483 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1484 /* STATs from IPA */
1485 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301486 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 "==== IPA_UC IPA TX ====\n"
1488 "NUM PROCD : %d\n"
1489 "CE DBELL : 0x%x\n"
1490 "NUM DBELL FIRED : %d\n"
1491 "COMP RNG FULL : %d\n"
1492 "COMP RNG EMPT : %d\n"
1493 "COMP RNG USE HGH : %d\n"
1494 "COMP RNG USE LOW : %d\n"
1495 "BAM FIFO FULL : %d\n"
1496 "BAM FIFO EMPT : %d\n"
1497 "BAM FIFO USE HGH : %d\n"
1498 "BAM FIFO USE LOW : %d\n"
1499 "NUM DBELL : %d\n"
1500 "NUM UNEXP DBELL : %d\n"
1501 "NUM BAM INT HDL : 0x%x\n"
1502 "NUM BAM INT NON-RUN : 0x%x\n"
1503 "NUM QMB INT HDL : 0x%x",
1504 ipa_stat.tx_ch_stats.num_pkts_processed,
1505 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1506 ipa_stat.tx_ch_stats.num_db_fired,
1507 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1508 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1509 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1510 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1511 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1512 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1513 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1514 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1515 ipa_stat.tx_ch_stats.num_db,
1516 ipa_stat.tx_ch_stats.num_unexpected_db,
1517 ipa_stat.tx_ch_stats.num_bam_int_handled,
1518 ipa_stat.tx_ch_stats.
1519 num_bam_int_in_non_runnning_state,
1520 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1521
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301522 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 "==== IPA_UC IPA RX ====\n"
1524 "MAX OST PKT : %d\n"
1525 "NUM PKT PRCSD : %d\n"
1526 "RNG RP : 0x%x\n"
1527 "COMP RNG FULL : %d\n"
1528 "COMP RNG EMPT : %d\n"
1529 "COMP RNG USE HGH : %d\n"
1530 "COMP RNG USE LOW : %d\n"
1531 "BAM FIFO FULL : %d\n"
1532 "BAM FIFO EMPT : %d\n"
1533 "BAM FIFO USE HGH : %d\n"
1534 "BAM FIFO USE LOW : %d\n"
1535 "NUM DB : %d\n"
1536 "NUM UNEXP DB : %d\n"
1537 "NUM BAM INT HNDL : 0x%x\n",
1538 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1539 ipa_stat.rx_ch_stats.num_pkts_processed,
1540 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1541 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1542 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1543 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1544 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1545 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1546 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1547 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1548 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1549 ipa_stat.rx_ch_stats.num_db,
1550 ipa_stat.rx_ch_stats.num_unexpected_db,
1551 ipa_stat.rx_ch_stats.num_bam_int_handled);
1552 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1553 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1554 /* STATs from FW */
1555 uc_fw_stat = (struct ipa_uc_fw_stats *)
1556 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301557 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001558 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1559 uc_fw_stat->tx_pkts_completed,
1560 hdd_ipa->ipa_p_tx_packets);
1561 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1562 (uc_fw_stat->rx_num_ind_drop_no_space +
1563 uc_fw_stat->rx_num_ind_drop_no_buf +
1564 uc_fw_stat->rx_num_pkts_indicated),
1565 hdd_ipa->ipa_p_rx_packets);
1566
1567 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1568 hdd_ipa->ipa_p_rx_packets =
1569 (uc_fw_stat->rx_num_ind_drop_no_space +
1570 uc_fw_stat->rx_num_ind_drop_no_buf +
1571 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301572 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001573 } else {
Yun Park8292dcb2016-10-07 16:46:06 -07001574 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
1575 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301577 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578}
1579
1580
1581/**
1582 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1583 * @adapter: device adapter instance
1584 * @offload_type: MCC or SCC
1585 * @enable: TX offload enable or disable
1586 *
1587 * Return: none
1588 */
1589static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1590 uint32_t offload_type, uint32_t enable)
1591{
1592 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07001593 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594
Yun Parka37592b2016-06-11 17:10:28 -07001595 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 return;
1597
Yun Park8292dcb2016-10-07 16:46:06 -07001598 iface_context = adapter->ipa_context;
1599
1600 if (!iface_context || (enable == iface_context->offload_enabled)) {
1601 /* IPA offload status is already set as desired */
1602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1603 "offload_type=%d, vdev_id=%d, enable=%d",
1604 offload_type, adapter->sessionId, enable);
1605 WARN_ON(1);
1606 return;
1607 }
1608
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1610 * channel change indication. Since these indications are sent by lower
1611 * layer as SAP updates and IPA doesn't have to do anything for these
1612 * updates so ignoring!
Yun Parka37592b2016-06-11 17:10:28 -07001613 */
1614 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 return;
1616
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301617 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 sizeof(ipa_offload_enable_disable));
1619 ipa_offload_enable_disable.offload_type = offload_type;
1620 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1621 ipa_offload_enable_disable.enable = enable;
1622
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301623 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001624 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 ipa_offload_enable_disable.offload_type,
1626 ipa_offload_enable_disable.vdev_id,
1627 ipa_offload_enable_disable.enable);
1628
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301629 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1631 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301632 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 "%s: Failure to enable IPA offload \
1634 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1635 ipa_offload_enable_disable.offload_type,
1636 ipa_offload_enable_disable.vdev_id,
1637 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001638 } else {
1639 /* Update the IPA offload status */
1640 iface_context->offload_enabled =
1641 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 }
1643}
1644
1645/**
1646 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1647 * @work: uC OP work
1648 *
1649 * Return: None
1650 */
1651static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1652{
1653 struct op_msg_type *msg;
1654 struct uc_op_work_struct *uc_op_work = container_of(work,
1655 struct uc_op_work_struct, work);
1656 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1657
1658 cds_ssr_protect(__func__);
1659
1660 msg = uc_op_work->msg;
1661 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301662 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 "%s, posted msg %d", __func__, msg->op_code);
1664
1665 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1666
1667 cds_ssr_unprotect(__func__);
1668
1669 return;
1670}
1671
1672/**
1673 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1674 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1675 * @op_msg: operation message received from firmware
1676 * @hdd_ctx: Global HDD context
1677 *
1678 * Return: None
1679 */
1680static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1681{
1682 struct hdd_ipa_priv *hdd_ipa;
1683 struct op_msg_type *msg;
1684 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301685 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001686
1687 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301688 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690
1691 msg = (struct op_msg_type *)op_msg;
1692 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1693
1694 if (unlikely(!hdd_ipa))
1695 goto end;
1696
1697 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301698 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001699 __func__, msg->op_code);
1700 goto end;
1701 }
1702
1703 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1704 if (uc_op_work->msg)
1705 /* When the same uC OPCODE is already pended, just return */
1706 goto end;
1707
1708 uc_op_work->msg = msg;
1709 schedule_work(&uc_op_work->work);
1710 return;
1711
1712end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301713 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714}
1715
1716/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001717 * hdd_ipa_init_uc_op_work - init ipa uc op work
1718 * @work: struct work_struct
1719 * @work_handler: work_handler
1720 *
1721 * Return: none
1722 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001723static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1724 work_func_t work_handler)
1725{
1726 INIT_WORK(work, work_handler);
1727}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001728
1729
1730/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1732 * @hdd_ctx: Global HDD context
1733 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301734 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001735 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301736static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001737{
1738 struct ipa_wdi_in_params pipe_in;
1739 struct ipa_wdi_out_params pipe_out;
1740 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1741 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1742 uint8_t i;
1743
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301744 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1745 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746
Anurag Chouhanffb21542016-02-17 14:33:03 +05301747 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301748 qdf_mutex_create(&ipa_ctxt->event_lock);
1749 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750
1751 /* TX PIPE */
1752 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1753 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1754 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1755 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1756 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1757 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1758 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1759 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1760 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1761 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1762 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1763 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1764 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301765 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1767 pipe_in.sys.keep_ipa_awake = true;
1768 }
1769
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001770 pipe_in.u.dl.comp_ring_base_pa =
1771 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001772 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001773 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1774 sizeof(qdf_dma_addr_t);
1775 pipe_in.u.dl.ce_ring_base_pa =
1776 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1777 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1778 pipe_in.u.dl.ce_ring_size =
1779 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1780 pipe_in.u.dl.num_tx_buffers =
1781 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782
1783 /* Connect WDI IPA PIPE */
1784 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1785 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301786 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1787 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1788 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1789 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001790 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791 /* WLAN TX PIPE Handle */
1792 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301793 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1795 " CERZ %d, NB %d, CDBPAD 0x%x",
1796 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1797 pipe_in.u.dl.comp_ring_size,
1798 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1799 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1800 pipe_in.u.dl.ce_ring_size,
1801 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001802 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803
1804 /* RX PIPE */
1805 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1806 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1807 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1808 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1809 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1810 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1811 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1812 sizeof(struct sps_iovec);
1813 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1814 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301815 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001816 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1817 pipe_in.sys.keep_ipa_awake = true;
1818 }
1819
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001820 pipe_in.u.ul.rdy_ring_base_pa =
1821 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1822 pipe_in.u.ul.rdy_ring_size =
1823 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1824 pipe_in.u.ul.rdy_ring_rp_pa =
1825 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001826 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001827 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001828 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001829 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301830 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1832 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1833 pipe_in.u.ul.rdy_ring_size,
1834 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001835 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001836
1837 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001838 ipa_ctxt->tx_comp_doorbell_paddr,
1839 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840
1841 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1842 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1843
1844 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001845 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846 hdd_ipa_uc_fw_op_event_handler);
1847 ipa_ctxt->uc_op_work[i].msg = NULL;
1848 }
1849
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301850 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001851}
1852
Leo Change3e49442015-10-26 20:07:13 -07001853/**
1854 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1855 * @hdd_ctx: hdd main context
1856 *
1857 * Force shutdown IPA pipe
1858 * Independent of FW pipe status, IPA pipe shutdonw progress
1859 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1860 * independent from FW pipe status
1861 *
1862 * Return: NONE
1863 */
1864void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1865{
1866 struct hdd_ipa_priv *hdd_ipa;
1867
1868 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1869 return;
1870
1871 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1872 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301873 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001874 "IPA pipes are not down yet, force shutdown");
1875 hdd_ipa_uc_disable_pipes(hdd_ipa);
1876 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301877 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001878 "IPA pipes are down, do nothing");
1879 }
1880
1881 return;
1882}
1883
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884/**
1885 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1886 *
1887 * Deinit basic IPA UC host side to be in sync reloaded FW during
1888 * SSR
1889 *
1890 * Return: 0 - Success
1891 */
1892int hdd_ipa_uc_ssr_deinit(void)
1893{
1894 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1895 int idx;
1896 struct hdd_ipa_iface_context *iface_context;
1897
Leo Chang3bc8fed2015-11-13 10:59:47 -08001898 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 return 0;
1900
1901 /* Clean up HDD IPA interfaces */
1902 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1903 (idx < HDD_IPA_MAX_IFACE); idx++) {
1904 iface_context = &hdd_ipa->iface_context[idx];
1905 if (iface_context && iface_context->adapter)
1906 hdd_ipa_cleanup_iface(iface_context);
1907 }
1908
1909 /* After SSR, wlan driver reloads FW again. But we need to protect
1910 * IPA submodule during SSR transient state. So deinit basic IPA
1911 * UC host side to be in sync with reloaded FW during SSR
1912 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001913 if (!hdd_ipa->ipa_pipes_down)
1914 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001915
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301916 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001917 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1918 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1919 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1920 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301921 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922
1923 /* Full IPA driver cleanup not required since wlan driver is now
1924 * unloaded and reloaded after SSR.
1925 */
1926 return 0;
1927}
1928
1929/**
1930 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1931 *
1932 * Init basic IPA UC host side to be in sync with reloaded FW after
1933 * SSR to resume IPA UC operations
1934 *
1935 * Return: 0 - Success
1936 */
1937int hdd_ipa_uc_ssr_reinit(void)
1938{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001939
1940 /* After SSR is complete, IPA UC can resume operation. But now wlan
1941 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1942 * and initialization. This is a placeholder func if IPA has to resume
1943 * operations without driver reload.
1944 */
1945 return 0;
1946}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001947
1948/**
1949 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1950 * @hdd_ctx: Global HDD context
1951 * @skb: skb sent to IPA
1952 * @session_id: send packet instance session id
1953 *
1954 * Send TX packet which generated by system to IPA.
1955 * This routine only will be used for function verification
1956 *
1957 * Return: NULL packet sent to IPA properly
1958 * NULL invalid packet drop
1959 * skb packet not sent to IPA. legacy data path should handle
1960 */
1961struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1962 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001963{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001964 struct ipa_header *ipa_header;
1965 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07001966 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001967
1968 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1969 return skb;
1970
Leo Chang07b28f62016-05-11 12:29:22 -07001971 if (!hdd_ipa)
1972 return skb;
1973
1974 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
1975 return skb;
1976
Leo Changcc923e22016-06-16 15:29:03 -07001977 if (skb_headroom(skb) <
1978 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07001979 return skb;
1980
Leo Chang3bc8fed2015-11-13 10:59:47 -08001981 ipa_header = (struct ipa_header *) skb_push(skb,
1982 sizeof(struct ipa_header));
1983 if (!ipa_header) {
1984 /* No headroom, legacy */
1985 return skb;
1986 }
1987 memset(ipa_header, 0, sizeof(*ipa_header));
1988 ipa_header->vdev_id = 0;
1989
1990 frag_header = (struct frag_header *) skb_push(skb,
1991 sizeof(struct frag_header));
1992 if (!frag_header) {
1993 /* No headroom, drop */
1994 kfree_skb(skb);
1995 return NULL;
1996 }
1997 memset(frag_header, 0, sizeof(*frag_header));
1998 frag_header->length = skb->len - sizeof(struct frag_header)
1999 - sizeof(struct ipa_header);
2000
2001 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2002 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002003}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004
2005/**
2006 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2007 * @work: scheduled work
2008 *
2009 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2010 * not want to immediately release the wake lock since the system
2011 * would then potentially try to suspend when there is a healthy data
2012 * rate. Deferred work is scheduled and this function handles the
2013 * work. When this function is called, if the IPA resource is still
2014 * released then we release the wake lock.
2015 *
2016 * Return: None
2017 */
2018static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2019{
2020 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2021 struct hdd_ipa_priv,
2022 wake_lock_work);
2023
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302024 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025
2026 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2027 goto end;
2028
2029 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302030 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031 WIFI_POWER_EVENT_WAKELOCK_IPA);
2032
2033end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302034 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035}
2036
2037/**
2038 * hdd_ipa_rm_request() - Request resource from IPA
2039 * @hdd_ipa: Global HDD IPA context
2040 *
2041 * Return: 0 on success, negative errno on error
2042 */
2043static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2044{
2045 int ret = 0;
2046
2047 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2048 return 0;
2049
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302050 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051
2052 switch (hdd_ipa->rm_state) {
2053 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302054 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002055 return 0;
2056 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302057 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058 return -EINPROGRESS;
2059 case HDD_IPA_RM_RELEASED:
2060 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2061 break;
2062 }
2063
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302064 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065
2066 ret = ipa_rm_inactivity_timer_request_resource(
2067 IPA_RM_RESOURCE_WLAN_PROD);
2068
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302069 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002070 if (ret == 0) {
2071 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2072 hdd_ipa->stats.num_rm_grant_imm++;
2073 }
2074
2075 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2076 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302077 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002078 WIFI_POWER_EVENT_WAKELOCK_IPA);
2079 hdd_ipa->wake_lock_released = false;
2080 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302081 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002082
2083 return ret;
2084}
2085
2086/**
2087 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2088 * @hdd_ipa: Global HDD IPA context
2089 *
2090 * Return: 0 if resources released, negative errno otherwise
2091 */
2092static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2093{
2094 int ret = 0;
2095
2096 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2097 return 0;
2098
2099 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2100 return -EAGAIN;
2101
2102 spin_lock_bh(&hdd_ipa->q_lock);
2103 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2104 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2105 spin_unlock_bh(&hdd_ipa->q_lock);
2106 return -EAGAIN;
2107 }
2108 spin_unlock_bh(&hdd_ipa->q_lock);
2109
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302110 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111
Nirav Shahcbc6d722016-03-01 16:24:53 +05302112 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302113 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114 return -EAGAIN;
2115 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302116 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302118 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 switch (hdd_ipa->rm_state) {
2120 case HDD_IPA_RM_GRANTED:
2121 break;
2122 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302123 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002124 return -EINPROGRESS;
2125 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302126 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002127 return 0;
2128 }
2129
2130 /* IPA driver returns immediately so set the state here to avoid any
2131 * race condition.
2132 */
2133 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2134 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302135 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002136
2137 ret =
2138 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2139
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302140 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002141 if (unlikely(ret != 0)) {
2142 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2143 WARN_ON(1);
2144 }
2145
2146 /*
2147 * If wake_lock is released immediately, kernel would try to suspend
2148 * immediately as well, Just avoid ping-pong between suspend-resume
2149 * while there is healthy amount of data transfer going on by
2150 * releasing the wake_lock after some delay.
2151 */
2152 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2153 msecs_to_jiffies
2154 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2155
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302156 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002157
2158 return ret;
2159}
2160
2161/**
2162 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2163 * @user_data: user data registered with IPA
2164 * @event: the IPA resource manager event that occurred
2165 * @data: the data associated with the event
2166 *
2167 * Return: None
2168 */
2169static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2170 unsigned long data)
2171{
2172 struct hdd_ipa_priv *hdd_ipa = user_data;
2173
2174 if (unlikely(!hdd_ipa))
2175 return;
2176
2177 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2178 return;
2179
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302180 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002181
2182 switch (event) {
2183 case IPA_RM_RESOURCE_GRANTED:
2184 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2185 /* RM Notification comes with ISR context
2186 * it should be serialized into work queue to avoid
2187 * ISR sleep problem
2188 */
2189 hdd_ipa->uc_rm_work.event = event;
2190 schedule_work(&hdd_ipa->uc_rm_work.work);
2191 break;
2192 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302193 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002194 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302195 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002196 hdd_ipa->stats.num_rm_grant++;
2197 break;
2198
2199 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302200 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002201 hdd_ipa->resource_unloading = false;
2202 break;
2203
2204 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302205 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002206 break;
2207 }
2208}
2209
2210/**
2211 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2212 *
2213 * Callback function registered with IPA that is called when IPA wants
2214 * to release the WLAN consumer resource
2215 *
2216 * Return: 0 if the request is granted, negative errno otherwise
2217 */
2218static int hdd_ipa_rm_cons_release(void)
2219{
2220 return 0;
2221}
2222
2223/**
2224 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2225 *
2226 * Callback function registered with IPA that is called when IPA wants
2227 * to access the WLAN consumer resource
2228 *
2229 * Return: 0 if the request is granted, negative errno otherwise
2230 */
2231static int hdd_ipa_rm_cons_request(void)
2232{
Yun Park4d8b60a2015-10-22 13:59:32 -07002233 int ret = 0;
2234
2235 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302236 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002237 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002238 __func__);
2239 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002240 ret = -EINPROGRESS;
2241 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302242 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002243 "%s: IPA resource unloading in progress",
2244 __func__);
2245 ghdd_ipa->pending_cons_req = true;
2246 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002247 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002248
2249 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250}
2251
2252/**
2253 * hdd_ipa_set_perf_level() - Set IPA performance level
2254 * @hdd_ctx: Global HDD context
2255 * @tx_packets: Number of packets transmitted in the last sample period
2256 * @rx_packets: Number of packets received in the last sample period
2257 *
2258 * Return: 0 on success, negative errno on error
2259 */
2260int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2261 uint64_t rx_packets)
2262{
2263 uint32_t next_cons_bw, next_prod_bw;
2264 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2265 struct ipa_rm_perf_profile profile;
2266 int ret;
2267
2268 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2269 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2270 return 0;
2271
2272 memset(&profile, 0, sizeof(profile));
2273
2274 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2275 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2276 else if (tx_packets >
2277 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2278 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2279 else
2280 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2281
2282 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2283 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2284 else if (rx_packets >
2285 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2286 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2287 else
2288 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2289
2290 HDD_IPA_LOG(LOG1,
2291 "CONS perf curr: %d, next: %d",
2292 hdd_ipa->curr_cons_bw, next_cons_bw);
2293 HDD_IPA_LOG(LOG1,
2294 "PROD perf curr: %d, next: %d",
2295 hdd_ipa->curr_prod_bw, next_prod_bw);
2296
2297 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302298 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002299 "Requesting CONS perf curr: %d, next: %d",
2300 hdd_ipa->curr_cons_bw, next_cons_bw);
2301 profile.max_supported_bandwidth_mbps = next_cons_bw;
2302 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2303 &profile);
2304 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302305 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002306 "RM CONS set perf profile failed: %d", ret);
2307
2308 return ret;
2309 }
2310 hdd_ipa->curr_cons_bw = next_cons_bw;
2311 hdd_ipa->stats.num_cons_perf_req++;
2312 }
2313
2314 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302315 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002316 "Requesting PROD perf curr: %d, next: %d",
2317 hdd_ipa->curr_prod_bw, next_prod_bw);
2318 profile.max_supported_bandwidth_mbps = next_prod_bw;
2319 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2320 &profile);
2321 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302322 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002323 "RM PROD set perf profile failed: %d", ret);
2324 return ret;
2325 }
2326 hdd_ipa->curr_prod_bw = next_prod_bw;
2327 hdd_ipa->stats.num_prod_perf_req++;
2328 }
2329
2330 return 0;
2331}
2332
2333/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002334 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2335 * @work: struct work_struct
2336 * @work_handler: work_handler
2337 *
2338 * Return: none
2339 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002340static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2341 work_func_t work_handler)
2342{
2343 INIT_WORK(work, work_handler);
2344}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002345
2346/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002347 * hdd_ipa_setup_rm() - Setup IPA resource management
2348 * @hdd_ipa: Global HDD IPA context
2349 *
2350 * Return: 0 on success, negative errno on error
2351 */
2352static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2353{
2354 struct ipa_rm_create_params create_params = { 0 };
2355 int ret;
2356
2357 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2358 return 0;
2359
Rajeev Kumar217f2172016-01-06 18:11:55 -08002360 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2361 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002362 memset(&create_params, 0, sizeof(create_params));
2363 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2364 create_params.reg_params.user_data = hdd_ipa;
2365 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2366 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2367
2368 ret = ipa_rm_create_resource(&create_params);
2369 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302370 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002371 "Create RM resource failed: %d", ret);
2372 goto setup_rm_fail;
2373 }
2374
2375 memset(&create_params, 0, sizeof(create_params));
2376 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2377 create_params.request_resource = hdd_ipa_rm_cons_request;
2378 create_params.release_resource = hdd_ipa_rm_cons_release;
2379 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2380
2381 ret = ipa_rm_create_resource(&create_params);
2382 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302383 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002384 "Create RM CONS resource failed: %d", ret);
2385 goto delete_prod;
2386 }
2387
2388 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2389 IPA_RM_RESOURCE_APPS_CONS);
2390
2391 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2392 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2393 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302394 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002395 ret);
2396 goto timer_init_failed;
2397 }
2398
2399 /* Set the lowest bandwidth to start with */
2400 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2401
2402 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302403 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 "Set perf level failed: %d", ret);
2405 goto set_perf_failed;
2406 }
2407
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302408 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002409 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2410 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302411 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2413 hdd_ipa->wake_lock_released = true;
2414 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2415
2416 return ret;
2417
2418set_perf_failed:
2419 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2420
2421timer_init_failed:
2422 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2423
2424delete_prod:
2425 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2426
2427setup_rm_fail:
2428 return ret;
2429}
2430
2431/**
2432 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2433 * @hdd_ipa: Global HDD IPA context
2434 *
2435 * Destroys all resources associated with the IPA resource manager
2436 *
2437 * Return: None
2438 */
2439static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2440{
2441 int ret;
2442
2443 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2444 return;
2445
2446 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302447 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002448
2449#ifdef WLAN_OPEN_SOURCE
2450 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2451#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302452 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002453
2454 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2455
2456 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2457 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302458 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002459 "RM PROD resource delete failed %d", ret);
2460
2461 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2462 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302463 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002464 "RM CONS resource delete failed %d", ret);
2465}
2466
2467/**
2468 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2469 * @skb: network buffer
2470 * @adapter: network adapter
2471 *
2472 * Called when a network buffer is received which should not be routed
2473 * to the IPA module.
2474 *
2475 * Return: None
2476 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302477static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002478 hdd_adapter_t *adapter)
2479{
2480 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2481 unsigned int cpu_index;
2482
2483 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302484 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002485 adapter);
2486 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002487 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 return;
2489 }
2490
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002491 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002492 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002493 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002494 return;
2495 }
2496
2497 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2498 skb->dev = adapter->dev;
2499 skb->protocol = eth_type_trans(skb, skb->dev);
2500 skb->ip_summed = CHECKSUM_NONE;
2501
2502 cpu_index = wlan_hdd_get_cpu();
2503
2504 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2505 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2506 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2507 else
2508 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2509
2510 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2511 adapter->dev->last_rx = jiffies;
2512}
2513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002514/**
Leo Chang69c39692016-10-12 20:11:12 -07002515 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2516 * @hdd_ipa: pointer to hdd ipa context
2517 * @adapter: network adapter
2518 * @skb: data pointer
2519 *
2520 * if exception packet has set forward bit, copied new packet should be
2521 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2522 * put into pm queue and tx procedure will be differed
2523 *
2524 * Return: None
2525 */
2526void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2527 hdd_adapter_t *adapter, qdf_nbuf_t skb)
2528{
2529 qdf_nbuf_t copy;
2530 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2531
2532 copy = qdf_nbuf_copy(skb);
2533 if (!copy) {
2534 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2535 return;
2536 }
2537
2538 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2539 /* WLAN subsystem is in suspend, put int queue */
2540 if (hdd_ipa->suspended) {
2541 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2542 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2543 "TX in SUSPEND PUT QUEUE");
2544 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2545 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2546 pm_tx_cb->exception = true;
2547 pm_tx_cb->adapter = adapter;
2548 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2549 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2550 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2551 hdd_ipa->stats.num_tx_queued++;
2552 } else {
2553 /* Resume, put packet into WLAN TX */
2554 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2555 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2556 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2557 "packet tx fail");
2558 } else {
2559 hdd_ipa->stats.num_tx_bcmc++;
2560 hdd_ipa->ipa_tx_forward++;
2561 }
2562 }
2563}
2564
2565/**
2566 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 * @priv: pointer to private data registered with IPA (we register a
2568 * pointer to the global IPA context)
2569 * @evt: the IPA event which triggered the callback
2570 * @data: data associated with the event
2571 *
2572 * Return: None
2573 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002574static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002575 unsigned long data)
2576{
2577 struct hdd_ipa_priv *hdd_ipa = NULL;
2578 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302579 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 uint8_t iface_id;
2581 uint8_t session_id;
2582 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002583 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002584 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002585
2586 hdd_ipa = (struct hdd_ipa_priv *)priv;
2587
2588 switch (evt) {
2589 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302590 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002591
2592 /*
2593 * When SSR is going on or driver is unloading,
2594 * just drop the packets.
2595 */
2596 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2597 if (0 != status) {
2598 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2599 "Invalid context: drop packet");
2600 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2601 kfree_skb(skb);
2602 return;
2603 }
2604
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002605 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2606 session_id = (uint8_t)skb->cb[0];
2607 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302608 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2610 session_id, iface_id);
2611 } else {
2612 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2613 }
2614
2615 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302616 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617 "IPA_RECEIVE: Invalid iface_id: %u",
2618 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302619 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002620 "w2i -- skb", skb->data, 8);
2621 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002622 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002623 return;
2624 }
2625
2626 iface_context = &hdd_ipa->iface_context[iface_id];
2627 adapter = iface_context->adapter;
2628
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302629 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002630 "w2i -- skb", skb->data, 8);
2631 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2632 hdd_ipa->stats.num_rx_excep++;
2633 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2634 } else {
2635 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2636 }
2637
2638 iface_context->stats.num_rx_ipa_excep++;
2639
2640 /* Disable to forward Intra-BSS Rx packets when
2641 * ap_isolate=1 in hostapd.conf
2642 */
Yun Park046101c2016-09-02 15:32:14 -07002643 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002644 /*
2645 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2646 * all Rx packets to IPA uC, which need to be forwarded
2647 * to other interface.
2648 * And, IPA driver will send back to WLAN host driver
2649 * through exception pipe with fw_desc field set by FW.
2650 * Here we are checking fw_desc field for FORWARD bit
2651 * set, and forward to Tx. Then copy to kernel stack
2652 * only when DISCARD bit is not set.
2653 */
2654 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002655 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302656 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302657 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002658 "Forward packet to Tx (fw_desc=%d)",
2659 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002660 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002661 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002662 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002663 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2664 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002665 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002666 break;
2667 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002668 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302669 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670 "Intra-BSS FWD is disabled-skip forward to Tx");
2671 }
2672
2673 hdd_ipa_send_skb_to_network(skb, adapter);
2674 break;
2675
2676 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302677 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002678 "w2i cb wrong event: 0x%x", evt);
2679 return;
2680 }
2681}
2682
2683/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002684 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2685 * @priv: pointer to private data registered with IPA (we register a
2686 * pointer to the global IPA context)
2687 * @evt: the IPA event which triggered the callback
2688 * @data: data associated with the event
2689 *
2690 * Return: None
2691 */
2692static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2693 unsigned long data)
2694{
2695 cds_ssr_protect(__func__);
2696 __hdd_ipa_w2i_cb(priv, evt, data);
2697 cds_ssr_unprotect(__func__);
2698}
2699
2700/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002701 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2702 * @skb: packet buffer which was transmitted
2703 *
2704 * Return: None
2705 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302706void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707{
2708 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2709
Govind Singhb6a89772016-08-12 11:23:35 +05302710 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302711 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002712 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302713 ipa_free_skb((struct ipa_rx_data *)
2714 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002715
2716 hdd_ipa->stats.num_tx_comp_cnt++;
2717
2718 atomic_dec(&hdd_ipa->tx_ref_cnt);
2719
2720 hdd_ipa_rm_try_release(hdd_ipa);
2721}
2722
2723/**
2724 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2725 * @iface_context: interface-specific IPA context
2726 * @ipa_tx_desc: packet data descriptor
2727 *
2728 * Return: None
2729 */
2730static void hdd_ipa_send_pkt_to_tl(
2731 struct hdd_ipa_iface_context *iface_context,
2732 struct ipa_rx_data *ipa_tx_desc)
2733{
2734 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2735 uint8_t interface_id;
2736 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302737 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002738
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302739 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 adapter = iface_context->adapter;
2741 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302742 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 ipa_free_skb(ipa_tx_desc);
2744 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302745 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746 hdd_ipa_rm_try_release(hdd_ipa);
2747 return;
2748 }
2749
2750 /*
2751 * During CAC period, data packets shouldn't be sent over the air so
2752 * drop all the packets here
2753 */
2754 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2755 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302756 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757 iface_context->stats.num_tx_cac_drop++;
2758 hdd_ipa_rm_try_release(hdd_ipa);
2759 return;
2760 }
2761
2762 interface_id = adapter->sessionId;
2763 ++adapter->stats.tx_packets;
2764
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302765 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002766
2767 skb = ipa_tx_desc->skb;
2768
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302769 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302770 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002771 /* FIXME: This is broken. No such field in cb any more:
2772 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002773 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302774 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002775 ipa_tx_desc->dma_addr
2776 + HDD_IPA_WLAN_FRAG_HEADER
2777 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778 ipa_tx_desc->skb->len -=
2779 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2780 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302781 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002782
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002783 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302784 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002785
2786 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2787
2788 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2789 ipa_tx_desc->skb);
2790 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302791 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792 ipa_free_skb(ipa_tx_desc);
2793 iface_context->stats.num_tx_err++;
2794 hdd_ipa_rm_try_release(hdd_ipa);
2795 return;
2796 }
2797
2798 atomic_inc(&hdd_ipa->tx_ref_cnt);
2799
2800 iface_context->stats.num_tx++;
2801
2802}
2803
2804/**
Leo Chang11545d62016-10-17 14:53:50 -07002805 * hdd_ipa_is_present() - get IPA hw status
2806 * @hdd_ctx: pointer to hdd context
2807 *
2808 * ipa_uc_reg_rdyCB is not directly designed to check
2809 * ipa hw status. This is an undocumented function which
2810 * has confirmed with IPA team.
2811 *
2812 * Return: true - ipa hw present
2813 * false - ipa hw not present
2814 */
2815bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2816{
2817 /* Check if ipa hw is enabled */
2818 if (ipa_uc_reg_rdyCB(NULL) != -EPERM)
2819 return true;
2820 else
2821 return false;
2822}
2823
2824/**
Leo Chang69c39692016-10-12 20:11:12 -07002825 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002826 * @work: pointer to the scheduled work
2827 *
2828 * Called during PM resume to send packets to TL which were queued
2829 * while host was in the process of suspending.
2830 *
2831 * Return: None
2832 */
Leo Chang69c39692016-10-12 20:11:12 -07002833static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002834{
2835 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2836 struct hdd_ipa_priv,
2837 pm_work);
2838 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302839 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002840 uint32_t dequeued = 0;
2841
Leo Chang69c39692016-10-12 20:11:12 -07002842 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2843 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302844 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302845 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2846 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302847 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002848
2849 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002851 if (pm_tx_cb->exception) {
2852 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2853 "FLUSH EXCEPTION");
2854 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2855 } else {
2856 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002857 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002858 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302859 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302861 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002862 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2863 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864
2865 hdd_ipa->stats.num_tx_dequeued += dequeued;
2866 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2867 hdd_ipa->stats.num_max_pm_queue = dequeued;
2868}
2869
2870/**
2871 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2872 * @priv: pointer to private data registered with IPA (we register a
2873 * pointer to the interface-specific IPA context)
2874 * @evt: the IPA event which triggered the callback
2875 * @data: data associated with the event
2876 *
2877 * Return: None
2878 */
2879static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2880 unsigned long data)
2881{
2882 struct hdd_ipa_priv *hdd_ipa = NULL;
2883 struct ipa_rx_data *ipa_tx_desc;
2884 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302885 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302887 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002888
Mukul Sharma81661ae2015-10-30 20:26:02 +05302889 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002890 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302891 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892 dev_kfree_skb_any(skb);
2893 iface_context->stats.num_tx_drop++;
2894 return;
2895 }
2896
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002897 ipa_tx_desc = (struct ipa_rx_data *)data;
2898
2899 hdd_ipa = iface_context->hdd_ipa;
2900
2901 /*
2902 * When SSR is going on or driver is unloading, just drop the packets.
2903 * During SSR, there is no use in queueing the packets as STA has to
2904 * connect back any way
2905 */
2906 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302907 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908 ipa_free_skb(ipa_tx_desc);
2909 iface_context->stats.num_tx_drop++;
2910 return;
2911 }
2912
2913 skb = ipa_tx_desc->skb;
2914
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302915 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002916
2917 /*
2918 * If PROD resource is not requested here then there may be cases where
2919 * IPA hardware may be clocked down because of not having proper
2920 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2921 * workaround to request PROD resource while data is going over CONS
2922 * pipe to prevent the IPA hardware clockdown.
2923 */
2924 hdd_ipa_rm_request(hdd_ipa);
2925
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302926 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 /*
2928 * If host is still suspended then queue the packets and these will be
2929 * drained later when resume completes. When packet is arrived here and
2930 * host is suspended, this means that there is already resume is in
2931 * progress.
2932 */
2933 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302934 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2936 pm_tx_cb->iface_context = iface_context;
2937 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302938 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002939 hdd_ipa->stats.num_tx_queued++;
2940
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302941 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002942 return;
2943 }
2944
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302945 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002946
2947 /*
2948 * If we are here means, host is not suspended, wait for the work queue
2949 * to finish.
2950 */
2951#ifdef WLAN_OPEN_SOURCE
2952 flush_work(&hdd_ipa->pm_work);
2953#endif
2954
2955 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2956}
2957
2958/**
2959 * hdd_ipa_suspend() - Suspend IPA
2960 * @hdd_ctx: Global HDD context
2961 *
2962 * Return: 0 on success, negativer errno on error
2963 */
2964int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2965{
2966 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2967
2968 if (!hdd_ipa_is_enabled(hdd_ctx))
2969 return 0;
2970
2971 /*
2972 * Check if IPA is ready for suspend, If we are here means, there is
2973 * high chance that suspend would go through but just to avoid any race
2974 * condition after suspend started, these checks are conducted before
2975 * allowing to suspend.
2976 */
2977 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2978 return -EAGAIN;
2979
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302980 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002981
2982 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302983 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984 return -EAGAIN;
2985 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302986 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002987
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302988 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002989 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302990 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002991
2992 return 0;
2993}
2994
2995/**
2996 * hdd_ipa_resume() - Resume IPA following suspend
2997 * hdd_ctx: Global HDD context
2998 *
2999 * Return: 0 on success, negative errno on error
3000 */
3001int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3002{
3003 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3004
3005 if (!hdd_ipa_is_enabled(hdd_ctx))
3006 return 0;
3007
3008 schedule_work(&hdd_ipa->pm_work);
3009
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303010 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303012 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003013
3014 return 0;
3015}
3016
3017/**
3018 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3019 * @hdd_ipa: Global HDD IPA context
3020 *
3021 * Return: 0 on success, negative errno on error
3022 */
3023static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3024{
3025 int i, ret = 0;
3026 struct ipa_sys_connect_params *ipa;
3027 uint32_t desc_fifo_sz;
3028
3029 /* The maximum number of descriptors that can be provided to a BAM at
3030 * once is one less than the total number of descriptors that the buffer
3031 * can contain.
3032 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3033 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3034 * be provided at once.
3035 * Because of above requirement, one extra descriptor will be added to
3036 * make sure hardware always has one descriptor.
3037 */
3038 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3039 + sizeof(struct sps_iovec);
3040
3041 /*setup TX pipes */
3042 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3043 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3044
3045 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3046 ipa->desc_fifo_sz = desc_fifo_sz;
3047 ipa->priv = &hdd_ipa->iface_context[i];
3048 ipa->notify = hdd_ipa_i2w_cb;
3049
3050 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3051 ipa->ipa_ep_cfg.hdr.hdr_len =
3052 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3053 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3054 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3055 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3056 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3057 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3058 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3059 } else {
3060 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3061 }
3062 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3063
3064 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3065 ipa->keep_ipa_awake = 1;
3066
3067 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3068 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303069 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003070 " ret: %d", i, ret);
3071 goto setup_sys_pipe_fail;
3072 }
3073 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3074 }
3075
3076 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3077 /*
3078 * Hard code it here, this can be extended if in case
3079 * PROD pipe is also per interface.
3080 * Right now there is no advantage of doing this.
3081 */
3082 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3083
3084 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3085
3086 ipa->client = hdd_ipa->prod_client;
3087
3088 ipa->desc_fifo_sz = desc_fifo_sz;
3089 ipa->priv = hdd_ipa;
3090 ipa->notify = hdd_ipa_w2i_cb;
3091
3092 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3093 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3094 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3095 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3096
3097 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3098 ipa->keep_ipa_awake = 1;
3099
3100 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3101 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303102 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003103 "Failed for RX pipe: %d", ret);
3104 goto setup_sys_pipe_fail;
3105 }
3106 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3107 }
3108
3109 return ret;
3110
3111setup_sys_pipe_fail:
3112
3113 while (--i >= 0) {
3114 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303115 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003116 sizeof(struct hdd_ipa_sys_pipe));
3117 }
3118
3119 return ret;
3120}
3121
3122/**
3123 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3124 * @hdd_ipa: Global HDD IPA context
3125 *
3126 * Return: None
3127 */
3128static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3129{
3130 int ret = 0, i;
3131 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3132 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3133 ret =
3134 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3135 conn_hdl);
3136 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303137 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138 ret);
3139
3140 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3141 }
3142 }
3143}
3144
3145/**
3146 * hdd_ipa_register_interface() - register IPA interface
3147 * @hdd_ipa: Global IPA context
3148 * @iface_context: Per-interface IPA context
3149 *
3150 * Return: 0 on success, negative errno on error
3151 */
3152static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3153 struct hdd_ipa_iface_context
3154 *iface_context)
3155{
3156 struct ipa_tx_intf tx_intf;
3157 struct ipa_rx_intf rx_intf;
3158 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3159 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3160 char *ifname = iface_context->adapter->dev->name;
3161
3162 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3163 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3164
3165 int num_prop = 1;
3166 int ret = 0;
3167
3168 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3169 num_prop++;
3170
3171 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3172 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303173 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303175 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003176 goto register_interface_fail;
3177 }
3178
3179 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3180 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303181 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303183 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184 goto register_interface_fail;
3185 }
3186
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303187 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3188 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003189
3190 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3191 ifname, HDD_IPA_IPV4_NAME_EXT);
3192 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3193 ifname, HDD_IPA_IPV6_NAME_EXT);
3194
3195 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3196 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3197 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3198 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3199
3200 /*
3201 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3202 * mask to identify the interface in IPA hardware
3203 */
3204 rx_prop[IPA_IP_v4].attrib.meta_data =
3205 htonl(iface_context->adapter->sessionId << 16);
3206 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3207
3208 rx_intf.num_props++;
3209 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3210 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3211 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3212 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3213 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3214 rx_prop[IPA_IP_v4].attrib.meta_data =
3215 htonl(iface_context->adapter->sessionId << 16);
3216 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3217
3218 rx_intf.num_props++;
3219 }
3220
3221 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3222 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3223 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3224 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3225 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3226 IPA_RESOURCE_NAME_MAX);
3227 tx_intf.num_props++;
3228
3229 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3230 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3231 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3232 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3233 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3234 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3235 IPA_RESOURCE_NAME_MAX);
3236 tx_intf.num_props++;
3237 }
3238
3239 tx_intf.prop = tx_prop;
3240 rx_intf.prop = rx_prop;
3241
3242 /* Call the ipa api to register interface */
3243 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3244
3245register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303246 qdf_mem_free(tx_prop);
3247 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248 return ret;
3249}
3250
3251/**
3252 * hdd_remove_ipa_header() - Remove a specific header from IPA
3253 * @name: Name of the header to be removed
3254 *
3255 * Return: None
3256 */
3257static void hdd_ipa_remove_header(char *name)
3258{
3259 struct ipa_ioc_get_hdr hdrlookup;
3260 int ret = 0, len;
3261 struct ipa_ioc_del_hdr *ipa_hdr;
3262
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303263 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3265 ret = ipa_get_hdr(&hdrlookup);
3266 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303267 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268 name, ret);
3269 return;
3270 }
3271
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303272 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303274 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303276 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 return;
3278 }
3279 ipa_hdr->num_hdls = 1;
3280 ipa_hdr->commit = 0;
3281 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3282 ipa_hdr->hdl[0].status = -1;
3283 ret = ipa_del_hdr(ipa_hdr);
3284 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303285 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 ret);
3287
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303288 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289}
3290
3291/**
3292 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3293 * @hdd_ipa: Global HDD IPA context
3294 * @iface_context: Interface-specific HDD IPA context
3295 * @mac_addr: Interface MAC address
3296 *
3297 * Return: 0 on success, negativer errno value on error
3298 */
3299static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3300 struct hdd_ipa_iface_context *iface_context,
3301 uint8_t *mac_addr)
3302{
3303 hdd_adapter_t *adapter = iface_context->adapter;
3304 char *ifname;
3305 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3306 int ret = -EINVAL;
3307 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3308 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3309
3310 ifname = adapter->dev->name;
3311
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303312 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003313 ifname, mac_addr);
3314
3315 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303316 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003317 + sizeof(struct ipa_hdr_add));
3318 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303319 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320 "%s: ipa_hdr allocation failed", ifname);
3321 ret = -ENOMEM;
3322 goto end;
3323 }
3324
3325 ipa_hdr->commit = 0;
3326 ipa_hdr->num_hdrs = 1;
3327
3328 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3329 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3330 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3331 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3332 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303333 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334 "ifname=%s, vdev_id=%d",
3335 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3336 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3337 ifname, HDD_IPA_IPV4_NAME_EXT);
3338 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3339 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3340 ipa_hdr->hdr[0].is_partial = 1;
3341 ipa_hdr->hdr[0].hdr_hdl = 0;
3342 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3343 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3344
3345 ret = ipa_add_hdr(ipa_hdr);
3346 } else {
3347 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3348
3349 /* Set the Source MAC */
3350 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3351 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3352
3353 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3354 ifname, HDD_IPA_IPV4_NAME_EXT);
3355 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3356 ipa_hdr->hdr[0].is_partial = 1;
3357 ipa_hdr->hdr[0].hdr_hdl = 0;
3358 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3359 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3360
3361 /* Set the type to IPV4 in the header */
3362 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3363
3364 ret = ipa_add_hdr(ipa_hdr);
3365 }
3366 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303367 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368 ifname, ret);
3369 goto end;
3370 }
3371
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303372 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3374
3375 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3376 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3377 ifname, HDD_IPA_IPV6_NAME_EXT);
3378
3379 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3380 uc_tx_hdr =
3381 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3382 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3383 } else {
3384 /* Set the type to IPV6 in the header */
3385 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3386 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3387 }
3388
3389 ret = ipa_add_hdr(ipa_hdr);
3390 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303391 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392 "%s: IPv6 add hdr failed: %d", ifname, ret);
3393 goto clean_ipv4_hdr;
3394 }
3395
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303396 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003397 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3398 }
3399
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303400 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401
3402 return ret;
3403
3404clean_ipv4_hdr:
3405 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3406 ifname, HDD_IPA_IPV4_NAME_EXT);
3407 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3408end:
3409 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303410 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411
3412 return ret;
3413}
3414
3415/**
3416 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3417 * @adapter: Adapter upon which IPA was previously configured
3418 *
3419 * Return: None
3420 */
3421static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3422{
3423 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3424 int ret;
3425 char name_ipa[IPA_RESOURCE_NAME_MAX];
3426
3427 /* Remove the headers */
3428 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3429 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3430 hdd_ipa_remove_header(name_ipa);
3431
3432 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3433 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3434 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3435 hdd_ipa_remove_header(name_ipa);
3436 }
3437 /* unregister the interface with IPA */
3438 ret = ipa_deregister_intf(adapter->dev->name);
3439 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303440 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 "%s: ipa_deregister_intf fail: %d",
3442 adapter->dev->name, ret);
3443}
3444
3445/**
3446 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3447 * @iface_context: interface-specific IPA context
3448 *
3449 * Return: None
3450 */
3451static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3452{
3453 if (iface_context == NULL)
3454 return;
3455
3456 hdd_ipa_clean_hdr(iface_context->adapter);
3457
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303458 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 iface_context->adapter->ipa_context = NULL;
3460 iface_context->adapter = NULL;
3461 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303462 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 iface_context->ifa_address = 0;
3464 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303465 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303467 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 }
3469 iface_context->hdd_ipa->num_iface--;
3470}
3471
3472/**
3473 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3474 * @hdd_ipa: HDD IPA global context
3475 * @adapter: Interface upon which IPA is being setup
3476 * @sta_id: Station ID of the API instance
3477 *
3478 * Return: 0 on success, negative errno value on error
3479 */
3480static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3481 hdd_adapter_t *adapter, uint8_t sta_id)
3482{
3483 struct hdd_ipa_iface_context *iface_context = NULL;
3484 void *tl_context = NULL;
3485 int i, ret = 0;
3486
3487 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3488 * channel change indication. Since these indications are sent by lower
3489 * layer as SAP updates and IPA doesn't have to do anything for these
3490 * updates so ignoring!
3491 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003492 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 return 0;
3494
3495 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3496 if (hdd_ipa->iface_context[i].adapter == NULL) {
3497 iface_context = &(hdd_ipa->iface_context[i]);
3498 break;
3499 }
3500 }
3501
3502 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303503 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504 "All the IPA interfaces are in use");
3505 ret = -ENOMEM;
3506 goto end;
3507 }
3508
3509 adapter->ipa_context = iface_context;
3510 iface_context->adapter = adapter;
3511 iface_context->sta_id = sta_id;
3512 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3513
3514 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303515 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516 "Not able to get TL context sta_id: %d", sta_id);
3517 ret = -EINVAL;
3518 goto end;
3519 }
3520
3521 iface_context->tl_context = tl_context;
3522
3523 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3524 adapter->dev->dev_addr);
3525
3526 if (ret)
3527 goto end;
3528
3529 /* Configure the TX and RX pipes filter rules */
3530 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3531 if (ret)
3532 goto cleanup_header;
3533
3534 hdd_ipa->num_iface++;
3535 return ret;
3536
3537cleanup_header:
3538
3539 hdd_ipa_clean_hdr(adapter);
3540end:
3541 if (iface_context)
3542 hdd_ipa_cleanup_iface(iface_context);
3543 return ret;
3544}
3545
3546/**
3547 * hdd_ipa_msg_free_fn() - Free an IPA message
3548 * @buff: pointer to the IPA message
3549 * @len: length of the IPA message
3550 * @type: type of IPA message
3551 *
3552 * Return: None
3553 */
3554static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3555{
3556 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3557 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303558 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559}
3560
Yun Parka27049a2016-10-11 12:30:49 -07003561#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562/**
3563 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3564 * @mcc_mode: 0=MCC/1=SCC
3565 *
3566 * Return: 0 on success, negative errno value on error
3567 */
3568int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3569{
3570 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303571 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003572 hdd_adapter_t *pAdapter;
3573 struct ipa_msg_meta meta;
3574 struct ipa_wlan_msg *msg;
3575 int ret;
3576
3577 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3578 return -EINVAL;
3579
3580 if (!pHddCtx->mcc_mode) {
3581 /* Flush TxRx queue for each adapter before switch to SCC */
3582 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303583 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003585 if (pAdapter->device_mode == QDF_STA_MODE ||
3586 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303587 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3589 pAdapter->device_mode);
3590 hdd_deinit_tx_rx(pAdapter);
3591 }
3592 status = hdd_get_next_adapter(
3593 pHddCtx, adapter_node, &next);
3594 adapter_node = next;
3595 }
3596 }
3597
3598 /* Send SCC/MCC Switching event to IPA */
3599 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303600 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601 if (msg == NULL) {
3602 hddLog(LOGE, "msg allocation failed");
3603 return -ENOMEM;
3604 }
3605
3606 meta.msg_type = mcc_mode ?
3607 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3608 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3609
3610 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3611
3612 if (ret) {
3613 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3614 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303615 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 }
3617
3618 return ret;
3619}
Yun Parka27049a2016-10-11 12:30:49 -07003620#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621
3622/**
3623 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3624 * @event: IPA WLAN event to be converted to a string
3625 *
3626 * Return: ASCII string representing the IPA WLAN event
3627 */
3628static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3629{
3630 switch (event) {
3631 case WLAN_CLIENT_CONNECT:
3632 return "WLAN_CLIENT_CONNECT";
3633 case WLAN_CLIENT_DISCONNECT:
3634 return "WLAN_CLIENT_DISCONNECT";
3635 case WLAN_CLIENT_POWER_SAVE_MODE:
3636 return "WLAN_CLIENT_POWER_SAVE_MODE";
3637 case WLAN_CLIENT_NORMAL_MODE:
3638 return "WLAN_CLIENT_NORMAL_MODE";
3639 case SW_ROUTING_ENABLE:
3640 return "SW_ROUTING_ENABLE";
3641 case SW_ROUTING_DISABLE:
3642 return "SW_ROUTING_DISABLE";
3643 case WLAN_AP_CONNECT:
3644 return "WLAN_AP_CONNECT";
3645 case WLAN_AP_DISCONNECT:
3646 return "WLAN_AP_DISCONNECT";
3647 case WLAN_STA_CONNECT:
3648 return "WLAN_STA_CONNECT";
3649 case WLAN_STA_DISCONNECT:
3650 return "WLAN_STA_DISCONNECT";
3651 case WLAN_CLIENT_CONNECT_EX:
3652 return "WLAN_CLIENT_CONNECT_EX";
3653
3654 case IPA_WLAN_EVENT_MAX:
3655 default:
3656 return "UNKNOWN";
3657 }
3658}
3659
3660/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003661 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3662 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3663 *
3664 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3665 */
3666static enum ipa_wlan_event
3667hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3668{
3669 enum ipa_wlan_event ipa_event;
3670
3671 switch (hdd_ipa_event_type) {
3672 case HDD_IPA_CLIENT_CONNECT:
3673 ipa_event = WLAN_CLIENT_CONNECT;
3674 break;
3675 case HDD_IPA_CLIENT_DISCONNECT:
3676 ipa_event = WLAN_CLIENT_DISCONNECT;
3677 break;
3678 case HDD_IPA_AP_CONNECT:
3679 ipa_event = WLAN_AP_CONNECT;
3680 break;
3681 case HDD_IPA_AP_DISCONNECT:
3682 ipa_event = WLAN_AP_DISCONNECT;
3683 break;
3684 case HDD_IPA_STA_CONNECT:
3685 ipa_event = WLAN_STA_CONNECT;
3686 break;
3687 case HDD_IPA_STA_DISCONNECT:
3688 ipa_event = WLAN_STA_DISCONNECT;
3689 break;
3690 case HDD_IPA_CLIENT_CONNECT_EX:
3691 ipa_event = WLAN_CLIENT_CONNECT_EX;
3692 break;
3693 case HDD_IPA_WLAN_EVENT_MAX:
3694 default:
3695 ipa_event = IPA_WLAN_EVENT_MAX;
3696 break;
3697 }
3698 return ipa_event;
3699
3700}
3701
3702/**
3703 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704 * @adapter: adapter upon which the event was received
3705 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003706 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 * @mac_address: MAC address associated with the event
3708 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003709 * This function is meant to be called from within wlan_hdd_ipa.c
3710 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003711 * Return: 0 on success, negative errno value on error
3712 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003713static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714 enum ipa_wlan_event type, uint8_t *mac_addr)
3715{
3716 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3717 struct ipa_msg_meta meta;
3718 struct ipa_wlan_msg *msg;
3719 struct ipa_wlan_msg_ex *msg_ex = NULL;
3720 int ret;
3721
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303722 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3724 mac_addr, sta_id);
3725
3726 if (type >= IPA_WLAN_EVENT_MAX)
3727 return -EINVAL;
3728
3729 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3730 return -EINVAL;
3731
3732 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303733 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734 return -EINVAL;
3735 }
3736
3737 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3738 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003739 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 return 0;
3741 }
3742
3743 /*
3744 * During IPA UC resource loading/unloading new events can be issued.
3745 * Store the events separately and handle them later.
3746 */
3747 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3748 ((hdd_ipa->resource_loading) ||
3749 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003750 unsigned int pending_event_count;
3751 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003752
Yun Parkf19e07d2015-11-20 11:34:27 -08003753 hdd_err("IPA resource %s inprogress",
3754 hdd_ipa->resource_loading ? "load":"unload");
3755
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303756 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003757
Anurag Chouhanffb21542016-02-17 14:33:03 +05303758 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003759 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3760 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303761 qdf_list_remove_front(&hdd_ipa->pending_event,
3762 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003763 } else {
3764 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303765 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003766 sizeof(struct ipa_uc_pending_event));
3767 }
3768
3769 if (!pending_event) {
3770 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303771 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772 return -ENOMEM;
3773 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003774
3775 pending_event->adapter = adapter;
3776 pending_event->sta_id = sta_id;
3777 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303778 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303780 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303781 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003782 &pending_event->node);
3783
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303784 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 return 0;
3786 }
3787
3788 hdd_ipa->stats.event[type]++;
3789
Leo Chang3bc8fed2015-11-13 10:59:47 -08003790 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791 switch (type) {
3792 case WLAN_STA_CONNECT:
3793 /* STA already connected and without disconnect, connect again
3794 * This is Roaming scenario
3795 */
3796 if (hdd_ipa->sta_connected)
3797 hdd_ipa_cleanup_iface(adapter->ipa_context);
3798
Yun Parka37592b2016-06-11 17:10:28 -07003799 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3800 (hdd_ipa->sap_num_connected_sta > 0) &&
3801 !hdd_ipa->sta_connected)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802 hdd_ipa_uc_offload_enable_disable(adapter,
3803 SIR_STA_RX_DATA_OFFLOAD, 1);
3804
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303805 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003807 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3808 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303809 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07003810 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3811 (hdd_ipa->sap_num_connected_sta > 0) &&
3812 !hdd_ipa->sta_connected)
3813 hdd_ipa_uc_offload_enable_disable(adapter,
3814 SIR_STA_RX_DATA_OFFLOAD, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003816 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818 vdev_to_iface[adapter->sessionId] =
3819 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003820 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303822 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823
3824 hdd_ipa->sta_connected = 1;
3825 break;
3826
3827 case WLAN_AP_CONNECT:
3828 /* For DFS channel we get two start_bss event (before and after
3829 * CAC). Also when ACS range includes both DFS and non DFS
3830 * channels, we could possibly change channel many times due to
3831 * RADAR detection and chosen channel may not be a DFS channels.
3832 * So dont return error here. Just discard the event.
3833 */
3834 if (adapter->ipa_context)
3835 return 0;
3836
Yun Parka37592b2016-06-11 17:10:28 -07003837 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003838 hdd_ipa_uc_offload_enable_disable(adapter,
3839 SIR_AP_RX_DATA_OFFLOAD, 1);
Yun Parka37592b2016-06-11 17:10:28 -07003840
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303841 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3843 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303844 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 "%s: Evt: %d, Interface setup failed",
3846 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303847 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003849 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851 vdev_to_iface[adapter->sessionId] =
3852 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003853 (adapter->ipa_context))->iface_id;
3854
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303855 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003856 break;
3857
3858 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303859 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860 hdd_ipa_cleanup_iface(adapter->ipa_context);
3861
3862 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303863 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864 "%s: Evt: %d, STA already disconnected",
3865 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303866 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 return -EINVAL;
3868 }
Yun Parka37592b2016-06-11 17:10:28 -07003869
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003871
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003872 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303873 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003874 "%s: IPA UC OFFLOAD NOT ENABLED",
3875 msg_ex->name);
3876 } else {
3877 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003878 if (!hdd_ipa->num_iface &&
3879 (HDD_IPA_UC_NUM_WDI_PIPE ==
3880 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882 }
3883
Yun Park74127cf2016-09-18 11:22:41 -07003884 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3885 (hdd_ipa->sap_num_connected_sta > 0)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 hdd_ipa_uc_offload_enable_disable(adapter,
3887 SIR_STA_RX_DATA_OFFLOAD, 0);
3888 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3889 }
3890
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303891 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003892 break;
3893
3894 case WLAN_AP_DISCONNECT:
3895 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303896 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 "%s: Evt: %d, SAP already disconnected",
3898 msg_ex->name, meta.msg_type);
3899 return -EINVAL;
3900 }
3901
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303902 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 hdd_ipa_cleanup_iface(adapter->ipa_context);
3904 if ((!hdd_ipa->num_iface) &&
3905 (HDD_IPA_UC_NUM_WDI_PIPE ==
3906 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003907 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 /*
3909 * We disable WDI pipes directly here since
3910 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3911 * processed when unloading WLAN driver is in
3912 * progress
3913 */
3914 hdd_ipa_uc_disable_pipes(hdd_ipa);
3915 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303916 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 "NO INTF left but still pipe clean up");
3918 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3919 }
3920 }
3921
3922 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3923 hdd_ipa_uc_offload_enable_disable(adapter,
3924 SIR_AP_RX_DATA_OFFLOAD, 0);
3925 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3926 }
Yun Parka37592b2016-06-11 17:10:28 -07003927
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303928 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 break;
3930
3931 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303932 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 adapter->dev->ifindex, sta_id);
3934
3935 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303936 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3938 adapter->dev->name, meta.msg_type);
3939 return 0;
3940 }
3941
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303942 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3944 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303945 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 "%s: STA ID %d found, not valid",
3947 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303948 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 return 0;
3950 }
Yun Park312f71a2015-12-08 10:22:42 -08003951
3952 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07003953 if (0 == hdd_ipa->sap_num_connected_sta) {
3954 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3955 hdd_ipa->sta_connected)
3956 hdd_ipa_uc_offload_enable_disable(
3957 hdd_get_adapter(hdd_ipa->hdd_ctx,
3958 QDF_STA_MODE),
3959 SIR_STA_RX_DATA_OFFLOAD, 1);
3960
Yun Park312f71a2015-12-08 10:22:42 -08003961 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3962 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303963 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303964 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003965 "%s: handle 1st con ret %d",
3966 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07003967
3968 if (hdd_ipa_uc_sta_is_enabled(
3969 hdd_ipa->hdd_ctx) &&
3970 hdd_ipa->sta_connected)
3971 hdd_ipa_uc_offload_enable_disable(
3972 hdd_get_adapter(
3973 hdd_ipa->hdd_ctx,
3974 QDF_STA_MODE),
3975 SIR_STA_RX_DATA_OFFLOAD, 0);
3976
Yun Park312f71a2015-12-08 10:22:42 -08003977 return ret;
3978 }
3979 }
3980
3981 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003982
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303983 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984
3985 meta.msg_type = type;
3986 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3987 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303988 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989
3990 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303991 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992 "msg_ex allocation failed");
3993 return -ENOMEM;
3994 }
3995 strlcpy(msg_ex->name, adapter->dev->name,
3996 IPA_RESOURCE_NAME_MAX);
3997 msg_ex->num_of_attribs = 1;
3998 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
3999 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4000 msg_ex->attribs[0].offset =
4001 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4002 } else {
4003 msg_ex->attribs[0].offset =
4004 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4005 }
4006 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4007 IPA_MAC_ADDR_SIZE);
4008
4009 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4010
4011 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304012 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304014 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015 return ret;
4016 }
4017 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 return ret;
4019
4020 case WLAN_CLIENT_DISCONNECT:
4021 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304022 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 "%s: IPA UC OFFLOAD NOT ENABLED",
4024 msg_ex->name);
4025 return 0;
4026 }
4027
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304028 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304030 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004031 "%s: STA ID %d NOT found, not valid",
4032 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304033 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034 return 0;
4035 }
4036 hdd_ipa->sap_num_connected_sta--;
4037 /* Disable IPA UC TX PIPE when last STA disconnected */
4038 if (!hdd_ipa->sap_num_connected_sta
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039 && (false == hdd_ipa->resource_unloading)
4040 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4041 hdd_ipa->activated_fw_pipe))
4042 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Yun Parka37592b2016-06-11 17:10:28 -07004043
4044 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4045 hdd_ipa->sta_connected)
4046 hdd_ipa_uc_offload_enable_disable(
4047 hdd_get_adapter(hdd_ipa->hdd_ctx,
4048 QDF_STA_MODE),
4049 SIR_STA_RX_DATA_OFFLOAD, 0);
4050
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304051 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052 break;
4053
4054 default:
4055 return 0;
4056 }
4057
4058 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304059 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004060 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304061 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062 return -ENOMEM;
4063 }
4064
4065 meta.msg_type = type;
4066 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4067 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4068
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304069 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004070 msg->name, meta.msg_type);
4071
4072 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4073
4074 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304075 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304077 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 return ret;
4079 }
4080
4081 hdd_ipa->stats.num_send_msg++;
4082
4083end:
4084 return ret;
4085}
4086
4087/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004088 * hdd_ipa_wlan_evt() - IPA event handler
4089 * @adapter: adapter upon which the event was received
4090 * @sta_id: station id for the event
4091 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4092 * @mac_address: MAC address associated with the event
4093 *
4094 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4095 *
4096 * Return: 0 on success, negative errno value on error
4097 */
4098int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4099 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4100{
4101 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4102
Leo Changa202b522016-10-14 16:13:50 -07004103 /* Data path offload only support for STA and SAP mode */
4104 if ((QDF_STA_MODE == adapter->device_mode) ||
4105 (QDF_SAP_MODE == adapter->device_mode))
4106 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4107
4108 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004109}
4110
4111/**
4112 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4113 * @hdd_ipa: Global HDD IPA context
4114 *
4115 * Return: None
4116 */
4117static void
4118hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4119{
4120 unsigned int pending_event_count;
4121 struct ipa_uc_pending_event *pending_event = NULL;
4122
4123 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4124 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4125 "%s, Pending Event Count %d", __func__, pending_event_count);
4126 if (!pending_event_count) {
4127 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4128 "%s, No Pending Event", __func__);
4129 return;
4130 }
4131
4132 qdf_list_remove_front(&hdd_ipa->pending_event,
4133 (qdf_list_node_t **)&pending_event);
4134 while (pending_event != NULL) {
4135 __hdd_ipa_wlan_evt(pending_event->adapter,
4136 pending_event->type,
4137 pending_event->sta_id,
4138 pending_event->mac_addr);
4139 qdf_mem_free(pending_event);
4140 pending_event = NULL;
4141 qdf_list_remove_front(&hdd_ipa->pending_event,
4142 (qdf_list_node_t **)&pending_event);
4143 }
4144}
4145
4146/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4148 * @state: IPA RM state value
4149 *
4150 * Return: ASCII string representing the IPA RM state
4151 */
4152static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4153{
4154 switch (state) {
4155 case HDD_IPA_RM_RELEASED:
4156 return "RELEASED";
4157 case HDD_IPA_RM_GRANT_PENDING:
4158 return "GRANT_PENDING";
4159 case HDD_IPA_RM_GRANTED:
4160 return "GRANTED";
4161 }
4162
4163 return "UNKNOWN";
4164}
4165
4166/**
4167 * hdd_ipa_init() - IPA initialization function
4168 * @hdd_ctx: HDD global context
4169 *
4170 * Allocate hdd_ipa resources, ipa pipe resource and register
4171 * wlan interface with IPA module.
4172 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304173 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304175QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176{
4177 struct hdd_ipa_priv *hdd_ipa = NULL;
4178 int ret, i;
4179 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004180 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181
4182 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304183 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184
Yun Park7f171ab2016-07-29 15:44:22 -07004185 if (!pdev) {
4186 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4187 goto fail_return;
4188 }
4189
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304190 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004191 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304192 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004193 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 }
4195
4196 hdd_ctx->hdd_ipa = hdd_ipa;
4197 ghdd_ipa = hdd_ipa;
4198 hdd_ipa->hdd_ctx = hdd_ctx;
4199 hdd_ipa->num_iface = 0;
Yun Park7f171ab2016-07-29 15:44:22 -07004200 ol_txrx_ipa_uc_get_resource(pdev, &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004201 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4202 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4203 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4204 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304205 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004206 "IPA UC resource alloc fail");
4207 goto fail_get_resource;
4208 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004209
4210 /* Create the interface context */
4211 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4212 iface_context = &hdd_ipa->iface_context[i];
4213 iface_context->hdd_ipa = hdd_ipa;
4214 iface_context->cons_client =
4215 hdd_ipa_adapter_2_client[i].cons_client;
4216 iface_context->prod_client =
4217 hdd_ipa_adapter_2_client[i].prod_client;
4218 iface_context->iface_id = i;
4219 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004220 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304221 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004222 }
4223
Leo Chang69c39692016-10-12 20:11:12 -07004224 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304225 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304226 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227
4228 ret = hdd_ipa_setup_rm(hdd_ipa);
4229 if (ret)
4230 goto fail_setup_rm;
4231
4232 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4233 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304234 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 hdd_ipa->sap_num_connected_sta = 0;
4236 hdd_ipa->ipa_tx_packets_diff = 0;
4237 hdd_ipa->ipa_rx_packets_diff = 0;
4238 hdd_ipa->ipa_p_tx_packets = 0;
4239 hdd_ipa->ipa_p_rx_packets = 0;
4240 hdd_ipa->resource_loading = false;
4241 hdd_ipa->resource_unloading = false;
4242 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004243 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 /* Setup IPA sys_pipe for MCC */
4245 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4246 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4247 if (ret)
4248 goto fail_create_sys_pipe;
4249 }
4250 hdd_ipa_uc_ol_init(hdd_ctx);
4251 } else {
4252 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4253 if (ret)
4254 goto fail_create_sys_pipe;
4255 }
4256
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304257 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258
4259fail_create_sys_pipe:
4260 hdd_ipa_destroy_rm_resource(hdd_ipa);
4261fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304262 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004263fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304264 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004265 hdd_ctx->hdd_ipa = NULL;
4266 ghdd_ipa = NULL;
4267fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304268 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269}
4270
4271/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004272 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4273 * @hdd_ipa: pointer to HDD IPA struct
4274 *
4275 * Return: none
4276 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004277static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004278{
4279 struct ipa_uc_pending_event *pending_event = NULL;
4280
Anurag Chouhanffb21542016-02-17 14:33:03 +05304281 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4282 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304283 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004284 }
4285
Anurag Chouhanffb21542016-02-17 14:33:03 +05304286 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004287}
4288
4289/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004290 * hdd_ipa_cleanup - IPA cleanup function
4291 * @hdd_ctx: HDD global context
4292 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304293 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304295QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296{
4297 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4298 int i;
4299 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304300 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4302
4303 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304304 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305
4306 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4307 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4308 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4309 }
4310
4311 /* Teardown IPA sys_pipe for MCC */
4312 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4313 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4314
4315 hdd_ipa_destroy_rm_resource(hdd_ipa);
4316
4317#ifdef WLAN_OPEN_SOURCE
4318 cancel_work_sync(&hdd_ipa->pm_work);
4319#endif
4320
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304321 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322
Nirav Shahcbc6d722016-03-01 16:24:53 +05304323 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4324 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304325 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326
4327 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4328 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4329
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304330 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304332 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304334 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335
4336 /* destory the interface lock */
4337 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4338 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304339 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 }
4341
4342 /* This should never hit but still make sure that there are no pending
4343 * descriptor in IPA hardware
4344 */
4345 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304346 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 "IPA Pending write done: %d Waiting!",
4348 hdd_ipa->pending_hw_desc_cnt);
4349
4350 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4351 usleep_range(100, 100);
4352 }
4353
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304354 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355 "IPA Pending write done: desc: %d %s(%d)!",
4356 hdd_ipa->pending_hw_desc_cnt,
4357 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4358 : "leak", i);
4359 }
4360 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4361 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304362 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304363 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4364 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004365 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304366 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304367 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4368 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304370 qdf_mutex_destroy(&hdd_ipa->event_lock);
4371 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004372 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373
4374#ifdef WLAN_OPEN_SOURCE
4375 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4376 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4377 hdd_ipa->uc_op_work[i].msg = NULL;
4378 }
4379#endif
4380 }
4381
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304382 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383 hdd_ctx->hdd_ipa = NULL;
4384
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304385 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386}
4387#endif /* IPA_OFFLOAD */