blob: f54f5528224bedace49276b55980383903744c34 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Siddharth Bhal4f6694f2015-02-27 17:24:21 +05302 * Copyright (c) 2012,2014-2015 The Linux Foundation. All rights reserved.
Kiet Lam1ed83fc2014-02-19 01:15:45 -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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam1ed83fc2014-02-19 01:15:45 -080021
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
Jeff Johnson295189b2012-06-20 16:38:30 -070028/**=========================================================================
29
30 \file wlan_qct_pal_api.c
31
32 \brief Implementation general APIs PAL exports.
33 wpt = (Wlan Pal Type) wpal = (Wlan PAL)
34
35 Definitions for platform Windows.
36
Jeff Johnson295189b2012-06-20 16:38:30 -070037
38 ========================================================================*/
39
40#include "wlan_qct_pal_api.h"
41#include "wlan_qct_pal_trace.h"
42#include "wlan_qct_pal_device.h"
43#include "vos_trace.h"
44#ifndef MEMORY_DEBUG
45#include "vos_memory.h"
46#endif /* MEMORY_DEBUG */
Katya Nigama0e98e42014-02-05 13:46:40 +053047#include "vos_sched.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070048#include "vos_api.h"
49
50#include "dma-mapping.h"
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +053051#include <linux/version.h>
52#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
53#include <soc/qcom/subsystem_restart.h>
54#else
Jeff Johnson295189b2012-06-20 16:38:30 -070055#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +053056#endif
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -070057#include <linux/wcnss_wlan.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070058
Jeff Johnson295189b2012-06-20 16:38:30 -070059
60#define WPAL_GET_NDIS_HANDLE(p) ( ((tPalContext *)(p))->devHandle )
61
62tPalContext gContext;
63
64//This structure need to be 4-byte aligned. No packing.
65typedef struct
66{
67 wpt_uint32 length;
68 //The offset from beginning of the buffer where it is allocated
69 wpt_uint32 offset;
70 wpt_uint32 phyAddr;
71} tPalDmaMemInfo;
72
73/*===========================================================================
74
75 FUNCTIONS
76
77===========================================================================*/
78
79/**
80 * @brief Initialize PAL
81 * In case of QNP, this does nothing.
82 * @param ppPalContext pointer to a caller allocated pointer. It
83 * is opaque to caller.
84 * Caller save the returned pointer for future use when
85 * calling PAL APIs.
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053086 * @param devHandle pointer to the OS specific device handle.
Jeff Johnson295189b2012-06-20 16:38:30 -070087 *
88 * @return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Otherwise fail.
89 */
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053090wpt_status wpalOpen(void **ppPalContext, void *devHandle)
Jeff Johnson295189b2012-06-20 16:38:30 -070091{
92 wpt_status status;
93
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053094 gContext.devHandle = devHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -070095
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053096 status = wpalDeviceInit(devHandle);
Jeff Johnson295189b2012-06-20 16:38:30 -070097 if (!WLAN_PAL_IS_STATUS_SUCCESS(status))
98 {
99 WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_FATAL,
100 "%s: wpalDeviceInit failed with status %u",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700101 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700102 }
103
104 return status;
105}
106
107/**
108 * @brief wpalClose - Release PAL
109 * In case of QNP, this does nothing.
110 * @param pPalContext pointer returned from wpalOpen.
111 *
112 * @return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Otherwise fail.
113 */
114wpt_status wpalClose(void *pPalContext)
115{
116 wpalDeviceClose(gContext.devHandle);
117 gContext.devHandle = NULL;
118
119 return eWLAN_PAL_STATUS_SUCCESS;
120}
121
122#ifndef MEMORY_DEBUG
123/**
124 * @brief wpalMemoryAllocate - Allocate memory
125 * @param size number of bytes to allocate
126 *
127 * @return void* A pointer to the allocated memory.
128 * NULL - fail to allocate memory
129 */
130void *wpalMemoryAllocate(wpt_uint32 size)
131{
132 return vos_mem_malloc( size );
133}
134
135/**
136 * @brief wpalMemoryFree - Free allocated memory
137 * @param pv pointer to buffer to be freed
138 */
139void wpalMemoryFree(void *pv)
140{
141 vos_mem_free( pv );
142}
143#endif /* MEMORY_DEBUG */
144/**
145 * @brief wpalMemoryCopy - copy memory
146 * @param dest address which data is copied to
147 * @param src address which data is copied from
148 * @param size number of bytes to copy
149 *
150 * @return wpt_status
151 * eWLAN_PAL_STATUS_SUCCESS
152 * eWLAN_PAL_STATUS_INVALID_PARAM
153 */
154wpt_status wpalMemoryCopy(void * dest, void * src, wpt_uint32 size)
155{
156 vos_mem_copy( dest, src, size );
157
158 return eWLAN_PAL_STATUS_SUCCESS;
159}
160
161/**
162 * @brief wpalMemoryCompare - compare memory
163 * @param buf1 address of buffer1
164 * @param buf2 address of buffer2
165 * @param size number of bytes to compare
166 *
167 * @return wpt_boolean
168 * eWLAN_PAL_TRUE - if two buffers have same content
169 * eWLAN_PAL_FALSE - not match
170 */
171wpt_boolean wpalMemoryCompare(void * buf1, void * buf2, wpt_uint32 size)
172{
173 return (wpt_boolean)vos_mem_compare( buf1, buf2, size );
174}
175
176
177/*---------------------------------------------------------------------------
178 wpalMemoryZero - Zero memory
179 Param:
180 buf - address of buffer to be zero
181 size - number of bytes to zero
182 Return:
183 None
184---------------------------------------------------------------------------*/
185void wpalMemoryZero(void *buf, wpt_uint32 size)
186{
187 vos_mem_zero( buf, size );
188}
189
190/**
191 * @brief wpalMemoryFill - Fill memory with one pattern
192 * @param buf address of buffer to be filled
193 * @param size number of bytes to fill
194 * @param bFill one byte of data to fill in (size) bytes from the start of the
195 * buffer
196 */
197void wpalMemoryFill(void *buf, wpt_uint32 size, wpt_byte bFill)
198{
199 vos_mem_set( buf, size, bFill );
200}
201
202/**
203 * @brief wpalDmaMemoryAllocate - Allocate memory ready for DMA. Aligned at 4-byte
204 * @param size number of bytes to allocate
205 * @param ppPhysicalAddr Physical address of the buffer if allocation succeeds
206 *
207 * @return void* A pointer to the allocated memory (virtual address).
208 * NULL - fail to allocate memory
209 */
210void *wpalDmaMemoryAllocate(wpt_uint32 size, void **ppPhysicalAddr)
211{
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530212 struct device *wcnss_device = (struct device *) gContext.devHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -0700213 void *pv = NULL;
214 dma_addr_t PhyAddr;
215 wpt_uint32 uAllocLen = size + sizeof(tPalDmaMemInfo);
216
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530217 pv = dma_alloc_coherent(wcnss_device, uAllocLen, &PhyAddr, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -0700218 if ( NULL == pv )
219 {
220 WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Arif Hussain9a5d5382013-11-17 22:05:35 -0800221 "%s Unable to allocate DMA buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700222 return NULL;
223 }
Mihir Shetef4e7bd32014-10-27 09:27:41 +0530224 wpalMemoryZero(pv, uAllocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -0700225
226
227 ((tPalDmaMemInfo *)pv)->length = uAllocLen;
228 ((tPalDmaMemInfo *)pv)->phyAddr = PhyAddr;
229 ((tPalDmaMemInfo *)pv)->offset = sizeof(tPalDmaMemInfo);
230 pv = (wpt_byte *)pv + sizeof(tPalDmaMemInfo);
231 *ppPhysicalAddr = (void*)PhyAddr + sizeof(tPalDmaMemInfo);
232
233
234 return (pv);
235}/*wpalDmaMemoryAllocate*/
236
237
238/**
239 * @brief wpalDmaMemoryFree - Free memory ready for DMA
240 * @param pv address for the buffer to be freed
241 */
242void wpalDmaMemoryFree(void *pv)
243{
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530244 struct device *wcnss_device = (struct device *) gContext.devHandle;
245
Jeff Johnson295189b2012-06-20 16:38:30 -0700246 tPalDmaMemInfo *pMemInfo = (tPalDmaMemInfo *)(((wpt_byte *)pv) -
247 sizeof(tPalDmaMemInfo));
248 if(pv)
249 {
250 pv = (wpt_byte *)pv - pMemInfo->offset;
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530251 dma_free_coherent(wcnss_device, pMemInfo->length, pv, pMemInfo->phyAddr);
Jeff Johnson295189b2012-06-20 16:38:30 -0700252 }
253
254}/*wpalDmaMemoryFree*/
255
256/**
257 * @brief wpalDbgReadRegister - Read register from the WiFi BB
258 chip
259 * @param regAddr - register address
260 * @param pregValue - return value from register if success
261 * @return
262 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
263 */
264wpt_status wpalDbgReadRegister(wpt_uint32 regAddr, wpt_uint32 *pregValue)
265{
266 if (NULL == pregValue)
267 {
268 return eWLAN_PAL_STATUS_E_INVAL;
269 }
270
271 return wpalReadRegister(regAddr, pregValue);
272}
273
274/**
275 * @brief wpalDbgWriteRegister - Write a value to the register
276 * in the WiFi BB chip Param:
277 * @param regAddr - register address
278 * @param regValue - value to be written
279 * @return
280 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
281*/
282wpt_status wpalDbgWriteRegister(wpt_uint32 regAddr, wpt_uint32 regValue)
283{
284 return wpalWriteRegister(regAddr, regValue);
285}
286
287/**
288 * @brief
289 wpalDbgReadMemory - Read memory from WiFi BB chip space
290 * @param memAddr - address of memory
291 * @param buf - output
292 * @param len - length to be read
293 * @return
294 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
295*/
296wpt_status wpalDbgReadMemory(wpt_uint32 memAddr, wpt_uint8 *buf, wpt_uint32 len)
297{
298 return wpalReadDeviceMemory(memAddr, buf, len);
299}
300
301/**
302 * @brief
303 wpalDbgWriteMemory - Write a value to the memory in the WiFi BB chip space
304 * @param memAddr - memory address
305 * @param buf - vlaue to be written
306 * @param len - length of buf
307 * @return
308 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
309*/
310wpt_status wpalDbgWriteMemory(wpt_uint32 memAddr, wpt_uint8 *buf, wpt_uint32 len)
311{
312 return wpalWriteDeviceMemory(memAddr, buf, len);
313}
314
315/*---------------------------------------------------------------------------
316 wpalDriverShutdown - Shutdown WLAN driver
317
318 This API is requied by SSR, call in to 'VOS shutdown' to shutdown WLAN
319 driver when Riva crashes.
320
321 Param:
322 None
323 Return:
324 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
325---------------------------------------------------------------------------*/
326wpt_status wpalDriverShutdown(void)
327{
328 VOS_STATUS vosStatus;
329 vosStatus = vos_wlanShutdown();
330
331 if (VOS_STATUS_SUCCESS == vosStatus) {
332 return eWLAN_PAL_STATUS_SUCCESS;
333 }
334 return eWLAN_PAL_STATUS_E_FAILURE;
335}
336
337/*---------------------------------------------------------------------------
338 wpalDriverShutdown - Re-init WLAN driver
339
340 This API is requied by SSR, call in to 'VOS re-init' to re-init WLAN
341 driver.
342
343 Param:
344 None
345 Return:
346 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
347---------------------------------------------------------------------------*/
348wpt_status wpalDriverReInit(void)
349{
350 VOS_STATUS vosStatus;
351
352 vosStatus = vos_wlanReInit();
353 if (VOS_STATUS_SUCCESS == vosStatus) {
354 return eWLAN_PAL_STATUS_SUCCESS;
355 }
356 return eWLAN_PAL_STATUS_E_FAILURE;
357}
358
359/*---------------------------------------------------------------------------
360 wpalRivaSubystemRestart - Initiate Riva SSR
361
362 This API is called by WLAN driver to initiate Riva SSR
363
364 Param:
365 None
366 Return:
367 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
368---------------------------------------------------------------------------*/
369wpt_status wpalRivaSubystemRestart(void)
370{
371 /* call SSR only if driver is not in load/unload process.
372 * A WDI timeout during load/unload cannot be fixed thru
373 * SSR */
374 if (vos_is_load_unload_in_progress(VOS_MODULE_ID_WDI, NULL))
375 {
376 WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_FATAL,
377 "%s: loading/unloading in progress,"
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700378 " SSR will be done at the end of unload", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700379 return eWLAN_PAL_STATUS_E_FAILURE;
380 }
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -0700381 if (0 == subsystem_restart("wcnss"))
Jeff Johnson295189b2012-06-20 16:38:30 -0700382 {
383 return eWLAN_PAL_STATUS_SUCCESS;
384 }
385 return eWLAN_PAL_STATUS_E_FAILURE;
386}
Jeff Johnsone7245742012-09-05 17:12:55 -0700387
388/*---------------------------------------------------------------------------
389 wpalWlanReload - Initiate WLAN Driver reload
390
391 Param:
392 None
393 Return:
394 NONE
395---------------------------------------------------------------------------*/
396void wpalWlanReload(void)
397{
398 vos_wlanRestart();
399 return;
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -0700400}
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -0700401
402/*---------------------------------------------------------------------------
403 wpalWcnssResetIntr - Trigger the reset FIQ to Riva
404
405 Param:
406 None
407 Return:
408 NONE
409---------------------------------------------------------------------------*/
410void wpalWcnssResetIntr(void)
411{
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -0800412#ifdef HAVE_WCNSS_RESET_INTR
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -0700413 wcnss_reset_intr();
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -0800414#endif
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -0700415 return;
416}
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530417
418/*---------------------------------------------------------------------------
Siddharth Bhalb7e8e882014-10-10 16:27:47 +0530419 wpalWcnssIsProntoHwVer3 - Check if Pronto Hw ver3
420
421 Param:
422 None
423 Return:
424 TRUE if Ponto Hw Ver 3
425 Therefore use WQ6 instead of WQ23 for TX Low/High Priority Channel
426---------------------------------------------------------------------------*/
427int wpalWcnssIsProntoHwVer3(void)
428{
429 return wcnss_is_hw_pronto_ver3();
430}
431
432/*---------------------------------------------------------------------------
Mihir Shetee2ae82a2015-03-16 14:08:49 +0530433 wpalIsFwLoggingEnabled - Check if Firmware will send logs using DXE
434
435 Param:
436 None
437 Return:
438 Check the documentation of vos_is_fw_logging_enabled
439---------------------------------------------------------------------------*/
440wpt_uint8 wpalIsFwLoggingEnabled(void)
441{
442 return vos_is_fw_logging_enabled();
443}
444
445/*---------------------------------------------------------------------------
Mihir Sheted6274602015-04-28 16:13:21 +0530446 wpalIsFwLoggingSupported - Check if Firmware supports the fw->host
447 logging infrastructure
448 This API can only be called after fw caps
449 are exchanged.
450
451 Param:
452 None
453 Return:
454 Check the documentation of vos_is_fw_logging_supported
455---------------------------------------------------------------------------*/
456wpt_uint8 wpalIsFwLoggingSupported(void)
457{
458 return vos_is_fw_logging_supported();
459}
460
461/*---------------------------------------------------------------------------
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530462 wpalFwDumpReq - Trigger the dump commands to Firmware
463
464 Param:
Siddharth Bhal68115602015-01-18 20:44:55 +0530465 cmd - Command No. to execute
466 arg1 - argument 1 to cmd
467 arg2 - argument 2 to cmd
468 arg3 - argument 3 to cmd
469 arg4 - argument 4 to cmd
470 async -asynchronous event. Don't wait for completion.
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530471 Return:
472 NONE
473---------------------------------------------------------------------------*/
474void wpalFwDumpReq(wpt_uint32 cmd, wpt_uint32 arg1, wpt_uint32 arg2,
Siddharth Bhal68115602015-01-18 20:44:55 +0530475 wpt_uint32 arg3, wpt_uint32 arg4, wpt_boolean async)
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530476{
Siddharth Bhal68115602015-01-18 20:44:55 +0530477 vos_fwDumpReq(cmd, arg1, arg2, arg3, arg4, async);
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530478 return;
479}
Leo Chang00708f62013-12-03 20:21:51 -0800480
481/*---------------------------------------------------------------------------
482 wpalDevicePanic - Trigger Device Panic
483 Trigger device panic to help debug
484
485 Param:
486 NONE
487
488 Return:
489 NONE
490---------------------------------------------------------------------------*/
491void wpalDevicePanic(void)
492{
Katya Nigam91d31cb2014-05-20 19:16:15 +0530493 BUG_ON(1);
Leo Chang00708f62013-12-03 20:21:51 -0800494 return;
495}
Katya Nigama0e98e42014-02-05 13:46:40 +0530496/*---------------------------------------------------------------------------
Siddharth Bhal4f6694f2015-02-27 17:24:21 +0530497 wpalIslogPInProgress - calls vos API vos_is_logp_in_progress()
Katya Nigama0e98e42014-02-05 13:46:40 +0530498
499 Param:
500 NONE
501 Return:
502 STATUS
503 ---------------------------------------------------------------------------*/
Siddharth Bhal4f6694f2015-02-27 17:24:21 +0530504int wpalIslogPInProgress(void)
Katya Nigama0e98e42014-02-05 13:46:40 +0530505{
Siddharth Bhal4f6694f2015-02-27 17:24:21 +0530506 return vos_is_logp_in_progress(VOS_MODULE_ID_WDI, NULL);
Katya Nigama0e98e42014-02-05 13:46:40 +0530507}
Leo Chang00708f62013-12-03 20:21:51 -0800508
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530509/*---------------------------------------------------------------------------
510 wpalIsSsrPanicOnFailure - calls vos API isSsrPanicOnFailure()
511
512 Param:
513 NONE
514 Return:
515 STATUS
516 ---------------------------------------------------------------------------*/
517int wpalIsSsrPanicOnFailure(void)
518{
519 return isSsrPanicOnFailure();
520}
521
Katya Nigama6fbf662015-03-17 18:35:47 +0530522int wpalGetDxeReplenishRXTimerVal(void)
523{
524 return vos_get_dxeReplenishRXTimerVal();
525}
526
527int wpalIsDxeSSREnable(void)
528{
529 return vos_get_dxeSSREnable();
530}
531