Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Kiet Lam | aa8e15a | 2014-02-11 23:30:06 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2012-2013 Qualcomm Atheros, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * Qualcomm Atheros Confidential and Proprietary. |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 5 | */ |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 6 | /**========================================================================= |
| 7 | |
| 8 | \file wlan_qct_pal_api.c |
| 9 | |
| 10 | \brief Implementation general APIs PAL exports. |
| 11 | wpt = (Wlan Pal Type) wpal = (Wlan PAL) |
| 12 | |
| 13 | Definitions for platform Windows. |
| 14 | |
| 15 | Copyright 2010 (c) Qualcomm, Incorporated. All Rights Reserved. |
| 16 | |
| 17 | Qualcomm Confidential and Proprietary. |
| 18 | |
| 19 | ========================================================================*/ |
| 20 | |
| 21 | #include "wlan_qct_pal_api.h" |
| 22 | #include "wlan_qct_pal_trace.h" |
| 23 | #include "wlan_qct_pal_device.h" |
| 24 | #include "vos_trace.h" |
| 25 | #ifndef MEMORY_DEBUG |
| 26 | #include "vos_memory.h" |
| 27 | #endif /* MEMORY_DEBUG */ |
| 28 | #include "vos_api.h" |
| 29 | |
| 30 | #include "dma-mapping.h" |
| 31 | #include <mach/subsystem_restart.h> |
Madan Mohan Koyyalamudi | 0bfd000 | 2012-10-24 14:39:37 -0700 | [diff] [blame] | 32 | #include <linux/wcnss_wlan.h> |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 33 | |
| 34 | typedef struct sPalStruct |
| 35 | { |
| 36 | /*?must check the data type*/ |
| 37 | void* devHandle; |
| 38 | } tPalContext; |
| 39 | |
| 40 | #define WPAL_GET_NDIS_HANDLE(p) ( ((tPalContext *)(p))->devHandle ) |
| 41 | |
| 42 | tPalContext gContext; |
| 43 | |
| 44 | //This structure need to be 4-byte aligned. No packing. |
| 45 | typedef struct |
| 46 | { |
| 47 | wpt_uint32 length; |
| 48 | //The offset from beginning of the buffer where it is allocated |
| 49 | wpt_uint32 offset; |
| 50 | wpt_uint32 phyAddr; |
| 51 | } tPalDmaMemInfo; |
| 52 | |
| 53 | /*=========================================================================== |
| 54 | |
| 55 | FUNCTIONS |
| 56 | |
| 57 | ===========================================================================*/ |
| 58 | |
| 59 | /** |
| 60 | * @brief Initialize PAL |
| 61 | * In case of QNP, this does nothing. |
| 62 | * @param ppPalContext pointer to a caller allocated pointer. It |
| 63 | * is opaque to caller. |
| 64 | * Caller save the returned pointer for future use when |
| 65 | * calling PAL APIs. |
| 66 | * @param pOSContext Pointer to a context that is OS specific. This is NULL is a |
| 67 | particular PAL doesn't use it for that OS. |
| 68 | * |
| 69 | * @return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Otherwise fail. |
| 70 | */ |
| 71 | wpt_status wpalOpen(void **ppPalContext, void *pOSContext) |
| 72 | { |
| 73 | wpt_status status; |
| 74 | |
| 75 | gContext.devHandle = pOSContext; |
| 76 | |
| 77 | status = wpalDeviceInit(pOSContext); |
| 78 | if (!WLAN_PAL_IS_STATUS_SUCCESS(status)) |
| 79 | { |
| 80 | WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_FATAL, |
| 81 | "%s: wpalDeviceInit failed with status %u", |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 82 | __func__, status); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return status; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @brief wpalClose - Release PAL |
| 90 | * In case of QNP, this does nothing. |
| 91 | * @param pPalContext pointer returned from wpalOpen. |
| 92 | * |
| 93 | * @return wpt_status eWLAN_PAL_STATUS_SUCCESS - success. Otherwise fail. |
| 94 | */ |
| 95 | wpt_status wpalClose(void *pPalContext) |
| 96 | { |
| 97 | wpalDeviceClose(gContext.devHandle); |
| 98 | gContext.devHandle = NULL; |
| 99 | |
| 100 | return eWLAN_PAL_STATUS_SUCCESS; |
| 101 | } |
| 102 | |
| 103 | #ifndef MEMORY_DEBUG |
| 104 | /** |
| 105 | * @brief wpalMemoryAllocate - Allocate memory |
| 106 | * @param size number of bytes to allocate |
| 107 | * |
| 108 | * @return void* A pointer to the allocated memory. |
| 109 | * NULL - fail to allocate memory |
| 110 | */ |
| 111 | void *wpalMemoryAllocate(wpt_uint32 size) |
| 112 | { |
| 113 | return vos_mem_malloc( size ); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @brief wpalMemoryFree - Free allocated memory |
| 118 | * @param pv pointer to buffer to be freed |
| 119 | */ |
| 120 | void wpalMemoryFree(void *pv) |
| 121 | { |
| 122 | vos_mem_free( pv ); |
| 123 | } |
| 124 | #endif /* MEMORY_DEBUG */ |
| 125 | /** |
| 126 | * @brief wpalMemoryCopy - copy memory |
| 127 | * @param dest address which data is copied to |
| 128 | * @param src address which data is copied from |
| 129 | * @param size number of bytes to copy |
| 130 | * |
| 131 | * @return wpt_status |
| 132 | * eWLAN_PAL_STATUS_SUCCESS |
| 133 | * eWLAN_PAL_STATUS_INVALID_PARAM |
| 134 | */ |
| 135 | wpt_status wpalMemoryCopy(void * dest, void * src, wpt_uint32 size) |
| 136 | { |
| 137 | vos_mem_copy( dest, src, size ); |
| 138 | |
| 139 | return eWLAN_PAL_STATUS_SUCCESS; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @brief wpalMemoryCompare - compare memory |
| 144 | * @param buf1 address of buffer1 |
| 145 | * @param buf2 address of buffer2 |
| 146 | * @param size number of bytes to compare |
| 147 | * |
| 148 | * @return wpt_boolean |
| 149 | * eWLAN_PAL_TRUE - if two buffers have same content |
| 150 | * eWLAN_PAL_FALSE - not match |
| 151 | */ |
| 152 | wpt_boolean wpalMemoryCompare(void * buf1, void * buf2, wpt_uint32 size) |
| 153 | { |
| 154 | return (wpt_boolean)vos_mem_compare( buf1, buf2, size ); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /*--------------------------------------------------------------------------- |
| 159 | wpalMemoryZero - Zero memory |
| 160 | Param: |
| 161 | buf - address of buffer to be zero |
| 162 | size - number of bytes to zero |
| 163 | Return: |
| 164 | None |
| 165 | ---------------------------------------------------------------------------*/ |
| 166 | void wpalMemoryZero(void *buf, wpt_uint32 size) |
| 167 | { |
| 168 | vos_mem_zero( buf, size ); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @brief wpalMemoryFill - Fill memory with one pattern |
| 173 | * @param buf address of buffer to be filled |
| 174 | * @param size number of bytes to fill |
| 175 | * @param bFill one byte of data to fill in (size) bytes from the start of the |
| 176 | * buffer |
| 177 | */ |
| 178 | void wpalMemoryFill(void *buf, wpt_uint32 size, wpt_byte bFill) |
| 179 | { |
| 180 | vos_mem_set( buf, size, bFill ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @brief wpalDmaMemoryAllocate - Allocate memory ready for DMA. Aligned at 4-byte |
| 185 | * @param size number of bytes to allocate |
| 186 | * @param ppPhysicalAddr Physical address of the buffer if allocation succeeds |
| 187 | * |
| 188 | * @return void* A pointer to the allocated memory (virtual address). |
| 189 | * NULL - fail to allocate memory |
| 190 | */ |
| 191 | void *wpalDmaMemoryAllocate(wpt_uint32 size, void **ppPhysicalAddr) |
| 192 | { |
| 193 | void *pv = NULL; |
| 194 | dma_addr_t PhyAddr; |
| 195 | wpt_uint32 uAllocLen = size + sizeof(tPalDmaMemInfo); |
| 196 | |
| 197 | pv = dma_alloc_coherent(NULL, uAllocLen, &PhyAddr, GFP_KERNEL); |
| 198 | if ( NULL == pv ) |
| 199 | { |
| 200 | WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR, |
Arif Hussain | 9a5d538 | 2013-11-17 22:05:35 -0800 | [diff] [blame] | 201 | "%s Unable to allocate DMA buffer", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 202 | return NULL; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | ((tPalDmaMemInfo *)pv)->length = uAllocLen; |
| 207 | ((tPalDmaMemInfo *)pv)->phyAddr = PhyAddr; |
| 208 | ((tPalDmaMemInfo *)pv)->offset = sizeof(tPalDmaMemInfo); |
| 209 | pv = (wpt_byte *)pv + sizeof(tPalDmaMemInfo); |
| 210 | *ppPhysicalAddr = (void*)PhyAddr + sizeof(tPalDmaMemInfo); |
| 211 | |
| 212 | |
| 213 | return (pv); |
| 214 | }/*wpalDmaMemoryAllocate*/ |
| 215 | |
| 216 | |
| 217 | /** |
| 218 | * @brief wpalDmaMemoryFree - Free memory ready for DMA |
| 219 | * @param pv address for the buffer to be freed |
| 220 | */ |
| 221 | void wpalDmaMemoryFree(void *pv) |
| 222 | { |
| 223 | tPalDmaMemInfo *pMemInfo = (tPalDmaMemInfo *)(((wpt_byte *)pv) - |
| 224 | sizeof(tPalDmaMemInfo)); |
| 225 | if(pv) |
| 226 | { |
| 227 | pv = (wpt_byte *)pv - pMemInfo->offset; |
| 228 | dma_free_coherent(NULL, pMemInfo->length, pv, pMemInfo->phyAddr); |
| 229 | } |
| 230 | |
| 231 | }/*wpalDmaMemoryFree*/ |
| 232 | |
| 233 | /** |
| 234 | * @brief wpalDbgReadRegister - Read register from the WiFi BB |
| 235 | chip |
| 236 | * @param regAddr - register address |
| 237 | * @param pregValue - return value from register if success |
| 238 | * @return |
| 239 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 240 | */ |
| 241 | wpt_status wpalDbgReadRegister(wpt_uint32 regAddr, wpt_uint32 *pregValue) |
| 242 | { |
| 243 | if (NULL == pregValue) |
| 244 | { |
| 245 | return eWLAN_PAL_STATUS_E_INVAL; |
| 246 | } |
| 247 | |
| 248 | return wpalReadRegister(regAddr, pregValue); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * @brief wpalDbgWriteRegister - Write a value to the register |
| 253 | * in the WiFi BB chip Param: |
| 254 | * @param regAddr - register address |
| 255 | * @param regValue - value to be written |
| 256 | * @return |
| 257 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 258 | */ |
| 259 | wpt_status wpalDbgWriteRegister(wpt_uint32 regAddr, wpt_uint32 regValue) |
| 260 | { |
| 261 | return wpalWriteRegister(regAddr, regValue); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @brief |
| 266 | wpalDbgReadMemory - Read memory from WiFi BB chip space |
| 267 | * @param memAddr - address of memory |
| 268 | * @param buf - output |
| 269 | * @param len - length to be read |
| 270 | * @return |
| 271 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 272 | */ |
| 273 | wpt_status wpalDbgReadMemory(wpt_uint32 memAddr, wpt_uint8 *buf, wpt_uint32 len) |
| 274 | { |
| 275 | return wpalReadDeviceMemory(memAddr, buf, len); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * @brief |
| 280 | wpalDbgWriteMemory - Write a value to the memory in the WiFi BB chip space |
| 281 | * @param memAddr - memory address |
| 282 | * @param buf - vlaue to be written |
| 283 | * @param len - length of buf |
| 284 | * @return |
| 285 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 286 | */ |
| 287 | wpt_status wpalDbgWriteMemory(wpt_uint32 memAddr, wpt_uint8 *buf, wpt_uint32 len) |
| 288 | { |
| 289 | return wpalWriteDeviceMemory(memAddr, buf, len); |
| 290 | } |
| 291 | |
| 292 | /*--------------------------------------------------------------------------- |
| 293 | wpalDriverShutdown - Shutdown WLAN driver |
| 294 | |
| 295 | This API is requied by SSR, call in to 'VOS shutdown' to shutdown WLAN |
| 296 | driver when Riva crashes. |
| 297 | |
| 298 | Param: |
| 299 | None |
| 300 | Return: |
| 301 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 302 | ---------------------------------------------------------------------------*/ |
| 303 | wpt_status wpalDriverShutdown(void) |
| 304 | { |
| 305 | VOS_STATUS vosStatus; |
| 306 | vosStatus = vos_wlanShutdown(); |
| 307 | |
| 308 | if (VOS_STATUS_SUCCESS == vosStatus) { |
| 309 | return eWLAN_PAL_STATUS_SUCCESS; |
| 310 | } |
| 311 | return eWLAN_PAL_STATUS_E_FAILURE; |
| 312 | } |
| 313 | |
| 314 | /*--------------------------------------------------------------------------- |
| 315 | wpalDriverShutdown - Re-init WLAN driver |
| 316 | |
| 317 | This API is requied by SSR, call in to 'VOS re-init' to re-init WLAN |
| 318 | driver. |
| 319 | |
| 320 | Param: |
| 321 | None |
| 322 | Return: |
| 323 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 324 | ---------------------------------------------------------------------------*/ |
| 325 | wpt_status wpalDriverReInit(void) |
| 326 | { |
| 327 | VOS_STATUS vosStatus; |
| 328 | |
| 329 | vosStatus = vos_wlanReInit(); |
| 330 | if (VOS_STATUS_SUCCESS == vosStatus) { |
| 331 | return eWLAN_PAL_STATUS_SUCCESS; |
| 332 | } |
| 333 | return eWLAN_PAL_STATUS_E_FAILURE; |
| 334 | } |
| 335 | |
| 336 | /*--------------------------------------------------------------------------- |
| 337 | wpalRivaSubystemRestart - Initiate Riva SSR |
| 338 | |
| 339 | This API is called by WLAN driver to initiate Riva SSR |
| 340 | |
| 341 | Param: |
| 342 | None |
| 343 | Return: |
| 344 | eWLAN_PAL_STATUS_SUCCESS - when everything is OK |
| 345 | ---------------------------------------------------------------------------*/ |
| 346 | wpt_status wpalRivaSubystemRestart(void) |
| 347 | { |
| 348 | /* call SSR only if driver is not in load/unload process. |
| 349 | * A WDI timeout during load/unload cannot be fixed thru |
| 350 | * SSR */ |
| 351 | if (vos_is_load_unload_in_progress(VOS_MODULE_ID_WDI, NULL)) |
| 352 | { |
| 353 | WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_FATAL, |
| 354 | "%s: loading/unloading in progress," |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 355 | " SSR will be done at the end of unload", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 356 | return eWLAN_PAL_STATUS_E_FAILURE; |
| 357 | } |
Madan Mohan Koyyalamudi | 3246f5b | 2012-10-15 15:40:02 -0700 | [diff] [blame] | 358 | if (0 == subsystem_restart("wcnss")) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 359 | { |
| 360 | return eWLAN_PAL_STATUS_SUCCESS; |
| 361 | } |
| 362 | return eWLAN_PAL_STATUS_E_FAILURE; |
| 363 | } |
Jeff Johnson | e724574 | 2012-09-05 17:12:55 -0700 | [diff] [blame] | 364 | |
| 365 | /*--------------------------------------------------------------------------- |
| 366 | wpalWlanReload - Initiate WLAN Driver reload |
| 367 | |
| 368 | Param: |
| 369 | None |
| 370 | Return: |
| 371 | NONE |
| 372 | ---------------------------------------------------------------------------*/ |
| 373 | void wpalWlanReload(void) |
| 374 | { |
| 375 | vos_wlanRestart(); |
| 376 | return; |
Madan Mohan Koyyalamudi | 3246f5b | 2012-10-15 15:40:02 -0700 | [diff] [blame] | 377 | } |
Madan Mohan Koyyalamudi | 0bfd000 | 2012-10-24 14:39:37 -0700 | [diff] [blame] | 378 | |
| 379 | /*--------------------------------------------------------------------------- |
| 380 | wpalWcnssResetIntr - Trigger the reset FIQ to Riva |
| 381 | |
| 382 | Param: |
| 383 | None |
| 384 | Return: |
| 385 | NONE |
| 386 | ---------------------------------------------------------------------------*/ |
| 387 | void wpalWcnssResetIntr(void) |
| 388 | { |
Madan Mohan Koyyalamudi | c72a4d6 | 2012-11-08 14:59:34 -0800 | [diff] [blame] | 389 | #ifdef HAVE_WCNSS_RESET_INTR |
Madan Mohan Koyyalamudi | 0bfd000 | 2012-10-24 14:39:37 -0700 | [diff] [blame] | 390 | wcnss_reset_intr(); |
Madan Mohan Koyyalamudi | c72a4d6 | 2012-11-08 14:59:34 -0800 | [diff] [blame] | 391 | #endif |
Madan Mohan Koyyalamudi | 0bfd000 | 2012-10-24 14:39:37 -0700 | [diff] [blame] | 392 | return; |
| 393 | } |
Madan Mohan Koyyalamudi | 6208028 | 2013-08-05 12:51:17 +0530 | [diff] [blame] | 394 | |
| 395 | /*--------------------------------------------------------------------------- |
| 396 | wpalFwDumpReq - Trigger the dump commands to Firmware |
| 397 | |
| 398 | Param: |
| 399 | cmd - Command No. to execute |
| 400 | arg1 - argument 1 to cmd |
| 401 | arg2 - argument 2 to cmd |
| 402 | arg3 - argument 3 to cmd |
| 403 | arg4 - argument 4 to cmd |
| 404 | Return: |
| 405 | NONE |
| 406 | ---------------------------------------------------------------------------*/ |
| 407 | void wpalFwDumpReq(wpt_uint32 cmd, wpt_uint32 arg1, wpt_uint32 arg2, |
| 408 | wpt_uint32 arg3, wpt_uint32 arg4) |
| 409 | { |
| 410 | vos_fwDumpReq(cmd, arg1, arg2, arg3, arg4); |
| 411 | return; |
| 412 | } |
Leo Chang | 00708f6 | 2013-12-03 20:21:51 -0800 | [diff] [blame] | 413 | |
| 414 | /*--------------------------------------------------------------------------- |
| 415 | wpalDevicePanic - Trigger Device Panic |
| 416 | Trigger device panic to help debug |
| 417 | |
| 418 | Param: |
| 419 | NONE |
| 420 | |
| 421 | Return: |
| 422 | NONE |
| 423 | ---------------------------------------------------------------------------*/ |
| 424 | void wpalDevicePanic(void) |
| 425 | { |
| 426 | BUG_ON(0); |
| 427 | return; |
| 428 | } |
| 429 | |