blob: 1327802a0d41a70f39c225f0970d4a7410b856fa [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302 * 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: wma_utis.c
30 * This file contains utilities and stats related functions.
31 */
32
33/* Header files */
34
35#include "wma.h"
36#include "wma_api.h"
37#include "cds_api.h"
38#include "wmi_unified_api.h"
39#include "wlan_qct_sys.h"
40#include "wni_api.h"
41#include "ani_global.h"
42#include "wmi_unified.h"
43#include "wni_cfg.h"
44#include "cfg_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080045
Nirav Shahcbc6d722016-03-01 16:24:53 +053046#include "qdf_nbuf.h"
Anurag Chouhan6d760662016-02-20 16:05:43 +053047#include "qdf_types.h"
Anurag Chouhan600c3a02016-03-01 10:33:54 +053048#include "qdf_mem.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080049
50#include "wma_types.h"
51#include "lim_api.h"
52#include "lim_session_utils.h"
53
54#include "cds_utils.h"
55
56#if !defined(REMOVE_PKT_LOG)
57#include "pktlog_ac.h"
58#endif /* REMOVE_PKT_LOG */
59
60#include "dbglog_host.h"
61#include "csr_api.h"
62#include "ol_fw.h"
63
64#include "dfs.h"
65#include "wma_internal.h"
Chandrasekaran, Manishekar0d814c72015-11-05 10:42:48 +053066#include "cds_concurrency.h"
Govind Singhd76a5b02016-03-08 15:12:14 +053067#include "wmi_unified_param.h"
Naveen Rawatc0c91cd2015-11-05 14:27:37 -080068#include "linux/ieee80211.h"
69
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080070/* MCS Based rate table */
71/* HT MCS parameters with Nss = 1 */
Ryan Hsu6139d2d2015-11-04 17:29:00 -080072static struct index_data_rate_type mcs_nss1[] = {
73 /* MCS L20 S20 L40 S40 */
74 {0, {65, 72}, {135, 150 } },
75 {1, {130, 144}, {270, 300 } },
76 {2, {195, 217}, {405, 450 } },
77 {3, {260, 289}, {540, 600 } },
78 {4, {390, 433}, {815, 900 } },
79 {5, {520, 578}, {1080, 1200} },
80 {6, {585, 650}, {1215, 1350} },
81 {7, {650, 722}, {1350, 1500} }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082};
83
84/* HT MCS parameters with Nss = 2 */
Ryan Hsu6139d2d2015-11-04 17:29:00 -080085static struct index_data_rate_type mcs_nss2[] = {
86 /* MCS L20 S20 L40 S40 */
87 {0, {130, 144}, {270, 300 } },
88 {1, {260, 289}, {540, 600 } },
89 {2, {390, 433}, {810, 900 } },
90 {3, {520, 578}, {1080, 1200} },
91 {4, {780, 867}, {1620, 1800} },
92 {5, {1040, 1156}, {2160, 2400} },
93 {6, {1170, 1300}, {2430, 2700} },
94 {7, {1300, 1440}, {2700, 3000} }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095};
96
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097/* MCS Based VHT rate table */
98/* MCS parameters with Nss = 1*/
Ryan Hsu6139d2d2015-11-04 17:29:00 -080099static struct index_vht_data_rate_type vht_mcs_nss1[] = {
100 /* MCS L20 S20 L40 S40 L80 S80 */
101 {0, {65, 72 }, {135, 150}, {293, 325} },
102 {1, {130, 144}, {270, 300}, {585, 650} },
103 {2, {195, 217}, {405, 450}, {878, 975} },
104 {3, {260, 289}, {540, 600}, {1170, 1300} },
105 {4, {390, 433}, {810, 900}, {1755, 1950} },
106 {5, {520, 578}, {1080, 1200}, {2340, 2600} },
107 {6, {585, 650}, {1215, 1350}, {2633, 2925} },
108 {7, {650, 722}, {1350, 1500}, {2925, 3250} },
109 {8, {780, 867}, {1620, 1800}, {3510, 3900} },
110 {9, {865, 960}, {1800, 2000}, {3900, 4333} }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800111};
112
113/*MCS parameters with Nss = 2*/
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800114static struct index_vht_data_rate_type vht_mcs_nss2[] = {
115 /* MCS L20 S20 L40 S40 L80 S80 */
116 {0, {130, 144}, {270, 300}, { 585, 650} },
117 {1, {260, 289}, {540, 600}, {1170, 1300} },
118 {2, {390, 433}, {810, 900}, {1755, 1950} },
119 {3, {520, 578}, {1080, 1200}, {2340, 2600} },
120 {4, {780, 867}, {1620, 1800}, {3510, 3900} },
121 {5, {1040, 1156}, {2160, 2400}, {4680, 5200} },
122 {6, {1170, 1300}, {2430, 2700}, {5265, 5850} },
123 {7, {1300, 1444}, {2700, 3000}, {5850, 6500} },
124 {8, {1560, 1733}, {3240, 3600}, {7020, 7800} },
125 {9, {1730, 1920}, {3600, 4000}, {7800, 8667} }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800126};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800127
128#ifdef BIG_ENDIAN_HOST
129
130/* ############# function definitions ############ */
131
132/**
133 * wma_swap_bytes() - swap bytes
134 * @pv: buffer
135 * @n: swap bytes
136 *
137 * Return: none
138 */
139void wma_swap_bytes(void *pv, uint32_t n)
140{
141 int32_t no_words;
142 int32_t i;
143 uint32_t *word_ptr;
144
145 no_words = n / sizeof(uint32_t);
146 word_ptr = (uint32_t *) pv;
147 for (i = 0; i < no_words; i++) {
148 *(word_ptr + i) = __cpu_to_le32(*(word_ptr + i));
149 }
150}
151
152#define SWAPME(x, len) wma_swap_bytes(&x, len);
153#endif /* BIG_ENDIAN_HOST */
154
155/**
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800156 * wma_mcs_rate_match() - find the match mcs rate
157 * @match_rate: the rate to look up
158 * @is_sgi: return if the SGI rate is found
159 * @nss: the nss in use
160 * @nss1_rate: the nss1 rate
161 * @nss1_srate: the nss1 SGI rate
162 * @nss2_rate: the nss2 rate
163 * @nss2_srate: the nss2 SGI rate
164 *
165 * This is a helper function to find the match of the tx_rate
166 * in terms of the nss1/nss2 rate with non-SGI/SGI.
167 *
168 * Return: the found rate or 0 otherwise
169 */
170static inline uint16_t wma_mcs_rate_match(uint16_t match_rate, bool *is_sgi,
171 uint8_t nss, uint16_t nss1_rate,
172 uint16_t nss1_srate,
173 uint16_t nss2_rate,
174 uint16_t nss2_srate)
175{
176 WMA_LOGD("%s match_rate: %d, %d %d %d %d",
177 __func__, match_rate, nss1_rate, nss1_srate, nss2_rate,
178 nss2_srate);
179
180 if (match_rate == nss1_rate) {
181 return nss1_rate;
182 } else if (match_rate == nss1_srate) {
183 *is_sgi = true;
184 return nss1_srate;
185 } else if (nss == 2 && match_rate == nss2_rate)
186 return nss2_rate;
187 else if (nss == 2 && match_rate == nss2_srate) {
188 *is_sgi = true;
189 return nss2_srate;
190 } else
191 return 0;
192}
193
194/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800195 * wma_get_mcs_idx() - get mcs index
196 * @maxRate: max rate
197 * @rate_flags: rate flags
198 * @nss: number of nss
199 * @mcsRateFlag: mcs rate flag
200 *
201 * Return: return mcs index
202 */
203static uint8_t wma_get_mcs_idx(uint16_t maxRate, uint8_t rate_flags,
204 uint8_t nss, uint8_t *mcsRateFlag)
205{
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800206 uint8_t index = 0;
Arif Hussainb8fef842016-07-19 09:43:13 -0700207 uint16_t match_rate = 0;
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800208 bool is_sgi = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800209
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800210 WMA_LOGD("%s rate:%d rate_flgs: 0x%x, nss: %d",
211 __func__, maxRate, rate_flags, nss);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212
213 *mcsRateFlag = rate_flags;
214 *mcsRateFlag &= ~eHAL_TX_RATE_SGI;
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800215 for (index = 0; index < MAX_VHT_MCS_IDX; index++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216 if (rate_flags & eHAL_TX_RATE_VHT80) {
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800217 /* check for vht80 nss1/2 rate set */
218 match_rate = wma_mcs_rate_match(maxRate, &is_sgi, nss,
219 vht_mcs_nss1[index].ht80_rate[0],
220 vht_mcs_nss1[index].ht80_rate[1],
221 vht_mcs_nss2[index].ht80_rate[0],
222 vht_mcs_nss2[index].ht80_rate[1]);
223 if (match_rate)
224 goto rate_found;
225 }
226 if ((rate_flags & eHAL_TX_RATE_VHT40) |
227 (rate_flags & eHAL_TX_RATE_VHT80)) {
228 /* check for vht40 nss1/2 rate set */
229 match_rate = wma_mcs_rate_match(maxRate, &is_sgi, nss,
230 vht_mcs_nss1[index].ht40_rate[0],
231 vht_mcs_nss1[index].ht40_rate[1],
232 vht_mcs_nss2[index].ht40_rate[0],
233 vht_mcs_nss2[index].ht40_rate[1]);
234 if (match_rate) {
235 *mcsRateFlag &= ~eHAL_TX_RATE_VHT80;
236 goto rate_found;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800237 }
238 }
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800239 if ((rate_flags & eHAL_TX_RATE_VHT20) |
240 (rate_flags & eHAL_TX_RATE_VHT40) |
241 (rate_flags & eHAL_TX_RATE_VHT80)) {
242 /* check for vht20 nss1/2 rate set */
243 match_rate = wma_mcs_rate_match(maxRate, &is_sgi, nss,
244 vht_mcs_nss1[index].ht20_rate[0],
245 vht_mcs_nss1[index].ht20_rate[1],
246 vht_mcs_nss2[index].ht20_rate[0],
247 vht_mcs_nss2[index].ht20_rate[1]);
248 if (match_rate) {
249 *mcsRateFlag &= ~(eHAL_TX_RATE_VHT80 |
250 eHAL_TX_RATE_VHT40);
251 goto rate_found;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252 }
253 }
254 }
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800255 for (index = 0; index < MAX_HT_MCS_IDX; index++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800256 if (rate_flags & eHAL_TX_RATE_HT40) {
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800257 /* check for ht40 nss1/2 rate set */
258 match_rate = wma_mcs_rate_match(maxRate, &is_sgi, nss,
259 mcs_nss1[index].ht40_rate[0],
260 mcs_nss1[index].ht40_rate[1],
261 mcs_nss2[index].ht40_rate[0],
262 mcs_nss2[index].ht40_rate[1]);
263 if (match_rate) {
264 *mcsRateFlag = eHAL_TX_RATE_HT40;
265 goto rate_found;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800266 }
267 }
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800268 if (rate_flags & eHAL_TX_RATE_HT20) {
269 /* check for ht20 nss1/2 rate set */
270 match_rate = wma_mcs_rate_match(maxRate, &is_sgi, nss,
271 mcs_nss1[index].ht20_rate[0],
272 mcs_nss1[index].ht20_rate[1],
273 mcs_nss2[index].ht20_rate[0],
274 mcs_nss2[index].ht20_rate[1]);
275 if (match_rate) {
276 *mcsRateFlag = eHAL_TX_RATE_HT20;
277 goto rate_found;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800278 }
279 }
280 }
281
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800282rate_found:
283 /* set SGI flag only if this is SGI rate */
284 if (match_rate && is_sgi == true)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800285 *mcsRateFlag |= eHAL_TX_RATE_SGI;
286
Ryan Hsu6139d2d2015-11-04 17:29:00 -0800287 WMA_LOGD("%s - match_rate: %d index: %d rate_flag: 0x%x is_sgi: %d",
288 __func__, match_rate, index, *mcsRateFlag, is_sgi);
289
290 return match_rate ? index : INVALID_MCS_IDX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800291}
292
293/**
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +0530294 * wma_peek_vdev_req() - peek what request message is queued for response.
295 * the function does not delete the node after found
296 * @wma: WMA handle
297 * @vdev_id: vdev ID
298 * @type: request message type
299 *
300 * Return: the request message found
301 */
302static struct wma_target_req *wma_peek_vdev_req(tp_wma_handle wma,
303 uint8_t vdev_id, uint8_t type)
304{
305 struct wma_target_req *req_msg = NULL;
306 bool found = false;
307 qdf_list_node_t *node1 = NULL, *node2 = NULL;
308
309 qdf_spin_lock_bh(&wma->vdev_respq_lock);
310 if (QDF_STATUS_SUCCESS != qdf_list_peek_front(&wma->vdev_resp_queue,
311 &node2)) {
312 qdf_spin_unlock_bh(&wma->vdev_respq_lock);
313 WMA_LOGE(FL("unable to get target req from vdev resp queue"));
314 return NULL;
315 }
316
317 do {
318 node1 = node2;
319 req_msg = qdf_container_of(node1, struct wma_target_req, node);
320 if (req_msg->vdev_id != vdev_id)
321 continue;
322 if (req_msg->type != type)
323 continue;
324
325 found = true;
326 break;
327 } while (QDF_STATUS_SUCCESS == qdf_list_peek_next(&wma->vdev_resp_queue,
328 node1, &node2));
329 qdf_spin_unlock_bh(&wma->vdev_respq_lock);
330 if (!found) {
331 WMA_LOGP(FL("target request not found for vdev_id %d type %d"),
332 vdev_id, type);
333 return NULL;
334 }
335 WMA_LOGD(FL("target request found for vdev id: %d type %d msg %d"),
336 vdev_id, type, req_msg->msg_type);
337 return req_msg;
338}
339
340void wma_lost_link_info_handler(tp_wma_handle wma, uint32_t vdev_id,
341 int32_t rssi)
342{
343 struct sir_lost_link_info *lost_link_info;
344 QDF_STATUS qdf_status;
345 cds_msg_t sme_msg = {0};
346
347 /* report lost link information only for STA mode */
348 if (wma->interfaces[vdev_id].vdev_up &&
349 (WMI_VDEV_TYPE_STA == wma->interfaces[vdev_id].type) &&
350 (0 == wma->interfaces[vdev_id].sub_type)) {
351 lost_link_info = qdf_mem_malloc(sizeof(*lost_link_info));
352 if (NULL == lost_link_info) {
353 WMA_LOGE("%s: failed to allocate memory", __func__);
354 return;
355 }
356 lost_link_info->vdev_id = vdev_id;
357 lost_link_info->rssi = rssi;
358 sme_msg.type = eWNI_SME_LOST_LINK_INFO_IND;
359 sme_msg.bodyptr = lost_link_info;
360 sme_msg.bodyval = 0;
361 WMA_LOGI("%s: post msg to SME, bss_idx %d, rssi %d", __func__,
362 lost_link_info->vdev_id, lost_link_info->rssi);
363
364 qdf_status = cds_mq_post_message(QDF_MODULE_ID_SME, &sme_msg);
365 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
366 WMA_LOGE("%s: fail to post msg to SME", __func__);
367 qdf_mem_free(lost_link_info);
368 }
369 }
370}
371
372/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800373 * host_map_smps_mode() - map fw smps mode to tSmpsModeValue
374 * @fw_smps_mode: fw smps mode
375 *
376 * Return: return tSmpsModeValue
377 */
378tSmpsModeValue host_map_smps_mode(A_UINT32 fw_smps_mode)
379{
380 tSmpsModeValue smps_mode = SMPS_MODE_DISABLED;
381 switch (fw_smps_mode) {
382 case WMI_SMPS_FORCED_MODE_STATIC:
383 smps_mode = STATIC_SMPS_MODE;
384 break;
385 case WMI_SMPS_FORCED_MODE_DYNAMIC:
386 smps_mode = DYNAMIC_SMPS_MODE;
387 break;
388 default:
389 smps_mode = SMPS_MODE_DISABLED;
390 }
391
392 return smps_mode;
393}
394
Archana Ramachandran20d2e232016-02-11 16:58:40 -0800395/**
396 * wma_smps_mode_to_force_mode_param() - Map smps mode to force
397 * mode commmand param
398 * @smps_mode: SMPS mode according to the protocol
399 *
400 * Return: int > 0 for success else failure
401 */
402int wma_smps_mode_to_force_mode_param(uint8_t smps_mode)
403{
404 int param = -EINVAL;
405
406 switch (smps_mode) {
407 case STATIC_SMPS_MODE:
408 param = WMI_SMPS_FORCED_MODE_STATIC;
409 break;
410 case DYNAMIC_SMPS_MODE:
411 param = WMI_SMPS_FORCED_MODE_DYNAMIC;
412 break;
413 case SMPS_MODE_DISABLED:
414 param = WMI_SMPS_FORCED_MODE_DISABLED;
415 break;
416 default:
417 WMA_LOGE(FL("smps mode cannot be mapped :%d "),
418 smps_mode);
419 }
420 return param;
421}
422
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800423#ifdef WLAN_FEATURE_STATS_EXT
424/**
425 * wma_stats_ext_event_handler() - extended stats event handler
426 * @handle: wma handle
427 * @event_buf: event buffer received from fw
428 * @len: length of data
429 *
430 * Return: 0 for success or error code
431 */
432int wma_stats_ext_event_handler(void *handle, uint8_t *event_buf,
433 uint32_t len)
434{
435 WMI_STATS_EXT_EVENTID_param_tlvs *param_buf;
436 tSirStatsExtEvent *stats_ext_event;
437 wmi_stats_ext_event_fixed_param *stats_ext_info;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530438 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800439 cds_msg_t cds_msg;
440 uint8_t *buf_ptr;
441 uint32_t alloc_len;
442
443 WMA_LOGD("%s: Posting stats ext event to SME", __func__);
444
445 param_buf = (WMI_STATS_EXT_EVENTID_param_tlvs *) event_buf;
446 if (!param_buf) {
447 WMA_LOGE("%s: Invalid stats ext event buf", __func__);
448 return -EINVAL;
449 }
450
451 stats_ext_info = param_buf->fixed_param;
452 buf_ptr = (uint8_t *) stats_ext_info;
453
454 alloc_len = sizeof(tSirStatsExtEvent);
455 alloc_len += stats_ext_info->data_len;
456
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530457 stats_ext_event = (tSirStatsExtEvent *) qdf_mem_malloc(alloc_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800458 if (NULL == stats_ext_event) {
459 WMA_LOGE("%s: Memory allocation failure", __func__);
460 return -ENOMEM;
461 }
462
463 buf_ptr += sizeof(wmi_stats_ext_event_fixed_param) + WMI_TLV_HDR_SIZE;
464
465 stats_ext_event->vdev_id = stats_ext_info->vdev_id;
466 stats_ext_event->event_data_len = stats_ext_info->data_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530467 qdf_mem_copy(stats_ext_event->event_data,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800468 buf_ptr, stats_ext_event->event_data_len);
469
470 cds_msg.type = eWNI_SME_STATS_EXT_EVENT;
471 cds_msg.bodyptr = (void *)stats_ext_event;
472 cds_msg.bodyval = 0;
473
474 status = cds_mq_post_message(CDS_MQ_ID_SME, &cds_msg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530475 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800476 WMA_LOGE("%s: Failed to post stats ext event to SME", __func__);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530477 qdf_mem_free(stats_ext_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478 return -EFAULT;
479 }
480
481 WMA_LOGD("%s: stats ext event Posted to SME", __func__);
482 return 0;
483}
484#endif /* WLAN_FEATURE_STATS_EXT */
485
Nirav Shah93e789e2016-04-14 19:47:43 +0530486
Govind Singha471e5e2015-10-12 17:11:14 +0530487/**
488 * wma_profile_data_report_event_handler() - fw profiling handler
489 * @handle: wma handle
490 * @event_buf: event buffer received from fw
491 * @len: length of data
492 *
493 * Return: 0 for success or error code
494 */
495int wma_profile_data_report_event_handler(void *handle, uint8_t *event_buf,
496 uint32_t len)
497{
498 WMI_WLAN_PROFILE_DATA_EVENTID_param_tlvs *param_buf;
499 wmi_wlan_profile_ctx_t *profile_ctx;
500 wmi_wlan_profile_t *profile_data;
501 uint32_t i = 0;
502 uint32_t entries;
503 uint8_t *buf_ptr;
Nirav Shah93e789e2016-04-14 19:47:43 +0530504 char temp_str[150];
Govind Singha471e5e2015-10-12 17:11:14 +0530505 param_buf = (WMI_WLAN_PROFILE_DATA_EVENTID_param_tlvs *) event_buf;
506
507 if (!param_buf) {
508 WMA_LOGE("%s: Invalid profile data event buf", __func__);
509 return -EINVAL;
510 }
511 profile_ctx = param_buf->profile_ctx;
512 buf_ptr = (uint8_t *)profile_ctx;
513 buf_ptr = buf_ptr + sizeof(wmi_wlan_profile_ctx_t) + WMI_TLV_HDR_SIZE;
514 profile_data = (wmi_wlan_profile_t *) buf_ptr;
515 entries = profile_ctx->bin_count;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530516 QDF_TRACE(QDF_MODULE_ID_WMA, QDF_TRACE_LEVEL_ERROR,
Govind Singha471e5e2015-10-12 17:11:14 +0530517 "Profile data stats\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530518 QDF_TRACE(QDF_MODULE_ID_WMA, QDF_TRACE_LEVEL_ERROR,
Govind Singha471e5e2015-10-12 17:11:14 +0530519 "TOT: %d\n"
520 "tx_msdu_cnt: %d\n"
521 "tx_mpdu_cnt: %d\n"
522 "tx_ppdu_cnt: %d\n"
523 "rx_msdu_cnt: %d\n"
524 "rx_mpdu_cnt: %d\n"
525 "bin_count: %d\n",
526 profile_ctx->tot,
527 profile_ctx->tx_msdu_cnt,
528 profile_ctx->tx_mpdu_cnt,
529 profile_ctx->tx_ppdu_cnt,
530 profile_ctx->rx_msdu_cnt,
531 profile_ctx->rx_mpdu_cnt,
532 profile_ctx->bin_count);
533
Nirav Shah93e789e2016-04-14 19:47:43 +0530534 QDF_TRACE(QDF_MODULE_ID_WMA, QDF_TRACE_LEVEL_ERROR,
535 "Profile ID: Count: TOT: Min: Max: hist_intvl: hist[0]: hist[1]:hist[2]");
536
Govind Singha471e5e2015-10-12 17:11:14 +0530537 for (i = 0; i < entries; i++) {
538 if (i == WMI_WLAN_PROFILE_MAX_BIN_CNT)
539 break;
Nirav Shah93e789e2016-04-14 19:47:43 +0530540 snprintf(temp_str, sizeof(temp_str),
541 " %d : %d : %d : %d : %d : %d : %d : %d : %d",
Govind Singha471e5e2015-10-12 17:11:14 +0530542 profile_data[i].id,
543 profile_data[i].cnt,
544 profile_data[i].tot,
545 profile_data[i].min,
546 profile_data[i].max,
547 profile_data[i].hist_intvl,
548 profile_data[i].hist[0],
549 profile_data[i].hist[1],
550 profile_data[i].hist[2]);
Nirav Shah93e789e2016-04-14 19:47:43 +0530551 QDF_TRACE(QDF_MODULE_ID_WMA, QDF_TRACE_LEVEL_ERROR,
552 "%s", temp_str);
Govind Singha471e5e2015-10-12 17:11:14 +0530553 }
554
555 return 0;
556}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800557
558#ifdef WLAN_FEATURE_LINK_LAYER_STATS
559
560/**
561 * wma_unified_link_peer_stats_event_handler() - peer stats event handler
562 * @handle: wma handle
563 * @cmd_param_info: data received with event from fw
564 * @len: length of data
565 *
566 * Return: 0 for success or error code
567 */
568static int wma_unified_link_peer_stats_event_handler(void *handle,
569 uint8_t *cmd_param_info,
570 uint32_t len)
571{
572 WMI_PEER_LINK_STATS_EVENTID_param_tlvs *param_tlvs;
573 wmi_peer_stats_event_fixed_param *fixed_param;
574 wmi_peer_link_stats *peer_stats, *temp_peer_stats;
575 wmi_rate_stats *rate_stats;
576 tSirLLStatsResults *link_stats_results;
577 uint8_t *results, *t_peer_stats, *t_rate_stats;
Kondabattini, Ganesh32be0832016-08-09 15:19:50 +0530578 uint32_t count, num_rates = 0, rate_cnt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579 uint32_t next_res_offset, next_peer_offset, next_rate_offset;
580 size_t peer_info_size, peer_stats_size, rate_stats_size;
581 size_t link_stats_results_size;
582
Anurag Chouhan6d760662016-02-20 16:05:43 +0530583 tpAniSirGlobal pMac = cds_get_context(QDF_MODULE_ID_PE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584
585 if (!pMac) {
586 WMA_LOGD("%s: NULL pMac ptr. Exiting", __func__);
587 return -EINVAL;
588 }
589
590 if (!pMac->sme.pLinkLayerStatsIndCallback) {
591 WMA_LOGD("%s: HDD callback is null", __func__);
592 return -EINVAL;
593 }
594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595 param_tlvs = (WMI_PEER_LINK_STATS_EVENTID_param_tlvs *) cmd_param_info;
596 if (!param_tlvs) {
597 WMA_LOGA("%s: Invalid stats event", __func__);
598 return -EINVAL;
599 }
600 /*
601 * cmd_param_info contains
602 * wmi_peer_stats_event_fixed_param fixed_param;
603 * num_peers * size of(struct wmi_peer_link_stats)
604 * num_rates * size of(struct wmi_rate_stats)
605 * num_rates is the sum of the rates of all the peers.
606 */
607 fixed_param = param_tlvs->fixed_param;
608 peer_stats = param_tlvs->peer_stats;
609 rate_stats = param_tlvs->peer_rate_stats;
610
611 if (!fixed_param || !peer_stats ||
612 (peer_stats->num_rates && !rate_stats)) {
613 WMA_LOGA("%s: Invalid param_tlvs for Peer Stats", __func__);
614 return -EINVAL;
615 }
616
617 /*
618 * num_rates - sum of the rates of all the peers
619 */
620 temp_peer_stats = (wmi_peer_link_stats *) peer_stats;
621 for (count = 0; count < fixed_param->num_peers; count++) {
622 num_rates += temp_peer_stats->num_rates;
623 temp_peer_stats++;
624 }
625
626 peer_stats_size = sizeof(tSirWifiPeerStat);
627 peer_info_size = sizeof(tSirWifiPeerInfo);
628 rate_stats_size = sizeof(tSirWifiRateStat);
629 link_stats_results_size =
630 sizeof(*link_stats_results) + peer_stats_size +
631 (fixed_param->num_peers * peer_info_size) +
632 (num_rates * rate_stats_size);
633
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530634 link_stats_results = qdf_mem_malloc(link_stats_results_size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800635 if (NULL == link_stats_results) {
636 WMA_LOGD("%s: could not allocate mem for stats results-len %zu",
637 __func__, link_stats_results_size);
638 return -ENOMEM;
639 }
640
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530641 qdf_mem_zero(link_stats_results, link_stats_results_size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642
643 link_stats_results->paramId = WMI_LINK_STATS_ALL_PEER;
644 link_stats_results->rspId = fixed_param->request_id;
645 link_stats_results->ifaceId = 0;
646 link_stats_results->num_peers = fixed_param->num_peers;
647 link_stats_results->peer_event_number = fixed_param->peer_event_number;
648 link_stats_results->moreResultToFollow = fixed_param->more_data;
649
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530650 qdf_mem_copy(link_stats_results->results,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800651 &fixed_param->num_peers, peer_stats_size);
652
653 results = (uint8_t *) link_stats_results->results;
654 t_peer_stats = (uint8_t *) peer_stats;
655 t_rate_stats = (uint8_t *) rate_stats;
656 next_res_offset = peer_stats_size;
657 next_peer_offset = WMI_TLV_HDR_SIZE;
658 next_rate_offset = WMI_TLV_HDR_SIZE;
Kondabattini, Ganesh32be0832016-08-09 15:19:50 +0530659 for (rate_cnt = 0; rate_cnt < fixed_param->num_peers; rate_cnt++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530660 qdf_mem_copy(results + next_res_offset,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800661 t_peer_stats + next_peer_offset, peer_info_size);
662 next_res_offset += peer_info_size;
663
664 /* Copy rate stats associated with this peer */
665 for (count = 0; count < peer_stats->num_rates; count++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800666 rate_stats++;
667
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530668 qdf_mem_copy(results + next_res_offset,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800669 t_rate_stats + next_rate_offset,
670 rate_stats_size);
671 next_res_offset += rate_stats_size;
672 next_rate_offset += sizeof(*rate_stats);
673 }
674 next_peer_offset += sizeof(*peer_stats);
675 peer_stats++;
676 }
677
678 /* call hdd callback with Link Layer Statistics
679 * vdev_id/ifacId in link_stats_results will be
680 * used to retrieve the correct HDD context
681 */
682 pMac->sme.pLinkLayerStatsIndCallback(pMac->hHdd,
683 WMA_LINK_LAYER_STATS_RESULTS_RSP,
684 link_stats_results);
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530685 qdf_mem_free(link_stats_results);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686
687 return 0;
688}
689
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700690/**
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700691 * wma_unified_radio_tx_mem_free() - Free radio tx power stats memory
692 * @handle: WMI handle
693 *
694 * Return: 0 on success, error number otherwise.
695 */
696static int wma_unified_radio_tx_mem_free(void *handle)
697{
698 tp_wma_handle wma_handle = (tp_wma_handle) handle;
699 tSirWifiRadioStat *rs_results;
700 uint32_t i = 0;
701
702 if (!wma_handle->link_stats_results)
703 return 0;
704
705 rs_results = (tSirWifiRadioStat *)&wma_handle->link_stats_results->results[0];
706 for (i = 0; i < wma_handle->link_stats_results->num_radio; i++) {
707 rs_results += i;
708 if (rs_results->tx_time_per_power_level) {
709 qdf_mem_free(rs_results->tx_time_per_power_level);
710 rs_results->tx_time_per_power_level = NULL;
711 }
712
713 if (rs_results->channels) {
714 qdf_mem_free(rs_results->channels);
715 rs_results->channels = NULL;
716 }
717 }
718
719 qdf_mem_free(wma_handle->link_stats_results);
720 wma_handle->link_stats_results = NULL;
721
722 return 0;
723}
724
725/**
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700726 * wma_unified_radio_tx_power_level_stats_event_handler() - tx power level stats
727 * @handle: WMI handle
728 * @cmd_param_info: command param info
729 * @len: Length of @cmd_param_info
730 *
731 * This is the WMI event handler function to receive radio stats tx
732 * power level stats.
733 *
734 * Return: 0 on success, error number otherwise.
735*/
736static int wma_unified_radio_tx_power_level_stats_event_handler(void *handle,
737 u_int8_t *cmd_param_info, u_int32_t len)
738{
739 tp_wma_handle wma_handle = (tp_wma_handle) handle;
740 WMI_RADIO_TX_POWER_LEVEL_STATS_EVENTID_param_tlvs *param_tlvs;
741 wmi_tx_power_level_stats_evt_fixed_param *fixed_param;
742 uint8_t *tx_power_level_values;
743 tSirLLStatsResults *link_stats_results;
744 tSirWifiRadioStat *rs_results;
745
746 tpAniSirGlobal mac = cds_get_context(QDF_MODULE_ID_PE);
747
748 if (!mac) {
749 WMA_LOGD("%s: NULL pMac ptr. Exiting", __func__);
750 return -EINVAL;
751 }
752
753 if (!mac->sme.pLinkLayerStatsIndCallback) {
754 WMA_LOGD("%s: HDD callback is null", __func__);
755 return -EINVAL;
756 }
757
758 param_tlvs = (WMI_RADIO_TX_POWER_LEVEL_STATS_EVENTID_param_tlvs *)cmd_param_info;
759 if (!param_tlvs) {
760 WMA_LOGA("%s: Invalid tx power level stats event", __func__);
761 return -EINVAL;
762 }
763
764 fixed_param = param_tlvs->fixed_param;
765 if (!fixed_param) {
766 WMA_LOGA("%s: Invalid param_tlvs for Radio tx_power level Stats", __func__);
767 return -EINVAL;
768 }
769
770 link_stats_results = wma_handle->link_stats_results;
Srinivas Girigowda52cbce42016-10-25 14:11:58 -0700771 if (!link_stats_results) {
772 WMA_LOGA("%s: link_stats_results is NULL", __func__);
773 return -EINVAL;
774 }
775
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700776 WMA_LOGD("%s: tot_num_tx_pwr_lvls: %u num_tx_pwr_lvls: %u pwr_lvl_offset: %u radio_id: %u",
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700777 __func__, fixed_param->total_num_tx_power_levels,
778 fixed_param->num_tx_power_levels,
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700779 fixed_param->power_level_offset,
780 fixed_param->radio_id);
781
782 rs_results = (tSirWifiRadioStat *) &link_stats_results->results[0] + fixed_param->radio_id;
783 tx_power_level_values = (uint8_t *) param_tlvs->tx_time_per_power_level;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700784
785 rs_results->total_num_tx_power_levels =
786 fixed_param->total_num_tx_power_levels;
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700787 if (!rs_results->total_num_tx_power_levels) {
788 link_stats_results->nr_received++;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700789 goto post_stats;
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700790 }
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700791
792 if (!rs_results->tx_time_per_power_level) {
793 rs_results->tx_time_per_power_level = qdf_mem_malloc(
794 sizeof(uint32_t) *
795 rs_results->total_num_tx_power_levels);
796 if (!rs_results->tx_time_per_power_level) {
797 WMA_LOGA("%s: Mem alloc failed for tx power level stats", __func__);
798 /* In error case, atleast send the radio stats without
799 * tx_power_level stats */
800 rs_results->total_num_tx_power_levels = 0;
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700801 link_stats_results->nr_received++;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700802 goto post_stats;
803 }
804 }
805 qdf_mem_copy(&rs_results->tx_time_per_power_level[fixed_param->power_level_offset],
806 tx_power_level_values,
807 sizeof(uint32_t) * fixed_param->num_tx_power_levels);
808 if (rs_results->total_num_tx_power_levels ==
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700809 (fixed_param->num_tx_power_levels + fixed_param->power_level_offset)) {
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700810 link_stats_results->moreResultToFollow = 0;
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700811 link_stats_results->nr_received++;
812 }
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700813
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700814 WMA_LOGD("%s: moreResultToFollow: %u nr: %u nr_received: %u",
815 __func__, link_stats_results->moreResultToFollow,
816 link_stats_results->num_radio,
817 link_stats_results->nr_received);
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700818
819 /* If still data to receive, return from here */
820 if (link_stats_results->moreResultToFollow)
821 return 0;
822
823post_stats:
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700824 if (link_stats_results->num_radio != link_stats_results->nr_received) {
825 /* Not received all radio stats yet, don't post yet */
826 return 0;
827 }
828
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700829 /* call hdd callback with Link Layer Statistics
830 * vdev_id/ifacId in link_stats_results will be
831 * used to retrieve the correct HDD context
832 */
833 mac->sme.pLinkLayerStatsIndCallback(mac->hHdd,
834 WMA_LINK_LAYER_STATS_RESULTS_RSP,
835 link_stats_results);
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700836 wma_unified_radio_tx_mem_free(handle);
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700837
838 return 0;
839}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840
841/**
842 * wma_unified_link_radio_stats_event_handler() - radio link stats event handler
843 * @handle: wma handle
844 * @cmd_param_info: data received with event from fw
845 * @len: length of data
846 *
847 * Return: 0 for success or error code
848 */
849static int wma_unified_link_radio_stats_event_handler(void *handle,
850 uint8_t *cmd_param_info,
851 uint32_t len)
852{
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700853 tp_wma_handle wma_handle = (tp_wma_handle) handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 WMI_RADIO_LINK_STATS_EVENTID_param_tlvs *param_tlvs;
855 wmi_radio_link_stats_event_fixed_param *fixed_param;
856 wmi_radio_link_stats *radio_stats;
857 wmi_channel_stats *channel_stats;
858 tSirLLStatsResults *link_stats_results;
859 uint8_t *results, *t_radio_stats, *t_channel_stats;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700860 uint32_t next_chan_offset, count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 size_t radio_stats_size, chan_stats_size;
862 size_t link_stats_results_size;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700863 tSirWifiRadioStat *rs_results;
864 tSirWifiChannelStats *chn_results;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865
Anurag Chouhan6d760662016-02-20 16:05:43 +0530866 tpAniSirGlobal pMac = cds_get_context(QDF_MODULE_ID_PE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867
868 if (!pMac) {
869 WMA_LOGD("%s: NULL pMac ptr. Exiting", __func__);
870 return -EINVAL;
871 }
872
873 if (!pMac->sme.pLinkLayerStatsIndCallback) {
874 WMA_LOGD("%s: HDD callback is null", __func__);
875 return -EINVAL;
876 }
877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878 param_tlvs = (WMI_RADIO_LINK_STATS_EVENTID_param_tlvs *) cmd_param_info;
879 if (!param_tlvs) {
880 WMA_LOGA("%s: Invalid stats event", __func__);
881 return -EINVAL;
882 }
883
884 /*
885 * cmd_param_info contains
886 * wmi_radio_link_stats_event_fixed_param fixed_param;
887 * size of(struct wmi_radio_link_stats);
888 * num_channels * size of(struct wmi_channel_stats)
889 */
890 fixed_param = param_tlvs->fixed_param;
891 radio_stats = param_tlvs->radio_stats;
892 channel_stats = param_tlvs->channel_stats;
893
894 if (!fixed_param || !radio_stats ||
895 (radio_stats->num_channels && !channel_stats)) {
896 WMA_LOGA("%s: Invalid param_tlvs for Radio Stats", __func__);
897 return -EINVAL;
898 }
899
900 radio_stats_size = sizeof(tSirWifiRadioStat);
901 chan_stats_size = sizeof(tSirWifiChannelStats);
902 link_stats_results_size = sizeof(*link_stats_results) +
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700903 fixed_param->num_radio * radio_stats_size;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700905 if (!wma_handle->link_stats_results) {
906 wma_handle->link_stats_results = qdf_mem_malloc(link_stats_results_size);
907 if (NULL == wma_handle->link_stats_results) {
908 WMA_LOGD("%s: could not allocate mem for stats results-len %zu",
909 __func__, link_stats_results_size);
910 return -ENOMEM;
911 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 }
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700913 link_stats_results = wma_handle->link_stats_results;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700915 WMA_LOGD("Radio stats Fixed Param:");
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700916 WMA_LOGD("req_id: %u num_radio: %u more_radio_events: %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 fixed_param->request_id, fixed_param->num_radio,
918 fixed_param->more_radio_events);
919
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700920 WMA_LOGD("Radio Info: radio_id: %u on_time: %u tx_time: %u rx_time: %u on_time_scan: %u "
921 "on_time_nbd: %u on_time_gscan: %u on_time_roam_scan: %u "
922 "on_time_pno_scan: %u on_time_hs20: %u num_channels: %u",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800923 radio_stats->radio_id, radio_stats->on_time,
924 radio_stats->tx_time, radio_stats->rx_time,
925 radio_stats->on_time_scan, radio_stats->on_time_nbd,
926 radio_stats->on_time_gscan,
927 radio_stats->on_time_roam_scan,
928 radio_stats->on_time_pno_scan,
929 radio_stats->on_time_hs20, radio_stats->num_channels);
930
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 link_stats_results->paramId = WMI_LINK_STATS_RADIO;
932 link_stats_results->rspId = fixed_param->request_id;
933 link_stats_results->ifaceId = 0;
934 link_stats_results->num_radio = fixed_param->num_radio;
935 link_stats_results->peer_event_number = 0;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700936
937 /*
938 * Backward compatibility:
939 * There are firmware(s) which will send Radio stats only with
940 * more_radio_events set to 0 and firmware which sends Radio stats
941 * followed by tx_power level stats with more_radio_events set to 1.
942 * if more_radio_events is set to 1, buffer the radio stats and
943 * wait for tx_power_level stats.
944 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945 link_stats_results->moreResultToFollow = fixed_param->more_radio_events;
946
947 results = (uint8_t *) link_stats_results->results;
948 t_radio_stats = (uint8_t *) radio_stats;
949 t_channel_stats = (uint8_t *) channel_stats;
950
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700951 rs_results = (tSirWifiRadioStat *) &results[0] + radio_stats->radio_id;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -0700952 rs_results->radio = radio_stats->radio_id;
953 rs_results->onTime = radio_stats->on_time;
954 rs_results->txTime = radio_stats->tx_time;
955 rs_results->rxTime = radio_stats->rx_time;
956 rs_results->onTimeScan = radio_stats->on_time_scan;
957 rs_results->onTimeNbd = radio_stats->on_time_nbd;
958 rs_results->onTimeGscan = radio_stats->on_time_gscan;
959 rs_results->onTimeRoamScan = radio_stats->on_time_roam_scan;
960 rs_results->onTimePnoScan = radio_stats->on_time_pno_scan;
961 rs_results->onTimeHs20 = radio_stats->on_time_hs20;
962 rs_results->total_num_tx_power_levels = 0;
963 rs_results->tx_time_per_power_level = NULL;
964 rs_results->numChannels = radio_stats->num_channels;
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700965 rs_results->channels = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800966
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700967 if (rs_results->numChannels) {
968 rs_results->channels = (tSirWifiChannelStats *) qdf_mem_malloc(
969 radio_stats->num_channels *
970 chan_stats_size);
971 if (rs_results->channels == NULL) {
972 WMA_LOGD("%s: could not allocate mem for channel stats (size=%zu)",
973 __func__, radio_stats->num_channels * chan_stats_size);
974 wma_unified_radio_tx_mem_free(handle);
975 return -ENOMEM;
976 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977
Srinivas Girigowda57b450e2016-10-27 21:00:46 -0700978 chn_results = (tSirWifiChannelStats *) &rs_results->channels[0];
979 next_chan_offset = WMI_TLV_HDR_SIZE;
980 WMA_LOGD("Channel Stats Info");
981 for (count = 0; count < radio_stats->num_channels; count++) {
982 WMA_LOGD("channel_width %u center_freq %u center_freq0 %u "
983 "center_freq1 %u radio_awake_time %u cca_busy_time %u",
984 channel_stats->channel_width,
985 channel_stats->center_freq,
986 channel_stats->center_freq0,
987 channel_stats->center_freq1,
988 channel_stats->radio_awake_time,
989 channel_stats->cca_busy_time);
990 channel_stats++;
991
992 qdf_mem_copy(chn_results,
993 t_channel_stats + next_chan_offset,
994 chan_stats_size);
995 chn_results++;
996 next_chan_offset += sizeof(*channel_stats);
997 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 }
999
Srinivas Girigowdaad874a82016-10-25 14:08:00 -07001000 if (link_stats_results->moreResultToFollow) {
1001 /* More results coming, don't post yet */
1002 return 0;
Srinivas Girigowda57b450e2016-10-27 21:00:46 -07001003 } else {
1004 link_stats_results->nr_received++;
1005 }
1006
1007 if (link_stats_results->num_radio != link_stats_results->nr_received) {
1008 /* Not received all radio stats yet, don't post yet */
1009 return 0;
Srinivas Girigowdaad874a82016-10-25 14:08:00 -07001010 }
1011
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 pMac->sme.pLinkLayerStatsIndCallback(pMac->hHdd,
1013 WMA_LINK_LAYER_STATS_RESULTS_RSP,
1014 link_stats_results);
Srinivas Girigowda57b450e2016-10-27 21:00:46 -07001015 wma_unified_radio_tx_mem_free(handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016
1017 return 0;
1018}
1019
1020/**
1021 * wma_register_ll_stats_event_handler() - register link layer stats related
1022 * event handler
1023 * @wma_handle: wma handle
1024 *
1025 * Return: none
1026 */
1027void wma_register_ll_stats_event_handler(tp_wma_handle wma_handle)
1028{
1029 if (NULL == wma_handle) {
1030 WMA_LOGE("%s: wma_handle is NULL", __func__);
1031 return;
1032 }
1033
1034 wmi_unified_register_event_handler(wma_handle->wmi_handle,
Govind Singhd76a5b02016-03-08 15:12:14 +05301035 WMI_IFACE_LINK_STATS_EVENTID,
1036 wma_unified_link_iface_stats_event_handler,
1037 WMA_RX_SERIALIZER_CTX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 wmi_unified_register_event_handler(wma_handle->wmi_handle,
Govind Singhd76a5b02016-03-08 15:12:14 +05301039 WMI_PEER_LINK_STATS_EVENTID,
1040 wma_unified_link_peer_stats_event_handler,
1041 WMA_RX_SERIALIZER_CTX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 wmi_unified_register_event_handler(wma_handle->wmi_handle,
Govind Singhd76a5b02016-03-08 15:12:14 +05301043 WMI_RADIO_LINK_STATS_EVENTID,
1044 wma_unified_link_radio_stats_event_handler,
1045 WMA_RX_SERIALIZER_CTX);
Srinivas Girigowdaad874a82016-10-25 14:08:00 -07001046 wmi_unified_register_event_handler(wma_handle->wmi_handle,
1047 WMI_RADIO_TX_POWER_LEVEL_STATS_EVENTID,
1048 wma_unified_radio_tx_power_level_stats_event_handler,
1049 WMA_RX_SERIALIZER_CTX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050
1051 return;
1052}
1053
1054
1055/**
1056 * wma_process_ll_stats_clear_req() - clear link layer stats
1057 * @wma: wma handle
1058 * @clearReq: ll stats clear request command params
1059 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301060 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301062QDF_STATUS wma_process_ll_stats_clear_req
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 (tp_wma_handle wma, const tpSirLLStatsClearReq clearReq)
1064{
Govind Singh4863da42016-03-08 11:45:00 +05301065 struct ll_stats_clear_params cmd = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 int ret;
1067
1068 if (!clearReq || !wma) {
1069 WMA_LOGE("%s: input pointer is NULL", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301070 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 }
1072
Govind Singh4863da42016-03-08 11:45:00 +05301073 cmd.stop_req = clearReq->stopReq;
1074 cmd.sta_id = clearReq->staId;
1075 cmd.stats_clear_mask = clearReq->statsClearReqMask;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076
Govind Singh4863da42016-03-08 11:45:00 +05301077 ret = wmi_unified_process_ll_stats_clear_cmd(wma->wmi_handle, &cmd,
1078 wma->interfaces[clearReq->staId].addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 if (ret) {
1080 WMA_LOGE("%s: Failed to send clear link stats req", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301081 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001082 }
1083
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301084 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085}
1086
1087/**
1088 * wma_process_ll_stats_set_req() - link layer stats set request
1089 * @wma: wma handle
1090 * @setReq: ll stats set request command params
1091 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301092 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301094QDF_STATUS wma_process_ll_stats_set_req
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001095 (tp_wma_handle wma, const tpSirLLStatsSetReq setReq)
1096{
Govind Singh4863da42016-03-08 11:45:00 +05301097 struct ll_stats_set_params cmd = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 int ret;
1099
1100 if (!setReq || !wma) {
1101 WMA_LOGE("%s: input pointer is NULL", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301102 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 }
1104
Govind Singh4863da42016-03-08 11:45:00 +05301105 cmd.mpdu_size_threshold = setReq->mpduSizeThreshold;
1106 cmd.aggressive_statistics_gathering =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107 setReq->aggressiveStatisticsGathering;
1108
Govind Singh4863da42016-03-08 11:45:00 +05301109 ret = wmi_unified_process_ll_stats_set_cmd(wma->wmi_handle,
1110 &cmd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 if (ret) {
1112 WMA_LOGE("%s: Failed to send set link stats request", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301113 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 }
1115
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301116 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117}
1118
1119/**
1120 * wma_process_ll_stats_get_req() - link layer stats get request
1121 * @wma:wma handle
1122 * @getReq:ll stats get request command params
1123 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301124 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301126QDF_STATUS wma_process_ll_stats_get_req
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 (tp_wma_handle wma, const tpSirLLStatsGetReq getReq)
1128{
Govind Singh4863da42016-03-08 11:45:00 +05301129 struct ll_stats_get_params cmd = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001130 int ret;
1131
1132 if (!getReq || !wma) {
1133 WMA_LOGE("%s: input pointer is NULL", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301134 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 }
1136
Selvaraj, Sridhar171e2252016-06-22 22:33:26 +05301137 if (!wma->interfaces[getReq->staId].vdev_active) {
1138 WMA_LOGE("%s: vdev not created yet", __func__);
1139 return QDF_STATUS_E_FAILURE;
1140 }
1141
Govind Singh4863da42016-03-08 11:45:00 +05301142 cmd.req_id = getReq->reqId;
1143 cmd.param_id_mask = getReq->paramIdMask;
1144 cmd.sta_id = getReq->staId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145
Govind Singh4863da42016-03-08 11:45:00 +05301146 ret = wmi_unified_process_ll_stats_get_cmd(wma->wmi_handle, &cmd,
1147 wma->interfaces[getReq->staId].addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 if (ret) {
1149 WMA_LOGE("%s: Failed to send get link stats request", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301150 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 }
1152
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301153 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154}
1155
1156/**
1157 * wma_unified_link_iface_stats_event_handler() - link iface stats event handler
1158 * @wma:wma handle
1159 * @cmd_param_info: data from event
1160 * @len: length
1161 *
1162 * Return: 0 for success or error code
1163 */
1164int wma_unified_link_iface_stats_event_handler(void *handle,
1165 uint8_t *cmd_param_info,
1166 uint32_t len)
1167{
1168 WMI_IFACE_LINK_STATS_EVENTID_param_tlvs *param_tlvs;
1169 wmi_iface_link_stats_event_fixed_param *fixed_param;
1170 wmi_iface_link_stats *link_stats;
1171 wmi_wmm_ac_stats *ac_stats;
1172 tSirLLStatsResults *link_stats_results;
1173 uint8_t *results, *t_link_stats, *t_ac_stats;
1174 uint32_t next_res_offset, next_ac_offset, count;
1175 uint32_t roaming_offset, roaming_size;
1176 size_t link_stats_size, ac_stats_size, iface_info_size;
1177 size_t link_stats_results_size;
1178
Anurag Chouhan6d760662016-02-20 16:05:43 +05301179 tpAniSirGlobal pMac = cds_get_context(QDF_MODULE_ID_PE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001180
1181 if (!pMac) {
1182 WMA_LOGD("%s: NULL pMac ptr. Exiting", __func__);
1183 return -EINVAL;
1184 }
1185
1186 if (!pMac->sme.pLinkLayerStatsIndCallback) {
1187 WMA_LOGD("%s: HDD callback is null", __func__);
1188 return -EINVAL;
1189 }
1190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001191 param_tlvs = (WMI_IFACE_LINK_STATS_EVENTID_param_tlvs *) cmd_param_info;
1192 if (!param_tlvs) {
1193 WMA_LOGA("%s: Invalid stats event", __func__);
1194 return -EINVAL;
1195 }
1196
1197 /*
1198 * cmd_param_info contains
1199 * wmi_iface_link_stats_event_fixed_param fixed_param;
1200 * wmi_iface_link_stats iface_link_stats;
1201 * iface_link_stats->num_ac * size of(struct wmi_wmm_ac_stats)
1202 */
1203 fixed_param = param_tlvs->fixed_param;
1204 link_stats = param_tlvs->iface_link_stats;
1205 ac_stats = param_tlvs->ac;
1206
1207 if (!fixed_param || !link_stats || (link_stats->num_ac && !ac_stats)) {
1208 WMA_LOGA("%s: Invalid param_tlvs for Iface Stats", __func__);
1209 return -EINVAL;
1210 }
1211
1212 link_stats_size = sizeof(tSirWifiIfaceStat);
1213 iface_info_size = sizeof(tSirWifiInterfaceInfo);
1214 ac_stats_size = sizeof(tSirWifiWmmAcStat);
1215 link_stats_results_size = sizeof(*link_stats_results) + link_stats_size;
1216
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301217 link_stats_results = qdf_mem_malloc(link_stats_results_size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001218 if (!link_stats_results) {
1219 WMA_LOGD("%s: could not allocate mem for stats results-len %zu",
1220 __func__, link_stats_results_size);
1221 return -ENOMEM;
1222 }
1223
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301224 qdf_mem_zero(link_stats_results, link_stats_results_size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001225
1226 link_stats_results->paramId = WMI_LINK_STATS_IFACE;
1227 link_stats_results->rspId = fixed_param->request_id;
1228 link_stats_results->ifaceId = fixed_param->vdev_id;
1229 link_stats_results->num_peers = link_stats->num_peers;
1230 link_stats_results->peer_event_number = 0;
1231 link_stats_results->moreResultToFollow = 0;
1232
1233 results = (uint8_t *) link_stats_results->results;
1234 t_link_stats = (uint8_t *) link_stats;
1235 t_ac_stats = (uint8_t *) ac_stats;
1236
1237 /* Copy roaming state */
1238 roaming_offset = offsetof(tSirWifiInterfaceInfo, roaming);
1239 roaming_size = member_size(tSirWifiInterfaceInfo, roaming);
1240
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301241 qdf_mem_copy(results + roaming_offset, &link_stats->roam_state,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 roaming_size);
1243
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301244 qdf_mem_copy(results + iface_info_size,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 t_link_stats + WMI_TLV_HDR_SIZE,
1246 link_stats_size - iface_info_size -
1247 WIFI_AC_MAX * ac_stats_size);
1248
1249 next_res_offset = link_stats_size - WIFI_AC_MAX * ac_stats_size;
1250 next_ac_offset = WMI_TLV_HDR_SIZE;
1251
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 for (count = 0; count < link_stats->num_ac; count++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001253 ac_stats++;
1254
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301255 qdf_mem_copy(results + next_res_offset,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001256 t_ac_stats + next_ac_offset, ac_stats_size);
1257 next_res_offset += ac_stats_size;
1258 next_ac_offset += sizeof(*ac_stats);
1259 }
1260
1261 /* call hdd callback with Link Layer Statistics
1262 * vdev_id/ifacId in link_stats_results will be
1263 * used to retrieve the correct HDD context
1264 */
1265 pMac->sme.pLinkLayerStatsIndCallback(pMac->hHdd,
1266 WMA_LINK_LAYER_STATS_RESULTS_RSP,
1267 link_stats_results);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301268 qdf_mem_free(link_stats_results);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269
1270 return 0;
1271}
1272
1273#endif /* WLAN_FEATURE_LINK_LAYER_STATS */
1274
1275/**
1276 * wma_update_pdev_stats() - update pdev stats
1277 * @wma: wma handle
1278 * @pdev_stats: pdev stats
1279 *
1280 * Return: none
1281 */
1282static void wma_update_pdev_stats(tp_wma_handle wma,
1283 wmi_pdev_stats *pdev_stats)
1284{
1285 tAniGetPEStatsRsp *stats_rsp_params;
1286 uint32_t temp_mask;
1287 uint8_t *stats_buf;
1288 tCsrGlobalClassAStatsInfo *classa_stats = NULL;
1289 struct wma_txrx_node *node;
1290 uint8_t i;
1291
1292 for (i = 0; i < wma->max_bssid; i++) {
1293 node = &wma->interfaces[i];
1294 stats_rsp_params = node->stats_rsp;
1295 if (stats_rsp_params) {
1296 node->fw_stats_set |= FW_PDEV_STATS_SET;
1297 WMA_LOGD("<---FW PDEV STATS received for vdevId:%d", i);
1298 stats_buf = (uint8_t *) (stats_rsp_params + 1);
1299 temp_mask = stats_rsp_params->statsMask;
1300 if (temp_mask & (1 << eCsrSummaryStats))
1301 stats_buf += sizeof(tCsrSummaryStatsInfo);
1302
1303 if (temp_mask & (1 << eCsrGlobalClassAStats)) {
1304 classa_stats =
1305 (tCsrGlobalClassAStatsInfo *) stats_buf;
1306 classa_stats->max_pwr = pdev_stats->chan_tx_pwr;
1307 }
1308 }
1309 }
1310}
1311
1312/**
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05301313 * wma_vdev_stats_lost_link_helper() - helper function to extract
1314 * lost link information from vdev statistics event while deleting BSS.
1315 * @wma: WMA handle
1316 * @vdev_stats: statistics information from firmware
1317 *
1318 * This is for informing HDD to collect lost link information while
1319 * disconnection. Following conditions to check
1320 * 1. vdev is up
1321 * 2. bssid is zero. When handling DELETE_BSS request message, it sets bssid to
1322 * zero, hence add the check here to indicate the event comes during deleting
1323 * BSS
1324 * 3. DELETE_BSS is the request message queued. Put this condition check on the
1325 * last one as it consumes more resource searching entries in the list
1326 *
1327 * Return: none
1328 */
1329static void wma_vdev_stats_lost_link_helper(tp_wma_handle wma,
1330 wmi_vdev_stats *vdev_stats)
1331{
1332 struct wma_txrx_node *node;
1333 int32_t rssi;
1334 struct wma_target_req *req_msg;
1335 static const uint8_t zero_mac[QDF_MAC_ADDR_SIZE] = {0};
1336
1337 node = &wma->interfaces[vdev_stats->vdev_id];
1338 if (node->vdev_up &&
1339 qdf_mem_cmp(node->bssid, zero_mac, QDF_MAC_ADDR_SIZE)) {
1340 req_msg = wma_peek_vdev_req(wma, vdev_stats->vdev_id,
1341 WMA_TARGET_REQ_TYPE_VDEV_STOP);
1342 if ((NULL == req_msg) ||
1343 (WMA_DELETE_BSS_REQ != req_msg->msg_type)) {
1344 WMA_LOGD(FL("cannot find DELETE_BSS request message"));
1345 return;
1346 }
1347 WMA_LOGD(FL("get vdev id %d, beancon snr %d, data snr %d"),
1348 vdev_stats->vdev_id,
1349 vdev_stats->vdev_snr.bcn_snr,
1350 vdev_stats->vdev_snr.dat_snr);
1351 if (WMA_TGT_INVALID_SNR != vdev_stats->vdev_snr.bcn_snr)
1352 rssi = vdev_stats->vdev_snr.bcn_snr;
1353 else if (WMA_TGT_INVALID_SNR != vdev_stats->vdev_snr.dat_snr)
1354 rssi = vdev_stats->vdev_snr.dat_snr;
1355 else
1356 rssi = WMA_TGT_INVALID_SNR;
1357
1358 /* Get the absolute rssi value from the current rssi value */
1359 rssi = rssi + WMA_TGT_NOISE_FLOOR_DBM;
1360 wma_lost_link_info_handler(wma, vdev_stats->vdev_id, rssi);
1361 }
1362}
1363
1364/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 * wma_update_vdev_stats() - update vdev stats
1366 * @wma: wma handle
1367 * @vdev_stats: vdev stats
1368 *
1369 * Return: none
1370 */
1371static void wma_update_vdev_stats(tp_wma_handle wma,
1372 wmi_vdev_stats *vdev_stats)
1373{
1374 tAniGetPEStatsRsp *stats_rsp_params;
1375 tCsrSummaryStatsInfo *summary_stats = NULL;
1376 uint8_t *stats_buf;
1377 struct wma_txrx_node *node;
1378 uint8_t i;
1379 int8_t rssi = 0;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301380 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 tAniGetRssiReq *pGetRssiReq = (tAniGetRssiReq *) wma->pGetRssiReq;
1382 cds_msg_t sme_msg = { 0 };
Varun Reddy Yeturu83ccb9b2016-06-29 11:55:41 -07001383 int8_t bcn_snr, dat_snr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384
Naveen Rawat2cb788d2016-10-11 17:44:44 -07001385 bcn_snr = vdev_stats->vdev_snr.bcn_snr;
1386 dat_snr = vdev_stats->vdev_snr.dat_snr;
1387 WMA_LOGD("vdev id %d beancon snr %d data snr %d",
1388 vdev_stats->vdev_id, bcn_snr, dat_snr);
1389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 node = &wma->interfaces[vdev_stats->vdev_id];
1391 stats_rsp_params = node->stats_rsp;
1392 if (stats_rsp_params) {
1393 stats_buf = (uint8_t *) (stats_rsp_params + 1);
1394 node->fw_stats_set |= FW_VDEV_STATS_SET;
1395 WMA_LOGD("<---FW VDEV STATS received for vdevId:%d",
1396 vdev_stats->vdev_id);
1397 if (stats_rsp_params->statsMask & (1 << eCsrSummaryStats)) {
1398 summary_stats = (tCsrSummaryStatsInfo *) stats_buf;
1399 for (i = 0; i < 4; i++) {
1400 summary_stats->tx_frm_cnt[i] =
1401 vdev_stats->tx_frm_cnt[i];
1402 summary_stats->fail_cnt[i] =
1403 vdev_stats->fail_cnt[i];
1404 summary_stats->multiple_retry_cnt[i] =
1405 vdev_stats->multiple_retry_cnt[i];
1406 }
1407
1408 summary_stats->rx_frm_cnt = vdev_stats->rx_frm_cnt;
1409 summary_stats->rx_error_cnt = vdev_stats->rx_err_cnt;
1410 summary_stats->rx_discard_cnt =
1411 vdev_stats->rx_discard_cnt;
1412 summary_stats->ack_fail_cnt = vdev_stats->ack_fail_cnt;
1413 summary_stats->rts_succ_cnt = vdev_stats->rts_succ_cnt;
1414 summary_stats->rts_fail_cnt = vdev_stats->rts_fail_cnt;
Naveen Rawat2cb788d2016-10-11 17:44:44 -07001415 /* Update SNR and RSSI in SummaryStats */
1416 if (bcn_snr != WMA_TGT_INVALID_SNR) {
1417 summary_stats->snr = bcn_snr;
1418 summary_stats->rssi =
1419 bcn_snr + WMA_TGT_NOISE_FLOOR_DBM;
1420 } else if (dat_snr != WMA_TGT_INVALID_SNR) {
1421 summary_stats->snr = dat_snr;
1422 summary_stats->rssi =
1423 bcn_snr + WMA_TGT_NOISE_FLOOR_DBM;
1424 } else {
1425 summary_stats->snr = WMA_TGT_INVALID_SNR;
1426 summary_stats->rssi = 0;
1427 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 }
1429 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001430
1431 if (pGetRssiReq && pGetRssiReq->sessionId == vdev_stats->vdev_id) {
Varun Reddy Yeturu83ccb9b2016-06-29 11:55:41 -07001432 if ((bcn_snr == WMA_TGT_INVALID_SNR) &&
1433 (dat_snr == WMA_TGT_INVALID_SNR)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 /*
1435 * Firmware sends invalid snr till it sees
1436 * Beacon/Data after connection since after
1437 * vdev up fw resets the snr to invalid.
1438 * In this duartion Host will return the last know
1439 * rssi during connection.
1440 */
1441 WMA_LOGE("Invalid SNR from firmware");
1442
1443 } else {
Varun Reddy Yeturu83ccb9b2016-06-29 11:55:41 -07001444 if (bcn_snr != WMA_TGT_INVALID_SNR) {
1445 rssi = bcn_snr;
1446 } else if (dat_snr != WMA_TGT_INVALID_SNR) {
1447 rssi = dat_snr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 }
1449
1450 /*
1451 * Get the absolute rssi value from the current rssi value
1452 * the sinr value is hardcoded into 0 in the core stack
1453 */
1454 rssi = rssi + WMA_TGT_NOISE_FLOOR_DBM;
1455 }
1456
1457 WMA_LOGD("Average Rssi = %d, vdev id= %d", rssi,
1458 pGetRssiReq->sessionId);
1459
1460 /* update the average rssi value to UMAC layer */
1461 if (NULL != pGetRssiReq->rssiCallback) {
1462 ((tCsrRssiCallback) (pGetRssiReq->rssiCallback))(rssi,
1463 pGetRssiReq->staId,
1464 pGetRssiReq->pDevContext);
1465 }
1466
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301467 qdf_mem_free(pGetRssiReq);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 wma->pGetRssiReq = NULL;
1469 }
1470
1471 if (node->psnr_req) {
1472 tAniGetSnrReq *p_snr_req = node->psnr_req;
1473
Varun Reddy Yeturu83ccb9b2016-06-29 11:55:41 -07001474 if (bcn_snr != WMA_TGT_INVALID_SNR)
1475 p_snr_req->snr = bcn_snr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 else
Naveen Rawat2cb788d2016-10-11 17:44:44 -07001477 p_snr_req->snr = dat_snr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478
1479 sme_msg.type = eWNI_SME_SNR_IND;
1480 sme_msg.bodyptr = p_snr_req;
1481 sme_msg.bodyval = 0;
1482
Anurag Chouhan6d760662016-02-20 16:05:43 +05301483 qdf_status = cds_mq_post_message(QDF_MODULE_ID_SME, &sme_msg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301484 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 WMA_LOGE("%s: Fail to post snr ind msg", __func__);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301486 qdf_mem_free(p_snr_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001487 }
1488
1489 node->psnr_req = NULL;
1490 }
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +05301491 wma_vdev_stats_lost_link_helper(wma, vdev_stats);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492}
1493
1494/**
1495 * wma_post_stats() - update stats to PE
1496 * @wma: wma handle
1497 * @node: txrx node
1498 *
1499 * Return: none
1500 */
1501static void wma_post_stats(tp_wma_handle wma, struct wma_txrx_node *node)
1502{
1503 tAniGetPEStatsRsp *stats_rsp_params;
1504
1505 stats_rsp_params = node->stats_rsp;
1506 /* send response to UMAC */
1507 wma_send_msg(wma, WMA_GET_STATISTICS_RSP, (void *)stats_rsp_params, 0);
1508 node->stats_rsp = NULL;
1509 node->fw_stats_set = 0;
1510}
1511
1512/**
1513 * wma_update_peer_stats() - update peer stats
1514 * @wma: wma handle
1515 * @peer_stats: peer stats
1516 *
1517 * Return: none
1518 */
1519static void wma_update_peer_stats(tp_wma_handle wma,
1520 wmi_peer_stats *peer_stats)
1521{
1522 tAniGetPEStatsRsp *stats_rsp_params;
1523 tCsrGlobalClassAStatsInfo *classa_stats = NULL;
1524 struct wma_txrx_node *node;
1525 uint8_t *stats_buf, vdev_id, macaddr[IEEE80211_ADDR_LEN], mcsRateFlags;
1526 uint32_t temp_mask;
1527
1528 WMI_MAC_ADDR_TO_CHAR_ARRAY(&peer_stats->peer_macaddr, &macaddr[0]);
1529 if (!wma_find_vdev_by_bssid(wma, macaddr, &vdev_id))
1530 return;
1531
1532 node = &wma->interfaces[vdev_id];
1533 if (node->stats_rsp) {
1534 node->fw_stats_set |= FW_PEER_STATS_SET;
1535 WMA_LOGD("<-- FW PEER STATS received for vdevId:%d", vdev_id);
1536 stats_rsp_params = (tAniGetPEStatsRsp *) node->stats_rsp;
1537 stats_buf = (uint8_t *) (stats_rsp_params + 1);
1538 temp_mask = stats_rsp_params->statsMask;
1539 if (temp_mask & (1 << eCsrSummaryStats))
1540 stats_buf += sizeof(tCsrSummaryStatsInfo);
1541
1542 if (temp_mask & (1 << eCsrGlobalClassAStats)) {
1543 classa_stats = (tCsrGlobalClassAStatsInfo *) stats_buf;
1544 WMA_LOGD("peer tx rate:%d", peer_stats->peer_tx_rate);
1545 /*The linkspeed returned by fw is in kbps so convert
1546 *it in to units of 500kbps which is expected by UMAC*/
1547 if (peer_stats->peer_tx_rate) {
1548 classa_stats->tx_rate =
1549 peer_stats->peer_tx_rate / 500;
1550 }
1551
1552 classa_stats->tx_rate_flags = node->rate_flags;
1553 if (!(node->rate_flags & eHAL_TX_RATE_LEGACY)) {
1554 classa_stats->mcs_index =
1555 wma_get_mcs_idx((peer_stats->peer_tx_rate /
1556 100), node->rate_flags,
1557 node->nss, &mcsRateFlags);
1558 /* rx_frag_cnt and promiscuous_rx_frag_cnt
1559 * parameter is currently not used. lets use the
1560 * same parameter to hold the nss value and mcs
1561 * rate flags */
1562 classa_stats->rx_frag_cnt = node->nss;
1563 classa_stats->promiscuous_rx_frag_cnt =
1564 mcsRateFlags;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001565 }
1566 /* FW returns tx power in intervals of 0.5 dBm
1567 Convert it back to intervals of 1 dBm */
1568 classa_stats->max_pwr =
1569 roundup(classa_stats->max_pwr, 2) >> 1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001571 }
1572}
1573
1574/**
1575 * wma_post_link_status() - post link status to SME
1576 * @pGetLinkStatus: SME Link status
1577 * @link_status: Link status
1578 *
1579 * Return: none
1580 */
1581void wma_post_link_status(tAniGetLinkStatus *pGetLinkStatus,
1582 uint8_t link_status)
1583{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301584 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001585 cds_msg_t sme_msg = { 0 };
1586
1587 pGetLinkStatus->linkStatus = link_status;
1588 sme_msg.type = eWNI_SME_LINK_STATUS_IND;
1589 sme_msg.bodyptr = pGetLinkStatus;
1590 sme_msg.bodyval = 0;
1591
Anurag Chouhan6d760662016-02-20 16:05:43 +05301592 qdf_status = cds_mq_post_message(QDF_MODULE_ID_SME, &sme_msg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301593 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594 WMA_LOGE("%s: Fail to post link status ind msg", __func__);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301595 qdf_mem_free(pGetLinkStatus);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 }
1597}
1598
1599/**
Himanshu Agarwal37e42412016-07-21 14:35:09 +05301600 * wma_update_per_chain_rssi_stats() - to store per chain rssi stats
1601 * @wma: wma handle
1602 * @rssi_stats: rssi stats
1603 * @rssi_per_chain_stats: buffer where rssi stats to be stored
1604 *
1605 * This function stores per chain rssi stats received from fw for all vdevs for
1606 * which the stats were requested into a csr stats structure.
1607 *
1608 * Return: void
1609 */
1610static void wma_update_per_chain_rssi_stats(tp_wma_handle wma,
1611 wmi_rssi_stats *rssi_stats,
1612 struct csr_per_chain_rssi_stats_info *rssi_per_chain_stats)
1613{
1614 int i;
1615 int8_t bcn_snr, dat_snr;
1616
1617 for (i = 0; i < NUM_CHAINS_MAX; i++) {
1618 bcn_snr = rssi_stats->rssi_avg_beacon[i];
1619 dat_snr = rssi_stats->rssi_avg_data[i];
1620 WMA_LOGD("chain %d beacon snr %d data snr %d",
1621 i, bcn_snr, dat_snr);
1622 if (dat_snr != WMA_TGT_INVALID_SNR)
1623 rssi_per_chain_stats->rssi[i] = dat_snr;
1624 else if (bcn_snr != WMA_TGT_INVALID_SNR)
1625 rssi_per_chain_stats->rssi[i] = bcn_snr;
1626 else
1627 /*
1628 * Firmware sends invalid snr till it sees
1629 * Beacon/Data after connection since after
1630 * vdev up fw resets the snr to invalid.
1631 * In this duartion Host will return an invalid rssi
1632 * value.
1633 */
1634 rssi_per_chain_stats->rssi[i] = WMA_TGT_RSSI_INVALID;
1635
1636 /*
1637 * Get the absolute rssi value from the current rssi value the
1638 * sinr value is hardcoded into 0 in the qcacld-new/CORE stack
1639 */
1640 rssi_per_chain_stats->rssi[i] += WMA_TGT_NOISE_FLOOR_DBM;
1641 WMI_MAC_ADDR_TO_CHAR_ARRAY(&(rssi_stats->peer_macaddr),
1642 rssi_per_chain_stats->peer_mac_addr);
1643 }
1644}
1645
1646/**
1647 * wma_update_rssi_stats() - to update rssi stats for all vdevs
1648 * for which the stats were requested.
1649 * @wma: wma handle
1650 * @rssi_stats: rssi stats
1651 *
1652 * This function updates the rssi stats for all vdevs for which
1653 * the stats were requested.
1654 *
1655 * Return: void
1656 */
1657static void wma_update_rssi_stats(tp_wma_handle wma,
1658 wmi_rssi_stats *rssi_stats)
1659{
1660 tAniGetPEStatsRsp *stats_rsp_params;
1661 struct csr_per_chain_rssi_stats_info *rssi_per_chain_stats = NULL;
1662 struct wma_txrx_node *node;
1663 uint8_t *stats_buf;
1664 uint32_t temp_mask;
1665 uint8_t vdev_id;
1666
1667 vdev_id = rssi_stats->vdev_id;
1668 node = &wma->interfaces[vdev_id];
1669 if (node->stats_rsp) {
1670 node->fw_stats_set |= FW_RSSI_PER_CHAIN_STATS_SET;
1671 WMA_LOGD("<-- FW RSSI PER CHAIN STATS received for vdevId:%d",
1672 vdev_id);
1673 stats_rsp_params = (tAniGetPEStatsRsp *) node->stats_rsp;
1674 stats_buf = (uint8_t *) (stats_rsp_params + 1);
1675 temp_mask = stats_rsp_params->statsMask;
1676
1677 if (temp_mask & (1 << eCsrSummaryStats))
1678 stats_buf += sizeof(tCsrSummaryStatsInfo);
1679 if (temp_mask & (1 << eCsrGlobalClassAStats))
1680 stats_buf += sizeof(tCsrGlobalClassAStatsInfo);
1681 if (temp_mask & (1 << eCsrGlobalClassBStats))
1682 stats_buf += sizeof(tCsrGlobalClassBStatsInfo);
1683 if (temp_mask & (1 << eCsrGlobalClassCStats))
1684 stats_buf += sizeof(tCsrGlobalClassCStatsInfo);
1685 if (temp_mask & (1 << eCsrGlobalClassDStats))
1686 stats_buf += sizeof(tCsrGlobalClassDStatsInfo);
1687 if (temp_mask & (1 << eCsrPerStaStats))
1688 stats_buf += sizeof(tCsrPerStaStatsInfo);
1689
1690 if (temp_mask & (1 << csr_per_chain_rssi_stats)) {
1691 rssi_per_chain_stats =
1692 (struct csr_per_chain_rssi_stats_info *)stats_buf;
1693 wma_update_per_chain_rssi_stats(wma, rssi_stats,
1694 rssi_per_chain_stats);
1695 }
1696 }
1697}
1698
1699
1700/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 * wma_link_status_event_handler() - link status event handler
1702 * @handle: wma handle
1703 * @cmd_param_info: data from event
1704 * @len: length
1705 *
1706 * Return: 0 for success or error code
1707 */
1708int wma_link_status_event_handler(void *handle, uint8_t *cmd_param_info,
1709 uint32_t len)
1710{
1711 tp_wma_handle wma = (tp_wma_handle) handle;
1712 WMI_UPDATE_VDEV_RATE_STATS_EVENTID_param_tlvs *param_buf;
1713 wmi_vdev_rate_stats_event_fixed_param *event;
1714 wmi_vdev_rate_ht_info *ht_info;
1715 struct wma_txrx_node *intr = wma->interfaces;
1716 uint8_t link_status = LINK_STATUS_LEGACY;
1717 int i;
1718
1719 param_buf =
1720 (WMI_UPDATE_VDEV_RATE_STATS_EVENTID_param_tlvs *) cmd_param_info;
1721 if (!param_buf) {
1722 WMA_LOGA("%s: Invalid stats event", __func__);
1723 return -EINVAL;
1724 }
1725
1726 event = (wmi_vdev_rate_stats_event_fixed_param *) param_buf->fixed_param;
1727 ht_info = (wmi_vdev_rate_ht_info *) param_buf->ht_info;
1728
1729 WMA_LOGD("num_vdev_stats: %d", event->num_vdev_stats);
1730 for (i = 0; (i < event->num_vdev_stats) && ht_info; i++) {
1731 WMA_LOGD("%s vdevId:%d tx_nss:%d rx_nss:%d tx_preamble:%d rx_preamble:%d",
1732 __func__, ht_info->vdevid, ht_info->tx_nss,
1733 ht_info->rx_nss, ht_info->tx_preamble,
1734 ht_info->rx_preamble);
1735 if (ht_info->vdevid < wma->max_bssid
1736 && intr[ht_info->vdevid].plink_status_req) {
1737 if (ht_info->tx_nss || ht_info->rx_nss)
1738 link_status = LINK_STATUS_MIMO;
1739
1740 if ((ht_info->tx_preamble == LINK_RATE_VHT) ||
1741 (ht_info->rx_preamble == LINK_RATE_VHT))
1742 link_status |= LINK_STATUS_VHT;
1743
1744 if (intr[ht_info->vdevid].nss == 2)
1745 link_status |= LINK_SUPPORT_MIMO;
1746
1747 if (intr[ht_info->vdevid].rate_flags &
1748 (eHAL_TX_RATE_VHT20 | eHAL_TX_RATE_VHT40 |
1749 eHAL_TX_RATE_VHT80))
1750 link_status |= LINK_SUPPORT_VHT;
1751
1752 wma_post_link_status(intr[ht_info->vdevid].plink_status_req,
1753 link_status);
1754 intr[ht_info->vdevid].plink_status_req = NULL;
1755 link_status = LINK_STATUS_LEGACY;
1756 }
1757
1758 ht_info++;
1759 }
1760
1761 return 0;
1762}
1763
1764/**
1765 * wma_stats_event_handler() - stats event handler
1766 * @handle: wma handle
1767 * @cmd_param_info: data from event
1768 * @len: length
1769 *
1770 * Return: 0 for success or error code
1771 */
1772int wma_stats_event_handler(void *handle, uint8_t *cmd_param_info,
1773 uint32_t len)
1774{
1775 tp_wma_handle wma = (tp_wma_handle) handle;
1776 WMI_UPDATE_STATS_EVENTID_param_tlvs *param_buf;
1777 wmi_stats_event_fixed_param *event;
1778 wmi_pdev_stats *pdev_stats;
1779 wmi_vdev_stats *vdev_stats;
1780 wmi_peer_stats *peer_stats;
Himanshu Agarwal37e42412016-07-21 14:35:09 +05301781 wmi_rssi_stats *rssi_stats;
1782 wmi_per_chain_rssi_stats *rssi_event;
1783 struct wma_txrx_node *node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784 uint8_t i, *temp;
1785
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786 param_buf = (WMI_UPDATE_STATS_EVENTID_param_tlvs *) cmd_param_info;
1787 if (!param_buf) {
1788 WMA_LOGA("%s: Invalid stats event", __func__);
1789 return -EINVAL;
1790 }
1791 event = param_buf->fixed_param;
1792 temp = (uint8_t *) param_buf->data;
1793
1794 WMA_LOGD("%s: num_stats: pdev: %u vdev: %u peer %u",
1795 __func__, event->num_pdev_stats, event->num_vdev_stats,
1796 event->num_peer_stats);
1797 if (event->num_pdev_stats > 0) {
1798 for (i = 0; i < event->num_pdev_stats; i++) {
1799 pdev_stats = (wmi_pdev_stats *) temp;
1800 wma_update_pdev_stats(wma, pdev_stats);
1801 temp += sizeof(wmi_pdev_stats);
1802 }
1803 }
1804
1805 if (event->num_vdev_stats > 0) {
1806 for (i = 0; i < event->num_vdev_stats; i++) {
1807 vdev_stats = (wmi_vdev_stats *) temp;
1808 wma_update_vdev_stats(wma, vdev_stats);
1809 temp += sizeof(wmi_vdev_stats);
1810 }
1811 }
1812
1813 if (event->num_peer_stats > 0) {
1814 for (i = 0; i < event->num_peer_stats; i++) {
1815 peer_stats = (wmi_peer_stats *) temp;
1816 wma_update_peer_stats(wma, peer_stats);
1817 temp += sizeof(wmi_peer_stats);
1818 }
1819 }
1820
Himanshu Agarwal37e42412016-07-21 14:35:09 +05301821 rssi_event = (wmi_per_chain_rssi_stats *) param_buf->chain_stats;
1822 if (rssi_event) {
Himanshu Agarwalcd8a84a2016-07-21 14:59:50 +05301823 if (((rssi_event->tlv_header & 0xFFFF0000) >> 16 ==
1824 WMITLV_TAG_STRUC_wmi_per_chain_rssi_stats) &&
1825 ((rssi_event->tlv_header & 0x0000FFFF) ==
1826 WMITLV_GET_STRUCT_TLVLEN(wmi_per_chain_rssi_stats))) {
Himanshu Agarwal37e42412016-07-21 14:35:09 +05301827 if (rssi_event->num_per_chain_rssi_stats > 0) {
1828 temp = (uint8_t *) rssi_event;
1829 temp += sizeof(*rssi_event);
Dustin Brownc4a5ba22016-11-10 17:21:18 -08001830
1831 /* skip past struct array tlv header */
1832 temp += WMI_TLV_HDR_SIZE;
1833
Himanshu Agarwal37e42412016-07-21 14:35:09 +05301834 for (i = 0;
1835 i < rssi_event->num_per_chain_rssi_stats;
1836 i++) {
1837 rssi_stats = (wmi_rssi_stats *)temp;
1838 wma_update_rssi_stats(wma, rssi_stats);
1839 temp += sizeof(wmi_rssi_stats);
1840 }
1841 }
1842 }
1843 }
1844
1845 for (i = 0; i < wma->max_bssid; i++) {
1846 node = &wma->interfaces[i];
1847 if (node->fw_stats_set & FW_PEER_STATS_SET) {
1848 WMA_LOGD("<--STATS RSP VDEV_ID:%d", i);
1849 wma_post_stats(wma, node);
1850 }
1851 }
1852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853 WMA_LOGI("%s: Exit", __func__);
1854 return 0;
1855}
1856
1857/**
1858 * wma_send_link_speed() - send link speed to SME
1859 * @link_speed: link speed
1860 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301861 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301863QDF_STATUS wma_send_link_speed(uint32_t link_speed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001864{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301865 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866 cds_msg_t sme_msg = { 0 };
1867 tSirLinkSpeedInfo *ls_ind =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301868 (tSirLinkSpeedInfo *) qdf_mem_malloc(sizeof(tSirLinkSpeedInfo));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869 if (!ls_ind) {
1870 WMA_LOGE("%s: Memory allocation failed.", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301871 qdf_status = QDF_STATUS_E_NOMEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001872 } else {
1873 ls_ind->estLinkSpeed = link_speed;
1874 sme_msg.type = eWNI_SME_LINK_SPEED_IND;
1875 sme_msg.bodyptr = ls_ind;
1876 sme_msg.bodyval = 0;
1877
Anurag Chouhan6d760662016-02-20 16:05:43 +05301878 qdf_status = cds_mq_post_message(QDF_MODULE_ID_SME, &sme_msg);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301879 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880 WMA_LOGE("%s: Fail to post linkspeed ind msg",
1881 __func__);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301882 qdf_mem_free(ls_ind);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001883 }
1884 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301885 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001886}
1887
1888/**
1889 * wma_link_speed_event_handler() - link speed event handler
1890 * @handle: wma handle
1891 * @cmd_param_info: event data
1892 * @len: length
1893 *
1894 * Return: 0 for success or error code
1895 */
1896int wma_link_speed_event_handler(void *handle, uint8_t *cmd_param_info,
1897 uint32_t len)
1898{
1899 WMI_PEER_ESTIMATED_LINKSPEED_EVENTID_param_tlvs *param_buf;
1900 wmi_peer_estimated_linkspeed_event_fixed_param *event;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301901 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001902
1903 param_buf =
1904 (WMI_PEER_ESTIMATED_LINKSPEED_EVENTID_param_tlvs *) cmd_param_info;
1905 if (!param_buf) {
1906 WMA_LOGE("%s: Invalid linkspeed event", __func__);
1907 return -EINVAL;
1908 }
1909 event = param_buf->fixed_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301910 qdf_status = wma_send_link_speed(event->est_linkspeed_kbps);
1911 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912 return -EINVAL;
1913 }
1914 return 0;
1915}
1916
1917/**
1918 * wma_wni_cfg_dnld() - cfg download request
1919 * @handle: wma handle
1920 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301921 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301923QDF_STATUS wma_wni_cfg_dnld(tp_wma_handle wma_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001924{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301925 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Anurag Chouhan6d760662016-02-20 16:05:43 +05301926 void *mac = cds_get_context(QDF_MODULE_ID_PE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001927
1928 WMA_LOGD("%s: Enter", __func__);
1929
1930 if (NULL == mac) {
1931 WMA_LOGP("%s: Invalid context", __func__);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301932 QDF_ASSERT(0);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301933 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001934 }
1935
1936 process_cfg_download_req(mac);
1937
1938 WMA_LOGD("%s: Exit", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301939 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940}
1941
1942/**
1943 * wma_unified_debug_print_event_handler() - debug print event handler
1944 * @handle: wma handle
1945 * @datap: data pointer
1946 * @len: length
1947 *
1948 * Return: 0 for success or error code
1949 */
1950int wma_unified_debug_print_event_handler(void *handle, uint8_t *datap,
1951 uint32_t len)
1952{
1953 WMI_DEBUG_PRINT_EVENTID_param_tlvs *param_buf;
1954 uint8_t *data;
1955 uint32_t datalen;
1956
1957 param_buf = (WMI_DEBUG_PRINT_EVENTID_param_tlvs *) datap;
1958 if (!param_buf) {
1959 WMA_LOGE("Get NULL point message from FW");
1960 return -ENOMEM;
1961 }
1962 data = param_buf->data;
1963 datalen = param_buf->num_data;
1964
1965#ifdef BIG_ENDIAN_HOST
1966 {
1967 char dbgbuf[500] = { 0 };
1968 memcpy(dbgbuf, data, datalen);
1969 SWAPME(dbgbuf, datalen);
1970 WMA_LOGD("FIRMWARE:%s", dbgbuf);
1971 return 0;
1972 }
1973#else
1974 WMA_LOGD("FIRMWARE:%s", data);
1975 return 0;
1976#endif /* BIG_ENDIAN_HOST */
1977}
1978
1979/**
1980 * wma_check_scan_in_progress() - check scan is progress or not
1981 * @handle: wma handle
1982 *
1983 * Return: true/false
1984 */
1985bool wma_check_scan_in_progress(WMA_HANDLE handle)
1986{
Nitesh Shah0f3fce52016-10-13 22:01:41 +05301987 tp_wma_handle wma = handle;
1988 return qdf_atomic_read(&wma->num_pending_scans) > 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989}
1990
1991/**
1992 * wma_is_sap_active() - check sap is active or not
1993 * @handle: wma handle
1994 *
1995 * Return: true/false
1996 */
1997bool wma_is_sap_active(tp_wma_handle wma_handle)
1998{
1999 int i;
2000
2001 for (i = 0; i < wma_handle->max_bssid; i++) {
2002 if (!wma_handle->interfaces[i].vdev_up)
2003 continue;
2004 if (wma_handle->interfaces[i].type == WMI_VDEV_TYPE_AP &&
2005 wma_handle->interfaces[i].sub_type == 0)
2006 return true;
2007 }
2008 return false;
2009}
2010
2011/**
2012 * wma_is_p2p_go_active() - check p2p go is active or not
2013 * @handle: wma handle
2014 *
2015 * Return: true/false
2016 */
2017bool wma_is_p2p_go_active(tp_wma_handle wma_handle)
2018{
2019 int i;
2020
2021 for (i = 0; i < wma_handle->max_bssid; i++) {
2022 if (!wma_handle->interfaces[i].vdev_up)
2023 continue;
2024 if (wma_handle->interfaces[i].type == WMI_VDEV_TYPE_AP &&
2025 wma_handle->interfaces[i].sub_type ==
2026 WMI_UNIFIED_VDEV_SUBTYPE_P2P_GO)
2027 return true;
2028 }
2029 return false;
2030}
2031
2032/**
2033 * wma_is_p2p_cli_active() - check p2p cli is active or not
2034 * @handle: wma handle
2035 *
2036 * Return: true/false
2037 */
2038bool wma_is_p2p_cli_active(tp_wma_handle wma_handle)
2039{
2040 int i;
2041
2042 for (i = 0; i < wma_handle->max_bssid; i++) {
2043 if (!wma_handle->interfaces[i].vdev_up)
2044 continue;
2045 if (wma_handle->interfaces[i].type == WMI_VDEV_TYPE_STA &&
2046 wma_handle->interfaces[i].sub_type ==
2047 WMI_UNIFIED_VDEV_SUBTYPE_P2P_CLIENT)
2048 return true;
2049 }
2050 return false;
2051}
2052
2053/**
2054 * wma_is_sta_active() - check sta is active or not
2055 * @handle: wma handle
2056 *
2057 * Return: true/false
2058 */
2059bool wma_is_sta_active(tp_wma_handle wma_handle)
2060{
2061 int i;
2062
2063 for (i = 0; i < wma_handle->max_bssid; i++) {
2064 if (!wma_handle->interfaces[i].vdev_up)
2065 continue;
2066 if (wma_handle->interfaces[i].type == WMI_VDEV_TYPE_STA &&
2067 wma_handle->interfaces[i].sub_type == 0)
2068 return true;
2069 if (wma_handle->interfaces[i].type == WMI_VDEV_TYPE_IBSS)
2070 return true;
2071 }
2072 return false;
2073}
2074
2075/**
2076 * wma_peer_phymode() - get phymode
2077 * @nw_type: nw type
2078 * @sta_type: sta type
2079 * @is_ht: is ht supported
2080 * @is_cw40: is channel width 40 supported
2081 * @is_vht: is vht supported
2082 * @is_cw_vht: is channel width 80 supported
2083 *
2084 * Return: WLAN_PHY_MODE
2085 */
2086WLAN_PHY_MODE wma_peer_phymode(tSirNwType nw_type, uint8_t sta_type,
2087 uint8_t is_ht, uint8_t ch_width,
2088 uint8_t is_vht)
2089{
2090 WLAN_PHY_MODE phymode = MODE_UNKNOWN;
2091
2092 switch (nw_type) {
2093 case eSIR_11B_NW_TYPE:
2094 phymode = MODE_11B;
2095 if (is_ht || is_vht)
2096 WMA_LOGE("HT/VHT is enabled with 11B NW type");
2097 break;
2098 case eSIR_11G_NW_TYPE:
2099 if (!(is_ht || is_vht)) {
2100 phymode = MODE_11G;
2101 break;
2102 }
2103 if (CH_WIDTH_40MHZ < ch_width)
2104 WMA_LOGE("80/160 MHz BW sent in 11G, configured 40MHz");
2105 if (ch_width)
2106 phymode = (is_vht) ?
Krishna Kumaar Natarajan294da812016-04-28 14:39:30 -07002107 MODE_11AC_VHT40_2G : MODE_11NG_HT40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002108 else
2109 phymode = (is_vht) ?
Krishna Kumaar Natarajan294da812016-04-28 14:39:30 -07002110 MODE_11AC_VHT20_2G : MODE_11NG_HT20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111 break;
2112 case eSIR_11A_NW_TYPE:
2113 if (!(is_ht || is_vht)) {
2114 phymode = MODE_11A;
2115 break;
2116 }
2117 if (is_vht) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002118 if (ch_width == CH_WIDTH_160MHZ)
2119 phymode = MODE_11AC_VHT160;
2120 else if (ch_width == CH_WIDTH_80P80MHZ)
2121 phymode = MODE_11AC_VHT80_80;
Amar Singhal046eb8a2016-05-05 12:50:15 -07002122 else if (ch_width == CH_WIDTH_80MHZ)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002123 phymode = MODE_11AC_VHT80;
2124 else
2125 phymode = (ch_width) ?
2126 MODE_11AC_VHT40 : MODE_11AC_VHT20;
2127 } else
2128 phymode = (ch_width) ? MODE_11NA_HT40 : MODE_11NA_HT20;
2129 break;
2130 default:
2131 WMA_LOGP("%s: Invalid nw type %d", __func__, nw_type);
2132 break;
2133 }
2134 WMA_LOGD("%s: nw_type %d is_ht %d ch_width %d is_vht %d phymode %d",
2135 __func__, nw_type, is_ht, ch_width, is_vht, phymode);
2136
2137 return phymode;
2138}
2139
2140/**
2141 * wma_txrx_fw_stats_reset() - reset txrx fw statistics
2142 * @wma_handle: wma handle
2143 * @vdev_id: vdev id
2144 * @value: value
2145 *
2146 * Return: 0 for success or return error
2147 */
2148int32_t wma_txrx_fw_stats_reset(tp_wma_handle wma_handle,
2149 uint8_t vdev_id, uint32_t value)
2150{
2151 struct ol_txrx_stats_req req;
Leo Chang96464902016-10-28 11:10:54 -07002152 void *vdev;
Nishank Aggarwala13b61d2016-12-01 12:53:58 +05302153 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2154
2155 if (!soc) {
2156 WMA_LOGE("%s:SOC context is NULL", __func__);
2157 return -EINVAL;
2158 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002159
2160 vdev = wma_find_vdev_by_id(wma_handle, vdev_id);
2161 if (!vdev) {
2162 WMA_LOGE("%s:Invalid vdev handle", __func__);
2163 return -EINVAL;
2164 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302165 qdf_mem_zero(&req, sizeof(req));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166 req.stats_type_reset_mask = value;
Nishank Aggarwala13b61d2016-12-01 12:53:58 +05302167 cdp_fw_stats_get(soc, vdev, &req,
Leo Chang96464902016-10-28 11:10:54 -07002168 false, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169
2170 return 0;
2171}
2172
2173#ifdef HELIUMPLUS
2174#define SET_UPLOAD_MASK(_mask, _rate_info) \
2175 ((_mask) = 1 << (_rate_info ## _V2))
2176#else /* !HELIUMPLUS */
2177#define SET_UPLOAD_MASK(_mask, _rate_info) \
2178 ((_mask) = 1 << (_rate_info))
2179#endif
2180
Nirav Shah93e789e2016-04-14 19:47:43 +05302181#ifdef HELIUMPLUS
Jeff Johnsonc4b47a92016-10-07 12:34:41 -07002182static bool wma_is_valid_fw_stats_cmd(uint32_t value)
Nirav Shah93e789e2016-04-14 19:47:43 +05302183{
2184 if (value > (HTT_DBG_NUM_STATS + 1) ||
2185 value == (HTT_DBG_STATS_RX_RATE_INFO + 1) ||
2186 value == (HTT_DBG_STATS_TX_RATE_INFO + 1) ||
2187 value == (HTT_DBG_STATS_TXBF_MUSU_NDPA_PKT + 1)) {
2188 WMA_LOGE("%s: Not supported", __func__);
2189 return false;
2190 }
2191 return true;
2192}
2193#else
Jeff Johnsonc4b47a92016-10-07 12:34:41 -07002194static bool wma_is_valid_fw_stats_cmd(uint32_t value)
Nirav Shah93e789e2016-04-14 19:47:43 +05302195{
2196 if (value > (HTT_DBG_NUM_STATS + 1) ||
2197 value == (HTT_DBG_STATS_RX_RATE_INFO_V2 + 1) ||
2198 value == (HTT_DBG_STATS_TX_RATE_INFO_V2 + 1) ||
2199 value == (HTT_DBG_STATS_TXBF_MUSU_NDPA_PKT + 1)) {
2200 WMA_LOGE("%s: Not supported", __func__);
2201 return false;
2202 }
2203 return true;
2204}
2205#endif
2206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002207/**
2208 * wma_set_txrx_fw_stats_level() - set txrx fw stats level
2209 * @wma_handle: wma handle
2210 * @vdev_id: vdev id
2211 * @value: value
2212 *
2213 * Return: 0 for success or return error
2214 */
2215int32_t wma_set_txrx_fw_stats_level(tp_wma_handle wma_handle,
2216 uint8_t vdev_id, uint32_t value)
2217{
2218 struct ol_txrx_stats_req req;
Leo Chang96464902016-10-28 11:10:54 -07002219 void *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002220 uint32_t l_up_mask;
Nishank Aggarwala13b61d2016-12-01 12:53:58 +05302221 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2222
2223 if (!soc) {
2224 WMA_LOGE("%s:SOC context is NULL", __func__);
2225 return -EINVAL;
2226 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002227
2228 vdev = wma_find_vdev_by_id(wma_handle, vdev_id);
2229 if (!vdev) {
2230 WMA_LOGE("%s:Invalid vdev handle", __func__);
2231 return -EINVAL;
2232 }
Nirav Shah93e789e2016-04-14 19:47:43 +05302233
2234 if (wma_is_valid_fw_stats_cmd(value) == false)
2235 return -EINVAL;
2236
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302237 qdf_mem_zero(&req, sizeof(req));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002238 req.print.verbose = 1;
2239
Nirav Shah93e789e2016-04-14 19:47:43 +05302240 /* TODO: Need to check how to avoid mem leak*/
2241 l_up_mask = 1 << (value - 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002242 req.stats_type_upload_mask = l_up_mask;
2243
Nishank Aggarwala13b61d2016-12-01 12:53:58 +05302244 cdp_fw_stats_get(soc, vdev, &req,
Leo Chang96464902016-10-28 11:10:54 -07002245 false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002246
2247 return 0;
2248}
2249
2250/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002251 * wma_get_stats_rsp_buf() - fill get stats response buffer
2252 * @get_stats_param: get stats parameters
2253 *
2254 * Return: stats response buffer
2255 */
2256static tAniGetPEStatsRsp *wma_get_stats_rsp_buf
2257 (tAniGetPEStatsReq *get_stats_param)
2258{
2259 tAniGetPEStatsRsp *stats_rsp_params;
2260 uint32_t len, temp_mask, counter = 0;
2261
2262 len = sizeof(tAniGetPEStatsRsp);
2263 temp_mask = get_stats_param->statsMask;
2264
2265 while (temp_mask) {
2266 if (temp_mask & 1) {
2267 switch (counter) {
2268 case eCsrSummaryStats:
2269 len += sizeof(tCsrSummaryStatsInfo);
2270 break;
2271 case eCsrGlobalClassAStats:
2272 len += sizeof(tCsrGlobalClassAStatsInfo);
2273 break;
2274 case eCsrGlobalClassBStats:
2275 len += sizeof(tCsrGlobalClassBStatsInfo);
2276 break;
2277 case eCsrGlobalClassCStats:
2278 len += sizeof(tCsrGlobalClassCStatsInfo);
2279 break;
2280 case eCsrGlobalClassDStats:
2281 len += sizeof(tCsrGlobalClassDStatsInfo);
2282 break;
2283 case eCsrPerStaStats:
2284 len += sizeof(tCsrPerStaStatsInfo);
2285 break;
Himanshu Agarwal37e42412016-07-21 14:35:09 +05302286 case csr_per_chain_rssi_stats:
2287 len +=
2288 sizeof(struct csr_per_chain_rssi_stats_info);
2289 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002290 }
2291 }
2292
2293 counter++;
2294 temp_mask >>= 1;
2295 }
2296
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302297 stats_rsp_params = (tAniGetPEStatsRsp *) qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002298 if (!stats_rsp_params) {
2299 WMA_LOGE("memory allocation failed for tAniGetPEStatsRsp");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302300 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002301 return NULL;
2302 }
2303
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302304 qdf_mem_zero(stats_rsp_params, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002305 stats_rsp_params->staId = get_stats_param->staId;
2306 stats_rsp_params->statsMask = get_stats_param->statsMask;
2307 stats_rsp_params->msgType = WMA_GET_STATISTICS_RSP;
2308 stats_rsp_params->msgLen = len - sizeof(tAniGetPEStatsRsp);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302309 stats_rsp_params->rc = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 return stats_rsp_params;
2311}
2312
2313/**
2314 * wma_get_stats_req() - get stats request
2315 * @handle: wma handle
2316 * @get_stats_param: stats params
2317 *
2318 * Return: none
2319 */
2320void wma_get_stats_req(WMA_HANDLE handle,
2321 tAniGetPEStatsReq *get_stats_param)
2322{
2323 tp_wma_handle wma_handle = (tp_wma_handle) handle;
2324 struct wma_txrx_node *node;
Govind Singh4863da42016-03-08 11:45:00 +05302325 struct pe_stats_req cmd = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002326 tAniGetPEStatsRsp *pGetPEStatsRspParams;
Govind Singh4863da42016-03-08 11:45:00 +05302327
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002328
2329 WMA_LOGD("%s: Enter", __func__);
2330 node = &wma_handle->interfaces[get_stats_param->sessionId];
2331 if (node->stats_rsp) {
2332 pGetPEStatsRspParams = node->stats_rsp;
2333 if (pGetPEStatsRspParams->staId == get_stats_param->staId &&
2334 pGetPEStatsRspParams->statsMask ==
2335 get_stats_param->statsMask) {
2336 WMA_LOGI("Stats for staId %d with stats mask %d "
2337 "is pending.... ignore new request",
2338 get_stats_param->staId,
2339 get_stats_param->statsMask);
2340 goto end;
2341 } else {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302342 qdf_mem_free(node->stats_rsp);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002343 node->stats_rsp = NULL;
2344 node->fw_stats_set = 0;
2345 }
2346 }
2347
2348 pGetPEStatsRspParams = wma_get_stats_rsp_buf(get_stats_param);
2349 if (!pGetPEStatsRspParams)
2350 goto end;
2351
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002352 node->fw_stats_set = 0;
2353 node->stats_rsp = pGetPEStatsRspParams;
Govind Singh4863da42016-03-08 11:45:00 +05302354
2355 cmd.session_id = get_stats_param->sessionId;
2356 if (wmi_unified_get_stats_cmd(wma_handle->wmi_handle, &cmd,
2357 node->bssid)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002358
2359 WMA_LOGE("%s: Failed to send WMI_REQUEST_STATS_CMDID",
2360 __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002361 goto failed;
2362 }
2363
2364 goto end;
2365failed:
2366
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302367 pGetPEStatsRspParams->rc = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 node->stats_rsp = NULL;
2369 /* send response to UMAC */
2370 wma_send_msg(wma_handle, WMA_GET_STATISTICS_RSP, pGetPEStatsRspParams,
2371 0);
2372end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302373 qdf_mem_free(get_stats_param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002374 WMA_LOGD("%s: Exit", __func__);
2375 return;
2376}
2377
2378/**
2379 * wma_get_beacon_buffer_by_vdev_id() - get the beacon buffer from vdev ID
2380 * @vdev_id: vdev id
2381 * @buffer_size: size of buffer
2382 *
2383 * Return: none
2384 */
2385void *wma_get_beacon_buffer_by_vdev_id(uint8_t vdev_id, uint32_t *buffer_size)
2386{
2387 tp_wma_handle wma;
2388 struct beacon_info *beacon;
2389 uint8_t *buf;
2390 uint32_t buf_size;
2391
Anurag Chouhan6d760662016-02-20 16:05:43 +05302392 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002393 if (!wma) {
2394 WMA_LOGE("%s: Invalid WMA handle", __func__);
2395 return NULL;
2396 }
2397
2398 if (vdev_id >= wma->max_bssid) {
2399 WMA_LOGE("%s: Invalid vdev_id %u", __func__, vdev_id);
2400 return NULL;
2401 }
2402
2403 if (!wma_is_vdev_in_ap_mode(wma, vdev_id)) {
2404 WMA_LOGE("%s: vdevid %d is not in AP mode", __func__, vdev_id);
2405 return NULL;
2406 }
2407
2408 beacon = wma->interfaces[vdev_id].beacon;
2409
2410 if (!beacon) {
2411 WMA_LOGE("%s: beacon invalid", __func__);
2412 return NULL;
2413 }
2414
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302415 qdf_spin_lock_bh(&beacon->lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416
Nirav Shahcbc6d722016-03-01 16:24:53 +05302417 buf_size = qdf_nbuf_len(beacon->buf);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302418 buf = qdf_mem_malloc(buf_size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002419
2420 if (!buf) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302421 qdf_spin_unlock_bh(&beacon->lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002422 WMA_LOGE("%s: alloc failed for beacon buf", __func__);
2423 return NULL;
2424 }
2425
Nirav Shahcbc6d722016-03-01 16:24:53 +05302426 qdf_mem_copy(buf, qdf_nbuf_data(beacon->buf), buf_size);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002427
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302428 qdf_spin_unlock_bh(&beacon->lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429
2430 if (buffer_size)
2431 *buffer_size = buf_size;
2432
2433 return buf;
2434}
2435
2436/**
2437 * wma_get_vdev_address_by_vdev_id() - lookup MAC address from vdev ID
2438 * @vdev_id: vdev id
2439 *
2440 * Return: mac address
2441 */
2442uint8_t *wma_get_vdev_address_by_vdev_id(uint8_t vdev_id)
2443{
2444 tp_wma_handle wma;
2445
Anurag Chouhan6d760662016-02-20 16:05:43 +05302446 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002447 if (!wma) {
2448 WMA_LOGE("%s: Invalid WMA handle", __func__);
2449 return NULL;
2450 }
2451
2452 if (vdev_id >= wma->max_bssid) {
2453 WMA_LOGE("%s: Invalid vdev_id %u", __func__, vdev_id);
2454 return NULL;
2455 }
2456
2457 return wma->interfaces[vdev_id].addr;
2458}
2459
2460/**
2461 * wma_get_interface_by_vdev_id() - lookup interface entry using vdev ID
2462 * @vdev_id: vdev id
2463 *
2464 * Return: entry from vdev table
2465 */
2466struct wma_txrx_node *wma_get_interface_by_vdev_id(uint8_t vdev_id)
2467{
2468 tp_wma_handle wma;
2469
Anurag Chouhan6d760662016-02-20 16:05:43 +05302470 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002471 if (!wma) {
2472 WMA_LOGE("%s: Invalid WMA handle", __func__);
2473 return NULL;
2474 }
2475
2476 if (vdev_id >= wma->max_bssid) {
2477 WMA_LOGE("%s: Invalid vdev_id %u", __func__, vdev_id);
2478 return NULL;
2479 }
2480
2481 return &wma->interfaces[vdev_id];
2482}
2483
2484/**
2485 * wma_is_vdev_up() - return whether a vdev is up
2486 * @vdev_id: vdev id
2487 *
2488 * Return: true if the vdev is up, false otherwise
2489 */
2490bool wma_is_vdev_up(uint8_t vdev_id)
2491{
2492 struct wma_txrx_node *vdev = wma_get_interface_by_vdev_id(vdev_id);
2493 if (vdev)
2494 return vdev->vdev_up;
2495 else
2496 return false;
2497}
2498
2499#if defined(QCA_WIFI_FTM)
2500/**
2501 * wma_utf_rsp() - utf response
2502 * @wma_handle: wma handle
2503 * @payload: payload
2504 * @len: length of payload
2505 *
2506 * Return: 0 for success or error code
2507 */
Jeff Johnsonc4b47a92016-10-07 12:34:41 -07002508static int wma_utf_rsp(tp_wma_handle wma_handle, uint8_t **payload,
2509 uint32_t *len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002510{
2511 int ret = -1;
2512 uint32_t payload_len;
2513
2514 payload_len = wma_handle->utf_event_info.length;
2515 if (payload_len) {
2516 ret = 0;
2517
2518 /*
2519 * The first 4 bytes holds the payload size
2520 * and the actual payload sits next to it
2521 */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302522 *payload = (uint8_t *) qdf_mem_malloc((uint32_t) payload_len
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002523 + sizeof(A_UINT32));
2524 *(A_UINT32 *) &(*payload[0]) =
2525 wma_handle->utf_event_info.length;
2526 memcpy(*payload + sizeof(A_UINT32),
2527 wma_handle->utf_event_info.data, payload_len);
2528 wma_handle->utf_event_info.length = 0;
2529 *len = payload_len;
2530 }
2531
2532 return ret;
2533}
2534
2535/**
2536 * wma_post_ftm_response() - post ftm response to upper layer
2537 * @wma_handle: wma handle
2538 *
2539 * Return: none
2540 */
2541static void wma_post_ftm_response(tp_wma_handle wma_handle)
2542{
2543 int ret;
2544 uint8_t *payload;
2545 uint32_t data_len;
2546 cds_msg_t msg = { 0 };
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302547 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548
2549 ret = wma_utf_rsp(wma_handle, &payload, &data_len);
2550
2551 if (ret) {
2552 return;
2553 }
2554
2555 sys_build_message_header(SYS_MSG_ID_FTM_RSP, &msg);
2556 msg.bodyptr = payload;
2557 msg.bodyval = 0;
2558
2559 status = cds_mq_post_message(CDS_MQ_ID_SYS, &msg);
2560
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302561 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562 WMA_LOGE("failed to post ftm response to SYS");
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302563 qdf_mem_free(payload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002564 }
2565}
2566
2567/**
2568 * wma_process_utf_event() - process utf event
2569 * @handle: wma handle
2570 * @datap: data buffer
2571 * @dataplen: data length
2572 *
2573 * Return: 0 for success or error code
2574 */
2575static int
2576wma_process_utf_event(WMA_HANDLE handle, uint8_t *datap, uint32_t dataplen)
2577{
2578 tp_wma_handle wma_handle = (tp_wma_handle) handle;
Govind Singhd76a5b02016-03-08 15:12:14 +05302579 struct seg_hdr_info segHdrInfo;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002580 uint8_t totalNumOfSegments, currentSeq;
2581 WMI_PDEV_UTF_EVENTID_param_tlvs *param_buf;
2582 uint8_t *data;
2583 uint32_t datalen;
2584
2585 param_buf = (WMI_PDEV_UTF_EVENTID_param_tlvs *) datap;
2586 if (!param_buf) {
2587 WMA_LOGE("Get NULL point message from FW");
2588 return -EINVAL;
2589 }
2590 data = param_buf->data;
2591 datalen = param_buf->num_data;
2592
Govind Singhd76a5b02016-03-08 15:12:14 +05302593 segHdrInfo = *(struct seg_hdr_info *) &(data[0]);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002594
2595 wma_handle->utf_event_info.currentSeq = (segHdrInfo.segmentInfo & 0xF);
2596
2597 currentSeq = (segHdrInfo.segmentInfo & 0xF);
2598 totalNumOfSegments = (segHdrInfo.segmentInfo >> 4) & 0xF;
2599
2600 datalen = datalen - sizeof(segHdrInfo);
2601
2602 if (currentSeq == 0) {
2603 wma_handle->utf_event_info.expectedSeq = 0;
2604 wma_handle->utf_event_info.offset = 0;
2605 } else {
2606 if (wma_handle->utf_event_info.expectedSeq != currentSeq)
2607 WMA_LOGE("Mismatch in expecting seq expected"
2608 " Seq %d got seq %d",
2609 wma_handle->utf_event_info.expectedSeq,
2610 currentSeq);
2611 }
2612
2613 memcpy(&wma_handle->utf_event_info.
2614 data[wma_handle->utf_event_info.offset],
2615 &data[sizeof(segHdrInfo)], datalen);
2616 wma_handle->utf_event_info.offset =
2617 wma_handle->utf_event_info.offset + datalen;
2618 wma_handle->utf_event_info.expectedSeq++;
2619
2620 if (wma_handle->utf_event_info.expectedSeq == totalNumOfSegments) {
2621 if (wma_handle->utf_event_info.offset != segHdrInfo.len)
2622 WMA_LOGE("All segs received total len mismatch.."
2623 " len %zu total len %d",
2624 wma_handle->utf_event_info.offset,
2625 segHdrInfo.len);
2626
2627 wma_handle->utf_event_info.length =
2628 wma_handle->utf_event_info.offset;
2629 }
2630
2631 wma_post_ftm_response(wma_handle);
2632
2633 return 0;
2634}
2635
2636/**
2637 * wma_utf_detach() - utf detach
2638 * @wma_handle: wma handle
2639 *
2640 * Return: none
2641 */
2642void wma_utf_detach(tp_wma_handle wma_handle)
2643{
2644 if (wma_handle->utf_event_info.data) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302645 qdf_mem_free(wma_handle->utf_event_info.data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002646 wma_handle->utf_event_info.data = NULL;
2647 wma_handle->utf_event_info.length = 0;
2648 wmi_unified_unregister_event_handler(wma_handle->wmi_handle,
2649 WMI_PDEV_UTF_EVENTID);
2650 }
2651}
2652
2653/**
2654 * wma_utf_attach() - utf attach
2655 * @wma_handle: wma handle
2656 *
2657 * Return: none
2658 */
2659void wma_utf_attach(tp_wma_handle wma_handle)
2660{
2661 int ret;
2662
2663 wma_handle->utf_event_info.data = (unsigned char *)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302664 qdf_mem_malloc(MAX_UTF_EVENT_LENGTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665 wma_handle->utf_event_info.length = 0;
2666
2667 ret = wmi_unified_register_event_handler(wma_handle->wmi_handle,
2668 WMI_PDEV_UTF_EVENTID,
Govind Singhd76a5b02016-03-08 15:12:14 +05302669 wma_process_utf_event,
2670 WMA_RX_SERIALIZER_CTX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002671
2672 if (ret)
2673 WMA_LOGP("%s: Failed to register UTF event callback", __func__);
2674}
2675
2676/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002677 * wma_utf_cmd() - utf command
2678 * @wma_handle: wma handle
2679 * @data: data
2680 * @len: length
2681 *
Govind Singhd76a5b02016-03-08 15:12:14 +05302682 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002683 */
Jeff Johnsonc4b47a92016-10-07 12:34:41 -07002684static QDF_STATUS wma_utf_cmd(tp_wma_handle wma_handle, uint8_t *data,
2685 uint16_t len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686{
Govind Singhd76a5b02016-03-08 15:12:14 +05302687 struct pdev_utf_params param = {0};
2688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002689 wma_handle->utf_event_info.length = 0;
Govind Singhd76a5b02016-03-08 15:12:14 +05302690 param.utf_payload = data;
2691 param.len = len;
2692
2693 return wmi_unified_pdev_utf_cmd_send(wma_handle->wmi_handle, &param,
2694 WMA_WILDCARD_PDEV_ID);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002695}
2696
2697/**
2698 * wma_process_ftm_command() - process ftm command
2699 * @wma_handle: wma handle
2700 * @msg_buffer: message buffer
2701 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302702 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002703 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302704QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002705wma_process_ftm_command(tp_wma_handle wma_handle,
2706 struct ar6k_testmode_cmd_data *msg_buffer)
2707{
2708 uint8_t *data = NULL;
2709 uint16_t len = 0;
2710 int ret;
2711
2712 if (!msg_buffer)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302713 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714
Anurag Chouhan6d760662016-02-20 16:05:43 +05302715 if (cds_get_conparam() != QDF_GLOBAL_FTM_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002716 WMA_LOGE("FTM command issued in non-FTM mode");
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302717 qdf_mem_free(msg_buffer->data);
2718 qdf_mem_free(msg_buffer);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302719 return QDF_STATUS_E_NOSUPPORT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002720 }
2721
2722 data = msg_buffer->data;
2723 len = msg_buffer->len;
2724
2725 ret = wma_utf_cmd(wma_handle, data, len);
2726
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302727 qdf_mem_free(msg_buffer->data);
2728 qdf_mem_free(msg_buffer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002729
2730 if (ret)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302731 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302733 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002734}
2735#endif /* QCA_WIFI_FTM */
2736
2737/**
2738 * wma_get_wcnss_software_version() - get wcnss software version
2739 * @p_cds_gctx: cds context
2740 * @pVersion: version pointer
2741 * @versionBufferSize: buffer size
2742 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302743 * Return: QDF_STATUS_SUCCESS for success or error code
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002744 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302745QDF_STATUS wma_get_wcnss_software_version(void *p_cds_gctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002746 uint8_t *pVersion,
2747 uint32_t versionBufferSize)
2748{
2749 tp_wma_handle wma_handle;
Anurag Chouhan6d760662016-02-20 16:05:43 +05302750 wma_handle = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002751
2752 if (NULL == wma_handle) {
2753 WMA_LOGE("%s: Failed to get wma", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302754 return QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755 }
2756
2757 snprintf(pVersion, versionBufferSize, "%x",
2758 (unsigned int)wma_handle->target_fw_version);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302759 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002760}
2761
2762/**
2763 * wma_get_tx_rx_ss_from_config() - Get Tx/Rx spatial stream from HW mode config
2764 * @mac_ss: Config which indicates the HW mode as per 'hw_mode_ss_config'
2765 * @tx_ss: Contains the Tx spatial stream
2766 * @rx_ss: Contains the Rx spatial stream
2767 *
2768 * Returns the number of spatial streams of Tx and Rx
2769 *
2770 * Return: None
2771 */
Jeff Johnsonc4b47a92016-10-07 12:34:41 -07002772static void wma_get_tx_rx_ss_from_config(enum hw_mode_ss_config mac_ss,
2773 uint32_t *tx_ss, uint32_t *rx_ss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002774{
2775 switch (mac_ss) {
2776 case HW_MODE_SS_0x0:
2777 *tx_ss = 0;
2778 *rx_ss = 0;
2779 break;
2780 case HW_MODE_SS_1x1:
2781 *tx_ss = 1;
2782 *rx_ss = 1;
2783 break;
2784 case HW_MODE_SS_2x2:
2785 *tx_ss = 2;
2786 *rx_ss = 2;
2787 break;
2788 case HW_MODE_SS_3x3:
2789 *tx_ss = 3;
2790 *rx_ss = 3;
2791 break;
2792 case HW_MODE_SS_4x4:
2793 *tx_ss = 4;
2794 *rx_ss = 4;
2795 break;
2796 default:
2797 *tx_ss = 0;
2798 *rx_ss = 0;
2799 }
2800}
2801
2802/**
2803 * wma_get_matching_hw_mode_index() - Get matching HW mode index
2804 * @wma: WMA handle
2805 * @mac0_tx_ss: Number of tx spatial streams of MAC0
2806 * @mac0_rx_ss: Number of rx spatial streams of MAC0
2807 * @mac0_bw: Bandwidth of MAC0 of type 'hw_mode_bandwidth'
2808 * @mac1_tx_ss: Number of tx spatial streams of MAC1
2809 * @mac1_rx_ss: Number of rx spatial streams of MAC1
2810 * @mac1_bw: Bandwidth of MAC1 of type 'hw_mode_bandwidth'
2811 * @dbs: DBS capability of type 'hw_mode_dbs_capab'
2812 * @dfs: Agile DFS capability of type 'hw_mode_agile_dfs_capab'
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302813 * @sbs: SBS capability of type 'hw_mode_sbs_capab'
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 *
2815 * Fetches the HW mode index corresponding to the HW mode provided
2816 *
2817 * Return: Positive hw mode index in case a match is found or a negative
2818 * value, otherwise
2819 */
2820static int8_t wma_get_matching_hw_mode_index(tp_wma_handle wma,
2821 uint32_t mac0_tx_ss, uint32_t mac0_rx_ss,
2822 enum hw_mode_bandwidth mac0_bw,
2823 uint32_t mac1_tx_ss, uint32_t mac1_rx_ss,
2824 enum hw_mode_bandwidth mac1_bw,
2825 enum hw_mode_dbs_capab dbs,
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302826 enum hw_mode_agile_dfs_capab dfs,
2827 enum hw_mode_sbs_capab sbs)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002828{
2829 uint32_t i;
2830 uint32_t t_mac0_tx_ss, t_mac0_rx_ss, t_mac0_bw;
2831 uint32_t t_mac1_tx_ss, t_mac1_rx_ss, t_mac1_bw;
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302832 uint32_t dbs_mode, agile_dfs_mode, sbs_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833 int8_t found = -EINVAL;
2834
2835 if (!wma) {
2836 WMA_LOGE("%s: Invalid WMA handle", __func__);
2837 return found;
2838 }
2839
2840 for (i = 0; i < wma->num_dbs_hw_modes; i++) {
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302841 t_mac0_tx_ss = WMA_HW_MODE_MAC0_TX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842 wma->hw_mode.hw_mode_list[i]);
2843 if (t_mac0_tx_ss != mac0_tx_ss)
2844 continue;
2845
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302846 t_mac0_rx_ss = WMA_HW_MODE_MAC0_RX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002847 wma->hw_mode.hw_mode_list[i]);
2848 if (t_mac0_rx_ss != mac0_rx_ss)
2849 continue;
2850
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302851 t_mac0_bw = WMA_HW_MODE_MAC0_BANDWIDTH_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002852 wma->hw_mode.hw_mode_list[i]);
Nitesh Shah877ad5d2016-09-22 19:27:58 +05302853 /*
2854 * Firmware advertises max bw capability as CBW 80+80
2855 * for single MAC. Thus CBW 20/40/80 should also be
2856 * supported, if CBW 80+80 is supported.
2857 */
2858 if (t_mac0_bw < mac0_bw)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002859 continue;
2860
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302861 t_mac1_tx_ss = WMA_HW_MODE_MAC1_TX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862 wma->hw_mode.hw_mode_list[i]);
2863 if (t_mac1_tx_ss != mac1_tx_ss)
2864 continue;
2865
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302866 t_mac1_rx_ss = WMA_HW_MODE_MAC1_RX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002867 wma->hw_mode.hw_mode_list[i]);
2868 if (t_mac1_rx_ss != mac1_rx_ss)
2869 continue;
2870
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302871 t_mac1_bw = WMA_HW_MODE_MAC1_BANDWIDTH_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002872 wma->hw_mode.hw_mode_list[i]);
Nitesh Shah877ad5d2016-09-22 19:27:58 +05302873 if (t_mac1_bw < mac1_bw)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002874 continue;
2875
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302876 dbs_mode = WMA_HW_MODE_DBS_MODE_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002877 wma->hw_mode.hw_mode_list[i]);
2878 if (dbs_mode != dbs)
2879 continue;
2880
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302881 agile_dfs_mode = WMA_HW_MODE_AGILE_DFS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002882 wma->hw_mode.hw_mode_list[i]);
2883 if (agile_dfs_mode != dfs)
2884 continue;
2885
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302886 sbs_mode = WMA_HW_MODE_SBS_MODE_GET(
2887 wma->hw_mode.hw_mode_list[i]);
2888 if (sbs_mode != sbs)
2889 continue;
2890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002891 found = i;
2892 WMA_LOGI("%s: hw_mode index %d found",
2893 __func__, i);
2894 break;
2895 }
2896 return found;
2897}
2898
2899/**
2900 * wma_get_hw_mode_from_dbs_hw_list() - Get hw_mode index
2901 * @mac0_ss: MAC0 spatial stream configuration
2902 * @mac0_bw: MAC0 bandwidth configuration
2903 * @mac1_ss: MAC1 spatial stream configuration
2904 * @mac1_bw: MAC1 bandwidth configuration
2905 * @dbs: HW DBS capability
2906 * @dfs: HW Agile DFS capability
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302907 * @sbs: HW SBS capability
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002908 *
2909 * Get the HW mode index corresponding to the HW modes spatial stream,
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302910 * bandwidth, DBS, Agile DFS and SBS capability
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002911 *
2912 * Return: Index number if a match is found or -negative value if not found
2913 */
2914int8_t wma_get_hw_mode_idx_from_dbs_hw_list(enum hw_mode_ss_config mac0_ss,
2915 enum hw_mode_bandwidth mac0_bw,
2916 enum hw_mode_ss_config mac1_ss,
2917 enum hw_mode_bandwidth mac1_bw,
2918 enum hw_mode_dbs_capab dbs,
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302919 enum hw_mode_agile_dfs_capab dfs,
2920 enum hw_mode_sbs_capab sbs)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921{
2922 tp_wma_handle wma;
2923 uint32_t mac0_tx_ss, mac0_rx_ss;
2924 uint32_t mac1_tx_ss, mac1_rx_ss;
2925
Anurag Chouhan6d760662016-02-20 16:05:43 +05302926 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 if (!wma) {
2928 WMA_LOGE("%s: Invalid WMA handle", __func__);
2929 return -EINVAL;
2930 }
2931
2932 wma_get_tx_rx_ss_from_config(mac0_ss, &mac0_tx_ss, &mac0_rx_ss);
2933 wma_get_tx_rx_ss_from_config(mac1_ss, &mac1_tx_ss, &mac1_rx_ss);
2934
2935 WMA_LOGI("%s: MAC0: TxSS=%d, RxSS=%d, BW=%d",
2936 __func__, mac0_tx_ss, mac0_rx_ss, mac0_bw);
2937 WMA_LOGI("%s: MAC1: TxSS=%d, RxSS=%d, BW=%d",
2938 __func__, mac1_tx_ss, mac1_rx_ss, mac1_bw);
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302939 WMA_LOGI("%s: DBS=%d, Agile DFS=%d, SBS=%d",
2940 __func__, dbs, dfs, sbs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002941
2942 return wma_get_matching_hw_mode_index(wma, mac0_tx_ss, mac0_rx_ss,
2943 mac0_bw,
2944 mac1_tx_ss, mac1_rx_ss,
2945 mac1_bw,
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302946 dbs, dfs, sbs);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947}
2948
2949/**
2950 * wma_get_hw_mode_from_idx() - Get HW mode based on index
2951 * @idx: HW mode index
2952 * @hw_mode: HW mode params
2953 *
2954 * Fetches the HW mode parameters
2955 *
2956 * Return: Success if hw mode is obtained and the hw mode params
2957 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302958QDF_STATUS wma_get_hw_mode_from_idx(uint32_t idx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002959 struct sir_hw_mode_params *hw_mode)
2960{
2961 tp_wma_handle wma;
2962 uint32_t param;
2963
Anurag Chouhan6d760662016-02-20 16:05:43 +05302964 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002965 if (!wma) {
2966 WMA_LOGE("%s: Invalid WMA handle", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302967 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002968 }
2969
2970 if (idx > wma->num_dbs_hw_modes) {
2971 WMA_LOGE("%s: Invalid index", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302972 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973 }
2974
Mahesh Kumar Kalikot Veetild43e1652015-11-02 15:35:10 -08002975 if (!wma->num_dbs_hw_modes) {
2976 WMA_LOGE("%s: No dbs hw modes available", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302977 return QDF_STATUS_E_FAILURE;
Mahesh Kumar Kalikot Veetild43e1652015-11-02 15:35:10 -08002978 }
2979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002980 param = wma->hw_mode.hw_mode_list[idx];
2981
Nitesh Shah5b7bae02016-09-28 18:58:33 +05302982 hw_mode->mac0_tx_ss = WMA_HW_MODE_MAC0_TX_STREAMS_GET(param);
2983 hw_mode->mac0_rx_ss = WMA_HW_MODE_MAC0_RX_STREAMS_GET(param);
2984 hw_mode->mac0_bw = WMA_HW_MODE_MAC0_BANDWIDTH_GET(param);
2985 hw_mode->mac1_tx_ss = WMA_HW_MODE_MAC1_TX_STREAMS_GET(param);
2986 hw_mode->mac1_rx_ss = WMA_HW_MODE_MAC1_RX_STREAMS_GET(param);
2987 hw_mode->mac1_bw = WMA_HW_MODE_MAC1_BANDWIDTH_GET(param);
2988 hw_mode->dbs_cap = WMA_HW_MODE_DBS_MODE_GET(param);
2989 hw_mode->agile_dfs_cap = WMA_HW_MODE_AGILE_DFS_GET(param);
2990 hw_mode->sbs_cap = WMA_HW_MODE_SBS_MODE_GET(param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002991
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302992 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002993}
2994
2995/**
2996 * wma_get_num_dbs_hw_modes() - Get number of HW mode
2997 *
2998 * Fetches the number of DBS HW modes returned by the FW
2999 *
3000 * Return: Negative value on error or returns the number of DBS HW modes
3001 */
3002int8_t wma_get_num_dbs_hw_modes(void)
3003{
3004 tp_wma_handle wma;
3005
Anurag Chouhan6d760662016-02-20 16:05:43 +05303006 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003007 if (!wma) {
3008 WMA_LOGE("%s: Invalid WMA handle", __func__);
3009 return -EINVAL;
3010 }
3011 return wma->num_dbs_hw_modes;
3012}
3013
3014/**
3015 * wma_is_hw_dbs_capable() - Check if HW is DBS capable
3016 *
3017 * Checks if the HW is DBS capable
3018 *
3019 * Return: true if the HW is DBS capable
3020 */
3021bool wma_is_hw_dbs_capable(void)
3022{
3023 tp_wma_handle wma;
3024 uint32_t param, i, found = 0;
3025
Anurag Chouhan6d760662016-02-20 16:05:43 +05303026 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027 if (!wma) {
3028 WMA_LOGE("%s: Invalid WMA handle", __func__);
3029 return false;
3030 }
3031
3032 if (!wma_is_dbs_enable()) {
3033 WMA_LOGI("%s: DBS is disabled", __func__);
3034 return false;
3035 }
3036
3037 WMA_LOGI("%s: DBS service bit map: %d", __func__,
3038 WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
3039 WMI_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT));
3040
3041 /* The agreement with FW is that: To know if the target is DBS
3042 * capable, DBS needs to be supported both in the HW mode list
3043 * and in the service ready event
3044 */
3045 if (!(WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
3046 WMI_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT)))
3047 return false;
3048
3049 for (i = 0; i < wma->num_dbs_hw_modes; i++) {
3050 param = wma->hw_mode.hw_mode_list[i];
3051 WMA_LOGI("%s: HW param: %x", __func__, param);
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303052 if (WMA_HW_MODE_DBS_MODE_GET(param)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053 WMA_LOGI("%s: HW (%d) is DBS capable", __func__, i);
3054 found = 1;
3055 break;
3056 }
3057 }
3058
3059 if (found)
3060 return true;
3061
3062 return false;
3063}
3064
3065/**
Aravind Narasimhan5b7c2cd2016-12-08 21:04:26 -08003066 * wma_is_hw_sbs_capable() - Check if HW is SBS capable
3067 *
3068 * Checks if the HW is SBS capable
3069 *
3070 * Return: true if the HW is SBS capable
3071 */
3072bool wma_is_hw_sbs_capable(void)
3073{
3074 tp_wma_handle wma;
3075 uint32_t param, i, found = 0;
3076
3077 wma = cds_get_context(QDF_MODULE_ID_WMA);
3078 if (!wma) {
3079 WMA_LOGE("%s: Invalid WMA handle", __func__);
3080 return false;
3081 }
3082
3083 WMA_LOGI("%s: SBS service bit map: %d", __func__,
3084 WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
3085 WMI_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT));
3086
3087 /* The agreement with FW is that: To know if the target is SBS
3088 * capable, SBS needs to be supported both in the HW mode list
3089 * and DBS needs to be supported in the service ready event
3090 */
3091 if (!(WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
3092 WMI_SERVICE_DUAL_BAND_SIMULTANEOUS_SUPPORT)))
3093 return false;
3094
3095 for (i = 0; i < wma->num_dbs_hw_modes; i++) {
3096 param = wma->hw_mode.hw_mode_list[i];
3097 WMA_LOGI("%s: HW param: %x", __func__, param);
3098 if (WMA_HW_MODE_SBS_MODE_GET(param)) {
3099 WMA_LOGI("%s: HW (%d) is SBS capable", __func__, i);
3100 found = 1;
3101 break;
3102 }
3103 }
3104
3105 if (found)
3106 return true;
3107
3108 return true;
3109}
3110
3111/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112 * wma_get_mac_id_of_vdev() - Get MAC id corresponding to a vdev
3113 * @vdev_id: VDEV whose MAC ID is required
3114 *
3115 * Get MAC id corresponding to a vdev id from the WMA structure
3116 *
3117 * Return: Negative value on failure and MAC id on success
3118 */
3119int8_t wma_get_mac_id_of_vdev(uint32_t vdev_id)
3120{
3121 tp_wma_handle wma;
3122
Anurag Chouhan6d760662016-02-20 16:05:43 +05303123 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 if (!wma) {
3125 WMA_LOGE("%s: Invalid WMA handle", __func__);
3126 return -EINVAL;
3127 }
3128
3129 if (wma->interfaces)
3130 return wma->interfaces[vdev_id].mac_id;
3131
3132 return -EINVAL;
3133}
3134
3135/**
3136 * wma_get_old_and_new_hw_index() - Get the old and new HW index
3137 * @old_hw_mode_index: Value at this pointer contains the old HW mode index
3138 * Default value when not configured is WMA_DEFAULT_HW_MODE_INDEX
3139 * @new_hw_mode_index: Value at this pointer contains the new HW mode index
3140 * Default value when not configured is WMA_DEFAULT_HW_MODE_INDEX
3141 *
3142 * Get the old and new HW index configured in the driver
3143 *
3144 * Return: Failure in case the HW mode indices cannot be fetched and Success
3145 * otherwise. When no HW mode transition has happened the values of
3146 * old_hw_mode_index and new_hw_mode_index will be the same.
3147 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303148QDF_STATUS wma_get_old_and_new_hw_index(uint32_t *old_hw_mode_index,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149 uint32_t *new_hw_mode_index)
3150{
3151 tp_wma_handle wma;
3152
Anurag Chouhan6d760662016-02-20 16:05:43 +05303153 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154 if (!wma) {
3155 WMA_LOGE("%s: Invalid WMA handle", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303156 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157 }
3158
3159 *old_hw_mode_index = wma->old_hw_mode_index;
3160 *new_hw_mode_index = wma->new_hw_mode_index;
3161
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303162 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163}
3164
3165/**
3166 * wma_update_intf_hw_mode_params() - Update WMA params
3167 * @vdev_id: VDEV id whose params needs to be updated
3168 * @mac_id: MAC id to be updated
3169 * @cfgd_hw_mode_index: HW mode index from which Tx and Rx SS will be updated
3170 *
3171 * Updates the MAC id, tx spatial stream, rx spatial stream in WMA
3172 *
3173 * Return: None
3174 */
3175void wma_update_intf_hw_mode_params(uint32_t vdev_id, uint32_t mac_id,
3176 uint32_t cfgd_hw_mode_index)
3177{
3178 tp_wma_handle wma;
Tushnim Bhattacharyya206bcac2015-11-10 15:20:06 -08003179 uint32_t param;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003180
Anurag Chouhan6d760662016-02-20 16:05:43 +05303181 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 if (!wma) {
3183 WMA_LOGE("%s: Invalid WMA handle", __func__);
3184 return;
3185 }
3186
3187 if (!wma->interfaces) {
3188 WMA_LOGE("%s: Interface is NULL", __func__);
3189 return;
3190 }
3191
Tushnim Bhattacharyya206bcac2015-11-10 15:20:06 -08003192 if (cfgd_hw_mode_index > wma->num_dbs_hw_modes) {
3193 WMA_LOGE("%s: Invalid index", __func__);
3194 return;
3195 }
3196
3197 param = wma->hw_mode.hw_mode_list[cfgd_hw_mode_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 wma->interfaces[vdev_id].mac_id = mac_id;
3199 if (mac_id == 0) {
3200 wma->interfaces[vdev_id].tx_streams =
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303201 WMA_HW_MODE_MAC0_TX_STREAMS_GET(param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202 wma->interfaces[vdev_id].rx_streams =
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303203 WMA_HW_MODE_MAC0_RX_STREAMS_GET(param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204 } else {
3205 wma->interfaces[vdev_id].tx_streams =
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303206 WMA_HW_MODE_MAC1_TX_STREAMS_GET(param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207 wma->interfaces[vdev_id].rx_streams =
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303208 WMA_HW_MODE_MAC1_RX_STREAMS_GET(param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209 }
3210}
3211
3212/**
3213 * wma_get_dbs_hw_modes() - Get the DBS HW modes for userspace
3214 * @one_by_one_dbs: 1x1 DBS capability of HW
3215 * @two_by_two_dbs: 2x2 DBS capability of HW
3216 *
3217 * Provides the DBS HW mode capability such as whether
3218 * 1x1 DBS, 2x2 DBS is supported by the HW or not.
3219 *
3220 * Return: Failure in case of error and 0 on success
3221 * one_by_one_dbs/two_by_two_dbs will be false,
3222 * if they are not supported.
3223 * one_by_one_dbs/two_by_two_dbs will be true,
3224 * if they are supported.
3225 * false values of one_by_one_dbs/two_by_two_dbs,
3226 * indicate DBS is disabled
3227 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303228QDF_STATUS wma_get_dbs_hw_modes(bool *one_by_one_dbs, bool *two_by_two_dbs)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003229{
3230 tp_wma_handle wma;
3231 uint32_t i;
3232 int8_t found_one_by_one = -EINVAL, found_two_by_two = -EINVAL;
3233 uint32_t conf1_tx_ss, conf1_rx_ss;
3234 uint32_t conf2_tx_ss, conf2_rx_ss;
3235
3236 *one_by_one_dbs = false;
3237 *two_by_two_dbs = false;
3238
3239 if (wma_is_hw_dbs_capable() == false) {
3240 WMA_LOGE("%s: HW is not DBS capable", __func__);
3241 /* Caller will understand that DBS is disabled */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303242 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243
3244 }
3245
Anurag Chouhan6d760662016-02-20 16:05:43 +05303246 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247 if (!wma) {
3248 WMA_LOGE("%s: Invalid WMA handle", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303249 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250 }
3251
3252 /* To check 1x1 capability */
3253 wma_get_tx_rx_ss_from_config(HW_MODE_SS_1x1,
3254 &conf1_tx_ss, &conf1_rx_ss);
3255 /* To check 2x2 capability */
3256 wma_get_tx_rx_ss_from_config(HW_MODE_SS_2x2,
3257 &conf2_tx_ss, &conf2_rx_ss);
3258
3259 for (i = 0; i < wma->num_dbs_hw_modes; i++) {
3260 uint32_t t_conf0_tx_ss, t_conf0_rx_ss;
3261 uint32_t t_conf1_tx_ss, t_conf1_rx_ss;
3262 uint32_t dbs_mode;
3263
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303264 t_conf0_tx_ss = WMA_HW_MODE_MAC0_TX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265 wma->hw_mode.hw_mode_list[i]);
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303266 t_conf0_rx_ss = WMA_HW_MODE_MAC0_RX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267 wma->hw_mode.hw_mode_list[i]);
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303268 t_conf1_tx_ss = WMA_HW_MODE_MAC1_TX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 wma->hw_mode.hw_mode_list[i]);
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303270 t_conf1_rx_ss = WMA_HW_MODE_MAC1_RX_STREAMS_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 wma->hw_mode.hw_mode_list[i]);
Nitesh Shah5b7bae02016-09-28 18:58:33 +05303272 dbs_mode = WMA_HW_MODE_DBS_MODE_GET(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273 wma->hw_mode.hw_mode_list[i]);
3274
3275 if (((((t_conf0_tx_ss == conf1_tx_ss) &&
3276 (t_conf0_rx_ss == conf1_rx_ss)) ||
3277 ((t_conf1_tx_ss == conf1_tx_ss) &&
3278 (t_conf1_rx_ss == conf1_rx_ss))) &&
3279 (dbs_mode == HW_MODE_DBS)) &&
3280 (found_one_by_one < 0)) {
3281 found_one_by_one = i;
3282 WMA_LOGI("%s: 1x1 hw_mode index %d found",
3283 __func__, i);
3284 /* Once an entry is found, need not check for 1x1
3285 * again
3286 */
3287 continue;
3288 }
3289
3290 if (((((t_conf0_tx_ss == conf2_tx_ss) &&
3291 (t_conf0_rx_ss == conf2_rx_ss)) ||
3292 ((t_conf1_tx_ss == conf2_tx_ss) &&
3293 (t_conf1_rx_ss == conf2_rx_ss))) &&
3294 (dbs_mode == HW_MODE_DBS)) &&
3295 (found_two_by_two < 0)) {
3296 found_two_by_two = i;
3297 WMA_LOGI("%s: 2x2 hw_mode index %d found",
3298 __func__, i);
3299 /* Once an entry is found, need not check for 2x2
3300 * again
3301 */
3302 continue;
3303 }
3304 }
3305
3306 if (found_one_by_one >= 0)
3307 *one_by_one_dbs = true;
3308 if (found_two_by_two >= 0)
3309 *two_by_two_dbs = true;
3310
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303311 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312}
3313
3314/**
3315 * wma_get_current_hw_mode() - Get current HW mode params
3316 * @hw_mode: HW mode parameters
3317 *
3318 * Provides the current HW mode parameters if the HW mode is initialized
3319 * in the driver
3320 *
3321 * Return: Success if the current HW mode params are successfully populated
3322 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303323QDF_STATUS wma_get_current_hw_mode(struct sir_hw_mode_params *hw_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303325 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326 uint32_t old_hw_index = 0, new_hw_index = 0;
3327
3328 WMA_LOGI("%s: Get the current hw mode", __func__);
3329
3330 status = wma_get_old_and_new_hw_index(&old_hw_index,
3331 &new_hw_index);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303332 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 WMA_LOGE("%s: Failed to get HW mode index", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303334 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335 }
3336
3337 if (new_hw_index == WMA_DEFAULT_HW_MODE_INDEX) {
3338 WMA_LOGE("%s: HW mode is not yet initialized", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303339 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340 }
3341
3342 status = wma_get_hw_mode_from_idx(new_hw_index, hw_mode);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303343 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 WMA_LOGE("%s: Failed to get HW mode index", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303345 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003346 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303347 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348}
3349
3350/**
3351 * wma_is_dbs_enable() - Check if master DBS control is enabled
3352 *
3353 * Checks if the master DBS control is enabled. This will be used
3354 * to override any other DBS capability
3355 *
3356 * Return: True if master DBS control is enabled
3357 */
3358bool wma_is_dbs_enable(void)
3359{
3360 tp_wma_handle wma;
3361
3362 if (wma_is_dual_mac_disabled_in_ini())
3363 return false;
3364
Anurag Chouhan6d760662016-02-20 16:05:43 +05303365 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 if (!wma) {
3367 WMA_LOGE("%s: Invalid WMA handle", __func__);
3368 return false;
3369 }
3370
3371 WMA_LOGD("%s: DBS=%d", __func__,
3372 WMI_DBS_FW_MODE_CFG_DBS_GET(wma->dual_mac_cfg.cur_fw_mode_config));
3373
3374 if (WMI_DBS_FW_MODE_CFG_DBS_GET(wma->dual_mac_cfg.cur_fw_mode_config))
3375 return true;
3376
3377 return false;
3378}
3379
3380/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 * wma_get_updated_scan_config() - Get the updated scan configuration
3382 * @scan_config: Pointer containing the updated scan config
3383 * @dbs_scan: 0 or 1 indicating if DBS scan needs to be enabled/disabled
3384 * @dbs_plus_agile_scan: 0 or 1 indicating if DBS plus agile scan needs to be
3385 * enabled/disabled
3386 * @single_mac_scan_with_dfs: 0 or 1 indicating if single MAC scan with DFS
3387 * needs to be enabled/disabled
3388 *
3389 * Takes the current scan configuration and set the necessary scan config
3390 * bits to either 0/1 and provides the updated value to the caller who
3391 * can use this to pass it on to the FW
3392 *
3393 * Return: 0 on success
3394 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303395QDF_STATUS wma_get_updated_scan_config(uint32_t *scan_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 bool dbs_scan,
3397 bool dbs_plus_agile_scan,
3398 bool single_mac_scan_with_dfs)
3399{
3400 tp_wma_handle wma;
3401
Anurag Chouhan6d760662016-02-20 16:05:43 +05303402 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003403 if (!wma) {
3404 WMA_LOGE("%s: Invalid WMA handle", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303405 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406 }
3407 *scan_config = wma->dual_mac_cfg.cur_scan_config;
3408
3409 WMI_DBS_CONC_SCAN_CFG_DBS_SCAN_SET(*scan_config, dbs_scan);
3410 WMI_DBS_CONC_SCAN_CFG_AGILE_SCAN_SET(*scan_config,
3411 dbs_plus_agile_scan);
3412 WMI_DBS_CONC_SCAN_CFG_AGILE_DFS_SCAN_SET(*scan_config,
3413 single_mac_scan_with_dfs);
3414
3415 WMA_LOGD("%s: *scan_config:%x ", __func__, *scan_config);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303416 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417}
3418
3419/**
3420 * wma_get_updated_fw_mode_config() - Get the updated fw mode configuration
3421 * @fw_mode_config: Pointer containing the updated fw mode config
3422 * @dbs: 0 or 1 indicating if DBS needs to be enabled/disabled
3423 * @agile_dfs: 0 or 1 indicating if agile DFS needs to be enabled/disabled
3424 *
3425 * Takes the current fw mode configuration and set the necessary fw mode config
3426 * bits to either 0/1 and provides the updated value to the caller who
3427 * can use this to pass it on to the FW
3428 *
3429 * Return: 0 on success
3430 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303431QDF_STATUS wma_get_updated_fw_mode_config(uint32_t *fw_mode_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432 bool dbs,
3433 bool agile_dfs)
3434{
3435 tp_wma_handle wma;
3436
Anurag Chouhan6d760662016-02-20 16:05:43 +05303437 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 if (!wma) {
3439 WMA_LOGE("%s: Invalid WMA handle", __func__);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303440 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 }
3442 *fw_mode_config = wma->dual_mac_cfg.cur_fw_mode_config;
3443
3444 WMI_DBS_FW_MODE_CFG_DBS_SET(*fw_mode_config, dbs);
3445 WMI_DBS_FW_MODE_CFG_AGILE_DFS_SET(*fw_mode_config, agile_dfs);
3446
3447 WMA_LOGD("%s: *fw_mode_config:%x ", __func__, *fw_mode_config);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303448 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449}
3450
3451/**
3452 * wma_get_dbs_config() - Get DBS bit
3453 *
3454 * Gets the DBS bit of fw_mode_config_bits
3455 *
3456 * Return: 0 or 1 to indicate the DBS bit
3457 */
3458bool wma_get_dbs_config(void)
3459{
3460 tp_wma_handle wma;
3461 uint32_t fw_mode_config;
3462
3463 if (wma_is_dual_mac_disabled_in_ini())
3464 return false;
3465
Anurag Chouhan6d760662016-02-20 16:05:43 +05303466 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467 if (!wma) {
3468 WMA_LOGE("%s: Invalid WMA handle", __func__);
3469 /* We take that it is disabled and proceed */
3470 return false;
3471 }
3472 fw_mode_config = wma->dual_mac_cfg.cur_fw_mode_config;
3473
3474 return WMI_DBS_FW_MODE_CFG_DBS_GET(fw_mode_config);
3475}
3476
3477/**
3478 * wma_get_agile_dfs_config() - Get Agile DFS bit
3479 *
3480 * Gets the Agile DFS bit of fw_mode_config_bits
3481 *
3482 * Return: 0 or 1 to indicate the Agile DFS bit
3483 */
3484bool wma_get_agile_dfs_config(void)
3485{
3486 tp_wma_handle wma;
3487 uint32_t fw_mode_config;
3488
3489 if (wma_is_dual_mac_disabled_in_ini())
3490 return false;
3491
Anurag Chouhan6d760662016-02-20 16:05:43 +05303492 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 if (!wma) {
3494 WMA_LOGE("%s: Invalid WMA handle", __func__);
3495 /* We take that it is disabled and proceed */
3496 return false;
3497 }
3498 fw_mode_config = wma->dual_mac_cfg.cur_fw_mode_config;
3499
3500 return WMI_DBS_FW_MODE_CFG_AGILE_DFS_GET(fw_mode_config);
3501}
3502
3503/**
3504 * wma_get_dbs_scan_config() - Get DBS scan bit
3505 *
3506 * Gets the DBS scan bit of concurrent_scan_config_bits
3507 *
3508 * Return: 0 or 1 to indicate the DBS scan bit
3509 */
3510bool wma_get_dbs_scan_config(void)
3511{
3512 tp_wma_handle wma;
3513 uint32_t scan_config;
3514
3515 if (wma_is_dual_mac_disabled_in_ini())
3516 return false;
3517
Anurag Chouhan6d760662016-02-20 16:05:43 +05303518 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003519 if (!wma) {
3520 WMA_LOGE("%s: Invalid WMA handle", __func__);
3521 /* We take that it is disabled and proceed */
3522 return false;
3523 }
3524 scan_config = wma->dual_mac_cfg.cur_scan_config;
3525
3526 return WMI_DBS_CONC_SCAN_CFG_DBS_SCAN_GET(scan_config);
3527}
3528
3529/**
3530 * wma_get_dbs_plus_agile_scan_config() - Get DBS plus agile scan bit
3531 *
3532 * Gets the DBS plus agile scan bit of concurrent_scan_config_bits
3533 *
3534 * Return: 0 or 1 to indicate the DBS plus agile scan bit
3535 */
3536bool wma_get_dbs_plus_agile_scan_config(void)
3537{
3538 tp_wma_handle wma;
3539 uint32_t scan_config;
3540
3541 if (wma_is_dual_mac_disabled_in_ini())
3542 return false;
3543
Anurag Chouhan6d760662016-02-20 16:05:43 +05303544 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003545 if (!wma) {
3546 WMA_LOGE("%s: Invalid WMA handle", __func__);
3547 /* We take that it is disabled and proceed */
3548 return false;
3549 }
3550 scan_config = wma->dual_mac_cfg.cur_scan_config;
3551
3552 return WMI_DBS_CONC_SCAN_CFG_AGILE_SCAN_GET(scan_config);
3553}
3554
3555/**
3556 * wma_get_single_mac_scan_with_dfs_config() - Get Single MAC scan with DFS bit
3557 *
3558 * Gets the Single MAC scan with DFS bit of concurrent_scan_config_bits
3559 *
3560 * Return: 0 or 1 to indicate the Single MAC scan with DFS bit
3561 */
3562bool wma_get_single_mac_scan_with_dfs_config(void)
3563{
3564 tp_wma_handle wma;
3565 uint32_t scan_config;
3566
3567 if (wma_is_dual_mac_disabled_in_ini())
3568 return false;
3569
Anurag Chouhan6d760662016-02-20 16:05:43 +05303570 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003571 if (!wma) {
3572 WMA_LOGE("%s: Invalid WMA handle", __func__);
3573 /* We take that it is disabled and proceed */
3574 return false;
3575 }
3576 scan_config = wma->dual_mac_cfg.cur_scan_config;
3577
3578 return WMI_DBS_CONC_SCAN_CFG_AGILE_DFS_SCAN_GET(scan_config);
3579}
3580
3581/**
3582 * wma_is_dual_mac_disabled_in_ini() - Check if dual mac is disabled in INI
3583 *
3584 * Checks if the dual mac feature is disabled in INI
3585 *
3586 * Return: true if the dual mac feature is disabled from INI
3587 */
3588bool wma_is_dual_mac_disabled_in_ini(void)
3589{
Anurag Chouhan6d760662016-02-20 16:05:43 +05303590 tpAniSirGlobal mac = cds_get_context(QDF_MODULE_ID_PE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591
3592 if (!mac) {
3593 WMA_LOGE("%s: Invalid mac pointer", __func__);
3594 return true;
3595 }
3596
3597 if (mac->dual_mac_feature_disable)
3598 return true;
3599
3600 return false;
3601}
3602
3603/**
3604 * wma_get_prev_dbs_config() - Get prev DBS bit
3605 *
3606 * Gets the previous DBS bit of fw_mode_config_bits
3607 *
3608 * Return: 0 or 1 to indicate the DBS bit
3609 */
3610bool wma_get_prev_dbs_config(void)
3611{
3612 tp_wma_handle wma;
3613 uint32_t fw_mode_config;
3614
3615 if (wma_is_dual_mac_disabled_in_ini())
3616 return false;
3617
Anurag Chouhan6d760662016-02-20 16:05:43 +05303618 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 if (!wma) {
3620 WMA_LOGE("%s: Invalid WMA handle", __func__);
3621 /* We take that it is disabled and proceed */
3622 return false;
3623 }
3624 fw_mode_config = wma->dual_mac_cfg.prev_fw_mode_config;
3625
3626 return WMI_DBS_FW_MODE_CFG_DBS_GET(fw_mode_config);
3627}
3628
3629/**
3630 * wma_get_prev_agile_dfs_config() - Get prev Agile DFS bit
3631 *
3632 * Gets the previous Agile DFS bit of fw_mode_config_bits
3633 *
3634 * Return: 0 or 1 to indicate the Agile DFS bit
3635 */
3636bool wma_get_prev_agile_dfs_config(void)
3637{
3638 tp_wma_handle wma;
3639 uint32_t fw_mode_config;
3640
3641 if (wma_is_dual_mac_disabled_in_ini())
3642 return false;
3643
Anurag Chouhan6d760662016-02-20 16:05:43 +05303644 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 if (!wma) {
3646 WMA_LOGE("%s: Invalid WMA handle", __func__);
3647 /* We take that it is disabled and proceed */
3648 return false;
3649 }
3650 fw_mode_config = wma->dual_mac_cfg.prev_fw_mode_config;
3651
3652 return WMI_DBS_FW_MODE_CFG_AGILE_DFS_GET(fw_mode_config);
3653}
3654
3655/**
3656 * wma_get_prev_dbs_scan_config() - Get prev DBS scan bit
3657 *
3658 * Gets the previous DBS scan bit of concurrent_scan_config_bits
3659 *
3660 * Return: 0 or 1 to indicate the DBS scan bit
3661 */
3662bool wma_get_prev_dbs_scan_config(void)
3663{
3664 tp_wma_handle wma;
3665 uint32_t scan_config;
3666
3667 if (wma_is_dual_mac_disabled_in_ini())
3668 return false;
3669
Anurag Chouhan6d760662016-02-20 16:05:43 +05303670 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003671 if (!wma) {
3672 WMA_LOGE("%s: Invalid WMA handle", __func__);
3673 /* We take that it is disabled and proceed */
3674 return false;
3675 }
3676 scan_config = wma->dual_mac_cfg.prev_scan_config;
3677
3678 return WMI_DBS_CONC_SCAN_CFG_DBS_SCAN_GET(scan_config);
3679}
3680
3681/**
3682 * wma_get_prev_dbs_plus_agile_scan_config() - Get prev DBS plus agile scan bit
3683 *
3684 * Gets the previous DBS plus agile scan bit of concurrent_scan_config_bits
3685 *
3686 * Return: 0 or 1 to indicate the DBS plus agile scan bit
3687 */
3688bool wma_get_prev_dbs_plus_agile_scan_config(void)
3689{
3690 tp_wma_handle wma;
3691 uint32_t scan_config;
3692
3693 if (wma_is_dual_mac_disabled_in_ini())
3694 return false;
3695
Anurag Chouhan6d760662016-02-20 16:05:43 +05303696 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 if (!wma) {
3698 WMA_LOGE("%s: Invalid WMA handle", __func__);
3699 /* We take that it is disabled and proceed */
3700 return false;
3701 }
3702 scan_config = wma->dual_mac_cfg.prev_scan_config;
3703
3704 return WMI_DBS_CONC_SCAN_CFG_AGILE_SCAN_GET(scan_config);
3705}
3706
3707/**
3708 * wma_get_prev_single_mac_scan_with_dfs_config() - Get prev Single MAC scan
3709 * with DFS bit
3710 *
3711 * Gets the previous Single MAC scan with DFS bit of concurrent_scan_config_bits
3712 *
3713 * Return: 0 or 1 to indicate the Single MAC scan with DFS bit
3714 */
3715bool wma_get_prev_single_mac_scan_with_dfs_config(void)
3716{
3717 tp_wma_handle wma;
3718 uint32_t scan_config;
3719
3720 if (wma_is_dual_mac_disabled_in_ini())
3721 return false;
3722
Anurag Chouhan6d760662016-02-20 16:05:43 +05303723 wma = cds_get_context(QDF_MODULE_ID_WMA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003724 if (!wma) {
3725 WMA_LOGE("%s: Invalid WMA handle", __func__);
3726 /* We take that it is disabled and proceed */
3727 return false;
3728 }
3729 scan_config = wma->dual_mac_cfg.prev_scan_config;
3730
3731 return WMI_DBS_CONC_SCAN_CFG_AGILE_DFS_SCAN_GET(scan_config);
3732}
3733
3734/**
3735 * wma_is_scan_simultaneous_capable() - Check if scan parallelization is
3736 * supported or not
3737 *
3738 * currently scan parallelization feature support is dependent on DBS but
3739 * it can be independent in future.
3740 *
3741 * Return: True if master DBS control is enabled
3742 */
3743bool wma_is_scan_simultaneous_capable(void)
3744{
3745 if (wma_is_hw_dbs_capable())
3746 return true;
3747
3748 return false;
3749}
Naveen Rawatc0c91cd2015-11-05 14:27:37 -08003750
3751/**
3752 * wma_get_vht_ch_width - return vht channel width
3753 *
3754 * Return: return vht channel width
3755 */
3756uint32_t wma_get_vht_ch_width(void)
3757{
3758 uint32_t fw_ch_wd = WNI_CFG_VHT_CHANNEL_WIDTH_80MHZ;
Anurag Chouhan6d760662016-02-20 16:05:43 +05303759 tp_wma_handle wm_hdl = cds_get_context(QDF_MODULE_ID_WMA);
Naveen Rawatc0c91cd2015-11-05 14:27:37 -08003760
3761 if (NULL == wm_hdl)
3762 return fw_ch_wd;
3763
Kiran Kumar Lokere02b9aa42016-05-26 14:54:49 -07003764 if (wm_hdl->vht_cap_info & WMI_VHT_CAP_CH_WIDTH_80P80_160MHZ)
Naveen Rawatc0c91cd2015-11-05 14:27:37 -08003765 fw_ch_wd = WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ;
Kiran Kumar Lokere02b9aa42016-05-26 14:54:49 -07003766 else if (wm_hdl->vht_cap_info & WMI_VHT_CAP_CH_WIDTH_160MHZ)
3767 fw_ch_wd = WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ;
Naveen Rawatc0c91cd2015-11-05 14:27:37 -08003768
3769 return fw_ch_wd;
3770}
Govind Singhd76a5b02016-03-08 15:12:14 +05303771
3772/**
Krunal Soniaa664da2016-06-15 23:46:40 -07003773 * wma_get_num_of_setbits_from_bitmask() - to get num of setbits from bitmask
3774 * @mask: given bitmask
3775 *
3776 * This helper function should return number of setbits from bitmask
3777 *
3778 * Return: number of setbits from bitmask
3779 */
3780uint32_t wma_get_num_of_setbits_from_bitmask(uint32_t mask)
3781{
3782 uint32_t num_of_setbits = 0;
3783
3784 while (mask) {
3785 mask &= (mask - 1);
3786 num_of_setbits++;
3787 }
3788 return num_of_setbits;
3789}
3790
3791/**
Govind Singhd76a5b02016-03-08 15:12:14 +05303792 * wma_config_debug_module_cmd - set debug log config
3793 * @wmi_handle: wmi layer handle
3794 * @param: debug log parameter
3795 * @val: debug log value
3796 * @module_id_bitmap: debug module id bitmap
3797 * @bitmap_len: debug module bitmap length
3798 *
3799 * Return: QDF_STATUS_SUCCESS for success or error code
3800 */
3801QDF_STATUS
3802wma_config_debug_module_cmd(wmi_unified_t wmi_handle, A_UINT32 param,
3803 A_UINT32 val, A_UINT32 *module_id_bitmap,
3804 A_UINT32 bitmap_len)
3805{
3806 struct dbglog_params dbg_param;
3807 dbg_param.param = param;
3808 dbg_param.val = val;
3809 dbg_param.module_id_bitmap = module_id_bitmap;
3810 dbg_param.bitmap_len = bitmap_len;
3811
3812 return wmi_unified_dbglog_cmd_send(wmi_handle, &dbg_param);
3813}
Peng Xu8fdaa492016-06-22 10:20:47 -07003814
3815/**
3816 * wma_is_p2p_lo_capable() - if driver is capable of p2p listen offload
3817 *
3818 * This function checks if driver is capable of p2p listen offload
3819 * true: capable of p2p offload
3820 * false: not capable
3821 *
3822 * Return: true - capable, false - not capable
3823 */
3824bool wma_is_p2p_lo_capable(void)
3825{
3826 tp_wma_handle wma;
3827
3828 wma = cds_get_context(QDF_MODULE_ID_WMA);
3829 if (!wma) {
3830 WMA_LOGE("%s: Invalid WMA handle", __func__);
3831 return false;
3832 }
3833
3834 if (WMI_SERVICE_IS_ENABLED(wma->wmi_service_bitmap,
3835 WMI_SERVICE_P2P_LISTEN_OFFLOAD_SUPPORT))
3836 return true;
3837
3838 return false;
3839}
Aravind Narasimhan5b7c2cd2016-12-08 21:04:26 -08003840
3841/**
3842 * wma_is_hw_dbs_2x2_capable() - if hardware is capable of dbs 2x2
3843 *
3844 * This function checks if hw_modes supported are always capable of
3845 * DBS 2x2.
3846 * true: DBS 2x2 can always be supported
3847 * false: hw_modes support DBS 1x1 as well
3848 *
3849 * Return: true - DBS2x2, false - DBS1x1
3850 */
3851bool wma_is_hw_dbs_2x2_capable(void)
3852{
3853 tp_wma_handle wma;
3854 int i, j = 0, max_mac;
3855 uint32_t ht_2g, ht_5g;
3856 struct extended_caps *phy_caps;
3857 WMI_MAC_PHY_CAPABILITIES *mac_cap;
3858 uint32_t tx_chain, rx_chain, final_min_rf_chains = 0;
3859 uint32_t min_rf_chains, min_2g_rf_chains, min_5g_rf_chains;
3860
3861 wma = cds_get_context(QDF_MODULE_ID_WMA);
3862 if (!wma) {
3863 WMA_LOGE("%s: Invalid WMA handle", __func__);
3864 return false;
3865 }
3866
3867 phy_caps = &wma->phy_caps;
3868 for (i = 0; i < phy_caps->num_hw_modes.num_hw_modes; i++) {
3869 if (phy_caps->each_hw_mode_cap[i].phy_id_map == PHY1_PHY2)
3870 max_mac = j + 2;
3871 else
3872 max_mac = j + 1;
3873 for ( ; j < max_mac; j++) {
3874 mac_cap = &phy_caps->each_phy_cap_per_hwmode[j];
3875 ht_2g = mac_cap->ht_cap_info_2G;
3876 ht_5g = mac_cap->ht_cap_info_5G;
3877 if (ht_5g && ht_2g) {
3878 tx_chain = mac_cap->tx_chain_mask_2G;
3879 rx_chain = mac_cap->rx_chain_mask_2G;
3880 min_2g_rf_chains = QDF_MIN(
3881 wma_get_num_of_setbits_from_bitmask(tx_chain),
3882 wma_get_num_of_setbits_from_bitmask(rx_chain));
3883 tx_chain = mac_cap->tx_chain_mask_5G;
3884 rx_chain = mac_cap->rx_chain_mask_5G;
3885 min_5g_rf_chains = QDF_MIN(
3886 wma_get_num_of_setbits_from_bitmask(tx_chain),
3887 wma_get_num_of_setbits_from_bitmask(rx_chain));
3888 min_rf_chains = QDF_MIN(min_2g_rf_chains,
3889 min_5g_rf_chains);
3890 } else {
3891 continue;
3892 }
3893 final_min_rf_chains = QDF_MIN(final_min_rf_chains,
3894 min_rf_chains);
3895 }
3896 }
3897 return (final_min_rf_chains == 2) ? true : false;
3898}