blob: 8ff2d3c5e4ee90b4b78d7dc280ffac7458d424de [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 /*
379 * IPA driver can send RM notifications with IRQ disabled so using cdf
380 * 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;
393 cdf_nbuf_queue_t pm_queue_head;
394 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;
908 cdf_mem_zero(hdd_ipa->rt_bug_buffer,
909 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);
1335 cdf_mem_free(pending_event);
1336 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");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378 cdf_mem_free(op_msg);
1379 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 }
1622 cdf_mem_free(op_msg);
1623}
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
1655 cdf_mem_zero(&ipa_offload_enable_disable,
1656 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:
1749 cdf_mem_free(op_msg);
1750}
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
1788 cdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1789 cdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
1790
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
2133 if (!cdf_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 */
2511static void hdd_ipa_send_skb_to_network(cdf_nbuf_t skb,
2512 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);
2521 cdf_nbuf_free(skb);
2522 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);
2527 cdf_nbuf_free(skb);
2528 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;
2562 cdf_nbuf_t skb;
2563 uint8_t iface_id;
2564 uint8_t session_id;
2565 struct hdd_ipa_iface_context *iface_context;
2566 cdf_nbuf_t copy;
2567 uint8_t fw_desc;
2568 int ret;
2569
2570 hdd_ipa = (struct hdd_ipa_priv *)priv;
2571
2572 switch (evt) {
2573 case IPA_RECEIVE:
2574 skb = (cdf_nbuf_t) data;
2575 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);
2592 cdf_nbuf_free(skb);
2593 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);
2631 copy = cdf_nbuf_copy(skb);
2632 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++;
2652 cdf_nbuf_free(skb);
2653 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 */
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002677void hdd_ipa_nbuf_cb(cdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002678{
2679 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2680
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302681 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%p", wlan_hdd_stub_priv_to_addr(NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002682 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
2683 ipa_free_skb((struct ipa_rx_data *)wlan_hdd_stub_priv_to_addr(NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002684
2685 hdd_ipa->stats.num_tx_comp_cnt++;
2686
2687 atomic_dec(&hdd_ipa->tx_ref_cnt);
2688
2689 hdd_ipa_rm_try_release(hdd_ipa);
2690}
2691
2692/**
2693 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2694 * @iface_context: interface-specific IPA context
2695 * @ipa_tx_desc: packet data descriptor
2696 *
2697 * Return: None
2698 */
2699static void hdd_ipa_send_pkt_to_tl(
2700 struct hdd_ipa_iface_context *iface_context,
2701 struct ipa_rx_data *ipa_tx_desc)
2702{
2703 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2704 uint8_t interface_id;
2705 hdd_adapter_t *adapter = NULL;
2706 cdf_nbuf_t skb;
2707
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302708 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709 adapter = iface_context->adapter;
2710 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302711 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002712 ipa_free_skb(ipa_tx_desc);
2713 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302714 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002715 hdd_ipa_rm_try_release(hdd_ipa);
2716 return;
2717 }
2718
2719 /*
2720 * During CAC period, data packets shouldn't be sent over the air so
2721 * drop all the packets here
2722 */
2723 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2724 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302725 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002726 iface_context->stats.num_tx_cac_drop++;
2727 hdd_ipa_rm_try_release(hdd_ipa);
2728 return;
2729 }
2730
2731 interface_id = adapter->sessionId;
2732 ++adapter->stats.tx_packets;
2733
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302734 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002735
2736 skb = ipa_tx_desc->skb;
2737
2738 cdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002739 cdf_nbuf_ipa_owned_set(skb);
2740 /* FIXME: This is broken. No such field in cb any more:
2741 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002742 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002743 cdf_nbuf_mapped_paddr_set(skb,
2744 ipa_tx_desc->dma_addr
2745 + HDD_IPA_WLAN_FRAG_HEADER
2746 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002747 ipa_tx_desc->skb->len -=
2748 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2749 } else
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002750 cdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002752 /* FIXME: This is broken: priv_data is 31 bits */
2753 cdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002754
2755 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2756
2757 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2758 ipa_tx_desc->skb);
2759 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302760 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002761 ipa_free_skb(ipa_tx_desc);
2762 iface_context->stats.num_tx_err++;
2763 hdd_ipa_rm_try_release(hdd_ipa);
2764 return;
2765 }
2766
2767 atomic_inc(&hdd_ipa->tx_ref_cnt);
2768
2769 iface_context->stats.num_tx++;
2770
2771}
2772
2773/**
2774 * hdd_ipa_pm_send_pkt_to_tl() - Send queued packets to TL
2775 * @work: pointer to the scheduled work
2776 *
2777 * Called during PM resume to send packets to TL which were queued
2778 * while host was in the process of suspending.
2779 *
2780 * Return: None
2781 */
2782static void hdd_ipa_pm_send_pkt_to_tl(struct work_struct *work)
2783{
2784 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2785 struct hdd_ipa_priv,
2786 pm_work);
2787 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
2788 cdf_nbuf_t skb;
2789 uint32_t dequeued = 0;
2790
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302791 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792
2793 while (((skb = cdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head)) != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302794 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002795
2796 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2797
2798 dequeued++;
2799
2800 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
2801 pm_tx_cb->ipa_tx_desc);
2802
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302803 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002804 }
2805
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302806 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807
2808 hdd_ipa->stats.num_tx_dequeued += dequeued;
2809 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2810 hdd_ipa->stats.num_max_pm_queue = dequeued;
2811}
2812
2813/**
2814 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2815 * @priv: pointer to private data registered with IPA (we register a
2816 * pointer to the interface-specific IPA context)
2817 * @evt: the IPA event which triggered the callback
2818 * @data: data associated with the event
2819 *
2820 * Return: None
2821 */
2822static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2823 unsigned long data)
2824{
2825 struct hdd_ipa_priv *hdd_ipa = NULL;
2826 struct ipa_rx_data *ipa_tx_desc;
2827 struct hdd_ipa_iface_context *iface_context;
2828 cdf_nbuf_t skb;
2829 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302830 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831
Mukul Sharma81661ae2015-10-30 20:26:02 +05302832 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833 if (evt != IPA_RECEIVE) {
2834 skb = (cdf_nbuf_t) data;
2835 dev_kfree_skb_any(skb);
2836 iface_context->stats.num_tx_drop++;
2837 return;
2838 }
2839
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002840 ipa_tx_desc = (struct ipa_rx_data *)data;
2841
2842 hdd_ipa = iface_context->hdd_ipa;
2843
2844 /*
2845 * When SSR is going on or driver is unloading, just drop the packets.
2846 * During SSR, there is no use in queueing the packets as STA has to
2847 * connect back any way
2848 */
2849 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2850 if (0 != status) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302851 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852 ipa_free_skb(ipa_tx_desc);
2853 iface_context->stats.num_tx_drop++;
2854 return;
2855 }
2856
2857 skb = ipa_tx_desc->skb;
2858
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302859 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860
2861 /*
2862 * If PROD resource is not requested here then there may be cases where
2863 * IPA hardware may be clocked down because of not having proper
2864 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2865 * workaround to request PROD resource while data is going over CONS
2866 * pipe to prevent the IPA hardware clockdown.
2867 */
2868 hdd_ipa_rm_request(hdd_ipa);
2869
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302870 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002871 /*
2872 * If host is still suspended then queue the packets and these will be
2873 * drained later when resume completes. When packet is arrived here and
2874 * host is suspended, this means that there is already resume is in
2875 * progress.
2876 */
2877 if (hdd_ipa->suspended) {
2878 cdf_mem_set(skb->cb, sizeof(skb->cb), 0);
2879 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2880 pm_tx_cb->iface_context = iface_context;
2881 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
2882 cdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
2883 hdd_ipa->stats.num_tx_queued++;
2884
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302885 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002886 return;
2887 }
2888
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302889 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002890
2891 /*
2892 * If we are here means, host is not suspended, wait for the work queue
2893 * to finish.
2894 */
2895#ifdef WLAN_OPEN_SOURCE
2896 flush_work(&hdd_ipa->pm_work);
2897#endif
2898
2899 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2900}
2901
2902/**
2903 * hdd_ipa_suspend() - Suspend IPA
2904 * @hdd_ctx: Global HDD context
2905 *
2906 * Return: 0 on success, negativer errno on error
2907 */
2908int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2909{
2910 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2911
2912 if (!hdd_ipa_is_enabled(hdd_ctx))
2913 return 0;
2914
2915 /*
2916 * Check if IPA is ready for suspend, If we are here means, there is
2917 * high chance that suspend would go through but just to avoid any race
2918 * condition after suspend started, these checks are conducted before
2919 * allowing to suspend.
2920 */
2921 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2922 return -EAGAIN;
2923
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302924 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002925
2926 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302927 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002928 return -EAGAIN;
2929 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302930 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002931
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302932 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002933 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302934 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935
2936 return 0;
2937}
2938
2939/**
2940 * hdd_ipa_resume() - Resume IPA following suspend
2941 * hdd_ctx: Global HDD context
2942 *
2943 * Return: 0 on success, negative errno on error
2944 */
2945int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2946{
2947 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2948
2949 if (!hdd_ipa_is_enabled(hdd_ctx))
2950 return 0;
2951
2952 schedule_work(&hdd_ipa->pm_work);
2953
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302954 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002955 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302956 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002957
2958 return 0;
2959}
2960
2961/**
2962 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
2963 * @hdd_ipa: Global HDD IPA context
2964 *
2965 * Return: 0 on success, negative errno on error
2966 */
2967static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
2968{
2969 int i, ret = 0;
2970 struct ipa_sys_connect_params *ipa;
2971 uint32_t desc_fifo_sz;
2972
2973 /* The maximum number of descriptors that can be provided to a BAM at
2974 * once is one less than the total number of descriptors that the buffer
2975 * can contain.
2976 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2977 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2978 * be provided at once.
2979 * Because of above requirement, one extra descriptor will be added to
2980 * make sure hardware always has one descriptor.
2981 */
2982 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
2983 + sizeof(struct sps_iovec);
2984
2985 /*setup TX pipes */
2986 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2987 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
2988
2989 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
2990 ipa->desc_fifo_sz = desc_fifo_sz;
2991 ipa->priv = &hdd_ipa->iface_context[i];
2992 ipa->notify = hdd_ipa_i2w_cb;
2993
2994 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2995 ipa->ipa_ep_cfg.hdr.hdr_len =
2996 HDD_IPA_UC_WLAN_TX_HDR_LEN;
2997 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2998 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2999 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3000 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3001 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3002 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3003 } else {
3004 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3005 }
3006 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3007
3008 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3009 ipa->keep_ipa_awake = 1;
3010
3011 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3012 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303013 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 " ret: %d", i, ret);
3015 goto setup_sys_pipe_fail;
3016 }
3017 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3018 }
3019
3020 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3021 /*
3022 * Hard code it here, this can be extended if in case
3023 * PROD pipe is also per interface.
3024 * Right now there is no advantage of doing this.
3025 */
3026 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3027
3028 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3029
3030 ipa->client = hdd_ipa->prod_client;
3031
3032 ipa->desc_fifo_sz = desc_fifo_sz;
3033 ipa->priv = hdd_ipa;
3034 ipa->notify = hdd_ipa_w2i_cb;
3035
3036 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3037 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3038 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3039 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3040
3041 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3042 ipa->keep_ipa_awake = 1;
3043
3044 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3045 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303046 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003047 "Failed for RX pipe: %d", ret);
3048 goto setup_sys_pipe_fail;
3049 }
3050 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3051 }
3052
3053 return ret;
3054
3055setup_sys_pipe_fail:
3056
3057 while (--i >= 0) {
3058 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
3059 cdf_mem_zero(&hdd_ipa->sys_pipe[i],
3060 sizeof(struct hdd_ipa_sys_pipe));
3061 }
3062
3063 return ret;
3064}
3065
3066/**
3067 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3068 * @hdd_ipa: Global HDD IPA context
3069 *
3070 * Return: None
3071 */
3072static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3073{
3074 int ret = 0, i;
3075 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3076 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3077 ret =
3078 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3079 conn_hdl);
3080 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303081 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 ret);
3083
3084 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3085 }
3086 }
3087}
3088
3089/**
3090 * hdd_ipa_register_interface() - register IPA interface
3091 * @hdd_ipa: Global IPA context
3092 * @iface_context: Per-interface IPA context
3093 *
3094 * Return: 0 on success, negative errno on error
3095 */
3096static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3097 struct hdd_ipa_iface_context
3098 *iface_context)
3099{
3100 struct ipa_tx_intf tx_intf;
3101 struct ipa_rx_intf rx_intf;
3102 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3103 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3104 char *ifname = iface_context->adapter->dev->name;
3105
3106 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3107 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3108
3109 int num_prop = 1;
3110 int ret = 0;
3111
3112 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3113 num_prop++;
3114
3115 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3116 tx_prop =
3117 cdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
3118 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303119 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 goto register_interface_fail;
3121 }
3122
3123 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3124 rx_prop =
3125 cdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
3126 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303127 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128 goto register_interface_fail;
3129 }
3130
3131 cdf_mem_zero(&tx_intf, sizeof(tx_intf));
3132 cdf_mem_zero(&rx_intf, sizeof(rx_intf));
3133
3134 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3135 ifname, HDD_IPA_IPV4_NAME_EXT);
3136 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3137 ifname, HDD_IPA_IPV6_NAME_EXT);
3138
3139 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3140 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3141 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3142 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3143
3144 /*
3145 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3146 * mask to identify the interface in IPA hardware
3147 */
3148 rx_prop[IPA_IP_v4].attrib.meta_data =
3149 htonl(iface_context->adapter->sessionId << 16);
3150 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3151
3152 rx_intf.num_props++;
3153 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3154 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3155 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3156 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3157 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3158 rx_prop[IPA_IP_v4].attrib.meta_data =
3159 htonl(iface_context->adapter->sessionId << 16);
3160 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3161
3162 rx_intf.num_props++;
3163 }
3164
3165 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3166 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3167 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3168 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3169 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3170 IPA_RESOURCE_NAME_MAX);
3171 tx_intf.num_props++;
3172
3173 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3174 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3175 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3176 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3177 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3178 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3179 IPA_RESOURCE_NAME_MAX);
3180 tx_intf.num_props++;
3181 }
3182
3183 tx_intf.prop = tx_prop;
3184 rx_intf.prop = rx_prop;
3185
3186 /* Call the ipa api to register interface */
3187 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3188
3189register_interface_fail:
3190 cdf_mem_free(tx_prop);
3191 cdf_mem_free(rx_prop);
3192 return ret;
3193}
3194
3195/**
3196 * hdd_remove_ipa_header() - Remove a specific header from IPA
3197 * @name: Name of the header to be removed
3198 *
3199 * Return: None
3200 */
3201static void hdd_ipa_remove_header(char *name)
3202{
3203 struct ipa_ioc_get_hdr hdrlookup;
3204 int ret = 0, len;
3205 struct ipa_ioc_del_hdr *ipa_hdr;
3206
3207 cdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
3208 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3209 ret = ipa_get_hdr(&hdrlookup);
3210 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303211 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 name, ret);
3213 return;
3214 }
3215
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303216 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
3218 ipa_hdr = (struct ipa_ioc_del_hdr *)cdf_mem_malloc(len);
3219 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303220 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003221 return;
3222 }
3223 ipa_hdr->num_hdls = 1;
3224 ipa_hdr->commit = 0;
3225 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3226 ipa_hdr->hdl[0].status = -1;
3227 ret = ipa_del_hdr(ipa_hdr);
3228 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303229 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230 ret);
3231
3232 cdf_mem_free(ipa_hdr);
3233}
3234
3235/**
3236 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3237 * @hdd_ipa: Global HDD IPA context
3238 * @iface_context: Interface-specific HDD IPA context
3239 * @mac_addr: Interface MAC address
3240 *
3241 * Return: 0 on success, negativer errno value on error
3242 */
3243static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3244 struct hdd_ipa_iface_context *iface_context,
3245 uint8_t *mac_addr)
3246{
3247 hdd_adapter_t *adapter = iface_context->adapter;
3248 char *ifname;
3249 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3250 int ret = -EINVAL;
3251 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3252 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3253
3254 ifname = adapter->dev->name;
3255
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303256 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257 ifname, mac_addr);
3258
3259 /* dynamically allocate the memory to add the hdrs */
3260 ipa_hdr = cdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
3261 + sizeof(struct ipa_hdr_add));
3262 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303263 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 "%s: ipa_hdr allocation failed", ifname);
3265 ret = -ENOMEM;
3266 goto end;
3267 }
3268
3269 ipa_hdr->commit = 0;
3270 ipa_hdr->num_hdrs = 1;
3271
3272 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3273 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3274 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3275 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3276 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303277 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278 "ifname=%s, vdev_id=%d",
3279 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3280 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3281 ifname, HDD_IPA_IPV4_NAME_EXT);
3282 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3283 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3284 ipa_hdr->hdr[0].is_partial = 1;
3285 ipa_hdr->hdr[0].hdr_hdl = 0;
3286 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3287 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3288
3289 ret = ipa_add_hdr(ipa_hdr);
3290 } else {
3291 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3292
3293 /* Set the Source MAC */
3294 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3295 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3296
3297 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3298 ifname, HDD_IPA_IPV4_NAME_EXT);
3299 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3300 ipa_hdr->hdr[0].is_partial = 1;
3301 ipa_hdr->hdr[0].hdr_hdl = 0;
3302 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3303 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3304
3305 /* Set the type to IPV4 in the header */
3306 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3307
3308 ret = ipa_add_hdr(ipa_hdr);
3309 }
3310 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303311 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 ifname, ret);
3313 goto end;
3314 }
3315
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303316 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003317 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3318
3319 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3320 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3321 ifname, HDD_IPA_IPV6_NAME_EXT);
3322
3323 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3324 uc_tx_hdr =
3325 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3326 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3327 } else {
3328 /* Set the type to IPV6 in the header */
3329 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3330 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3331 }
3332
3333 ret = ipa_add_hdr(ipa_hdr);
3334 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303335 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336 "%s: IPv6 add hdr failed: %d", ifname, ret);
3337 goto clean_ipv4_hdr;
3338 }
3339
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303340 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3342 }
3343
3344 cdf_mem_free(ipa_hdr);
3345
3346 return ret;
3347
3348clean_ipv4_hdr:
3349 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3350 ifname, HDD_IPA_IPV4_NAME_EXT);
3351 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3352end:
3353 if (ipa_hdr)
3354 cdf_mem_free(ipa_hdr);
3355
3356 return ret;
3357}
3358
3359/**
3360 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3361 * @adapter: Adapter upon which IPA was previously configured
3362 *
3363 * Return: None
3364 */
3365static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3366{
3367 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3368 int ret;
3369 char name_ipa[IPA_RESOURCE_NAME_MAX];
3370
3371 /* Remove the headers */
3372 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3373 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3374 hdd_ipa_remove_header(name_ipa);
3375
3376 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3377 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3378 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3379 hdd_ipa_remove_header(name_ipa);
3380 }
3381 /* unregister the interface with IPA */
3382 ret = ipa_deregister_intf(adapter->dev->name);
3383 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303384 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 "%s: ipa_deregister_intf fail: %d",
3386 adapter->dev->name, ret);
3387}
3388
3389/**
3390 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3391 * @iface_context: interface-specific IPA context
3392 *
3393 * Return: None
3394 */
3395static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3396{
3397 if (iface_context == NULL)
3398 return;
3399
3400 hdd_ipa_clean_hdr(iface_context->adapter);
3401
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303402 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403 iface_context->adapter->ipa_context = NULL;
3404 iface_context->adapter = NULL;
3405 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303406 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 iface_context->ifa_address = 0;
3408 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303409 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303411 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 }
3413 iface_context->hdd_ipa->num_iface--;
3414}
3415
3416/**
3417 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3418 * @hdd_ipa: HDD IPA global context
3419 * @adapter: Interface upon which IPA is being setup
3420 * @sta_id: Station ID of the API instance
3421 *
3422 * Return: 0 on success, negative errno value on error
3423 */
3424static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3425 hdd_adapter_t *adapter, uint8_t sta_id)
3426{
3427 struct hdd_ipa_iface_context *iface_context = NULL;
3428 void *tl_context = NULL;
3429 int i, ret = 0;
3430
3431 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3432 * channel change indication. Since these indications are sent by lower
3433 * layer as SAP updates and IPA doesn't have to do anything for these
3434 * updates so ignoring!
3435 */
3436 if (WLAN_HDD_SOFTAP == adapter->device_mode && adapter->ipa_context)
3437 return 0;
3438
3439 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3440 if (hdd_ipa->iface_context[i].adapter == NULL) {
3441 iface_context = &(hdd_ipa->iface_context[i]);
3442 break;
3443 }
3444 }
3445
3446 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303447 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448 "All the IPA interfaces are in use");
3449 ret = -ENOMEM;
3450 goto end;
3451 }
3452
3453 adapter->ipa_context = iface_context;
3454 iface_context->adapter = adapter;
3455 iface_context->sta_id = sta_id;
3456 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3457
3458 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303459 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 "Not able to get TL context sta_id: %d", sta_id);
3461 ret = -EINVAL;
3462 goto end;
3463 }
3464
3465 iface_context->tl_context = tl_context;
3466
3467 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3468 adapter->dev->dev_addr);
3469
3470 if (ret)
3471 goto end;
3472
3473 /* Configure the TX and RX pipes filter rules */
3474 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3475 if (ret)
3476 goto cleanup_header;
3477
3478 hdd_ipa->num_iface++;
3479 return ret;
3480
3481cleanup_header:
3482
3483 hdd_ipa_clean_hdr(adapter);
3484end:
3485 if (iface_context)
3486 hdd_ipa_cleanup_iface(iface_context);
3487 return ret;
3488}
3489
3490/**
3491 * hdd_ipa_msg_free_fn() - Free an IPA message
3492 * @buff: pointer to the IPA message
3493 * @len: length of the IPA message
3494 * @type: type of IPA message
3495 *
3496 * Return: None
3497 */
3498static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3499{
3500 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3501 ghdd_ipa->stats.num_free_msg++;
3502 cdf_mem_free(buff);
3503}
3504
3505/**
3506 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3507 * @mcc_mode: 0=MCC/1=SCC
3508 *
3509 * Return: 0 on success, negative errno value on error
3510 */
3511int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3512{
3513 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303514 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515 hdd_adapter_t *pAdapter;
3516 struct ipa_msg_meta meta;
3517 struct ipa_wlan_msg *msg;
3518 int ret;
3519
3520 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3521 return -EINVAL;
3522
3523 if (!pHddCtx->mcc_mode) {
3524 /* Flush TxRx queue for each adapter before switch to SCC */
3525 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303526 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003527 pAdapter = adapter_node->pAdapter;
3528 if (pAdapter->device_mode == WLAN_HDD_INFRA_STATION ||
3529 pAdapter->device_mode == WLAN_HDD_SOFTAP) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303530 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3532 pAdapter->device_mode);
3533 hdd_deinit_tx_rx(pAdapter);
3534 }
3535 status = hdd_get_next_adapter(
3536 pHddCtx, adapter_node, &next);
3537 adapter_node = next;
3538 }
3539 }
3540
3541 /* Send SCC/MCC Switching event to IPA */
3542 meta.msg_len = sizeof(*msg);
3543 msg = cdf_mem_malloc(meta.msg_len);
3544 if (msg == NULL) {
3545 hddLog(LOGE, "msg allocation failed");
3546 return -ENOMEM;
3547 }
3548
3549 meta.msg_type = mcc_mode ?
3550 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3551 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3552
3553 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3554
3555 if (ret) {
3556 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3557 meta.msg_type, ret);
3558 cdf_mem_free(msg);
3559 }
3560
3561 return ret;
3562}
3563
3564/**
3565 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3566 * @event: IPA WLAN event to be converted to a string
3567 *
3568 * Return: ASCII string representing the IPA WLAN event
3569 */
3570static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3571{
3572 switch (event) {
3573 case WLAN_CLIENT_CONNECT:
3574 return "WLAN_CLIENT_CONNECT";
3575 case WLAN_CLIENT_DISCONNECT:
3576 return "WLAN_CLIENT_DISCONNECT";
3577 case WLAN_CLIENT_POWER_SAVE_MODE:
3578 return "WLAN_CLIENT_POWER_SAVE_MODE";
3579 case WLAN_CLIENT_NORMAL_MODE:
3580 return "WLAN_CLIENT_NORMAL_MODE";
3581 case SW_ROUTING_ENABLE:
3582 return "SW_ROUTING_ENABLE";
3583 case SW_ROUTING_DISABLE:
3584 return "SW_ROUTING_DISABLE";
3585 case WLAN_AP_CONNECT:
3586 return "WLAN_AP_CONNECT";
3587 case WLAN_AP_DISCONNECT:
3588 return "WLAN_AP_DISCONNECT";
3589 case WLAN_STA_CONNECT:
3590 return "WLAN_STA_CONNECT";
3591 case WLAN_STA_DISCONNECT:
3592 return "WLAN_STA_DISCONNECT";
3593 case WLAN_CLIENT_CONNECT_EX:
3594 return "WLAN_CLIENT_CONNECT_EX";
3595
3596 case IPA_WLAN_EVENT_MAX:
3597 default:
3598 return "UNKNOWN";
3599 }
3600}
3601
3602/**
3603 * hdd_ipa_wlan_evt() - IPA event handler
3604 * @adapter: adapter upon which the event was received
3605 * @sta_id: station id for the event
3606 * @type: the event type
3607 * @mac_address: MAC address associated with the event
3608 *
3609 * Return: 0 on success, negative errno value on error
3610 */
3611int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
3612 enum ipa_wlan_event type, uint8_t *mac_addr)
3613{
3614 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3615 struct ipa_msg_meta meta;
3616 struct ipa_wlan_msg *msg;
3617 struct ipa_wlan_msg_ex *msg_ex = NULL;
3618 int ret;
3619
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303620 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3622 mac_addr, sta_id);
3623
3624 if (type >= IPA_WLAN_EVENT_MAX)
3625 return -EINVAL;
3626
3627 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3628 return -EINVAL;
3629
3630 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303631 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 return -EINVAL;
3633 }
3634
3635 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3636 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3637 (WLAN_HDD_SOFTAP != adapter->device_mode)) {
3638 return 0;
3639 }
3640
3641 /*
3642 * During IPA UC resource loading/unloading new events can be issued.
3643 * Store the events separately and handle them later.
3644 */
3645 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3646 ((hdd_ipa->resource_loading) ||
3647 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003648 unsigned int pending_event_count;
3649 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650
Yun Parkf19e07d2015-11-20 11:34:27 -08003651 hdd_err("IPA resource %s inprogress",
3652 hdd_ipa->resource_loading ? "load":"unload");
3653
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303654 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003655
Anurag Chouhanffb21542016-02-17 14:33:03 +05303656 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003657 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3658 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303659 qdf_list_remove_front(&hdd_ipa->pending_event,
3660 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003661 } else {
3662 pending_event =
3663 (struct ipa_uc_pending_event *)cdf_mem_malloc(
3664 sizeof(struct ipa_uc_pending_event));
3665 }
3666
3667 if (!pending_event) {
3668 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303669 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 return -ENOMEM;
3671 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003672
3673 pending_event->adapter = adapter;
3674 pending_event->sta_id = sta_id;
3675 pending_event->type = type;
3676 cdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303678 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303679 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003680 &pending_event->node);
3681
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303682 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683 return 0;
3684 }
3685
3686 hdd_ipa->stats.event[type]++;
3687
Leo Chang3bc8fed2015-11-13 10:59:47 -08003688 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 switch (type) {
3690 case WLAN_STA_CONNECT:
3691 /* STA already connected and without disconnect, connect again
3692 * This is Roaming scenario
3693 */
3694 if (hdd_ipa->sta_connected)
3695 hdd_ipa_cleanup_iface(adapter->ipa_context);
3696
3697 if ((hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) &&
3698 (!hdd_ipa->sta_connected))
3699 hdd_ipa_uc_offload_enable_disable(adapter,
3700 SIR_STA_RX_DATA_OFFLOAD, 1);
3701
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303702 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703
3704 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303705 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3707 msg_ex->name, meta.msg_type);
3708 } else if ((!hdd_ipa->sap_num_connected_sta) &&
3709 (!hdd_ipa->sta_connected)) {
3710 /* Enable IPA UC TX PIPE when STA connected */
3711 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
Yun Park4cab6ee2015-10-27 11:43:40 -07003712 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303713 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303714 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 "handle 1st con ret %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716 hdd_ipa_uc_offload_enable_disable(adapter,
3717 SIR_STA_RX_DATA_OFFLOAD, 0);
3718 goto end;
3719 }
3720 }
3721 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3722 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303723 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003724 hdd_ipa_uc_offload_enable_disable(adapter,
3725 SIR_STA_RX_DATA_OFFLOAD, 0);
3726 goto end;
3727
3728#ifdef IPA_UC_OFFLOAD
3729 vdev_to_iface[adapter->sessionId] =
3730 ((struct hdd_ipa_iface_context *)
3731 (adapter->ipa_context))->iface_id;
3732#endif /* IPA_UC_OFFLOAD */
3733 }
3734
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303735 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736
3737 hdd_ipa->sta_connected = 1;
3738 break;
3739
3740 case WLAN_AP_CONNECT:
3741 /* For DFS channel we get two start_bss event (before and after
3742 * CAC). Also when ACS range includes both DFS and non DFS
3743 * channels, we could possibly change channel many times due to
3744 * RADAR detection and chosen channel may not be a DFS channels.
3745 * So dont return error here. Just discard the event.
3746 */
3747 if (adapter->ipa_context)
3748 return 0;
3749
3750 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3751 hdd_ipa_uc_offload_enable_disable(adapter,
3752 SIR_AP_RX_DATA_OFFLOAD, 1);
3753 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303754 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3756 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303757 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758 "%s: Evt: %d, Interface setup failed",
3759 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303760 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761 goto end;
3762
3763#ifdef IPA_UC_OFFLOAD
3764 vdev_to_iface[adapter->sessionId] =
3765 ((struct hdd_ipa_iface_context *)
3766 (adapter->ipa_context))->iface_id;
3767#endif /* IPA_UC_OFFLOAD */
3768 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303769 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003770 break;
3771
3772 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303773 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 hdd_ipa_cleanup_iface(adapter->ipa_context);
3775
3776 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303777 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 "%s: Evt: %d, STA already disconnected",
3779 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303780 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781 return -EINVAL;
3782 }
3783 hdd_ipa->sta_connected = 0;
3784 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303785 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786 "%s: IPA UC OFFLOAD NOT ENABLED",
3787 msg_ex->name);
3788 } else {
3789 /* Disable IPA UC TX PIPE when STA disconnected */
3790 if ((!hdd_ipa->sap_num_connected_sta) ||
3791 ((!hdd_ipa->num_iface) &&
3792 (HDD_IPA_UC_NUM_WDI_PIPE ==
3793 hdd_ipa->activated_fw_pipe))) {
3794 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3795 }
3796 }
3797
3798 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3799 hdd_ipa_uc_offload_enable_disable(adapter,
3800 SIR_STA_RX_DATA_OFFLOAD, 0);
3801 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3802 }
3803
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303804 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805 break;
3806
3807 case WLAN_AP_DISCONNECT:
3808 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303809 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 "%s: Evt: %d, SAP already disconnected",
3811 msg_ex->name, meta.msg_type);
3812 return -EINVAL;
3813 }
3814
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303815 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816 hdd_ipa_cleanup_iface(adapter->ipa_context);
3817 if ((!hdd_ipa->num_iface) &&
3818 (HDD_IPA_UC_NUM_WDI_PIPE ==
3819 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003820 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821 /*
3822 * We disable WDI pipes directly here since
3823 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3824 * processed when unloading WLAN driver is in
3825 * progress
3826 */
3827 hdd_ipa_uc_disable_pipes(hdd_ipa);
3828 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303829 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 "NO INTF left but still pipe clean up");
3831 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3832 }
3833 }
3834
3835 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3836 hdd_ipa_uc_offload_enable_disable(adapter,
3837 SIR_AP_RX_DATA_OFFLOAD, 0);
3838 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3839 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303840 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 break;
3842
3843 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303844 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845 adapter->dev->ifindex, sta_id);
3846
3847 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303848 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003849 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3850 adapter->dev->name, meta.msg_type);
3851 return 0;
3852 }
3853
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303854 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3856 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303857 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 "%s: STA ID %d found, not valid",
3859 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303860 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861 return 0;
3862 }
Yun Park312f71a2015-12-08 10:22:42 -08003863
3864 /* Enable IPA UC Data PIPEs when first STA connected */
3865 if ((0 == hdd_ipa->sap_num_connected_sta) &&
3866 (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3867 !hdd_ipa->sta_connected)) {
3868 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3869 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303870 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303871 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003872 "%s: handle 1st con ret %d",
3873 adapter->dev->name, ret);
3874 return ret;
3875 }
3876 }
3877
3878 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003879
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303880 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881
3882 meta.msg_type = type;
3883 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3884 sizeof(struct ipa_wlan_hdr_attrib_val));
3885 msg_ex = cdf_mem_malloc(meta.msg_len);
3886
3887 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303888 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 "msg_ex allocation failed");
3890 return -ENOMEM;
3891 }
3892 strlcpy(msg_ex->name, adapter->dev->name,
3893 IPA_RESOURCE_NAME_MAX);
3894 msg_ex->num_of_attribs = 1;
3895 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
3896 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3897 msg_ex->attribs[0].offset =
3898 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3899 } else {
3900 msg_ex->attribs[0].offset =
3901 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3902 }
3903 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
3904 IPA_MAC_ADDR_SIZE);
3905
3906 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
3907
3908 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303909 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910 msg_ex->name, meta.msg_type, ret);
3911 cdf_mem_free(msg_ex);
3912 return ret;
3913 }
3914 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003915 return ret;
3916
3917 case WLAN_CLIENT_DISCONNECT:
3918 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303919 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 "%s: IPA UC OFFLOAD NOT ENABLED",
3921 msg_ex->name);
3922 return 0;
3923 }
3924
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303925 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303927 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 "%s: STA ID %d NOT found, not valid",
3929 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303930 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 return 0;
3932 }
3933 hdd_ipa->sap_num_connected_sta--;
3934 /* Disable IPA UC TX PIPE when last STA disconnected */
3935 if (!hdd_ipa->sap_num_connected_sta
3936 && (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3937 !hdd_ipa->sta_connected)
3938 && (false == hdd_ipa->resource_unloading)
3939 && (HDD_IPA_UC_NUM_WDI_PIPE ==
3940 hdd_ipa->activated_fw_pipe))
3941 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303942 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 break;
3944
3945 default:
3946 return 0;
3947 }
3948
3949 meta.msg_len = sizeof(struct ipa_wlan_msg);
3950 msg = cdf_mem_malloc(meta.msg_len);
3951 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303952 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953 return -ENOMEM;
3954 }
3955
3956 meta.msg_type = type;
3957 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
3958 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
3959
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303960 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003961 msg->name, meta.msg_type);
3962
3963 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3964
3965 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303966 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 msg->name, meta.msg_type, ret);
3968 cdf_mem_free(msg);
3969 return ret;
3970 }
3971
3972 hdd_ipa->stats.num_send_msg++;
3973
3974end:
3975 return ret;
3976}
3977
3978/**
3979 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
3980 * @state: IPA RM state value
3981 *
3982 * Return: ASCII string representing the IPA RM state
3983 */
3984static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
3985{
3986 switch (state) {
3987 case HDD_IPA_RM_RELEASED:
3988 return "RELEASED";
3989 case HDD_IPA_RM_GRANT_PENDING:
3990 return "GRANT_PENDING";
3991 case HDD_IPA_RM_GRANTED:
3992 return "GRANTED";
3993 }
3994
3995 return "UNKNOWN";
3996}
3997
3998/**
3999 * hdd_ipa_init() - IPA initialization function
4000 * @hdd_ctx: HDD global context
4001 *
4002 * Allocate hdd_ipa resources, ipa pipe resource and register
4003 * wlan interface with IPA module.
4004 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304005 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304007QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008{
4009 struct hdd_ipa_priv *hdd_ipa = NULL;
4010 int ret, i;
4011 struct hdd_ipa_iface_context *iface_context = NULL;
4012
4013 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304014 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015
4016 hdd_ipa = cdf_mem_malloc(sizeof(*hdd_ipa));
4017 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304018 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004019 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020 }
4021
4022 hdd_ctx->hdd_ipa = hdd_ipa;
4023 ghdd_ipa = hdd_ipa;
4024 hdd_ipa->hdd_ctx = hdd_ctx;
4025 hdd_ipa->num_iface = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +05304026 ol_txrx_ipa_uc_get_resource(cds_get_context(QDF_MODULE_ID_TXRX),
Leo Chang3bc8fed2015-11-13 10:59:47 -08004027 &hdd_ipa->ce_sr_base_paddr,
4028 &hdd_ipa->ce_sr_ring_size,
4029 &hdd_ipa->ce_reg_paddr,
4030 &hdd_ipa->tx_comp_ring_base_paddr,
4031 &hdd_ipa->tx_comp_ring_size,
4032 &hdd_ipa->tx_num_alloc_buffer,
4033 &hdd_ipa->rx_rdy_ring_base_paddr,
4034 &hdd_ipa->rx_rdy_ring_size,
4035 &hdd_ipa->rx_proc_done_idx_paddr,
4036 &hdd_ipa->rx_proc_done_idx_vaddr,
4037 &hdd_ipa->rx2_rdy_ring_base_paddr,
4038 &hdd_ipa->rx2_rdy_ring_size,
4039 &hdd_ipa->rx2_proc_done_idx_paddr,
4040 &hdd_ipa->rx2_proc_done_idx_vaddr);
4041 if ((0 == hdd_ipa->ce_sr_base_paddr) ||
4042 (0 == hdd_ipa->tx_comp_ring_base_paddr) ||
4043 (0 == hdd_ipa->rx_rdy_ring_base_paddr) ||
4044 (0 == hdd_ipa->rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304045 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004046 "IPA UC resource alloc fail");
4047 goto fail_get_resource;
4048 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049
4050 /* Create the interface context */
4051 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4052 iface_context = &hdd_ipa->iface_context[i];
4053 iface_context->hdd_ipa = hdd_ipa;
4054 iface_context->cons_client =
4055 hdd_ipa_adapter_2_client[i].cons_client;
4056 iface_context->prod_client =
4057 hdd_ipa_adapter_2_client[i].prod_client;
4058 iface_context->iface_id = i;
4059 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304060 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 }
4062
4063#ifdef CONFIG_CNSS
4064 cnss_init_work(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
4065#else
4066 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
4067#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304068 qdf_spinlock_create(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 cdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
4070
4071 ret = hdd_ipa_setup_rm(hdd_ipa);
4072 if (ret)
4073 goto fail_setup_rm;
4074
4075 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4076 hdd_ipa_uc_rt_debug_init(hdd_ctx);
4077 cdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
4078 hdd_ipa->sap_num_connected_sta = 0;
4079 hdd_ipa->ipa_tx_packets_diff = 0;
4080 hdd_ipa->ipa_rx_packets_diff = 0;
4081 hdd_ipa->ipa_p_tx_packets = 0;
4082 hdd_ipa->ipa_p_rx_packets = 0;
4083 hdd_ipa->resource_loading = false;
4084 hdd_ipa->resource_unloading = false;
4085 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004086 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 /* Setup IPA sys_pipe for MCC */
4088 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4089 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4090 if (ret)
4091 goto fail_create_sys_pipe;
4092 }
4093 hdd_ipa_uc_ol_init(hdd_ctx);
4094 } else {
4095 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4096 if (ret)
4097 goto fail_create_sys_pipe;
4098 }
4099
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304100 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004101
4102fail_create_sys_pipe:
4103 hdd_ipa_destroy_rm_resource(hdd_ipa);
4104fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304105 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004106fail_get_resource:
4107 cdf_mem_free(hdd_ipa);
4108 hdd_ctx->hdd_ipa = NULL;
4109 ghdd_ipa = NULL;
4110fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304111 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112}
4113
4114/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004115 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4116 * @hdd_ipa: pointer to HDD IPA struct
4117 *
4118 * Return: none
4119 */
4120void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
4121{
4122 struct ipa_uc_pending_event *pending_event = NULL;
4123
Anurag Chouhanffb21542016-02-17 14:33:03 +05304124 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4125 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Yun Parkf19e07d2015-11-20 11:34:27 -08004126 cdf_mem_free(pending_event);
4127 }
4128
Anurag Chouhanffb21542016-02-17 14:33:03 +05304129 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004130}
4131
4132/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004133 * hdd_ipa_cleanup - IPA cleanup function
4134 * @hdd_ctx: HDD global context
4135 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304136 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304138QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139{
4140 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4141 int i;
4142 struct hdd_ipa_iface_context *iface_context = NULL;
4143 cdf_nbuf_t skb;
4144 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4145
4146 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304147 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004148
4149 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4150 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4151 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4152 }
4153
4154 /* Teardown IPA sys_pipe for MCC */
4155 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4156 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4157
4158 hdd_ipa_destroy_rm_resource(hdd_ipa);
4159
4160#ifdef WLAN_OPEN_SOURCE
4161 cancel_work_sync(&hdd_ipa->pm_work);
4162#endif
4163
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304164 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165
4166 while (((skb = cdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head)) != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304167 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168
4169 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4170 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4171
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304172 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304174 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304176 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177
4178 /* destory the interface lock */
4179 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4180 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304181 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004182 }
4183
4184 /* This should never hit but still make sure that there are no pending
4185 * descriptor in IPA hardware
4186 */
4187 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304188 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004189 "IPA Pending write done: %d Waiting!",
4190 hdd_ipa->pending_hw_desc_cnt);
4191
4192 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4193 usleep_range(100, 100);
4194 }
4195
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304196 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 "IPA Pending write done: desc: %d %s(%d)!",
4198 hdd_ipa->pending_hw_desc_cnt,
4199 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4200 : "leak", i);
4201 }
4202 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4203 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304204 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 "%s: Disconnect TX PIPE", __func__);
4206 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304207 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 "%s: Disconnect RX PIPE", __func__);
4209 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304210 qdf_mutex_destroy(&hdd_ipa->event_lock);
4211 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004212 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213
4214#ifdef WLAN_OPEN_SOURCE
4215 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4216 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4217 hdd_ipa->uc_op_work[i].msg = NULL;
4218 }
4219#endif
4220 }
4221
4222 cdf_mem_free(hdd_ipa);
4223 hdd_ctx->hdd_ipa = NULL;
4224
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304225 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226}
4227#endif /* IPA_OFFLOAD */