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