blob: 8c6dc29ed9f723f99ad20dc5ea58d024e35f8fd9 [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 */
38#include <wlan_hdd_includes.h>
39#include <wlan_hdd_ipa.h>
40
41#include <linux/etherdevice.h>
42#include <linux/atomic.h>
43#include <linux/netdevice.h>
44#include <linux/skbuff.h>
45#include <linux/list.h>
46#include <linux/debugfs.h>
47#include <linux/inetdevice.h>
48#include <linux/ip.h>
49#include <wlan_hdd_softap_tx_rx.h>
50#include <ol_txrx_osif_api.h>
51
52#include "cds_sched.h"
53
54#include "wma.h"
55#include "wma_api.h"
56
57#define HDD_IPA_DESC_BUFFER_RATIO 4
58#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
59#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
60
61#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
62#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET 12
63#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
64/* WDI TX and RX PIPE */
65#define HDD_IPA_UC_NUM_WDI_PIPE 2
66#define HDD_IPA_UC_MAX_PENDING_EVENT 33
67
68#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
69#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
70#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
71#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
72
73#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
74#define HDD_IPA_MAX_IFACE 3
75#define HDD_IPA_MAX_SYSBAM_PIPE 4
76#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
77#define HDD_IPA_ENABLE_MASK BIT(0)
78#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
79#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
80#define HDD_IPA_RM_ENABLE_MASK BIT(3)
81#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
82#define HDD_IPA_UC_ENABLE_MASK BIT(5)
83#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
84#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
85
Yun Parkf19e07d2015-11-20 11:34:27 -080086#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
87
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088typedef enum {
89 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
90 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
91 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
92 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
93 HDD_IPA_UC_OPCODE_STATS = 4,
94 /* keep this last */
95 HDD_IPA_UC_OPCODE_MAX
96} hdd_ipa_uc_op_code;
97
98/**
99 * enum - Reason codes for stat query
100 *
101 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
102 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
103 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
104 */
105enum {
106 HDD_IPA_UC_STAT_REASON_NONE,
107 HDD_IPA_UC_STAT_REASON_DEBUG,
108 HDD_IPA_UC_STAT_REASON_BW_CAL
109};
110
111/**
112 * enum hdd_ipa_rm_state - IPA resource manager state
113 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
114 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
115 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
116 */
117enum hdd_ipa_rm_state {
118 HDD_IPA_RM_RELEASED,
119 HDD_IPA_RM_GRANT_PENDING,
120 HDD_IPA_RM_GRANTED,
121};
122
123struct llc_snap_hdr {
124 uint8_t dsap;
125 uint8_t ssap;
126 uint8_t resv[4];
127 __be16 eth_type;
128} __packed;
129
Leo Chang3bc8fed2015-11-13 10:59:47 -0800130/**
131 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
132 * @eth: ether II header
133 * @llc_snap: LLC snap header
134 *
135 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800136struct hdd_ipa_tx_hdr {
137 struct ethhdr eth;
138 struct llc_snap_hdr llc_snap;
139} __packed;
140
Leo Chang3bc8fed2015-11-13 10:59:47 -0800141/**
142 * struct frag_header - fragment header type registered to IPA hardware
143 * @length: fragment length
144 * @reserved1: Reserved not used
145 * @reserved2: Reserved not used
146 *
147 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800149 uint16_t length;
150 uint32_t reserved1;
151 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800152} __packed;
153
Leo Chang3bc8fed2015-11-13 10:59:47 -0800154/**
155 * struct ipa_header - ipa header type registered to IPA hardware
156 * @vdev_id: vdev id
157 * @reserved: Reserved not used
158 *
159 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160struct ipa_header {
161 uint32_t
162 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
163 reserved:24;
164} __packed;
165
Leo Chang3bc8fed2015-11-13 10:59:47 -0800166/**
167 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
168 * @frag_hd: fragment header
169 * @ipa_hd: ipa header
170 * @eth: ether II header
171 *
172 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800173struct hdd_ipa_uc_tx_hdr {
174 struct frag_header frag_hd;
175 struct ipa_header ipa_hd;
176 struct ethhdr eth;
177} __packed;
178
179#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
180#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct frag_header)
181
182/**
183 * struct hdd_ipa_cld_hdr - IPA CLD Header
184 * @reserved: reserved fields
185 * @iface_id: interface ID
186 * @sta_id: Station ID
187 *
188 * Packed 32-bit structure
189 * +----------+----------+--------------+--------+
190 * | Reserved | QCMAP ID | interface id | STA ID |
191 * +----------+----------+--------------+--------+
192 */
193struct hdd_ipa_cld_hdr {
194 uint8_t reserved[2];
195 uint8_t iface_id;
196 uint8_t sta_id;
197} __packed;
198
199struct hdd_ipa_rx_hdr {
200 struct hdd_ipa_cld_hdr cld_hdr;
201 struct ethhdr eth;
202} __packed;
203
204struct hdd_ipa_pm_tx_cb {
205 struct hdd_ipa_iface_context *iface_context;
206 struct ipa_rx_data *ipa_tx_desc;
207};
208
209struct hdd_ipa_uc_rx_hdr {
210 struct ethhdr eth;
211} __packed;
212
213struct hdd_ipa_sys_pipe {
214 uint32_t conn_hdl;
215 uint8_t conn_hdl_valid;
216 struct ipa_sys_connect_params ipa_sys_params;
217};
218
219struct hdd_ipa_iface_stats {
220 uint64_t num_tx;
221 uint64_t num_tx_drop;
222 uint64_t num_tx_err;
223 uint64_t num_tx_cac_drop;
224 uint64_t num_rx_prefilter;
225 uint64_t num_rx_ipa_excep;
226 uint64_t num_rx_recv;
227 uint64_t num_rx_recv_mul;
228 uint64_t num_rx_send_desc_err;
229 uint64_t max_rx_mul;
230};
231
232struct hdd_ipa_priv;
233
234struct hdd_ipa_iface_context {
235 struct hdd_ipa_priv *hdd_ipa;
236 hdd_adapter_t *adapter;
237 void *tl_context;
238
239 enum ipa_client_type cons_client;
240 enum ipa_client_type prod_client;
241
242 uint8_t iface_id; /* This iface ID */
243 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530244 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800245 uint32_t ifa_address;
246 struct hdd_ipa_iface_stats stats;
247};
248
249struct hdd_ipa_stats {
250 uint32_t event[IPA_WLAN_EVENT_MAX];
251 uint64_t num_send_msg;
252 uint64_t num_free_msg;
253
254 uint64_t num_rm_grant;
255 uint64_t num_rm_release;
256 uint64_t num_rm_grant_imm;
257 uint64_t num_cons_perf_req;
258 uint64_t num_prod_perf_req;
259
260 uint64_t num_rx_drop;
261 uint64_t num_rx_ipa_tx_dp;
262 uint64_t num_rx_ipa_splice;
263 uint64_t num_rx_ipa_loop;
264 uint64_t num_rx_ipa_tx_dp_err;
265 uint64_t num_rx_ipa_write_done;
266 uint64_t num_max_ipa_tx_mul;
267 uint64_t num_rx_ipa_hw_maxed_out;
268 uint64_t max_pend_q_cnt;
269
270 uint64_t num_tx_comp_cnt;
271 uint64_t num_tx_queued;
272 uint64_t num_tx_dequeued;
273 uint64_t num_max_pm_queue;
274
275 uint64_t num_freeq_empty;
276 uint64_t num_pri_freeq_empty;
277 uint64_t num_rx_excep;
278 uint64_t num_tx_bcmc;
279 uint64_t num_tx_bcmc_err;
280};
281
282struct ipa_uc_stas_map {
283 bool is_reserved;
284 uint8_t sta_id;
285};
286struct op_msg_type {
287 uint8_t msg_t;
288 uint8_t rsvd;
289 uint16_t op_code;
290 uint16_t len;
291 uint16_t rsvd_snd;
292};
293
294struct ipa_uc_fw_stats {
295 uint32_t tx_comp_ring_base;
296 uint32_t tx_comp_ring_size;
297 uint32_t tx_comp_ring_dbell_addr;
298 uint32_t tx_comp_ring_dbell_ind_val;
299 uint32_t tx_comp_ring_dbell_cached_val;
300 uint32_t tx_pkts_enqueued;
301 uint32_t tx_pkts_completed;
302 uint32_t tx_is_suspend;
303 uint32_t tx_reserved;
304 uint32_t rx_ind_ring_base;
305 uint32_t rx_ind_ring_size;
306 uint32_t rx_ind_ring_dbell_addr;
307 uint32_t rx_ind_ring_dbell_ind_val;
308 uint32_t rx_ind_ring_dbell_ind_cached_val;
309 uint32_t rx_ind_ring_rdidx_addr;
310 uint32_t rx_ind_ring_rd_idx_cached_val;
311 uint32_t rx_refill_idx;
312 uint32_t rx_num_pkts_indicated;
313 uint32_t rx_buf_refilled;
314 uint32_t rx_num_ind_drop_no_space;
315 uint32_t rx_num_ind_drop_no_buf;
316 uint32_t rx_is_suspend;
317 uint32_t rx_reserved;
318};
319
320struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530321 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322 hdd_adapter_t *adapter;
323 enum ipa_wlan_event type;
324 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530325 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326};
327
328/**
329 * struct uc_rm_work_struct
330 * @work: uC RM work
331 * @event: IPA RM event
332 */
333struct uc_rm_work_struct {
334 struct work_struct work;
335 enum ipa_rm_event event;
336};
337
338/**
339 * struct uc_op_work_struct
340 * @work: uC OP work
341 * @msg: OP message
342 */
343struct uc_op_work_struct {
344 struct work_struct work;
345 struct op_msg_type *msg;
346};
347static uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
348
349/**
350 * struct uc_rt_debug_info
351 * @time: system time
352 * @ipa_excep_count: IPA exception packet count
353 * @rx_drop_count: IPA Rx drop packet count
354 * @net_sent_count: IPA Rx packet sent to network stack count
355 * @rx_discard_count: IPA Rx discard packet count
356 * @rx_mcbc_count: IPA Rx BCMC packet count
357 * @tx_mcbc_count: IPA Tx BCMC packet countt
358 * @tx_fwd_count: IPA Tx forward packet count
359 * @rx_destructor_call: IPA Rx packet destructor count
360 */
361struct uc_rt_debug_info {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530362 unsigned long time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 uint64_t ipa_excep_count;
364 uint64_t rx_drop_count;
365 uint64_t net_sent_count;
366 uint64_t rx_discard_count;
367 uint64_t rx_mcbc_count;
368 uint64_t tx_mcbc_count;
369 uint64_t tx_fwd_count;
370 uint64_t rx_destructor_call;
371};
372
373struct hdd_ipa_priv {
374 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
375 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
376 uint8_t num_iface;
377 enum hdd_ipa_rm_state rm_state;
378 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530379 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 * APIs as it is taken care gracefully. Without this, kernel would throw
381 * an warning if spin_lock_bh is used while IRQ is disabled
382 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530383 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800384 struct uc_rm_work_struct uc_rm_work;
385 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530386 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 struct delayed_work wake_lock_work;
388 bool wake_lock_released;
389
390 enum ipa_client_type prod_client;
391
392 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530393 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800394 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530395 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396 bool suspended;
397
398 uint32_t pending_hw_desc_cnt;
399 uint32_t hw_desc_cnt;
400 spinlock_t q_lock;
401 uint32_t freeq_cnt;
402 struct list_head free_desc_head;
403
404 uint32_t pend_q_cnt;
405 struct list_head pend_desc_head;
406
407 hdd_context_t *hdd_ctx;
408
409 struct dentry *debugfs_dir;
410 struct hdd_ipa_stats stats;
411
412 struct notifier_block ipv4_notifier;
413 uint32_t curr_prod_bw;
414 uint32_t curr_cons_bw;
415
416 uint8_t activated_fw_pipe;
417 uint8_t sap_num_connected_sta;
418 uint8_t sta_connected;
419 uint32_t tx_pipe_handle;
420 uint32_t rx_pipe_handle;
421 bool resource_loading;
422 bool resource_unloading;
423 bool pending_cons_req;
424 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530425 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530426 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700427 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800428 uint32_t ipa_tx_packets_diff;
429 uint32_t ipa_rx_packets_diff;
430 uint32_t ipa_p_tx_packets;
431 uint32_t ipa_p_rx_packets;
432 uint32_t stat_req_reason;
433 uint64_t ipa_tx_forward;
434 uint64_t ipa_rx_discard;
435 uint64_t ipa_rx_net_send_count;
436 uint64_t ipa_rx_internel_drop_count;
437 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530438 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800439 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
440 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530441 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530442 qdf_mutex_t rt_debug_lock;
443 qdf_mutex_t ipa_lock;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800444
445 /* CE resources */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530446 qdf_dma_addr_t ce_sr_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800447 uint32_t ce_sr_ring_size;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530448 qdf_dma_addr_t ce_reg_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800449
450 /* WLAN TX:IPA->WLAN */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530451 qdf_dma_addr_t tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800452 uint32_t tx_comp_ring_size;
453 uint32_t tx_num_alloc_buffer;
454
455 /* WLAN RX:WLAN->IPA */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530456 qdf_dma_addr_t rx_rdy_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800457 uint32_t rx_rdy_ring_size;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530458 qdf_dma_addr_t rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800459 void *rx_proc_done_idx_vaddr;
460
461 /* WLAN RX2:WLAN->IPA */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530462 qdf_dma_addr_t rx2_rdy_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800463 uint32_t rx2_rdy_ring_size;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530464 qdf_dma_addr_t rx2_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800465 void *rx2_proc_done_idx_vaddr;
466
467 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530468 qdf_dma_addr_t tx_comp_doorbell_paddr;
469 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800470};
471
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800472/**
473 * FIXME: The following conversion routines will are just stubs.
474 * They will be implemented fully by another update.
475 * The stubs will let the compile go ahead, and functionality
476 * is broken.
477 * This should be OK and IPA is not enabled yet
478 */
479void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
480{
481 void *vaddr;
482 uint32_t ipa_priv = priv;
483
484 vaddr = &ipa_priv; /* just to use the var */
485 vaddr = NULL;
486 return vaddr;
487}
488
489uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
490{
491 uint32_t ipa_priv = 0;
492
493 BUG_ON(ptr == NULL);
494 return ipa_priv;
495}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
497#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
498#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
499#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
500#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
501#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
502
Leo Chang3bc8fed2015-11-13 10:59:47 -0800503#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
504#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
505
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800506#define HDD_IPA_GET_IFACE_ID(_data) \
507 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
508
509#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530510 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511 "%s:%d: "fmt, __func__, __LINE__, ## args)
512
513#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
514 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530515 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
516 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800517 } while (0)
518
519#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
520 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
521
522#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
523 do { \
524 hdd_ipa->ipa_rx_internel_drop_count++; \
525 } while (0)
526#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
527 do { \
528 hdd_ipa->ipa_rx_net_send_count++; \
529 } while (0)
530#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
531
Leo Chang3bc8fed2015-11-13 10:59:47 -0800532/* Temporary macro to make a build without IPA V2 */
533#ifdef IPA_V2
534#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
535do { \
536 pipe_in.u.ul.rdy_ring_rp_va = ipa_ctxt->rx_proc_done_idx_vaddr; \
537 pipe_in.u.ul.rdy_comp_ring_base_pa = ipa_ctxt->rx2_rdy_ring_base_paddr;\
538 pipe_in.u.ul.rdy_comp_ring_size = ipa_ctxt->rx2_rdy_ring_size; \
539 pipe_in.u.ul.rdy_comp_ring_wp_pa = ipa_ctxt->rx2_proc_done_idx_paddr; \
540 pipe_in.u.ul.rdy_comp_ring_wp_va = ipa_ctxt->rx2_proc_done_idx_vaddr; \
541} while (0)
542#else
543/* Do nothing */
544#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
545#endif /* IPA_V2 */
546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800547static struct hdd_ipa_adapter_2_client {
548 enum ipa_client_type cons_client;
549 enum ipa_client_type prod_client;
550} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
551 {
552 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
553 }, {
554 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
555 }, {
556 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
557 },
558};
559
560/* For Tx pipes, use Ethernet-II Header format */
561struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
562 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800563 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564 0x00000000,
565 0x00000000
566 },
567 {
568 0x00000000
569 },
570 {
571 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
572 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
573 0x0008
574 }
575};
576
577/* For Tx pipes, use 802.3 Header format */
578static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
579 {
580 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
581 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
582 0x00 /* length can be zero */
583 },
584 {
585 /* LLC SNAP header 8 bytes */
586 0xaa, 0xaa,
587 {0x03, 0x00, 0x00, 0x00},
588 0x0008 /* type value(2 bytes) ,filled by wlan */
589 /* 0x0800 - IPV4, 0x86dd - IPV6 */
590 }
591};
592
593static const char *op_string[] = {
594 "TX_SUSPEND",
595 "TX_RESUME",
596 "RX_SUSPEND",
597 "RX_RESUME",
598 "STATS",
599};
600
601static struct hdd_ipa_priv *ghdd_ipa;
602
603/* Local Function Prototypes */
604static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
605 unsigned long data);
606static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
607 unsigned long data);
608
609static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
610
611/**
612 * hdd_ipa_is_enabled() - Is IPA enabled?
613 * @hdd_ctx: Global HDD context
614 *
615 * Return: true if IPA is enabled, false otherwise
616 */
617bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
618{
619 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
620}
621
622/**
623 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
624 * @hdd_ctx: Global HDD context
625 *
626 * Return: true if IPA uC offload is enabled, false otherwise
627 */
628bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
629{
630 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
631}
632
633/**
634 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
635 * @hdd_ctx: Global HDD context
636 *
637 * Return: true if STA mode IPA uC offload is enabled, false otherwise
638 */
639static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
640{
641 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
642}
643
644/**
645 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
646 * @hdd_ipa: Global HDD IPA context
647 *
648 * Return: true if pre-filter is enabled, otherwise false
649 */
650static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
651{
652 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
653 HDD_IPA_PRE_FILTER_ENABLE_MASK);
654}
655
656/**
657 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
658 * @hdd_ipa: Global HDD IPA context
659 *
660 * Return: true if IPv6 is enabled, otherwise false
661 */
662static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
663{
664 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
665}
666
667/**
668 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
669 * @hdd_ipa: Global HDD IPA context
670 *
671 * Return: true if resource manager is enabled, otherwise false
672 */
673static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
674{
675 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
676}
677
678/**
679 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
680 * @hdd_ipa: Global HDD IPA context
681 *
682 * Return: true if resource manager is enabled, otherwise false
683 */
684static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
685{
686 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
687}
688
689/**
690 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
691 * @hdd_ipa: Global HDD IPA context
692 *
693 * Return: true if clock scaling is enabled, otherwise false
694 */
695static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
696{
697 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
698 HDD_IPA_CLK_SCALING_ENABLE_MASK |
699 HDD_IPA_RM_ENABLE_MASK);
700}
701
702/**
703 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
704 * @ctext: pointer to hdd context.
705 *
706 * If rt debug enabled, periodically called, and fill debug buffer
707 *
708 * Return: none
709 */
710static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
711{
712 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
713 struct hdd_ipa_priv *hdd_ipa;
714 struct uc_rt_debug_info *dump_info = NULL;
715
716 if (wlan_hdd_validate_context(hdd_ctx))
717 return;
718
719 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530720 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800721 "%s: IPA UC is not enabled", __func__);
722 return;
723 }
724
725 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
726
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530727 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800728 dump_info = &hdd_ipa->rt_bug_buffer[
729 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
730
Anurag Chouhan210db072016-02-22 18:42:15 +0530731 dump_info->time = qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800732 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
733 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
734 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
735 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
736 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
737 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
738 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
739 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530740 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741
Anurag Chouhan210db072016-02-22 18:42:15 +0530742 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
744}
745
746/**
747 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
748 * @hdd_ctx: pointer to hdd context.
749 *
750 * If rt debug enabled, dump debug buffer contents based on requirement
751 *
752 * Return: none
753 */
754void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
755{
756 struct hdd_ipa_priv *hdd_ipa;
757 unsigned int dump_count;
758 unsigned int dump_index;
759 struct uc_rt_debug_info *dump_info = NULL;
760
761 if (wlan_hdd_validate_context(hdd_ctx))
762 return;
763
764 hdd_ipa = hdd_ctx->hdd_ipa;
765 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530766 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800767 "%s: IPA UC is not enabled", __func__);
768 return;
769 }
770
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530771 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530773 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
775
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530776 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777 for (dump_count = 0;
778 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
779 dump_count++) {
780 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
781 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
782 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530783 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 "%12lu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
785 dump_info->time, dump_info->ipa_excep_count,
786 dump_info->rx_drop_count, dump_info->net_sent_count,
787 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
788 dump_info->rx_destructor_call,
789 dump_info->rx_discard_count);
790 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530791 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530792 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
794}
795
796/**
797 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
798 * @ctext: pointer to hdd context.
799 *
800 * periodically called by timer expire
801 * will try to alloc dummy memory and detect out of memory condition
802 * if out of memory detected, dump wlan-ipa stats
803 *
804 * Return: none
805 */
806static void hdd_ipa_uc_rt_debug_handler(void *ctext)
807{
808 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
809 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
810 void *dummy_ptr = NULL;
811
812 if (wlan_hdd_validate_context(hdd_ctx))
813 return;
814
815 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530816 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 "%s: IPA RT debug is not enabled", __func__);
818 return;
819 }
820
821 /* Allocate dummy buffer periodically and free immediately. this will
822 * proactively detect OOM and if allocation fails dump ipa stats
823 */
824 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
825 GFP_KERNEL | GFP_ATOMIC);
826 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530827 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 "%s: Dummy alloc fail", __func__);
829 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
830 hdd_ipa_uc_stat_request(
831 hdd_get_adapter(hdd_ctx, WLAN_HDD_SOFTAP), 1);
832 } else {
833 kfree(dummy_ptr);
834 }
835
Anurag Chouhan210db072016-02-22 18:42:15 +0530836 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 HDD_IPA_UC_RT_DEBUG_PERIOD);
838}
839
840/**
841 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
842 * @skb: packet pinter
843 *
844 * when free data packet, will be invoked by wlan client and will increase
845 * free counter
846 *
847 * Return: none
848 */
849void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
850{
851 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530852 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 "%s: invalid hdd context", __func__);
854 return;
855 }
856
857 ghdd_ipa->ipa_rx_destructor_count++;
858}
859
860/**
861 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
862 * @hdd_ctx: hdd main context
863 *
864 * free all rt debugging resources
865 *
866 * Return: none
867 */
868static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
869{
870 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
871
Anurag Chouhan210db072016-02-22 18:42:15 +0530872 if (QDF_TIMER_STATE_STOPPED !=
873 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
874 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530876 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530877 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878
879 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530880 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881 "%s: IPA RT debug is not enabled", __func__);
882 return;
883 }
884
Anurag Chouhan210db072016-02-22 18:42:15 +0530885 if (QDF_TIMER_STATE_STOPPED !=
886 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
887 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530889 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890}
891
892/**
893 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
894 * @hdd_ctx: hdd main context
895 *
896 * alloc and initialize all rt debugging resources
897 *
898 * Return: none
899 */
900static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
901{
902 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
903
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530904 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530905 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800906 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
907 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530908 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 sizeof(struct uc_rt_debug_info) *
910 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
911 hdd_ipa->ipa_tx_forward = 0;
912 hdd_ipa->ipa_rx_discard = 0;
913 hdd_ipa->ipa_rx_net_send_count = 0;
914 hdd_ipa->ipa_rx_internel_drop_count = 0;
915 hdd_ipa->ipa_rx_destructor_count = 0;
916
Anurag Chouhan210db072016-02-22 18:42:15 +0530917 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
919
920 /* Reatime debug enable on feature enable */
921 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530922 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 "%s: IPA RT debug is not enabled", __func__);
924 return;
925 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530926 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530928 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800929 HDD_IPA_UC_RT_DEBUG_PERIOD);
930
931}
932
933/**
934 * hdd_ipa_uc_stat_query() - Query the IPA stats
935 * @hdd_ctx: Global HDD context
936 * @ipa_tx_diff: tx packet count diff from previous
937 * tx packet count
938 * @ipa_rx_diff: rx packet count diff from previous
939 * rx packet count
940 *
941 * Return: true if IPA is enabled, false otherwise
942 */
943void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
944 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
945{
946 struct hdd_ipa_priv *hdd_ipa;
947
948 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
949 *ipa_tx_diff = 0;
950 *ipa_rx_diff = 0;
951
952 if (!hdd_ipa_is_enabled(pHddCtx) ||
953 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
954 return;
955 }
956
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530957 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800958 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
959 (false == hdd_ipa->resource_loading)) {
960 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
961 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
962 HDD_IPA_LOG(LOG1, "STAT Query TX DIFF %d, RX DIFF %d",
963 *ipa_tx_diff, *ipa_rx_diff);
964 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530965 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966 return;
967}
968
969/**
970 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
971 * @adapter: network adapter
972 * @reason: STAT REQ Reason
973 *
974 * Return: None
975 */
976void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
977{
978 hdd_context_t *pHddCtx;
979 struct hdd_ipa_priv *hdd_ipa;
980
981 if (!adapter) {
982 return;
983 }
984
985 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
986 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
987 if (!hdd_ipa_is_enabled(pHddCtx) ||
988 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
989 return;
990 }
991
992 HDD_IPA_LOG(LOG1, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530993 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
995 (false == hdd_ipa->resource_loading)) {
996 hdd_ipa->stat_req_reason = reason;
997 wma_cli_set_command(
998 (int)adapter->sessionId,
999 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
1000 0, VDEV_CMD);
1001 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301002 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003}
1004
1005/**
1006 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1007 * @hdd_ipa: Global HDD IPA context
1008 * @sta_add: Should station be added
1009 * @sta_id: ID of the station being queried
1010 *
1011 * Return: true if the station was found
1012 */
1013static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1014 bool sta_add, uint8_t sta_id)
1015{
1016 bool sta_found = false;
1017 uint8_t idx;
1018 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1019 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1020 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1021 sta_found = true;
1022 break;
1023 }
1024 }
1025 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301026 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 "%s: STA ID %d already exist, cannot add",
1028 __func__, sta_id);
1029 return sta_found;
1030 }
1031 if (sta_add) {
1032 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1033 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1034 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1035 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1036 return sta_found;
1037 }
1038 }
1039 }
1040 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301041 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 "%s: STA ID %d does not exist, cannot delete",
1043 __func__, sta_id);
1044 return sta_found;
1045 }
1046 if (!sta_add) {
1047 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1048 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1049 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1050 hdd_ipa->assoc_stas_map[idx].is_reserved =
1051 false;
1052 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1053 return sta_found;
1054 }
1055 }
1056 }
1057 return sta_found;
1058}
1059
1060/**
1061 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1062 * @hdd_ipa: Global HDD IPA context
1063 *
1064 * Return: 0 on success, negative errno if error
1065 */
1066static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1067{
1068 int result;
1069 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1070
1071 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301072 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001073 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1074 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1076 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301077 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001078 "%s: Enable TX PIPE fail, code %d",
1079 __func__, result);
1080 return result;
1081 }
1082 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1083 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301084 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 "%s: Resume TX PIPE fail, code %d",
1086 __func__, result);
1087 return result;
1088 }
1089 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1090
1091 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301092 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001093 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1094 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1096 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301097 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 "%s: Enable RX PIPE fail, code %d",
1099 __func__, result);
1100 return result;
1101 }
1102 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1103 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301104 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 "%s: Resume RX PIPE fail, code %d",
1106 __func__, result);
1107 return result;
1108 }
1109 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001110 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 return 0;
1112}
1113
1114/**
1115 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1116 * @hdd_ipa: Global HDD IPA context
1117 *
1118 * Return: 0 on success, negative errno if error
1119 */
1120static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1121{
1122 int result;
1123
Leo Change3e49442015-10-26 20:07:13 -07001124 hdd_ipa->ipa_pipes_down = true;
1125
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301126 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1128 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301129 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001130 "%s: Suspend RX PIPE fail, code %d",
1131 __func__, result);
1132 return result;
1133 }
1134 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1135 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301136 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001137 "%s: Disable RX PIPE fail, code %d",
1138 __func__, result);
1139 return result;
1140 }
1141
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301142 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001143 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1144 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301145 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 "%s: Suspend TX PIPE fail, code %d",
1147 __func__, result);
1148 return result;
1149 }
1150 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1151 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301152 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001153 "%s: Disable TX PIPE fail, code %d",
1154 __func__, result);
1155 return result;
1156 }
1157
1158 return 0;
1159}
1160
1161/**
1162 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1163 * @hdd_ipa: Global HDD IPA context
1164 *
1165 * Return: 0 on success, negative errno if error
1166 */
1167static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1168{
1169 hdd_ipa->activated_fw_pipe = 0;
1170 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001172 /* If RM feature enabled
1173 * Request PROD Resource first
1174 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001175 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1176 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1177 /* RM PROD request sync return
1178 * enable pipe immediately
1179 */
1180 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301181 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001182 "%s: IPA WDI Pipe activation failed",
1183 __func__);
1184 hdd_ipa->resource_loading = false;
1185 return -EBUSY;
1186 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 }
1188 } else {
1189 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001190 * Just enabled all the PIPEs
1191 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301193 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001194 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195 __func__);
1196 hdd_ipa->resource_loading = false;
1197 return -EBUSY;
1198 }
1199 hdd_ipa->resource_loading = false;
1200 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001201
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301202 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001203 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 return 0;
1205}
1206
1207/**
1208 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1209 * @hdd_ipa: Global HDD IPA context
1210 *
1211 * Return: None
1212 */
1213static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1214{
1215 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1216
1217 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301218 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301220 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1222}
1223
1224/**
1225 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1226 * @context: User context registered with TL (the IPA Global context is
1227 * registered
1228 * @rxpkt: Packet containing the notification
1229 * @staid: ID of the station associated with the packet
1230 *
1231 * Return: None
1232 */
1233static void
1234hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1235{
1236 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301237 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001238
1239 /*
1240 * When SSR is going on or driver is unloading, just return.
1241 */
1242 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
1243 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301244 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 return;
1246 }
1247
1248 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1249 return;
1250
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301251 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 __func__, event);
1253
1254 switch (event) {
1255 case IPA_RM_RESOURCE_GRANTED:
1256 /* Differed RM Granted */
1257 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301258 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259 if ((false == hdd_ipa->resource_unloading) &&
1260 (!hdd_ipa->activated_fw_pipe)) {
1261 hdd_ipa_uc_enable_pipes(hdd_ipa);
1262 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301263 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 break;
1265
1266 case IPA_RM_RESOURCE_RELEASED:
1267 /* Differed RM Released */
1268 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 break;
1270
1271 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301272 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273 "%s, invalid event code %d", __func__, event);
1274 break;
1275 }
1276}
1277
1278/**
1279 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1280 * @hdd_ipa: Global HDD IPA context
1281 * @event: IPA resource manager event to be deferred
1282 *
1283 * This function is called when a resource manager event is received
1284 * from firmware in interrupt context. This function will defer the
1285 * handling to the OL RX thread
1286 *
1287 * Return: None
1288 */
1289static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1290{
1291 enum ipa_rm_event event;
1292 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1293 struct uc_rm_work_struct, work);
1294 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1295 struct hdd_ipa_priv, uc_rm_work);
1296
1297 cds_ssr_protect(__func__);
1298 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301299 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001300 "%s, posted event %d", __func__, event);
1301
1302 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1303 cds_ssr_unprotect(__func__);
1304
1305 return;
1306}
1307
1308/**
1309 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
1310 * @hdd_ipa: Global HDD IPA context
1311 *
1312 * Return: None
1313 */
1314static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
1315{
1316 unsigned int pending_event_count;
1317 struct ipa_uc_pending_event *pending_event = NULL;
1318
Anurag Chouhanffb21542016-02-17 14:33:03 +05301319 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301320 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 "%s, Pending Event Count %d", __func__, pending_event_count);
1322 if (!pending_event_count) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301323 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324 "%s, No Pending Event", __func__);
1325 return;
1326 }
1327
Anurag Chouhanffb21542016-02-17 14:33:03 +05301328 qdf_list_remove_front(&hdd_ipa->pending_event,
1329 (qdf_list_node_t **)&pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 while (pending_event != NULL) {
1331 hdd_ipa_wlan_evt(pending_event->adapter,
1332 pending_event->type,
1333 pending_event->sta_id,
1334 pending_event->mac_addr);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301335 qdf_mem_free(pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001336 pending_event = NULL;
Anurag Chouhanffb21542016-02-17 14:33:03 +05301337 qdf_list_remove_front(&hdd_ipa->pending_event,
1338 (qdf_list_node_t **)&pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001339 }
1340}
1341
1342/**
1343 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1344 * @op_msg: operation message received from firmware
1345 * @usr_ctxt: user context registered with TL (we register the HDD Global
1346 * context)
1347 *
1348 * Return: None
1349 */
1350static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1351{
1352 struct op_msg_type *msg = op_msg;
1353 struct ipa_uc_fw_stats *uc_fw_stat;
1354 struct IpaHwStatsWDIInfoData_t ipa_stat;
1355 struct hdd_ipa_priv *hdd_ipa;
1356 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301357 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358
1359 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301360 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 return;
1362 }
1363
1364 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301365 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1367 return;
1368 }
1369
1370 hdd_ctx = (hdd_context_t *) usr_ctxt;
1371
1372 /*
1373 * When SSR is going on or driver is unloading, just return.
1374 */
1375 status = wlan_hdd_validate_context(hdd_ctx);
1376 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301377 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301378 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 return;
1380 }
1381
1382 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1383
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301384 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1386
1387 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1388 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301389 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 hdd_ipa->activated_fw_pipe++;
1391 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1392 hdd_ipa->resource_loading = false;
1393 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001394 if (hdd_ipa->pending_cons_req)
1395 ipa_rm_notify_completion(
1396 IPA_RM_RESOURCE_GRANTED,
1397 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001398 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301400 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 }
1402
1403 if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
1404 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301405 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 hdd_ipa->activated_fw_pipe--;
1407 if (!hdd_ipa->activated_fw_pipe) {
1408 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001409 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1410 ipa_rm_release_resource(
1411 IPA_RM_RESOURCE_WLAN_PROD);
1412 /* Sync return success from IPA
1413 * Enable/resume all the PIPEs */
1414 hdd_ipa->resource_unloading = false;
1415 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1416 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301418 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 }
1420
1421 if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1422 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
1423
1424 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301425 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001427 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 "CE RING SIZE: %d\n"
1429 "CE REG ADDR : 0x%llx",
Manikandan Mohan22b83722015-12-15 15:03:23 -08001430 (unsigned long long)hdd_ipa->ce_sr_base_paddr,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001431 hdd_ipa->ce_sr_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001432 (unsigned long long)hdd_ipa->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301433 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001435 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001436 "COMP RING SIZE: %d\n"
1437 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001438 "COMP RING DBELL : 0x%llx",
Manikandan Mohan22b83722015-12-15 15:03:23 -08001439 (unsigned long long)hdd_ipa->tx_comp_ring_base_paddr,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001440 hdd_ipa->tx_comp_ring_size,
1441 hdd_ipa->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001442 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301443 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001445 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001447 "IND RING DBELL : 0x%llx\n"
1448 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 "NUM EXCP PKT : %llu\n"
1450 "NUM TX BCMC : %llu\n"
1451 "NUM TX BCMC ERR : %llu",
Manikandan Mohan22b83722015-12-15 15:03:23 -08001452 (unsigned long long)hdd_ipa->rx_rdy_ring_base_paddr,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001453 hdd_ipa->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001454 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
1455 (unsigned long long)hdd_ipa->rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 hdd_ipa->stats.num_rx_excep,
1457 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001458 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301459 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1461 "SAP NUM STAs: %d\n"
1462 "STA CONNECTED: %d\n"
1463 "TX PIPE HDL: %d\n"
1464 "RX PIPE HDL : %d\n"
1465 "RSC LOADING : %d\n"
1466 "RSC UNLOADING : %d\n"
1467 "PNDNG CNS RQT : %d",
1468 hdd_ipa->sap_num_connected_sta,
1469 hdd_ipa->sta_connected,
1470 hdd_ipa->tx_pipe_handle,
1471 hdd_ipa->rx_pipe_handle,
1472 (unsigned int)hdd_ipa->resource_loading,
1473 (unsigned int)hdd_ipa->resource_unloading,
1474 (unsigned int)hdd_ipa->pending_cons_req);
1475
1476 /* STATs from FW */
1477 uc_fw_stat = (struct ipa_uc_fw_stats *)
1478 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301479 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480 "==== IPA_UC WLAN_FW TX ====\n"
1481 "COMP RING BASE: 0x%x\n"
1482 "COMP RING SIZE: %d\n"
1483 "COMP RING DBELL : 0x%x\n"
1484 "COMP RING DBELL IND VAL : %d\n"
1485 "COMP RING DBELL CACHED VAL : %d\n"
1486 "COMP RING DBELL CACHED VAL : %d\n"
1487 "PKTS ENQ : %d\n"
1488 "PKTS COMP : %d\n"
1489 "IS SUSPEND : %d\n"
1490 "RSVD : 0x%x",
1491 uc_fw_stat->tx_comp_ring_base,
1492 uc_fw_stat->tx_comp_ring_size,
1493 uc_fw_stat->tx_comp_ring_dbell_addr,
1494 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1495 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1496 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1497 uc_fw_stat->tx_pkts_enqueued,
1498 uc_fw_stat->tx_pkts_completed,
1499 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301500 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001501 "==== IPA_UC WLAN_FW RX ====\n"
1502 "IND RING BASE: 0x%x\n"
1503 "IND RING SIZE: %d\n"
1504 "IND RING DBELL : 0x%x\n"
1505 "IND RING DBELL IND VAL : %d\n"
1506 "IND RING DBELL CACHED VAL : %d\n"
1507 "RDY IND ADDR : 0x%x\n"
1508 "RDY IND CACHE VAL : %d\n"
1509 "RFIL IND : %d\n"
1510 "NUM PKT INDICAT : %d\n"
1511 "BUF REFIL : %d\n"
1512 "NUM DROP NO SPC : %d\n"
1513 "NUM DROP NO BUF : %d\n"
1514 "IS SUSPND : %d\n"
1515 "RSVD : 0x%x\n",
1516 uc_fw_stat->rx_ind_ring_base,
1517 uc_fw_stat->rx_ind_ring_size,
1518 uc_fw_stat->rx_ind_ring_dbell_addr,
1519 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1520 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1521 uc_fw_stat->rx_ind_ring_rdidx_addr,
1522 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1523 uc_fw_stat->rx_refill_idx,
1524 uc_fw_stat->rx_num_pkts_indicated,
1525 uc_fw_stat->rx_buf_refilled,
1526 uc_fw_stat->rx_num_ind_drop_no_space,
1527 uc_fw_stat->rx_num_ind_drop_no_buf,
1528 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1529 /* STATs from IPA */
1530 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301531 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 "==== IPA_UC IPA TX ====\n"
1533 "NUM PROCD : %d\n"
1534 "CE DBELL : 0x%x\n"
1535 "NUM DBELL FIRED : %d\n"
1536 "COMP RNG FULL : %d\n"
1537 "COMP RNG EMPT : %d\n"
1538 "COMP RNG USE HGH : %d\n"
1539 "COMP RNG USE LOW : %d\n"
1540 "BAM FIFO FULL : %d\n"
1541 "BAM FIFO EMPT : %d\n"
1542 "BAM FIFO USE HGH : %d\n"
1543 "BAM FIFO USE LOW : %d\n"
1544 "NUM DBELL : %d\n"
1545 "NUM UNEXP DBELL : %d\n"
1546 "NUM BAM INT HDL : 0x%x\n"
1547 "NUM BAM INT NON-RUN : 0x%x\n"
1548 "NUM QMB INT HDL : 0x%x",
1549 ipa_stat.tx_ch_stats.num_pkts_processed,
1550 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1551 ipa_stat.tx_ch_stats.num_db_fired,
1552 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1553 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1554 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1555 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1556 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1557 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1558 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1559 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1560 ipa_stat.tx_ch_stats.num_db,
1561 ipa_stat.tx_ch_stats.num_unexpected_db,
1562 ipa_stat.tx_ch_stats.num_bam_int_handled,
1563 ipa_stat.tx_ch_stats.
1564 num_bam_int_in_non_runnning_state,
1565 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1566
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301567 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 "==== IPA_UC IPA RX ====\n"
1569 "MAX OST PKT : %d\n"
1570 "NUM PKT PRCSD : %d\n"
1571 "RNG RP : 0x%x\n"
1572 "COMP RNG FULL : %d\n"
1573 "COMP RNG EMPT : %d\n"
1574 "COMP RNG USE HGH : %d\n"
1575 "COMP RNG USE LOW : %d\n"
1576 "BAM FIFO FULL : %d\n"
1577 "BAM FIFO EMPT : %d\n"
1578 "BAM FIFO USE HGH : %d\n"
1579 "BAM FIFO USE LOW : %d\n"
1580 "NUM DB : %d\n"
1581 "NUM UNEXP DB : %d\n"
1582 "NUM BAM INT HNDL : 0x%x\n",
1583 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1584 ipa_stat.rx_ch_stats.num_pkts_processed,
1585 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1586 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1587 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1588 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1589 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1590 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1591 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1592 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1593 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1594 ipa_stat.rx_ch_stats.num_db,
1595 ipa_stat.rx_ch_stats.num_unexpected_db,
1596 ipa_stat.rx_ch_stats.num_bam_int_handled);
1597 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1598 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1599 /* STATs from FW */
1600 uc_fw_stat = (struct ipa_uc_fw_stats *)
1601 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301602 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1604 uc_fw_stat->tx_pkts_completed,
1605 hdd_ipa->ipa_p_tx_packets);
1606 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1607 (uc_fw_stat->rx_num_ind_drop_no_space +
1608 uc_fw_stat->rx_num_ind_drop_no_buf +
1609 uc_fw_stat->rx_num_pkts_indicated),
1610 hdd_ipa->ipa_p_rx_packets);
1611
1612 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1613 hdd_ipa->ipa_p_rx_packets =
1614 (uc_fw_stat->rx_num_ind_drop_no_space +
1615 uc_fw_stat->rx_num_ind_drop_no_buf +
1616 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301617 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 } else {
1619 HDD_IPA_LOG(LOGE, "INVALID REASON %d",
1620 hdd_ipa->stat_req_reason);
1621 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301622 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623}
1624
1625
1626/**
1627 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1628 * @adapter: device adapter instance
1629 * @offload_type: MCC or SCC
1630 * @enable: TX offload enable or disable
1631 *
1632 * Return: none
1633 */
1634static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1635 uint32_t offload_type, uint32_t enable)
1636{
1637 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
1638
1639 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1640 * channel change indication. Since these indications are sent by lower
1641 * layer as SAP updates and IPA doesn't have to do anything for these
1642 * updates so ignoring!
1643 */
1644 if (WLAN_HDD_SOFTAP == adapter->device_mode && adapter->ipa_context)
1645 return;
1646
1647 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1648 * channel change indication. Since these indications are sent by lower
1649 * layer as SAP updates and IPA doesn't have to do anything for these
1650 * updates so ignoring!
1651 */
1652 if (adapter->ipa_context)
1653 return;
1654
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301655 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656 sizeof(ipa_offload_enable_disable));
1657 ipa_offload_enable_disable.offload_type = offload_type;
1658 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1659 ipa_offload_enable_disable.enable = enable;
1660
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301661 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662 "%s: offload_type=%d, vdev_id=%d, enable=%d", __func__,
1663 ipa_offload_enable_disable.offload_type,
1664 ipa_offload_enable_disable.vdev_id,
1665 ipa_offload_enable_disable.enable);
1666
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301667 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001668 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1669 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301670 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671 "%s: Failure to enable IPA offload \
1672 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1673 ipa_offload_enable_disable.offload_type,
1674 ipa_offload_enable_disable.vdev_id,
1675 ipa_offload_enable_disable.enable);
1676 }
1677}
1678
1679/**
1680 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1681 * @work: uC OP work
1682 *
1683 * Return: None
1684 */
1685static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1686{
1687 struct op_msg_type *msg;
1688 struct uc_op_work_struct *uc_op_work = container_of(work,
1689 struct uc_op_work_struct, work);
1690 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1691
1692 cds_ssr_protect(__func__);
1693
1694 msg = uc_op_work->msg;
1695 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301696 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 "%s, posted msg %d", __func__, msg->op_code);
1698
1699 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1700
1701 cds_ssr_unprotect(__func__);
1702
1703 return;
1704}
1705
1706/**
1707 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1708 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1709 * @op_msg: operation message received from firmware
1710 * @hdd_ctx: Global HDD context
1711 *
1712 * Return: None
1713 */
1714static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1715{
1716 struct hdd_ipa_priv *hdd_ipa;
1717 struct op_msg_type *msg;
1718 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301719 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001720
1721 status = wlan_hdd_validate_context(hdd_ctx);
1722 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301723 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724 goto end;
1725 }
1726
1727 msg = (struct op_msg_type *)op_msg;
1728 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1729
1730 if (unlikely(!hdd_ipa))
1731 goto end;
1732
1733 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301734 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001735 __func__, msg->op_code);
1736 goto end;
1737 }
1738
1739 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1740 if (uc_op_work->msg)
1741 /* When the same uC OPCODE is already pended, just return */
1742 goto end;
1743
1744 uc_op_work->msg = msg;
1745 schedule_work(&uc_op_work->work);
1746 return;
1747
1748end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301749 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001750}
1751
1752/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001753 * hdd_ipa_init_uc_op_work - init ipa uc op work
1754 * @work: struct work_struct
1755 * @work_handler: work_handler
1756 *
1757 * Return: none
1758 */
1759#ifdef CONFIG_CNSS
1760static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1761 work_func_t work_handler)
1762{
1763 cnss_init_work(work, work_handler);
1764}
1765#else
1766static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1767 work_func_t work_handler)
1768{
1769 INIT_WORK(work, work_handler);
1770}
1771#endif
1772
1773
1774/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001775 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1776 * @hdd_ctx: Global HDD context
1777 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301778 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001779 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301780static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001781{
1782 struct ipa_wdi_in_params pipe_in;
1783 struct ipa_wdi_out_params pipe_out;
1784 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1785 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1786 uint8_t i;
1787
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301788 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1789 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001790
Anurag Chouhanffb21542016-02-17 14:33:03 +05301791 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301792 qdf_mutex_create(&ipa_ctxt->event_lock);
1793 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794
1795 /* TX PIPE */
1796 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1797 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1798 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1799 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1800 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1801 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1802 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1803 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1804 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1805 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1806 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1807 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1808 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301809 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001810 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1811 pipe_in.sys.keep_ipa_awake = true;
1812 }
1813
Leo Chang3bc8fed2015-11-13 10:59:47 -08001814 pipe_in.u.dl.comp_ring_base_pa = ipa_ctxt->tx_comp_ring_base_paddr;
1815 pipe_in.u.dl.comp_ring_size =
Anurag Chouhan6d760662016-02-20 16:05:43 +05301816 ipa_ctxt->tx_comp_ring_size * sizeof(qdf_dma_addr_t);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001817 pipe_in.u.dl.ce_ring_base_pa = ipa_ctxt->ce_sr_base_paddr;
1818 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ce_reg_paddr;
1819 pipe_in.u.dl.ce_ring_size = ipa_ctxt->ce_sr_ring_size;
1820 pipe_in.u.dl.num_tx_buffers = ipa_ctxt->tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821
1822 /* Connect WDI IPA PIPE */
1823 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1824 /* Micro Controller Doorbell register */
Leo Chang3bc8fed2015-11-13 10:59:47 -08001825 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001826 /* WLAN TX PIPE Handle */
1827 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301828 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001829 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1830 " CERZ %d, NB %d, CDBPAD 0x%x",
1831 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1832 pipe_in.u.dl.comp_ring_size,
1833 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1834 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1835 pipe_in.u.dl.ce_ring_size,
1836 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001837 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001838
1839 /* RX PIPE */
1840 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1841 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1842 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1843 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1844 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1845 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1846 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1847 sizeof(struct sps_iovec);
1848 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1849 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301850 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001851 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1852 pipe_in.sys.keep_ipa_awake = true;
1853 }
1854
Leo Chang3bc8fed2015-11-13 10:59:47 -08001855 pipe_in.u.ul.rdy_ring_base_pa = ipa_ctxt->rx_rdy_ring_base_paddr;
1856 pipe_in.u.ul.rdy_ring_size = ipa_ctxt->rx_rdy_ring_size;
1857 pipe_in.u.ul.rdy_ring_rp_pa = ipa_ctxt->rx_proc_done_idx_paddr;
1858 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001859 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001860 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301862 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1864 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1865 pipe_in.u.ul.rdy_ring_size,
1866 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001867 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001868
1869 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001870 ipa_ctxt->tx_comp_doorbell_paddr,
1871 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872
1873 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1874 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1875
1876 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001877 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 hdd_ipa_uc_fw_op_event_handler);
1879 ipa_ctxt->uc_op_work[i].msg = NULL;
1880 }
1881
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301882 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883}
1884
Leo Change3e49442015-10-26 20:07:13 -07001885/**
1886 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1887 * @hdd_ctx: hdd main context
1888 *
1889 * Force shutdown IPA pipe
1890 * Independent of FW pipe status, IPA pipe shutdonw progress
1891 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1892 * independent from FW pipe status
1893 *
1894 * Return: NONE
1895 */
1896void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1897{
1898 struct hdd_ipa_priv *hdd_ipa;
1899
1900 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1901 return;
1902
1903 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1904 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301905 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001906 "IPA pipes are not down yet, force shutdown");
1907 hdd_ipa_uc_disable_pipes(hdd_ipa);
1908 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301909 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001910 "IPA pipes are down, do nothing");
1911 }
1912
1913 return;
1914}
1915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916/**
1917 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1918 *
1919 * Deinit basic IPA UC host side to be in sync reloaded FW during
1920 * SSR
1921 *
1922 * Return: 0 - Success
1923 */
1924int hdd_ipa_uc_ssr_deinit(void)
1925{
1926 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1927 int idx;
1928 struct hdd_ipa_iface_context *iface_context;
1929
Leo Chang3bc8fed2015-11-13 10:59:47 -08001930 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931 return 0;
1932
1933 /* Clean up HDD IPA interfaces */
1934 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1935 (idx < HDD_IPA_MAX_IFACE); idx++) {
1936 iface_context = &hdd_ipa->iface_context[idx];
1937 if (iface_context && iface_context->adapter)
1938 hdd_ipa_cleanup_iface(iface_context);
1939 }
1940
1941 /* After SSR, wlan driver reloads FW again. But we need to protect
1942 * IPA submodule during SSR transient state. So deinit basic IPA
1943 * UC host side to be in sync with reloaded FW during SSR
1944 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001945 if (!hdd_ipa->ipa_pipes_down)
1946 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001947
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301948 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001949 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1950 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1951 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1952 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301953 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954
1955 /* Full IPA driver cleanup not required since wlan driver is now
1956 * unloaded and reloaded after SSR.
1957 */
1958 return 0;
1959}
1960
1961/**
1962 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1963 *
1964 * Init basic IPA UC host side to be in sync with reloaded FW after
1965 * SSR to resume IPA UC operations
1966 *
1967 * Return: 0 - Success
1968 */
1969int hdd_ipa_uc_ssr_reinit(void)
1970{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971
1972 /* After SSR is complete, IPA UC can resume operation. But now wlan
1973 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1974 * and initialization. This is a placeholder func if IPA has to resume
1975 * operations without driver reload.
1976 */
1977 return 0;
1978}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001979
1980/**
1981 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1982 * @hdd_ctx: Global HDD context
1983 * @skb: skb sent to IPA
1984 * @session_id: send packet instance session id
1985 *
1986 * Send TX packet which generated by system to IPA.
1987 * This routine only will be used for function verification
1988 *
1989 * Return: NULL packet sent to IPA properly
1990 * NULL invalid packet drop
1991 * skb packet not sent to IPA. legacy data path should handle
1992 */
1993struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1994 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001995{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001996 struct ipa_header *ipa_header;
1997 struct frag_header *frag_header;
1998
1999 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2000 return skb;
2001
2002 ipa_header = (struct ipa_header *) skb_push(skb,
2003 sizeof(struct ipa_header));
2004 if (!ipa_header) {
2005 /* No headroom, legacy */
2006 return skb;
2007 }
2008 memset(ipa_header, 0, sizeof(*ipa_header));
2009 ipa_header->vdev_id = 0;
2010
2011 frag_header = (struct frag_header *) skb_push(skb,
2012 sizeof(struct frag_header));
2013 if (!frag_header) {
2014 /* No headroom, drop */
2015 kfree_skb(skb);
2016 return NULL;
2017 }
2018 memset(frag_header, 0, sizeof(*frag_header));
2019 frag_header->length = skb->len - sizeof(struct frag_header)
2020 - sizeof(struct ipa_header);
2021
2022 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2023 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002024}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025
2026/**
2027 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2028 * @work: scheduled work
2029 *
2030 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2031 * not want to immediately release the wake lock since the system
2032 * would then potentially try to suspend when there is a healthy data
2033 * rate. Deferred work is scheduled and this function handles the
2034 * work. When this function is called, if the IPA resource is still
2035 * released then we release the wake lock.
2036 *
2037 * Return: None
2038 */
2039static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2040{
2041 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2042 struct hdd_ipa_priv,
2043 wake_lock_work);
2044
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302045 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046
2047 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2048 goto end;
2049
2050 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302051 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002052 WIFI_POWER_EVENT_WAKELOCK_IPA);
2053
2054end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302055 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002056}
2057
2058/**
2059 * hdd_ipa_rm_request() - Request resource from IPA
2060 * @hdd_ipa: Global HDD IPA context
2061 *
2062 * Return: 0 on success, negative errno on error
2063 */
2064static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2065{
2066 int ret = 0;
2067
2068 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2069 return 0;
2070
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302071 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002072
2073 switch (hdd_ipa->rm_state) {
2074 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302075 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076 return 0;
2077 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302078 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002079 return -EINPROGRESS;
2080 case HDD_IPA_RM_RELEASED:
2081 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2082 break;
2083 }
2084
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302085 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002086
2087 ret = ipa_rm_inactivity_timer_request_resource(
2088 IPA_RM_RESOURCE_WLAN_PROD);
2089
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302090 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091 if (ret == 0) {
2092 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2093 hdd_ipa->stats.num_rm_grant_imm++;
2094 }
2095
2096 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2097 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302098 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002099 WIFI_POWER_EVENT_WAKELOCK_IPA);
2100 hdd_ipa->wake_lock_released = false;
2101 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302102 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002103
2104 return ret;
2105}
2106
2107/**
2108 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2109 * @hdd_ipa: Global HDD IPA context
2110 *
2111 * Return: 0 if resources released, negative errno otherwise
2112 */
2113static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2114{
2115 int ret = 0;
2116
2117 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2118 return 0;
2119
2120 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2121 return -EAGAIN;
2122
2123 spin_lock_bh(&hdd_ipa->q_lock);
2124 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2125 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2126 spin_unlock_bh(&hdd_ipa->q_lock);
2127 return -EAGAIN;
2128 }
2129 spin_unlock_bh(&hdd_ipa->q_lock);
2130
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302131 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002132
Nirav Shahcbc6d722016-03-01 16:24:53 +05302133 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302134 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135 return -EAGAIN;
2136 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302137 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302139 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002140 switch (hdd_ipa->rm_state) {
2141 case HDD_IPA_RM_GRANTED:
2142 break;
2143 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302144 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 return -EINPROGRESS;
2146 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302147 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148 return 0;
2149 }
2150
2151 /* IPA driver returns immediately so set the state here to avoid any
2152 * race condition.
2153 */
2154 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2155 hdd_ipa->stats.num_rm_release++;
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 ret =
2159 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2160
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302161 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 if (unlikely(ret != 0)) {
2163 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2164 WARN_ON(1);
2165 }
2166
2167 /*
2168 * If wake_lock is released immediately, kernel would try to suspend
2169 * immediately as well, Just avoid ping-pong between suspend-resume
2170 * while there is healthy amount of data transfer going on by
2171 * releasing the wake_lock after some delay.
2172 */
2173 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2174 msecs_to_jiffies
2175 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2176
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302177 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002178
2179 return ret;
2180}
2181
2182/**
2183 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2184 * @user_data: user data registered with IPA
2185 * @event: the IPA resource manager event that occurred
2186 * @data: the data associated with the event
2187 *
2188 * Return: None
2189 */
2190static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2191 unsigned long data)
2192{
2193 struct hdd_ipa_priv *hdd_ipa = user_data;
2194
2195 if (unlikely(!hdd_ipa))
2196 return;
2197
2198 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2199 return;
2200
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302201 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002202
2203 switch (event) {
2204 case IPA_RM_RESOURCE_GRANTED:
2205 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2206 /* RM Notification comes with ISR context
2207 * it should be serialized into work queue to avoid
2208 * ISR sleep problem
2209 */
2210 hdd_ipa->uc_rm_work.event = event;
2211 schedule_work(&hdd_ipa->uc_rm_work.work);
2212 break;
2213 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302214 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002215 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302216 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002217 hdd_ipa->stats.num_rm_grant++;
2218 break;
2219
2220 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302221 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002222 hdd_ipa->resource_unloading = false;
2223 break;
2224
2225 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302226 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002227 break;
2228 }
2229}
2230
2231/**
2232 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2233 *
2234 * Callback function registered with IPA that is called when IPA wants
2235 * to release the WLAN consumer resource
2236 *
2237 * Return: 0 if the request is granted, negative errno otherwise
2238 */
2239static int hdd_ipa_rm_cons_release(void)
2240{
2241 return 0;
2242}
2243
2244/**
2245 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2246 *
2247 * Callback function registered with IPA that is called when IPA wants
2248 * to access the WLAN consumer resource
2249 *
2250 * Return: 0 if the request is granted, negative errno otherwise
2251 */
2252static int hdd_ipa_rm_cons_request(void)
2253{
Yun Park4d8b60a2015-10-22 13:59:32 -07002254 int ret = 0;
2255
2256 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302257 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002258 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002259 __func__);
2260 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002261 ret = -EINPROGRESS;
2262 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302263 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002264 "%s: IPA resource unloading in progress",
2265 __func__);
2266 ghdd_ipa->pending_cons_req = true;
2267 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002268 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002269
2270 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002271}
2272
2273/**
2274 * hdd_ipa_set_perf_level() - Set IPA performance level
2275 * @hdd_ctx: Global HDD context
2276 * @tx_packets: Number of packets transmitted in the last sample period
2277 * @rx_packets: Number of packets received in the last sample period
2278 *
2279 * Return: 0 on success, negative errno on error
2280 */
2281int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2282 uint64_t rx_packets)
2283{
2284 uint32_t next_cons_bw, next_prod_bw;
2285 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2286 struct ipa_rm_perf_profile profile;
2287 int ret;
2288
2289 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2290 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2291 return 0;
2292
2293 memset(&profile, 0, sizeof(profile));
2294
2295 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2296 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2297 else if (tx_packets >
2298 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2299 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2300 else
2301 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2302
2303 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2304 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2305 else if (rx_packets >
2306 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2307 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2308 else
2309 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2310
2311 HDD_IPA_LOG(LOG1,
2312 "CONS perf curr: %d, next: %d",
2313 hdd_ipa->curr_cons_bw, next_cons_bw);
2314 HDD_IPA_LOG(LOG1,
2315 "PROD perf curr: %d, next: %d",
2316 hdd_ipa->curr_prod_bw, next_prod_bw);
2317
2318 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302319 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002320 "Requesting CONS perf curr: %d, next: %d",
2321 hdd_ipa->curr_cons_bw, next_cons_bw);
2322 profile.max_supported_bandwidth_mbps = next_cons_bw;
2323 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2324 &profile);
2325 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302326 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002327 "RM CONS set perf profile failed: %d", ret);
2328
2329 return ret;
2330 }
2331 hdd_ipa->curr_cons_bw = next_cons_bw;
2332 hdd_ipa->stats.num_cons_perf_req++;
2333 }
2334
2335 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302336 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002337 "Requesting PROD perf curr: %d, next: %d",
2338 hdd_ipa->curr_prod_bw, next_prod_bw);
2339 profile.max_supported_bandwidth_mbps = next_prod_bw;
2340 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2341 &profile);
2342 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302343 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002344 "RM PROD set perf profile failed: %d", ret);
2345 return ret;
2346 }
2347 hdd_ipa->curr_prod_bw = next_prod_bw;
2348 hdd_ipa->stats.num_prod_perf_req++;
2349 }
2350
2351 return 0;
2352}
2353
2354/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002355 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2356 * @work: struct work_struct
2357 * @work_handler: work_handler
2358 *
2359 * Return: none
2360 */
2361#ifdef CONFIG_CNSS
2362static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2363 work_func_t work_handler)
2364{
2365 cnss_init_work(work, work_handler);
2366}
2367#else
2368static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2369 work_func_t work_handler)
2370{
2371 INIT_WORK(work, work_handler);
2372}
2373#endif
2374
2375/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002376 * hdd_ipa_setup_rm() - Setup IPA resource management
2377 * @hdd_ipa: Global HDD IPA context
2378 *
2379 * Return: 0 on success, negative errno on error
2380 */
2381static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2382{
2383 struct ipa_rm_create_params create_params = { 0 };
2384 int ret;
2385
2386 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2387 return 0;
2388
Rajeev Kumar217f2172016-01-06 18:11:55 -08002389 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2390 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002391 memset(&create_params, 0, sizeof(create_params));
2392 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2393 create_params.reg_params.user_data = hdd_ipa;
2394 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2395 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2396
2397 ret = ipa_rm_create_resource(&create_params);
2398 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302399 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002400 "Create RM resource failed: %d", ret);
2401 goto setup_rm_fail;
2402 }
2403
2404 memset(&create_params, 0, sizeof(create_params));
2405 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2406 create_params.request_resource = hdd_ipa_rm_cons_request;
2407 create_params.release_resource = hdd_ipa_rm_cons_release;
2408 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2409
2410 ret = ipa_rm_create_resource(&create_params);
2411 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302412 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002413 "Create RM CONS resource failed: %d", ret);
2414 goto delete_prod;
2415 }
2416
2417 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2418 IPA_RM_RESOURCE_APPS_CONS);
2419
2420 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2421 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2422 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302423 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002424 ret);
2425 goto timer_init_failed;
2426 }
2427
2428 /* Set the lowest bandwidth to start with */
2429 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2430
2431 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302432 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433 "Set perf level failed: %d", ret);
2434 goto set_perf_failed;
2435 }
2436
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302437 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002438#ifdef CONFIG_CNSS
2439 cnss_init_delayed_work(&hdd_ipa->wake_lock_work,
2440 hdd_ipa_wake_lock_timer_func);
2441#else
2442 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2443 hdd_ipa_wake_lock_timer_func);
2444#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302445 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002446 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2447 hdd_ipa->wake_lock_released = true;
2448 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2449
2450 return ret;
2451
2452set_perf_failed:
2453 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2454
2455timer_init_failed:
2456 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2457
2458delete_prod:
2459 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2460
2461setup_rm_fail:
2462 return ret;
2463}
2464
2465/**
2466 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2467 * @hdd_ipa: Global HDD IPA context
2468 *
2469 * Destroys all resources associated with the IPA resource manager
2470 *
2471 * Return: None
2472 */
2473static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2474{
2475 int ret;
2476
2477 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2478 return;
2479
2480 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302481 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002482
2483#ifdef WLAN_OPEN_SOURCE
2484 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2485#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302486 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002487
2488 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2489
2490 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2491 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302492 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002493 "RM PROD resource delete failed %d", ret);
2494
2495 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2496 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302497 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002498 "RM CONS resource delete failed %d", ret);
2499}
2500
2501/**
2502 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2503 * @skb: network buffer
2504 * @adapter: network adapter
2505 *
2506 * Called when a network buffer is received which should not be routed
2507 * to the IPA module.
2508 *
2509 * Return: None
2510 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302511static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002512 hdd_adapter_t *adapter)
2513{
2514 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2515 unsigned int cpu_index;
2516
2517 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302518 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002519 adapter);
2520 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302521 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002522 return;
2523 }
2524
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002525 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002526 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302527 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002528 return;
2529 }
2530
2531 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2532 skb->dev = adapter->dev;
2533 skb->protocol = eth_type_trans(skb, skb->dev);
2534 skb->ip_summed = CHECKSUM_NONE;
2535
2536 cpu_index = wlan_hdd_get_cpu();
2537
2538 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2539 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2540 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2541 else
2542 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2543
2544 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2545 adapter->dev->last_rx = jiffies;
2546}
2547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548/**
2549 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
2550 * @priv: pointer to private data registered with IPA (we register a
2551 * pointer to the global IPA context)
2552 * @evt: the IPA event which triggered the callback
2553 * @data: data associated with the event
2554 *
2555 * Return: None
2556 */
2557static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2558 unsigned long data)
2559{
2560 struct hdd_ipa_priv *hdd_ipa = NULL;
2561 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302562 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002563 uint8_t iface_id;
2564 uint8_t session_id;
2565 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302566 qdf_nbuf_t copy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 uint8_t fw_desc;
2568 int ret;
2569
2570 hdd_ipa = (struct hdd_ipa_priv *)priv;
2571
2572 switch (evt) {
2573 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302574 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002575 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2576 session_id = (uint8_t)skb->cb[0];
2577 iface_id = vdev_to_iface[session_id];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302578 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002579 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2580 session_id, iface_id);
2581 } else {
2582 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2583 }
2584
2585 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302586 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002587 "IPA_RECEIVE: Invalid iface_id: %u",
2588 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302589 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002590 "w2i -- skb", skb->data, 8);
2591 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302592 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593 return;
2594 }
2595
2596 iface_context = &hdd_ipa->iface_context[iface_id];
2597 adapter = iface_context->adapter;
2598
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302599 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002600 "w2i -- skb", skb->data, 8);
2601 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2602 hdd_ipa->stats.num_rx_excep++;
2603 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2604 } else {
2605 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2606 }
2607
2608 iface_context->stats.num_rx_ipa_excep++;
2609
2610 /* Disable to forward Intra-BSS Rx packets when
2611 * ap_isolate=1 in hostapd.conf
2612 */
2613 if (adapter->sessionCtx.ap.apDisableIntraBssFwd) {
2614 /*
2615 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2616 * all Rx packets to IPA uC, which need to be forwarded
2617 * to other interface.
2618 * And, IPA driver will send back to WLAN host driver
2619 * through exception pipe with fw_desc field set by FW.
2620 * Here we are checking fw_desc field for FORWARD bit
2621 * set, and forward to Tx. Then copy to kernel stack
2622 * only when DISCARD bit is not set.
2623 */
2624 fw_desc = (uint8_t)skb->cb[1];
2625
Leo Chang3bc8fed2015-11-13 10:59:47 -08002626 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302628 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002629 "Forward packet to Tx (fw_desc=%d)",
2630 fw_desc);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302631 copy = qdf_nbuf_copy(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002632 if (copy) {
2633 hdd_ipa->ipa_tx_forward++;
2634 ret = hdd_softap_hard_start_xmit(
2635 (struct sk_buff *)copy,
2636 adapter->dev);
2637 if (ret) {
2638 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302639 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002640 "Forward packet tx fail");
2641 hdd_ipa->stats.
2642 num_tx_bcmc_err++;
2643 } else {
2644 hdd_ipa->stats.num_tx_bcmc++;
2645 }
2646 }
2647 }
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002648
Leo Chang3bc8fed2015-11-13 10:59:47 -08002649 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002650 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2651 hdd_ipa->ipa_rx_discard++;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302652 qdf_nbuf_free(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002653 break;
2654 }
2655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002656 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302657 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002658 "Intra-BSS FWD is disabled-skip forward to Tx");
2659 }
2660
2661 hdd_ipa_send_skb_to_network(skb, adapter);
2662 break;
2663
2664 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302665 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002666 "w2i cb wrong event: 0x%x", evt);
2667 return;
2668 }
2669}
2670
2671/**
2672 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2673 * @skb: packet buffer which was transmitted
2674 *
2675 * Return: None
2676 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302677void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002678{
2679 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2680
Nirav Shahcbc6d722016-03-01 16:24:53 +05302681 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
2682 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002683 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302684 ipa_free_skb((struct ipa_rx_data *)
2685 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686
2687 hdd_ipa->stats.num_tx_comp_cnt++;
2688
2689 atomic_dec(&hdd_ipa->tx_ref_cnt);
2690
2691 hdd_ipa_rm_try_release(hdd_ipa);
2692}
2693
2694/**
2695 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2696 * @iface_context: interface-specific IPA context
2697 * @ipa_tx_desc: packet data descriptor
2698 *
2699 * Return: None
2700 */
2701static void hdd_ipa_send_pkt_to_tl(
2702 struct hdd_ipa_iface_context *iface_context,
2703 struct ipa_rx_data *ipa_tx_desc)
2704{
2705 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2706 uint8_t interface_id;
2707 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302708 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302710 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711 adapter = iface_context->adapter;
2712 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302713 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714 ipa_free_skb(ipa_tx_desc);
2715 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302716 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002717 hdd_ipa_rm_try_release(hdd_ipa);
2718 return;
2719 }
2720
2721 /*
2722 * During CAC period, data packets shouldn't be sent over the air so
2723 * drop all the packets here
2724 */
2725 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2726 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302727 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728 iface_context->stats.num_tx_cac_drop++;
2729 hdd_ipa_rm_try_release(hdd_ipa);
2730 return;
2731 }
2732
2733 interface_id = adapter->sessionId;
2734 ++adapter->stats.tx_packets;
2735
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302736 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002737
2738 skb = ipa_tx_desc->skb;
2739
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302740 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302741 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002742 /* FIXME: This is broken. No such field in cb any more:
2743 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302745 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002746 ipa_tx_desc->dma_addr
2747 + HDD_IPA_WLAN_FRAG_HEADER
2748 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002749 ipa_tx_desc->skb->len -=
2750 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2751 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302752 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002753
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002754 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302755 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756
2757 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2758
2759 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2760 ipa_tx_desc->skb);
2761 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302762 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002763 ipa_free_skb(ipa_tx_desc);
2764 iface_context->stats.num_tx_err++;
2765 hdd_ipa_rm_try_release(hdd_ipa);
2766 return;
2767 }
2768
2769 atomic_inc(&hdd_ipa->tx_ref_cnt);
2770
2771 iface_context->stats.num_tx++;
2772
2773}
2774
2775/**
2776 * hdd_ipa_pm_send_pkt_to_tl() - Send queued packets to TL
2777 * @work: pointer to the scheduled work
2778 *
2779 * Called during PM resume to send packets to TL which were queued
2780 * while host was in the process of suspending.
2781 *
2782 * Return: None
2783 */
2784static void hdd_ipa_pm_send_pkt_to_tl(struct work_struct *work)
2785{
2786 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2787 struct hdd_ipa_priv,
2788 pm_work);
2789 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302790 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791 uint32_t dequeued = 0;
2792
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302793 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002794
Nirav Shahcbc6d722016-03-01 16:24:53 +05302795 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2796 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302797 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002798
2799 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2800
2801 dequeued++;
2802
2803 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
2804 pm_tx_cb->ipa_tx_desc);
2805
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302806 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807 }
2808
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302809 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002810
2811 hdd_ipa->stats.num_tx_dequeued += dequeued;
2812 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2813 hdd_ipa->stats.num_max_pm_queue = dequeued;
2814}
2815
2816/**
2817 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2818 * @priv: pointer to private data registered with IPA (we register a
2819 * pointer to the interface-specific IPA context)
2820 * @evt: the IPA event which triggered the callback
2821 * @data: data associated with the event
2822 *
2823 * Return: None
2824 */
2825static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2826 unsigned long data)
2827{
2828 struct hdd_ipa_priv *hdd_ipa = NULL;
2829 struct ipa_rx_data *ipa_tx_desc;
2830 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302831 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002832 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302833 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002834
Mukul Sharma81661ae2015-10-30 20:26:02 +05302835 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002836 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302837 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002838 dev_kfree_skb_any(skb);
2839 iface_context->stats.num_tx_drop++;
2840 return;
2841 }
2842
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843 ipa_tx_desc = (struct ipa_rx_data *)data;
2844
2845 hdd_ipa = iface_context->hdd_ipa;
2846
2847 /*
2848 * When SSR is going on or driver is unloading, just drop the packets.
2849 * During SSR, there is no use in queueing the packets as STA has to
2850 * connect back any way
2851 */
2852 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2853 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302854 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002855 ipa_free_skb(ipa_tx_desc);
2856 iface_context->stats.num_tx_drop++;
2857 return;
2858 }
2859
2860 skb = ipa_tx_desc->skb;
2861
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302862 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002863
2864 /*
2865 * If PROD resource is not requested here then there may be cases where
2866 * IPA hardware may be clocked down because of not having proper
2867 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2868 * workaround to request PROD resource while data is going over CONS
2869 * pipe to prevent the IPA hardware clockdown.
2870 */
2871 hdd_ipa_rm_request(hdd_ipa);
2872
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302873 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874 /*
2875 * If host is still suspended then queue the packets and these will be
2876 * drained later when resume completes. When packet is arrived here and
2877 * host is suspended, this means that there is already resume is in
2878 * progress.
2879 */
2880 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302881 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002882 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2883 pm_tx_cb->iface_context = iface_context;
2884 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302885 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 hdd_ipa->stats.num_tx_queued++;
2887
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302888 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002889 return;
2890 }
2891
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302892 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002893
2894 /*
2895 * If we are here means, host is not suspended, wait for the work queue
2896 * to finish.
2897 */
2898#ifdef WLAN_OPEN_SOURCE
2899 flush_work(&hdd_ipa->pm_work);
2900#endif
2901
2902 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2903}
2904
2905/**
2906 * hdd_ipa_suspend() - Suspend IPA
2907 * @hdd_ctx: Global HDD context
2908 *
2909 * Return: 0 on success, negativer errno on error
2910 */
2911int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2912{
2913 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2914
2915 if (!hdd_ipa_is_enabled(hdd_ctx))
2916 return 0;
2917
2918 /*
2919 * Check if IPA is ready for suspend, If we are here means, there is
2920 * high chance that suspend would go through but just to avoid any race
2921 * condition after suspend started, these checks are conducted before
2922 * allowing to suspend.
2923 */
2924 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2925 return -EAGAIN;
2926
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302927 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002928
2929 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302930 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002931 return -EAGAIN;
2932 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302933 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302935 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302937 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002938
2939 return 0;
2940}
2941
2942/**
2943 * hdd_ipa_resume() - Resume IPA following suspend
2944 * hdd_ctx: Global HDD context
2945 *
2946 * Return: 0 on success, negative errno on error
2947 */
2948int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2949{
2950 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2951
2952 if (!hdd_ipa_is_enabled(hdd_ctx))
2953 return 0;
2954
2955 schedule_work(&hdd_ipa->pm_work);
2956
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302957 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002958 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302959 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002960
2961 return 0;
2962}
2963
2964/**
2965 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
2966 * @hdd_ipa: Global HDD IPA context
2967 *
2968 * Return: 0 on success, negative errno on error
2969 */
2970static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
2971{
2972 int i, ret = 0;
2973 struct ipa_sys_connect_params *ipa;
2974 uint32_t desc_fifo_sz;
2975
2976 /* The maximum number of descriptors that can be provided to a BAM at
2977 * once is one less than the total number of descriptors that the buffer
2978 * can contain.
2979 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2980 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2981 * be provided at once.
2982 * Because of above requirement, one extra descriptor will be added to
2983 * make sure hardware always has one descriptor.
2984 */
2985 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
2986 + sizeof(struct sps_iovec);
2987
2988 /*setup TX pipes */
2989 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2990 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
2991
2992 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
2993 ipa->desc_fifo_sz = desc_fifo_sz;
2994 ipa->priv = &hdd_ipa->iface_context[i];
2995 ipa->notify = hdd_ipa_i2w_cb;
2996
2997 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2998 ipa->ipa_ep_cfg.hdr.hdr_len =
2999 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3000 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3001 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3002 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3003 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3004 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3005 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3006 } else {
3007 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3008 }
3009 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3010
3011 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3012 ipa->keep_ipa_awake = 1;
3013
3014 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3015 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303016 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003017 " ret: %d", i, ret);
3018 goto setup_sys_pipe_fail;
3019 }
3020 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3021 }
3022
3023 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3024 /*
3025 * Hard code it here, this can be extended if in case
3026 * PROD pipe is also per interface.
3027 * Right now there is no advantage of doing this.
3028 */
3029 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3030
3031 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3032
3033 ipa->client = hdd_ipa->prod_client;
3034
3035 ipa->desc_fifo_sz = desc_fifo_sz;
3036 ipa->priv = hdd_ipa;
3037 ipa->notify = hdd_ipa_w2i_cb;
3038
3039 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3040 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3041 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3042 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3043
3044 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3045 ipa->keep_ipa_awake = 1;
3046
3047 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3048 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303049 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003050 "Failed for RX pipe: %d", ret);
3051 goto setup_sys_pipe_fail;
3052 }
3053 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3054 }
3055
3056 return ret;
3057
3058setup_sys_pipe_fail:
3059
3060 while (--i >= 0) {
3061 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303062 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063 sizeof(struct hdd_ipa_sys_pipe));
3064 }
3065
3066 return ret;
3067}
3068
3069/**
3070 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3071 * @hdd_ipa: Global HDD IPA context
3072 *
3073 * Return: None
3074 */
3075static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3076{
3077 int ret = 0, i;
3078 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3079 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3080 ret =
3081 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3082 conn_hdl);
3083 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303084 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003085 ret);
3086
3087 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3088 }
3089 }
3090}
3091
3092/**
3093 * hdd_ipa_register_interface() - register IPA interface
3094 * @hdd_ipa: Global IPA context
3095 * @iface_context: Per-interface IPA context
3096 *
3097 * Return: 0 on success, negative errno on error
3098 */
3099static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3100 struct hdd_ipa_iface_context
3101 *iface_context)
3102{
3103 struct ipa_tx_intf tx_intf;
3104 struct ipa_rx_intf rx_intf;
3105 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3106 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3107 char *ifname = iface_context->adapter->dev->name;
3108
3109 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3110 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3111
3112 int num_prop = 1;
3113 int ret = 0;
3114
3115 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3116 num_prop++;
3117
3118 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3119 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303120 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303122 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123 goto register_interface_fail;
3124 }
3125
3126 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3127 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303128 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003129 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303130 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003131 goto register_interface_fail;
3132 }
3133
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303134 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3135 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003136
3137 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3138 ifname, HDD_IPA_IPV4_NAME_EXT);
3139 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3140 ifname, HDD_IPA_IPV6_NAME_EXT);
3141
3142 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3143 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3144 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3145 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3146
3147 /*
3148 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3149 * mask to identify the interface in IPA hardware
3150 */
3151 rx_prop[IPA_IP_v4].attrib.meta_data =
3152 htonl(iface_context->adapter->sessionId << 16);
3153 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3154
3155 rx_intf.num_props++;
3156 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3157 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3158 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3159 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3160 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3161 rx_prop[IPA_IP_v4].attrib.meta_data =
3162 htonl(iface_context->adapter->sessionId << 16);
3163 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3164
3165 rx_intf.num_props++;
3166 }
3167
3168 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3169 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3170 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3171 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3172 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3173 IPA_RESOURCE_NAME_MAX);
3174 tx_intf.num_props++;
3175
3176 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3177 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3178 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3179 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3180 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3181 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3182 IPA_RESOURCE_NAME_MAX);
3183 tx_intf.num_props++;
3184 }
3185
3186 tx_intf.prop = tx_prop;
3187 rx_intf.prop = rx_prop;
3188
3189 /* Call the ipa api to register interface */
3190 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3191
3192register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303193 qdf_mem_free(tx_prop);
3194 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195 return ret;
3196}
3197
3198/**
3199 * hdd_remove_ipa_header() - Remove a specific header from IPA
3200 * @name: Name of the header to be removed
3201 *
3202 * Return: None
3203 */
3204static void hdd_ipa_remove_header(char *name)
3205{
3206 struct ipa_ioc_get_hdr hdrlookup;
3207 int ret = 0, len;
3208 struct ipa_ioc_del_hdr *ipa_hdr;
3209
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303210 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3212 ret = ipa_get_hdr(&hdrlookup);
3213 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303214 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 name, ret);
3216 return;
3217 }
3218
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303219 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303221 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303223 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224 return;
3225 }
3226 ipa_hdr->num_hdls = 1;
3227 ipa_hdr->commit = 0;
3228 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3229 ipa_hdr->hdl[0].status = -1;
3230 ret = ipa_del_hdr(ipa_hdr);
3231 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303232 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003233 ret);
3234
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303235 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236}
3237
3238/**
3239 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3240 * @hdd_ipa: Global HDD IPA context
3241 * @iface_context: Interface-specific HDD IPA context
3242 * @mac_addr: Interface MAC address
3243 *
3244 * Return: 0 on success, negativer errno value on error
3245 */
3246static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3247 struct hdd_ipa_iface_context *iface_context,
3248 uint8_t *mac_addr)
3249{
3250 hdd_adapter_t *adapter = iface_context->adapter;
3251 char *ifname;
3252 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3253 int ret = -EINVAL;
3254 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3255 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3256
3257 ifname = adapter->dev->name;
3258
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303259 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003260 ifname, mac_addr);
3261
3262 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303263 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 + sizeof(struct ipa_hdr_add));
3265 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303266 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 "%s: ipa_hdr allocation failed", ifname);
3268 ret = -ENOMEM;
3269 goto end;
3270 }
3271
3272 ipa_hdr->commit = 0;
3273 ipa_hdr->num_hdrs = 1;
3274
3275 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3276 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3277 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3278 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3279 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303280 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003281 "ifname=%s, vdev_id=%d",
3282 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3283 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3284 ifname, HDD_IPA_IPV4_NAME_EXT);
3285 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3286 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3287 ipa_hdr->hdr[0].is_partial = 1;
3288 ipa_hdr->hdr[0].hdr_hdl = 0;
3289 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3290 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3291
3292 ret = ipa_add_hdr(ipa_hdr);
3293 } else {
3294 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3295
3296 /* Set the Source MAC */
3297 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3298 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3299
3300 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3301 ifname, HDD_IPA_IPV4_NAME_EXT);
3302 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3303 ipa_hdr->hdr[0].is_partial = 1;
3304 ipa_hdr->hdr[0].hdr_hdl = 0;
3305 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3306 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3307
3308 /* Set the type to IPV4 in the header */
3309 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3310
3311 ret = ipa_add_hdr(ipa_hdr);
3312 }
3313 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303314 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003315 ifname, ret);
3316 goto end;
3317 }
3318
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303319 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3321
3322 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3323 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3324 ifname, HDD_IPA_IPV6_NAME_EXT);
3325
3326 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3327 uc_tx_hdr =
3328 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3329 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3330 } else {
3331 /* Set the type to IPV6 in the header */
3332 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3333 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3334 }
3335
3336 ret = ipa_add_hdr(ipa_hdr);
3337 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303338 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 "%s: IPv6 add hdr failed: %d", ifname, ret);
3340 goto clean_ipv4_hdr;
3341 }
3342
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303343 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3345 }
3346
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303347 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348
3349 return ret;
3350
3351clean_ipv4_hdr:
3352 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3353 ifname, HDD_IPA_IPV4_NAME_EXT);
3354 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3355end:
3356 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303357 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358
3359 return ret;
3360}
3361
3362/**
3363 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3364 * @adapter: Adapter upon which IPA was previously configured
3365 *
3366 * Return: None
3367 */
3368static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3369{
3370 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3371 int ret;
3372 char name_ipa[IPA_RESOURCE_NAME_MAX];
3373
3374 /* Remove the headers */
3375 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3376 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3377 hdd_ipa_remove_header(name_ipa);
3378
3379 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3380 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3381 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3382 hdd_ipa_remove_header(name_ipa);
3383 }
3384 /* unregister the interface with IPA */
3385 ret = ipa_deregister_intf(adapter->dev->name);
3386 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303387 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388 "%s: ipa_deregister_intf fail: %d",
3389 adapter->dev->name, ret);
3390}
3391
3392/**
3393 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3394 * @iface_context: interface-specific IPA context
3395 *
3396 * Return: None
3397 */
3398static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3399{
3400 if (iface_context == NULL)
3401 return;
3402
3403 hdd_ipa_clean_hdr(iface_context->adapter);
3404
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303405 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406 iface_context->adapter->ipa_context = NULL;
3407 iface_context->adapter = NULL;
3408 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303409 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 iface_context->ifa_address = 0;
3411 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303412 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003413 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303414 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415 }
3416 iface_context->hdd_ipa->num_iface--;
3417}
3418
3419/**
3420 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3421 * @hdd_ipa: HDD IPA global context
3422 * @adapter: Interface upon which IPA is being setup
3423 * @sta_id: Station ID of the API instance
3424 *
3425 * Return: 0 on success, negative errno value on error
3426 */
3427static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3428 hdd_adapter_t *adapter, uint8_t sta_id)
3429{
3430 struct hdd_ipa_iface_context *iface_context = NULL;
3431 void *tl_context = NULL;
3432 int i, ret = 0;
3433
3434 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3435 * channel change indication. Since these indications are sent by lower
3436 * layer as SAP updates and IPA doesn't have to do anything for these
3437 * updates so ignoring!
3438 */
3439 if (WLAN_HDD_SOFTAP == adapter->device_mode && adapter->ipa_context)
3440 return 0;
3441
3442 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3443 if (hdd_ipa->iface_context[i].adapter == NULL) {
3444 iface_context = &(hdd_ipa->iface_context[i]);
3445 break;
3446 }
3447 }
3448
3449 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303450 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003451 "All the IPA interfaces are in use");
3452 ret = -ENOMEM;
3453 goto end;
3454 }
3455
3456 adapter->ipa_context = iface_context;
3457 iface_context->adapter = adapter;
3458 iface_context->sta_id = sta_id;
3459 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3460
3461 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303462 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 "Not able to get TL context sta_id: %d", sta_id);
3464 ret = -EINVAL;
3465 goto end;
3466 }
3467
3468 iface_context->tl_context = tl_context;
3469
3470 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3471 adapter->dev->dev_addr);
3472
3473 if (ret)
3474 goto end;
3475
3476 /* Configure the TX and RX pipes filter rules */
3477 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3478 if (ret)
3479 goto cleanup_header;
3480
3481 hdd_ipa->num_iface++;
3482 return ret;
3483
3484cleanup_header:
3485
3486 hdd_ipa_clean_hdr(adapter);
3487end:
3488 if (iface_context)
3489 hdd_ipa_cleanup_iface(iface_context);
3490 return ret;
3491}
3492
3493/**
3494 * hdd_ipa_msg_free_fn() - Free an IPA message
3495 * @buff: pointer to the IPA message
3496 * @len: length of the IPA message
3497 * @type: type of IPA message
3498 *
3499 * Return: None
3500 */
3501static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3502{
3503 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3504 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303505 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003506}
3507
3508/**
3509 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3510 * @mcc_mode: 0=MCC/1=SCC
3511 *
3512 * Return: 0 on success, negative errno value on error
3513 */
3514int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3515{
3516 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303517 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 hdd_adapter_t *pAdapter;
3519 struct ipa_msg_meta meta;
3520 struct ipa_wlan_msg *msg;
3521 int ret;
3522
3523 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3524 return -EINVAL;
3525
3526 if (!pHddCtx->mcc_mode) {
3527 /* Flush TxRx queue for each adapter before switch to SCC */
3528 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303529 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 pAdapter = adapter_node->pAdapter;
3531 if (pAdapter->device_mode == WLAN_HDD_INFRA_STATION ||
3532 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303533 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3535 pAdapter->device_mode);
3536 hdd_deinit_tx_rx(pAdapter);
3537 }
3538 status = hdd_get_next_adapter(
3539 pHddCtx, adapter_node, &next);
3540 adapter_node = next;
3541 }
3542 }
3543
3544 /* Send SCC/MCC Switching event to IPA */
3545 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303546 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547 if (msg == NULL) {
3548 hddLog(LOGE, "msg allocation failed");
3549 return -ENOMEM;
3550 }
3551
3552 meta.msg_type = mcc_mode ?
3553 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3554 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3555
3556 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3557
3558 if (ret) {
3559 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3560 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303561 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 }
3563
3564 return ret;
3565}
3566
3567/**
3568 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3569 * @event: IPA WLAN event to be converted to a string
3570 *
3571 * Return: ASCII string representing the IPA WLAN event
3572 */
3573static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3574{
3575 switch (event) {
3576 case WLAN_CLIENT_CONNECT:
3577 return "WLAN_CLIENT_CONNECT";
3578 case WLAN_CLIENT_DISCONNECT:
3579 return "WLAN_CLIENT_DISCONNECT";
3580 case WLAN_CLIENT_POWER_SAVE_MODE:
3581 return "WLAN_CLIENT_POWER_SAVE_MODE";
3582 case WLAN_CLIENT_NORMAL_MODE:
3583 return "WLAN_CLIENT_NORMAL_MODE";
3584 case SW_ROUTING_ENABLE:
3585 return "SW_ROUTING_ENABLE";
3586 case SW_ROUTING_DISABLE:
3587 return "SW_ROUTING_DISABLE";
3588 case WLAN_AP_CONNECT:
3589 return "WLAN_AP_CONNECT";
3590 case WLAN_AP_DISCONNECT:
3591 return "WLAN_AP_DISCONNECT";
3592 case WLAN_STA_CONNECT:
3593 return "WLAN_STA_CONNECT";
3594 case WLAN_STA_DISCONNECT:
3595 return "WLAN_STA_DISCONNECT";
3596 case WLAN_CLIENT_CONNECT_EX:
3597 return "WLAN_CLIENT_CONNECT_EX";
3598
3599 case IPA_WLAN_EVENT_MAX:
3600 default:
3601 return "UNKNOWN";
3602 }
3603}
3604
3605/**
3606 * hdd_ipa_wlan_evt() - IPA event handler
3607 * @adapter: adapter upon which the event was received
3608 * @sta_id: station id for the event
3609 * @type: the event type
3610 * @mac_address: MAC address associated with the event
3611 *
3612 * Return: 0 on success, negative errno value on error
3613 */
3614int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
3615 enum ipa_wlan_event type, uint8_t *mac_addr)
3616{
3617 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3618 struct ipa_msg_meta meta;
3619 struct ipa_wlan_msg *msg;
3620 struct ipa_wlan_msg_ex *msg_ex = NULL;
3621 int ret;
3622
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303623 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003624 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3625 mac_addr, sta_id);
3626
3627 if (type >= IPA_WLAN_EVENT_MAX)
3628 return -EINVAL;
3629
3630 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3631 return -EINVAL;
3632
3633 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303634 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635 return -EINVAL;
3636 }
3637
3638 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3639 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3640 (WLAN_HDD_SOFTAP != adapter->device_mode)) {
3641 return 0;
3642 }
3643
3644 /*
3645 * During IPA UC resource loading/unloading new events can be issued.
3646 * Store the events separately and handle them later.
3647 */
3648 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3649 ((hdd_ipa->resource_loading) ||
3650 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003651 unsigned int pending_event_count;
3652 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653
Yun Parkf19e07d2015-11-20 11:34:27 -08003654 hdd_err("IPA resource %s inprogress",
3655 hdd_ipa->resource_loading ? "load":"unload");
3656
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303657 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003658
Anurag Chouhanffb21542016-02-17 14:33:03 +05303659 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003660 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3661 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303662 qdf_list_remove_front(&hdd_ipa->pending_event,
3663 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003664 } else {
3665 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303666 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003667 sizeof(struct ipa_uc_pending_event));
3668 }
3669
3670 if (!pending_event) {
3671 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303672 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003673 return -ENOMEM;
3674 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003675
3676 pending_event->adapter = adapter;
3677 pending_event->sta_id = sta_id;
3678 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303679 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303681 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303682 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003683 &pending_event->node);
3684
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303685 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686 return 0;
3687 }
3688
3689 hdd_ipa->stats.event[type]++;
3690
Leo Chang3bc8fed2015-11-13 10:59:47 -08003691 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 switch (type) {
3693 case WLAN_STA_CONNECT:
3694 /* STA already connected and without disconnect, connect again
3695 * This is Roaming scenario
3696 */
3697 if (hdd_ipa->sta_connected)
3698 hdd_ipa_cleanup_iface(adapter->ipa_context);
3699
3700 if ((hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) &&
3701 (!hdd_ipa->sta_connected))
3702 hdd_ipa_uc_offload_enable_disable(adapter,
3703 SIR_STA_RX_DATA_OFFLOAD, 1);
3704
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303705 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706
3707 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303708 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3710 msg_ex->name, meta.msg_type);
3711 } else if ((!hdd_ipa->sap_num_connected_sta) &&
3712 (!hdd_ipa->sta_connected)) {
3713 /* Enable IPA UC TX PIPE when STA connected */
3714 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
Yun Park4cab6ee2015-10-27 11:43:40 -07003715 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303716 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303717 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003718 "handle 1st con ret %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003719 hdd_ipa_uc_offload_enable_disable(adapter,
3720 SIR_STA_RX_DATA_OFFLOAD, 0);
3721 goto end;
3722 }
3723 }
3724 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3725 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303726 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727 hdd_ipa_uc_offload_enable_disable(adapter,
3728 SIR_STA_RX_DATA_OFFLOAD, 0);
3729 goto end;
3730
3731#ifdef IPA_UC_OFFLOAD
3732 vdev_to_iface[adapter->sessionId] =
3733 ((struct hdd_ipa_iface_context *)
3734 (adapter->ipa_context))->iface_id;
3735#endif /* IPA_UC_OFFLOAD */
3736 }
3737
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303738 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003739
3740 hdd_ipa->sta_connected = 1;
3741 break;
3742
3743 case WLAN_AP_CONNECT:
3744 /* For DFS channel we get two start_bss event (before and after
3745 * CAC). Also when ACS range includes both DFS and non DFS
3746 * channels, we could possibly change channel many times due to
3747 * RADAR detection and chosen channel may not be a DFS channels.
3748 * So dont return error here. Just discard the event.
3749 */
3750 if (adapter->ipa_context)
3751 return 0;
3752
3753 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3754 hdd_ipa_uc_offload_enable_disable(adapter,
3755 SIR_AP_RX_DATA_OFFLOAD, 1);
3756 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303757 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3759 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303760 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761 "%s: Evt: %d, Interface setup failed",
3762 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303763 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003764 goto end;
3765
3766#ifdef IPA_UC_OFFLOAD
3767 vdev_to_iface[adapter->sessionId] =
3768 ((struct hdd_ipa_iface_context *)
3769 (adapter->ipa_context))->iface_id;
3770#endif /* IPA_UC_OFFLOAD */
3771 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303772 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773 break;
3774
3775 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303776 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003777 hdd_ipa_cleanup_iface(adapter->ipa_context);
3778
3779 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303780 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781 "%s: Evt: %d, STA already disconnected",
3782 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303783 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003784 return -EINVAL;
3785 }
3786 hdd_ipa->sta_connected = 0;
3787 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303788 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003789 "%s: IPA UC OFFLOAD NOT ENABLED",
3790 msg_ex->name);
3791 } else {
3792 /* Disable IPA UC TX PIPE when STA disconnected */
3793 if ((!hdd_ipa->sap_num_connected_sta) ||
3794 ((!hdd_ipa->num_iface) &&
3795 (HDD_IPA_UC_NUM_WDI_PIPE ==
3796 hdd_ipa->activated_fw_pipe))) {
3797 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3798 }
3799 }
3800
3801 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3802 hdd_ipa_uc_offload_enable_disable(adapter,
3803 SIR_STA_RX_DATA_OFFLOAD, 0);
3804 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3805 }
3806
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303807 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808 break;
3809
3810 case WLAN_AP_DISCONNECT:
3811 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303812 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 "%s: Evt: %d, SAP already disconnected",
3814 msg_ex->name, meta.msg_type);
3815 return -EINVAL;
3816 }
3817
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303818 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819 hdd_ipa_cleanup_iface(adapter->ipa_context);
3820 if ((!hdd_ipa->num_iface) &&
3821 (HDD_IPA_UC_NUM_WDI_PIPE ==
3822 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003823 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003824 /*
3825 * We disable WDI pipes directly here since
3826 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3827 * processed when unloading WLAN driver is in
3828 * progress
3829 */
3830 hdd_ipa_uc_disable_pipes(hdd_ipa);
3831 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303832 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833 "NO INTF left but still pipe clean up");
3834 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3835 }
3836 }
3837
3838 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3839 hdd_ipa_uc_offload_enable_disable(adapter,
3840 SIR_AP_RX_DATA_OFFLOAD, 0);
3841 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3842 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303843 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844 break;
3845
3846 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303847 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003848 adapter->dev->ifindex, sta_id);
3849
3850 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303851 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3853 adapter->dev->name, meta.msg_type);
3854 return 0;
3855 }
3856
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303857 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3859 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303860 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861 "%s: STA ID %d found, not valid",
3862 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303863 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864 return 0;
3865 }
Yun Park312f71a2015-12-08 10:22:42 -08003866
3867 /* Enable IPA UC Data PIPEs when first STA connected */
3868 if ((0 == hdd_ipa->sap_num_connected_sta) &&
3869 (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3870 !hdd_ipa->sta_connected)) {
3871 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3872 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303873 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303874 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003875 "%s: handle 1st con ret %d",
3876 adapter->dev->name, ret);
3877 return ret;
3878 }
3879 }
3880
3881 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003882
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303883 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884
3885 meta.msg_type = type;
3886 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3887 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303888 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889
3890 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303891 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003892 "msg_ex allocation failed");
3893 return -ENOMEM;
3894 }
3895 strlcpy(msg_ex->name, adapter->dev->name,
3896 IPA_RESOURCE_NAME_MAX);
3897 msg_ex->num_of_attribs = 1;
3898 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
3899 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3900 msg_ex->attribs[0].offset =
3901 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3902 } else {
3903 msg_ex->attribs[0].offset =
3904 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3905 }
3906 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
3907 IPA_MAC_ADDR_SIZE);
3908
3909 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
3910
3911 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303912 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303914 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003915 return ret;
3916 }
3917 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003918 return ret;
3919
3920 case WLAN_CLIENT_DISCONNECT:
3921 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303922 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923 "%s: IPA UC OFFLOAD NOT ENABLED",
3924 msg_ex->name);
3925 return 0;
3926 }
3927
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303928 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303930 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 "%s: STA ID %d NOT found, not valid",
3932 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303933 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934 return 0;
3935 }
3936 hdd_ipa->sap_num_connected_sta--;
3937 /* Disable IPA UC TX PIPE when last STA disconnected */
3938 if (!hdd_ipa->sap_num_connected_sta
3939 && (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3940 !hdd_ipa->sta_connected)
3941 && (false == hdd_ipa->resource_unloading)
3942 && (HDD_IPA_UC_NUM_WDI_PIPE ==
3943 hdd_ipa->activated_fw_pipe))
3944 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303945 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946 break;
3947
3948 default:
3949 return 0;
3950 }
3951
3952 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303953 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303955 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 return -ENOMEM;
3957 }
3958
3959 meta.msg_type = type;
3960 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
3961 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
3962
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303963 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 msg->name, meta.msg_type);
3965
3966 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3967
3968 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303969 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303971 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 return ret;
3973 }
3974
3975 hdd_ipa->stats.num_send_msg++;
3976
3977end:
3978 return ret;
3979}
3980
3981/**
3982 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
3983 * @state: IPA RM state value
3984 *
3985 * Return: ASCII string representing the IPA RM state
3986 */
3987static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
3988{
3989 switch (state) {
3990 case HDD_IPA_RM_RELEASED:
3991 return "RELEASED";
3992 case HDD_IPA_RM_GRANT_PENDING:
3993 return "GRANT_PENDING";
3994 case HDD_IPA_RM_GRANTED:
3995 return "GRANTED";
3996 }
3997
3998 return "UNKNOWN";
3999}
4000
4001/**
4002 * hdd_ipa_init() - IPA initialization function
4003 * @hdd_ctx: HDD global context
4004 *
4005 * Allocate hdd_ipa resources, ipa pipe resource and register
4006 * wlan interface with IPA module.
4007 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304008 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004009 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304010QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011{
4012 struct hdd_ipa_priv *hdd_ipa = NULL;
4013 int ret, i;
4014 struct hdd_ipa_iface_context *iface_context = NULL;
4015
4016 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304017 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304019 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304021 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004022 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 }
4024
4025 hdd_ctx->hdd_ipa = hdd_ipa;
4026 ghdd_ipa = hdd_ipa;
4027 hdd_ipa->hdd_ctx = hdd_ctx;
4028 hdd_ipa->num_iface = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304029 ol_txrx_ipa_uc_get_resource(cds_get_context(QDF_MODULE_ID_TXRX),
Leo Chang3bc8fed2015-11-13 10:59:47 -08004030 &hdd_ipa->ce_sr_base_paddr,
4031 &hdd_ipa->ce_sr_ring_size,
4032 &hdd_ipa->ce_reg_paddr,
4033 &hdd_ipa->tx_comp_ring_base_paddr,
4034 &hdd_ipa->tx_comp_ring_size,
4035 &hdd_ipa->tx_num_alloc_buffer,
4036 &hdd_ipa->rx_rdy_ring_base_paddr,
4037 &hdd_ipa->rx_rdy_ring_size,
4038 &hdd_ipa->rx_proc_done_idx_paddr,
4039 &hdd_ipa->rx_proc_done_idx_vaddr,
4040 &hdd_ipa->rx2_rdy_ring_base_paddr,
4041 &hdd_ipa->rx2_rdy_ring_size,
4042 &hdd_ipa->rx2_proc_done_idx_paddr,
4043 &hdd_ipa->rx2_proc_done_idx_vaddr);
4044 if ((0 == hdd_ipa->ce_sr_base_paddr) ||
4045 (0 == hdd_ipa->tx_comp_ring_base_paddr) ||
4046 (0 == hdd_ipa->rx_rdy_ring_base_paddr) ||
4047 (0 == hdd_ipa->rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304048 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004049 "IPA UC resource alloc fail");
4050 goto fail_get_resource;
4051 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052
4053 /* Create the interface context */
4054 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4055 iface_context = &hdd_ipa->iface_context[i];
4056 iface_context->hdd_ipa = hdd_ipa;
4057 iface_context->cons_client =
4058 hdd_ipa_adapter_2_client[i].cons_client;
4059 iface_context->prod_client =
4060 hdd_ipa_adapter_2_client[i].prod_client;
4061 iface_context->iface_id = i;
4062 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304063 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004064 }
4065
4066#ifdef CONFIG_CNSS
4067 cnss_init_work(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
4068#else
4069 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
4070#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304071 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304072 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073
4074 ret = hdd_ipa_setup_rm(hdd_ipa);
4075 if (ret)
4076 goto fail_setup_rm;
4077
4078 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4079 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304080 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 hdd_ipa->sap_num_connected_sta = 0;
4082 hdd_ipa->ipa_tx_packets_diff = 0;
4083 hdd_ipa->ipa_rx_packets_diff = 0;
4084 hdd_ipa->ipa_p_tx_packets = 0;
4085 hdd_ipa->ipa_p_rx_packets = 0;
4086 hdd_ipa->resource_loading = false;
4087 hdd_ipa->resource_unloading = false;
4088 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004089 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004090 /* Setup IPA sys_pipe for MCC */
4091 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4092 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4093 if (ret)
4094 goto fail_create_sys_pipe;
4095 }
4096 hdd_ipa_uc_ol_init(hdd_ctx);
4097 } else {
4098 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4099 if (ret)
4100 goto fail_create_sys_pipe;
4101 }
4102
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304103 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104
4105fail_create_sys_pipe:
4106 hdd_ipa_destroy_rm_resource(hdd_ipa);
4107fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304108 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004109fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304110 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004111 hdd_ctx->hdd_ipa = NULL;
4112 ghdd_ipa = NULL;
4113fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304114 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115}
4116
4117/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004118 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4119 * @hdd_ipa: pointer to HDD IPA struct
4120 *
4121 * Return: none
4122 */
4123void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
4124{
4125 struct ipa_uc_pending_event *pending_event = NULL;
4126
Anurag Chouhanffb21542016-02-17 14:33:03 +05304127 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4128 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304129 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004130 }
4131
Anurag Chouhanffb21542016-02-17 14:33:03 +05304132 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004133}
4134
4135/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004136 * hdd_ipa_cleanup - IPA cleanup function
4137 * @hdd_ctx: HDD global context
4138 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304139 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004140 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304141QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004142{
4143 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4144 int i;
4145 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304146 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4148
4149 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304150 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004151
4152 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4153 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4154 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4155 }
4156
4157 /* Teardown IPA sys_pipe for MCC */
4158 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4159 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4160
4161 hdd_ipa_destroy_rm_resource(hdd_ipa);
4162
4163#ifdef WLAN_OPEN_SOURCE
4164 cancel_work_sync(&hdd_ipa->pm_work);
4165#endif
4166
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304167 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168
Nirav Shahcbc6d722016-03-01 16:24:53 +05304169 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4170 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304171 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172
4173 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4174 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4175
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304176 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304178 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304180 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181
4182 /* destory the interface lock */
4183 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4184 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304185 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 }
4187
4188 /* This should never hit but still make sure that there are no pending
4189 * descriptor in IPA hardware
4190 */
4191 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304192 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193 "IPA Pending write done: %d Waiting!",
4194 hdd_ipa->pending_hw_desc_cnt);
4195
4196 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4197 usleep_range(100, 100);
4198 }
4199
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304200 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201 "IPA Pending write done: desc: %d %s(%d)!",
4202 hdd_ipa->pending_hw_desc_cnt,
4203 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4204 : "leak", i);
4205 }
4206 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4207 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304208 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004209 "%s: Disconnect TX PIPE", __func__);
4210 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304211 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 "%s: Disconnect RX PIPE", __func__);
4213 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304214 qdf_mutex_destroy(&hdd_ipa->event_lock);
4215 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004216 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217
4218#ifdef WLAN_OPEN_SOURCE
4219 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4220 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4221 hdd_ipa->uc_op_work[i].msg = NULL;
4222 }
4223#endif
4224 }
4225
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304226 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227 hdd_ctx->hdd_ipa = NULL;
4228
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304229 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230}
4231#endif /* IPA_OFFLOAD */