blob: e1dfa1bf671dcc2f185d446fc6276a3db6489f4f [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +05302 * Copyright (c) 2012,2014 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
37 Copyright 2010 (c) Qualcomm, Incorporated. All Rights Reserved.
38
39 Qualcomm Confidential and Proprietary.
40
41 ========================================================================*/
42
43#include "wlan_qct_pal_api.h"
44#include "wlan_qct_pal_trace.h"
45#include "wlan_qct_pal_device.h"
46#include "vos_trace.h"
47#ifndef MEMORY_DEBUG
48#include "vos_memory.h"
49#endif /* MEMORY_DEBUG */
Katya Nigama0e98e42014-02-05 13:46:40 +053050#include "vos_sched.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070051#include "vos_api.h"
52
53#include "dma-mapping.h"
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +053054#include <linux/version.h>
55#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0))
56#include <soc/qcom/subsystem_restart.h>
57#else
Jeff Johnson295189b2012-06-20 16:38:30 -070058#include <mach/subsystem_restart.h>
Arun Kumar Khandavalli74fe3032014-03-17 20:35:34 +053059#endif
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -070060#include <linux/wcnss_wlan.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070061
Jeff Johnson295189b2012-06-20 16:38:30 -070062
63#define WPAL_GET_NDIS_HANDLE(p) ( ((tPalContext *)(p))->devHandle )
64
65tPalContext gContext;
66
67//This structure need to be 4-byte aligned. No packing.
68typedef struct
69{
70 wpt_uint32 length;
71 //The offset from beginning of the buffer where it is allocated
72 wpt_uint32 offset;
73 wpt_uint32 phyAddr;
74} tPalDmaMemInfo;
75
76/*===========================================================================
77
78 FUNCTIONS
79
80===========================================================================*/
81
82/**
83 * @brief Initialize PAL
84 * In case of QNP, this does nothing.
85 * @param ppPalContext pointer to a caller allocated pointer. It
86 * is opaque to caller.
87 * Caller save the returned pointer for future use when
88 * calling PAL APIs.
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053089 * @param devHandle pointer to the OS specific device handle.
Jeff Johnson295189b2012-06-20 16:38:30 -070090 *
91 * @return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Otherwise fail.
92 */
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053093wpt_status wpalOpen(void **ppPalContext, void *devHandle)
Jeff Johnson295189b2012-06-20 16:38:30 -070094{
95 wpt_status status;
96
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053097 gContext.devHandle = devHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -070098
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +053099 status = wpalDeviceInit(devHandle);
Jeff Johnson295189b2012-06-20 16:38:30 -0700100 if (!WLAN_PAL_IS_STATUS_SUCCESS(status))
101 {
102 WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_FATAL,
103 "%s: wpalDeviceInit failed with status %u",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700104 __func__, status);
Jeff Johnson295189b2012-06-20 16:38:30 -0700105 }
106
107 return status;
108}
109
110/**
111 * @brief wpalClose - Release PAL
112 * In case of QNP, this does nothing.
113 * @param pPalContext pointer returned from wpalOpen.
114 *
115 * @return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Otherwise fail.
116 */
117wpt_status wpalClose(void *pPalContext)
118{
119 wpalDeviceClose(gContext.devHandle);
120 gContext.devHandle = NULL;
121
122 return eWLAN_PAL_STATUS_SUCCESS;
123}
124
125#ifndef MEMORY_DEBUG
126/**
127 * @brief wpalMemoryAllocate - Allocate memory
128 * @param size number of bytes to allocate
129 *
130 * @return void* A pointer to the allocated memory.
131 * NULL - fail to allocate memory
132 */
133void *wpalMemoryAllocate(wpt_uint32 size)
134{
135 return vos_mem_malloc( size );
136}
137
138/**
139 * @brief wpalMemoryFree - Free allocated memory
140 * @param pv pointer to buffer to be freed
141 */
142void wpalMemoryFree(void *pv)
143{
144 vos_mem_free( pv );
145}
146#endif /* MEMORY_DEBUG */
147/**
148 * @brief wpalMemoryCopy - copy memory
149 * @param dest address which data is copied to
150 * @param src address which data is copied from
151 * @param size number of bytes to copy
152 *
153 * @return wpt_status
154 * eWLAN_PAL_STATUS_SUCCESS
155 * eWLAN_PAL_STATUS_INVALID_PARAM
156 */
157wpt_status wpalMemoryCopy(void * dest, void * src, wpt_uint32 size)
158{
159 vos_mem_copy( dest, src, size );
160
161 return eWLAN_PAL_STATUS_SUCCESS;
162}
163
164/**
165 * @brief wpalMemoryCompare - compare memory
166 * @param buf1 address of buffer1
167 * @param buf2 address of buffer2
168 * @param size number of bytes to compare
169 *
170 * @return wpt_boolean
171 * eWLAN_PAL_TRUE - if two buffers have same content
172 * eWLAN_PAL_FALSE - not match
173 */
174wpt_boolean wpalMemoryCompare(void * buf1, void * buf2, wpt_uint32 size)
175{
176 return (wpt_boolean)vos_mem_compare( buf1, buf2, size );
177}
178
179
180/*---------------------------------------------------------------------------
181 wpalMemoryZero - Zero memory
182 Param:
183 buf - address of buffer to be zero
184 size - number of bytes to zero
185 Return:
186 None
187---------------------------------------------------------------------------*/
188void wpalMemoryZero(void *buf, wpt_uint32 size)
189{
190 vos_mem_zero( buf, size );
191}
192
193/**
194 * @brief wpalMemoryFill - Fill memory with one pattern
195 * @param buf address of buffer to be filled
196 * @param size number of bytes to fill
197 * @param bFill one byte of data to fill in (size) bytes from the start of the
198 * buffer
199 */
200void wpalMemoryFill(void *buf, wpt_uint32 size, wpt_byte bFill)
201{
202 vos_mem_set( buf, size, bFill );
203}
204
205/**
206 * @brief wpalDmaMemoryAllocate - Allocate memory ready for DMA. Aligned at 4-byte
207 * @param size number of bytes to allocate
208 * @param ppPhysicalAddr Physical address of the buffer if allocation succeeds
209 *
210 * @return void* A pointer to the allocated memory (virtual address).
211 * NULL - fail to allocate memory
212 */
213void *wpalDmaMemoryAllocate(wpt_uint32 size, void **ppPhysicalAddr)
214{
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530215 struct device *wcnss_device = (struct device *) gContext.devHandle;
Jeff Johnson295189b2012-06-20 16:38:30 -0700216 void *pv = NULL;
217 dma_addr_t PhyAddr;
218 wpt_uint32 uAllocLen = size + sizeof(tPalDmaMemInfo);
219
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530220 pv = dma_alloc_coherent(wcnss_device, uAllocLen, &PhyAddr, GFP_KERNEL);
Jeff Johnson295189b2012-06-20 16:38:30 -0700221 if ( NULL == pv )
222 {
223 WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
Arif Hussain9a5d5382013-11-17 22:05:35 -0800224 "%s Unable to allocate DMA buffer", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700225 return NULL;
226 }
Mihir Shetef4e7bd32014-10-27 09:27:41 +0530227 wpalMemoryZero(pv, uAllocLen);
Jeff Johnson295189b2012-06-20 16:38:30 -0700228
229
230 ((tPalDmaMemInfo *)pv)->length = uAllocLen;
231 ((tPalDmaMemInfo *)pv)->phyAddr = PhyAddr;
232 ((tPalDmaMemInfo *)pv)->offset = sizeof(tPalDmaMemInfo);
233 pv = (wpt_byte *)pv + sizeof(tPalDmaMemInfo);
234 *ppPhysicalAddr = (void*)PhyAddr + sizeof(tPalDmaMemInfo);
235
236
237 return (pv);
238}/*wpalDmaMemoryAllocate*/
239
240
241/**
242 * @brief wpalDmaMemoryFree - Free memory ready for DMA
243 * @param pv address for the buffer to be freed
244 */
245void wpalDmaMemoryFree(void *pv)
246{
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530247 struct device *wcnss_device = (struct device *) gContext.devHandle;
248
Jeff Johnson295189b2012-06-20 16:38:30 -0700249 tPalDmaMemInfo *pMemInfo = (tPalDmaMemInfo *)(((wpt_byte *)pv) -
250 sizeof(tPalDmaMemInfo));
251 if(pv)
252 {
253 pv = (wpt_byte *)pv - pMemInfo->offset;
Arun Kumar Khandavalliebb19482014-03-25 13:56:53 +0530254 dma_free_coherent(wcnss_device, pMemInfo->length, pv, pMemInfo->phyAddr);
Jeff Johnson295189b2012-06-20 16:38:30 -0700255 }
256
257}/*wpalDmaMemoryFree*/
258
259/**
260 * @brief wpalDbgReadRegister - Read register from the WiFi BB
261 chip
262 * @param regAddr - register address
263 * @param pregValue - return value from register if success
264 * @return
265 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
266 */
267wpt_status wpalDbgReadRegister(wpt_uint32 regAddr, wpt_uint32 *pregValue)
268{
269 if (NULL == pregValue)
270 {
271 return eWLAN_PAL_STATUS_E_INVAL;
272 }
273
274 return wpalReadRegister(regAddr, pregValue);
275}
276
277/**
278 * @brief wpalDbgWriteRegister - Write a value to the register
279 * in the WiFi BB chip Param:
280 * @param regAddr - register address
281 * @param regValue - value to be written
282 * @return
283 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
284*/
285wpt_status wpalDbgWriteRegister(wpt_uint32 regAddr, wpt_uint32 regValue)
286{
287 return wpalWriteRegister(regAddr, regValue);
288}
289
290/**
291 * @brief
292 wpalDbgReadMemory - Read memory from WiFi BB chip space
293 * @param memAddr - address of memory
294 * @param buf - output
295 * @param len - length to be read
296 * @return
297 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
298*/
299wpt_status wpalDbgReadMemory(wpt_uint32 memAddr, wpt_uint8 *buf, wpt_uint32 len)
300{
301 return wpalReadDeviceMemory(memAddr, buf, len);
302}
303
304/**
305 * @brief
306 wpalDbgWriteMemory - Write a value to the memory in the WiFi BB chip space
307 * @param memAddr - memory address
308 * @param buf - vlaue to be written
309 * @param len - length of buf
310 * @return
311 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
312*/
313wpt_status wpalDbgWriteMemory(wpt_uint32 memAddr, wpt_uint8 *buf, wpt_uint32 len)
314{
315 return wpalWriteDeviceMemory(memAddr, buf, len);
316}
317
318/*---------------------------------------------------------------------------
319 wpalDriverShutdown - Shutdown WLAN driver
320
321 This API is requied by SSR, call in to 'VOS shutdown' to shutdown WLAN
322 driver when Riva crashes.
323
324 Param:
325 None
326 Return:
327 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
328---------------------------------------------------------------------------*/
329wpt_status wpalDriverShutdown(void)
330{
331 VOS_STATUS vosStatus;
332 vosStatus = vos_wlanShutdown();
333
334 if (VOS_STATUS_SUCCESS == vosStatus) {
335 return eWLAN_PAL_STATUS_SUCCESS;
336 }
337 return eWLAN_PAL_STATUS_E_FAILURE;
338}
339
340/*---------------------------------------------------------------------------
341 wpalDriverShutdown - Re-init WLAN driver
342
343 This API is requied by SSR, call in to 'VOS re-init' to re-init WLAN
344 driver.
345
346 Param:
347 None
348 Return:
349 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
350---------------------------------------------------------------------------*/
351wpt_status wpalDriverReInit(void)
352{
353 VOS_STATUS vosStatus;
354
355 vosStatus = vos_wlanReInit();
356 if (VOS_STATUS_SUCCESS == vosStatus) {
357 return eWLAN_PAL_STATUS_SUCCESS;
358 }
359 return eWLAN_PAL_STATUS_E_FAILURE;
360}
361
362/*---------------------------------------------------------------------------
363 wpalRivaSubystemRestart - Initiate Riva SSR
364
365 This API is called by WLAN driver to initiate Riva SSR
366
367 Param:
368 None
369 Return:
370 eWLAN_PAL_STATUS_SUCCESS - when everything is OK
371---------------------------------------------------------------------------*/
372wpt_status wpalRivaSubystemRestart(void)
373{
374 /* call SSR only if driver is not in load/unload process.
375 * A WDI timeout during load/unload cannot be fixed thru
376 * SSR */
377 if (vos_is_load_unload_in_progress(VOS_MODULE_ID_WDI, NULL))
378 {
379 WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_FATAL,
380 "%s: loading/unloading in progress,"
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700381 " SSR will be done at the end of unload", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700382 return eWLAN_PAL_STATUS_E_FAILURE;
383 }
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -0700384 if (0 == subsystem_restart("wcnss"))
Jeff Johnson295189b2012-06-20 16:38:30 -0700385 {
386 return eWLAN_PAL_STATUS_SUCCESS;
387 }
388 return eWLAN_PAL_STATUS_E_FAILURE;
389}
Jeff Johnsone7245742012-09-05 17:12:55 -0700390
391/*---------------------------------------------------------------------------
392 wpalWlanReload - Initiate WLAN Driver reload
393
394 Param:
395 None
396 Return:
397 NONE
398---------------------------------------------------------------------------*/
399void wpalWlanReload(void)
400{
401 vos_wlanRestart();
402 return;
Madan Mohan Koyyalamudi3246f5b2012-10-15 15:40:02 -0700403}
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -0700404
405/*---------------------------------------------------------------------------
406 wpalWcnssResetIntr - Trigger the reset FIQ to Riva
407
408 Param:
409 None
410 Return:
411 NONE
412---------------------------------------------------------------------------*/
413void wpalWcnssResetIntr(void)
414{
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -0800415#ifdef HAVE_WCNSS_RESET_INTR
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -0700416 wcnss_reset_intr();
Madan Mohan Koyyalamudic72a4d62012-11-08 14:59:34 -0800417#endif
Madan Mohan Koyyalamudi0bfd0002012-10-24 14:39:37 -0700418 return;
419}
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530420
421/*---------------------------------------------------------------------------
Siddharth Bhalb7e8e882014-10-10 16:27:47 +0530422 wpalWcnssIsProntoHwVer3 - Check if Pronto Hw ver3
423
424 Param:
425 None
426 Return:
427 TRUE if Ponto Hw Ver 3
428 Therefore use WQ6 instead of WQ23 for TX Low/High Priority Channel
429---------------------------------------------------------------------------*/
430int wpalWcnssIsProntoHwVer3(void)
431{
432 return wcnss_is_hw_pronto_ver3();
433}
434
435/*---------------------------------------------------------------------------
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530436 wpalFwDumpReq - Trigger the dump commands to Firmware
437
438 Param:
Siddharth Bhal68115602015-01-18 20:44:55 +0530439 cmd - Command No. to execute
440 arg1 - argument 1 to cmd
441 arg2 - argument 2 to cmd
442 arg3 - argument 3 to cmd
443 arg4 - argument 4 to cmd
444 async -asynchronous event. Don't wait for completion.
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530445 Return:
446 NONE
447---------------------------------------------------------------------------*/
448void wpalFwDumpReq(wpt_uint32 cmd, wpt_uint32 arg1, wpt_uint32 arg2,
Siddharth Bhal68115602015-01-18 20:44:55 +0530449 wpt_uint32 arg3, wpt_uint32 arg4, wpt_boolean async)
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530450{
Siddharth Bhal68115602015-01-18 20:44:55 +0530451 vos_fwDumpReq(cmd, arg1, arg2, arg3, arg4, async);
Madan Mohan Koyyalamudi62080282013-08-05 12:51:17 +0530452 return;
453}
Leo Chang00708f62013-12-03 20:21:51 -0800454
455/*---------------------------------------------------------------------------
456 wpalDevicePanic - Trigger Device Panic
457 Trigger device panic to help debug
458
459 Param:
460 NONE
461
462 Return:
463 NONE
464---------------------------------------------------------------------------*/
465void wpalDevicePanic(void)
466{
Katya Nigam91d31cb2014-05-20 19:16:15 +0530467 BUG_ON(1);
Leo Chang00708f62013-12-03 20:21:51 -0800468 return;
469}
Katya Nigama0e98e42014-02-05 13:46:40 +0530470/*---------------------------------------------------------------------------
471 wpalIsWDresetInProgress - calls vos API isWDresetInProgress()
472
473 Param:
474 NONE
475 Return:
476 STATUS
477 ---------------------------------------------------------------------------*/
478int wpalIsWDresetInProgress(void)
479{
480 return isWDresetInProgress();
481}
Leo Chang00708f62013-12-03 20:21:51 -0800482
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530483/*---------------------------------------------------------------------------
484 wpalIsSsrPanicOnFailure - calls vos API isSsrPanicOnFailure()
485
486 Param:
487 NONE
488 Return:
489 STATUS
490 ---------------------------------------------------------------------------*/
491int wpalIsSsrPanicOnFailure(void)
492{
493 return isSsrPanicOnFailure();
494}
495