Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. 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 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame] | 22 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 23 | * |
| 24 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 25 | * |
| 26 | * |
| 27 | * Permission to use, copy, modify, and/or distribute this software for |
| 28 | * any purpose with or without fee is hereby granted, provided that the |
| 29 | * above copyright notice and this permission notice appear in all |
| 30 | * copies. |
| 31 | * |
| 32 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 33 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 34 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 35 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 36 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 37 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 38 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 39 | * PERFORMANCE OF THIS SOFTWARE. |
| 40 | */ |
| 41 | |
| 42 | /**========================================================================= |
| 43 | |
| 44 | EDIT HISTORY FOR FILE |
| 45 | |
| 46 | |
| 47 | This section contains comments describing changes made to the module. |
| 48 | Notice that changes are listed in reverse chronological order. |
| 49 | |
| 50 | |
| 51 | $Header:$ $DateTime: $ $Author: $ |
| 52 | |
| 53 | |
| 54 | when who what, where, why |
| 55 | -------- --- -------------------------------------------------------- |
| 56 | 03/29/11 tbh Created module. |
| 57 | |
| 58 | ==========================================================================*/ |
| 59 | |
| 60 | /*---------------------------------------------------------------------------- |
| 61 | * Include Files |
| 62 | * -------------------------------------------------------------------------*/ |
| 63 | #include <wlan_hdd_dev_pwr.h> |
| 64 | #ifdef ANI_BUS_TYPE_PLATFORM |
| 65 | #include <linux/wcnss_wlan.h> |
| 66 | #else |
| 67 | #include <wcnss_wlan.h> |
| 68 | #endif // ANI_BUS_TYP_PLATFORM |
| 69 | |
| 70 | /*---------------------------------------------------------------------------- |
| 71 | * Preprocessor Definitions and Constants |
| 72 | * -------------------------------------------------------------------------*/ |
| 73 | |
| 74 | /*---------------------------------------------------------------------------- |
| 75 | * Type Declarations |
| 76 | * -------------------------------------------------------------------------*/ |
| 77 | |
| 78 | |
| 79 | /*------------------------------------------------------------------------- |
| 80 | * Global variables. |
| 81 | *-------------------------------------------------------------------------*/ |
| 82 | |
| 83 | /*------------------------------------------------------------------------- |
| 84 | * Local variables. |
| 85 | *-------------------------------------------------------------------------*/ |
| 86 | /* Reference VoIP, 100msec delay make disconnect. |
| 87 | * So TX sleep must be less than 100msec |
| 88 | * Every 20msec TX frame will goes out. |
| 89 | * 10 frame means 2seconds TX operation */ |
| 90 | static const hdd_tmLevelAction_t thermalMigrationAction[WLAN_HDD_TM_LEVEL_MAX] = |
| 91 | { |
| 92 | /* TM Level 0, Do nothing, just normal operaton */ |
| 93 | {1, 0, 0, 0, 0xFFFFF}, |
| 94 | /* Tm Level 1, disable TX AMPDU */ |
| 95 | {0, 0, 0, 0, 0xFFFFF}, |
| 96 | /* TM Level 2, disable AMDPU, |
| 97 | * TX sleep 100msec if TX frame count is larger than 16 during 300msec */ |
| 98 | {0, 0, 100, 300, 16}, |
| 99 | /* TM Level 3, disable AMDPU, |
| 100 | * TX sleep 500msec if TX frame count is larger than 11 during 500msec */ |
| 101 | {0, 0, 500, 500, 11}, |
| 102 | /* TM Level 4, MAX TM level, enter IMPS */ |
| 103 | {0, 1, 1000, 500, 10} |
| 104 | }; |
Madan Mohan Koyyalamudi | c72a4d6 | 2012-11-08 14:59:34 -0800 | [diff] [blame] | 105 | #ifdef HAVE_WCNSS_SUSPEND_RESUME_NOTIFY |
| 106 | static bool suspend_notify_sent; |
| 107 | #endif |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 108 | |
| 109 | |
| 110 | /*---------------------------------------------------------------------------- |
| 111 | |
| 112 | @brief Function to suspend the wlan driver. |
| 113 | |
| 114 | @param hdd_context_t pHddCtx |
| 115 | Global hdd context |
| 116 | |
| 117 | |
| 118 | @return None |
| 119 | |
| 120 | ----------------------------------------------------------------------------*/ |
| 121 | static int wlan_suspend(hdd_context_t* pHddCtx) |
| 122 | { |
| 123 | int rc = 0; |
| 124 | |
| 125 | pVosSchedContext vosSchedContext = NULL; |
| 126 | |
| 127 | /* Get the global VOSS context */ |
| 128 | vosSchedContext = get_vos_sched_ctxt(); |
| 129 | |
| 130 | if(!vosSchedContext) { |
| 131 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_FATAL,"%s: Global VOS_SCHED context is Null",__func__); |
| 132 | return 0; |
| 133 | } |
| 134 | if(!vos_is_apps_power_collapse_allowed(pHddCtx)) |
| 135 | { |
| 136 | /* Fail this suspend */ |
| 137 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, "%s: Fail wlan suspend: not in IMPS/BMPS", __func__); |
Madan Mohan Koyyalamudi | cae253a | 2012-11-06 19:10:35 -0800 | [diff] [blame] | 138 | return -EPERM; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 141 | /* |
| 142 | Suspending MC Thread, Rx Thread and Tx Thread as the platform driver is going to Suspend. |
| 143 | */ |
| 144 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Suspending Mc, Rx and Tx Threads",__func__); |
| 145 | |
| 146 | init_completion(&pHddCtx->tx_sus_event_var); |
| 147 | |
| 148 | /* Indicate Tx Thread to Suspend */ |
| 149 | set_bit(TX_SUSPEND_EVENT_MASK, &vosSchedContext->txEventFlag); |
| 150 | |
| 151 | wake_up_interruptible(&vosSchedContext->txWaitQueue); |
| 152 | |
| 153 | /* Wait for Suspend Confirmation from Tx Thread */ |
| 154 | rc = wait_for_completion_interruptible_timeout(&pHddCtx->tx_sus_event_var, msecs_to_jiffies(200)); |
| 155 | |
| 156 | if(!rc) |
| 157 | { |
| 158 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s: Not able to suspend TX thread timeout happened", __func__); |
| 159 | clear_bit(TX_SUSPEND_EVENT_MASK, &vosSchedContext->txEventFlag); |
| 160 | |
Madan Mohan Koyyalamudi | cae253a | 2012-11-06 19:10:35 -0800 | [diff] [blame] | 161 | return -ETIME; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 162 | } |
| 163 | /* Set the Tx Thread as Suspended */ |
| 164 | pHddCtx->isTxThreadSuspended = TRUE; |
| 165 | |
| 166 | init_completion(&pHddCtx->rx_sus_event_var); |
| 167 | |
| 168 | /* Indicate Rx Thread to Suspend */ |
| 169 | set_bit(RX_SUSPEND_EVENT_MASK, &vosSchedContext->rxEventFlag); |
| 170 | |
| 171 | wake_up_interruptible(&vosSchedContext->rxWaitQueue); |
| 172 | |
| 173 | /* Wait for Suspend Confirmation from Rx Thread */ |
| 174 | rc = wait_for_completion_interruptible_timeout(&pHddCtx->rx_sus_event_var, msecs_to_jiffies(200)); |
| 175 | |
| 176 | if(!rc) |
| 177 | { |
| 178 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s: Not able to suspend Rx thread timeout happened", __func__); |
| 179 | |
| 180 | clear_bit(RX_SUSPEND_EVENT_MASK, &vosSchedContext->rxEventFlag); |
| 181 | |
| 182 | /* Indicate Tx Thread to Resume */ |
| 183 | complete(&vosSchedContext->ResumeTxEvent); |
| 184 | |
| 185 | /* Set the Tx Thread as Resumed */ |
| 186 | pHddCtx->isTxThreadSuspended = FALSE; |
| 187 | |
Madan Mohan Koyyalamudi | cae253a | 2012-11-06 19:10:35 -0800 | [diff] [blame] | 188 | return -ETIME; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* Set the Rx Thread as Suspended */ |
| 192 | pHddCtx->isRxThreadSuspended = TRUE; |
| 193 | |
| 194 | init_completion(&pHddCtx->mc_sus_event_var); |
| 195 | |
| 196 | /* Indicate MC Thread to Suspend */ |
| 197 | set_bit(MC_SUSPEND_EVENT_MASK, &vosSchedContext->mcEventFlag); |
| 198 | |
| 199 | wake_up_interruptible(&vosSchedContext->mcWaitQueue); |
| 200 | |
| 201 | /* Wait for Suspend Confirmation from MC Thread */ |
| 202 | rc = wait_for_completion_interruptible_timeout(&pHddCtx->mc_sus_event_var, msecs_to_jiffies(200)); |
| 203 | |
| 204 | if(!rc) |
| 205 | { |
| 206 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, "%s: Not able to suspend MC thread timeout happened", __func__); |
| 207 | |
| 208 | clear_bit(MC_SUSPEND_EVENT_MASK, &vosSchedContext->mcEventFlag); |
| 209 | |
| 210 | /* Indicate Rx Thread to Resume */ |
| 211 | complete(&vosSchedContext->ResumeRxEvent); |
| 212 | |
| 213 | /* Set the Rx Thread as Resumed */ |
| 214 | pHddCtx->isRxThreadSuspended = FALSE; |
| 215 | |
| 216 | /* Indicate Tx Thread to Resume */ |
| 217 | complete(&vosSchedContext->ResumeTxEvent); |
| 218 | |
| 219 | /* Set the Tx Thread as Resumed */ |
| 220 | pHddCtx->isTxThreadSuspended = FALSE; |
| 221 | |
Madan Mohan Koyyalamudi | cae253a | 2012-11-06 19:10:35 -0800 | [diff] [blame] | 222 | return -ETIME; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* Set the Mc Thread as Suspended */ |
| 226 | pHddCtx->isMcThreadSuspended = TRUE; |
| 227 | |
| 228 | /* Set the Station state as Suspended */ |
| 229 | pHddCtx->isWlanSuspended = TRUE; |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | /*---------------------------------------------------------------------------- |
| 235 | |
| 236 | @brief Function to resume the wlan driver. |
| 237 | |
| 238 | @param hdd_context_t pHddCtx |
| 239 | Global hdd context |
| 240 | |
| 241 | |
| 242 | @return None |
| 243 | |
| 244 | ----------------------------------------------------------------------------*/ |
| 245 | static void wlan_resume(hdd_context_t* pHddCtx) |
| 246 | { |
| 247 | pVosSchedContext vosSchedContext = NULL; |
| 248 | |
| 249 | //Get the global VOSS context. |
| 250 | vosSchedContext = get_vos_sched_ctxt(); |
| 251 | |
| 252 | if(!vosSchedContext) { |
| 253 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_FATAL,"%s: Global VOS_SCHED context is Null",__func__); |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | Resuming Mc, Rx and Tx Thread as platform Driver is resuming. |
| 259 | */ |
| 260 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Resuming Mc, Rx and Tx Thread",__func__); |
| 261 | |
| 262 | /* Indicate MC Thread to Resume */ |
| 263 | complete(&vosSchedContext->ResumeMcEvent); |
| 264 | |
| 265 | /* Set the Mc Thread as Resumed */ |
| 266 | pHddCtx->isMcThreadSuspended = FALSE; |
| 267 | |
| 268 | /* Indicate Rx Thread to Resume */ |
| 269 | complete(&vosSchedContext->ResumeRxEvent); |
| 270 | |
| 271 | /* Set the Rx Thread as Resumed */ |
| 272 | pHddCtx->isRxThreadSuspended = FALSE; |
| 273 | |
| 274 | /* Indicate Tx Thread to Resume */ |
| 275 | complete(&vosSchedContext->ResumeTxEvent); |
| 276 | |
| 277 | /* Set the Tx Thread as Resumed */ |
| 278 | pHddCtx->isTxThreadSuspended = FALSE; |
| 279 | |
| 280 | /* Set the Station state as Suspended */ |
| 281 | pHddCtx->isWlanSuspended = FALSE; |
| 282 | } |
| 283 | |
| 284 | /*---------------------------------------------------------------------------- |
| 285 | |
| 286 | @brief Function to suspend the wlan driver. |
| 287 | This function will get called by platform driver Suspend on System Suspend |
| 288 | |
| 289 | @param dev platform_func_device |
| 290 | |
| 291 | |
| 292 | @return None |
| 293 | |
| 294 | ----------------------------------------------------------------------------*/ |
| 295 | int hddDevSuspendHdlr(struct device *dev) |
| 296 | { |
| 297 | int ret = 0; |
| 298 | hdd_context_t* pHddCtx = NULL; |
| 299 | |
| 300 | pHddCtx = (hdd_context_t*)wcnss_wlan_get_drvdata(dev); |
| 301 | |
| 302 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: WLAN suspended by platform driver",__func__); |
| 303 | |
| 304 | /* Get the HDD context */ |
| 305 | if(!pHddCtx) { |
| 306 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__); |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | if(pHddCtx->isWlanSuspended == TRUE) |
| 311 | { |
| 312 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_FATAL,"%s: WLAN is already in suspended state",__func__); |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* Suspend the wlan driver */ |
| 317 | ret = wlan_suspend(pHddCtx); |
| 318 | if(ret != 0) |
| 319 | { |
| 320 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_FATAL,"%s: Not able to suspend wlan",__func__); |
| 321 | return ret; |
| 322 | } |
| 323 | |
Madan Mohan Koyyalamudi | c72a4d6 | 2012-11-08 14:59:34 -0800 | [diff] [blame] | 324 | #ifdef HAVE_WCNSS_SUSPEND_RESUME_NOTIFY |
| 325 | if(hdd_is_suspend_notify_allowed(pHddCtx)) |
| 326 | { |
| 327 | wcnss_suspend_notify(); |
| 328 | suspend_notify_sent = true; |
| 329 | } |
| 330 | #endif |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /*---------------------------------------------------------------------------- |
| 335 | |
| 336 | @brief Function to resume the wlan driver. |
| 337 | This function will get called by platform driver Resume on System Resume |
| 338 | |
| 339 | @param dev platform_func_device |
| 340 | |
| 341 | |
| 342 | @return None |
| 343 | |
| 344 | ----------------------------------------------------------------------------*/ |
| 345 | int hddDevResumeHdlr(struct device *dev) |
| 346 | { |
| 347 | hdd_context_t* pHddCtx = NULL; |
| 348 | |
| 349 | pHddCtx = (hdd_context_t*)wcnss_wlan_get_drvdata(dev); |
| 350 | |
| 351 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO, "%s: WLAN being resumed by Android OS",__func__); |
| 352 | |
| 353 | if(pHddCtx->isWlanSuspended != TRUE) |
| 354 | { |
| 355 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_FATAL,"%s: WLAN is already in resumed state",__func__); |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | /* Resume the wlan driver */ |
| 360 | wlan_resume(pHddCtx); |
Madan Mohan Koyyalamudi | c72a4d6 | 2012-11-08 14:59:34 -0800 | [diff] [blame] | 361 | #ifdef HAVE_WCNSS_SUSPEND_RESUME_NOTIFY |
| 362 | if(suspend_notify_sent == true) |
| 363 | { |
| 364 | wcnss_resume_notify(); |
| 365 | suspend_notify_sent = false; |
| 366 | } |
| 367 | #endif |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static const struct dev_pm_ops pm_ops = { |
| 373 | .suspend = hddDevSuspendHdlr, |
| 374 | .resume = hddDevResumeHdlr, |
| 375 | }; |
| 376 | |
| 377 | /*---------------------------------------------------------------------------- |
| 378 | * |
| 379 | |
| 380 | @brief Registration function. |
| 381 | Register suspend, resume callback functions with platform driver. |
| 382 | |
| 383 | @param hdd_context_t pHddCtx |
| 384 | Global hdd context |
| 385 | |
| 386 | @return General status code |
| 387 | VOS_STATUS_SUCCESS Registration Success |
| 388 | VOS_STATUS_E_FAILURE Registration Fail |
| 389 | |
| 390 | ----------------------------------------------------------------------------*/ |
| 391 | VOS_STATUS hddRegisterPmOps(hdd_context_t *pHddCtx) |
| 392 | { |
| 393 | wcnss_wlan_set_drvdata(pHddCtx->parent_dev, pHddCtx); |
| 394 | #ifndef FEATURE_R33D |
| 395 | wcnss_wlan_register_pm_ops(pHddCtx->parent_dev, &pm_ops); |
| 396 | #endif /* FEATURE_R33D */ |
| 397 | return VOS_STATUS_SUCCESS; |
| 398 | } |
| 399 | |
| 400 | /*---------------------------------------------------------------------------- |
| 401 | |
| 402 | @brief De-registration function. |
| 403 | Deregister the suspend, resume callback functions with platform driver |
| 404 | |
| 405 | @param hdd_context_t pHddCtx |
| 406 | Global hdd context |
| 407 | |
| 408 | @return General status code |
| 409 | VOS_STATUS_SUCCESS De-Registration Success |
| 410 | VOS_STATUS_E_FAILURE De-Registration Fail |
| 411 | |
| 412 | ----------------------------------------------------------------------------*/ |
| 413 | VOS_STATUS hddDeregisterPmOps(hdd_context_t *pHddCtx) |
| 414 | { |
| 415 | #ifndef FEATURE_R33D |
| 416 | wcnss_wlan_unregister_pm_ops(pHddCtx->parent_dev, &pm_ops); |
| 417 | #endif /* FEATURE_R33D */ |
| 418 | return VOS_STATUS_SUCCESS; |
| 419 | } |
| 420 | |
| 421 | /*---------------------------------------------------------------------------- |
| 422 | |
| 423 | @brief TX frame block timeout handler |
| 424 | Resume TX, and reset TX frame count |
| 425 | |
| 426 | @param hdd_context_t pHddCtx |
| 427 | Global hdd context |
| 428 | |
| 429 | @return NONE |
| 430 | |
| 431 | ----------------------------------------------------------------------------*/ |
| 432 | void hddDevTmTxBlockTimeoutHandler(void *usrData) |
| 433 | { |
| 434 | hdd_context_t *pHddCtx = (hdd_context_t *)usrData; |
| 435 | hdd_adapter_t *staAdapater; |
| 436 | /* Sanity, This should not happen */ |
| 437 | if(NULL == pHddCtx) |
| 438 | { |
| 439 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR, |
| 440 | "%s: NULL Context", __func__); |
| 441 | VOS_ASSERT(0); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | staAdapater = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION); |
Madan Mohan Koyyalamudi | c75be96 | 2012-10-18 19:19:03 -0700 | [diff] [blame] | 446 | |
| 447 | if(NULL == staAdapater) |
| 448 | { |
| 449 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR, |
| 450 | "%s: NULL Adapter", __func__); |
| 451 | VOS_ASSERT(0); |
| 452 | return; |
| 453 | } |
| 454 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 455 | if(mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock)) |
| 456 | { |
| 457 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR, |
Jeff Johnson | 1250df4 | 2012-12-10 14:31:52 -0800 | [diff] [blame] | 458 | "%s: Acquire lock fail", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | pHddCtx->tmInfo.txFrameCount = 0; |
| 462 | |
| 463 | /* Resume TX flow */ |
Madan Mohan Koyyalamudi | c75be96 | 2012-10-18 19:19:03 -0700 | [diff] [blame] | 464 | |
Leo Chang | 50bbd25 | 2013-04-25 14:58:01 -0700 | [diff] [blame^] | 465 | netif_tx_wake_all_queues(staAdapater->dev); |
| 466 | pHddCtx->tmInfo.qBlocked = VOS_FALSE; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 467 | mutex_unlock(&pHddCtx->tmInfo.tmOperationLock); |
| 468 | |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | /*---------------------------------------------------------------------------- |
| 473 | |
| 474 | @brief TM Level Change handler |
| 475 | Received Tm Level changed notification |
| 476 | |
| 477 | @param dev : Device context |
| 478 | changedTmLevel : Changed new TM level |
| 479 | |
| 480 | @return |
| 481 | |
| 482 | ----------------------------------------------------------------------------*/ |
| 483 | void hddDevTmLevelChangedHandler(struct device *dev, int changedTmLevel) |
| 484 | { |
| 485 | hdd_context_t *pHddCtx = NULL; |
| 486 | WLAN_TmLevelEnumType newTmLevel = changedTmLevel; |
| 487 | hdd_adapter_t *staAdapater; |
| 488 | |
| 489 | pHddCtx = (hdd_context_t*)wcnss_wlan_get_drvdata(dev); |
| 490 | |
Jeff Johnson | 4416a78 | 2013-03-25 14:17:50 -0700 | [diff] [blame] | 491 | if ((pHddCtx->tmInfo.currentTmLevel == newTmLevel) || |
| 492 | (!pHddCtx->cfg_ini->thermalMitigationEnable)) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 493 | { |
| 494 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_WARN, |
| 495 | "%s: TM Not enabled %d or Level does not changed %d", |
| 496 | __func__, pHddCtx->cfg_ini->thermalMitigationEnable, newTmLevel); |
| 497 | /* TM Level does not changed, |
| 498 | * Or feature does not enabled |
| 499 | * do nothing */ |
| 500 | return; |
| 501 | } |
| 502 | |
Jeff Johnson | 4416a78 | 2013-03-25 14:17:50 -0700 | [diff] [blame] | 503 | if ((newTmLevel < WLAN_HDD_TM_LEVEL_0) || |
| 504 | (newTmLevel >= WLAN_HDD_TM_LEVEL_MAX)) |
| 505 | { |
| 506 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR, |
| 507 | "%s: TM level %d out of range", |
| 508 | __func__, newTmLevel); |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | if (changedTmLevel != WLAN_HDD_TM_LEVEL_4) |
Venkata Prathyusha Kuntupalli | 9e289cc | 2013-03-12 12:08:06 -0700 | [diff] [blame] | 513 | sme_SetTmLevel(pHddCtx->hHal, changedTmLevel, 0); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 514 | |
Jeff Johnson | 4416a78 | 2013-03-25 14:17:50 -0700 | [diff] [blame] | 515 | if (mutex_lock_interruptible(&pHddCtx->tmInfo.tmOperationLock)) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 516 | { |
| 517 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR, |
Jeff Johnson | 1250df4 | 2012-12-10 14:31:52 -0800 | [diff] [blame] | 518 | "%s: Acquire lock fail", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | |
| 522 | pHddCtx->tmInfo.currentTmLevel = changedTmLevel; |
| 523 | pHddCtx->tmInfo.txFrameCount = 0; |
| 524 | vos_mem_copy(&pHddCtx->tmInfo.tmAction, |
| 525 | &thermalMigrationAction[newTmLevel], |
| 526 | sizeof(hdd_tmLevelAction_t)); |
| 527 | |
| 528 | |
Jeff Johnson | 4416a78 | 2013-03-25 14:17:50 -0700 | [diff] [blame] | 529 | if (pHddCtx->tmInfo.tmAction.enterImps) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 530 | { |
| 531 | staAdapater = hdd_get_adapter(pHddCtx, WLAN_HDD_INFRA_STATION); |
Jeff Johnson | 4416a78 | 2013-03-25 14:17:50 -0700 | [diff] [blame] | 532 | if (staAdapater) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 533 | { |
Jeff Johnson | 4416a78 | 2013-03-25 14:17:50 -0700 | [diff] [blame] | 534 | if (hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(staAdapater))) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 535 | { |
| 536 | sme_RoamDisconnect(pHddCtx->hHal, |
| 537 | staAdapater->sessionId, |
| 538 | eCSR_DISCONNECT_REASON_UNSPECIFIED); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | mutex_unlock(&pHddCtx->tmInfo.tmOperationLock); |
| 544 | |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | /*---------------------------------------------------------------------------- |
| 549 | |
| 550 | @brief Register function |
| 551 | Register Thermal Mitigation Level Changed handle callback function |
| 552 | |
| 553 | @param hdd_context_t pHddCtx |
| 554 | Global hdd context |
| 555 | |
| 556 | @return General status code |
| 557 | VOS_STATUS_SUCCESS Registration Success |
| 558 | VOS_STATUS_E_FAILURE Registration Fail |
| 559 | |
| 560 | ----------------------------------------------------------------------------*/ |
| 561 | VOS_STATUS hddDevTmRegisterNotifyCallback(hdd_context_t *pHddCtx) |
| 562 | { |
| 563 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_INFO, |
| 564 | "%s: Register TM Handler", __func__); |
| 565 | |
| 566 | wcnss_register_thermal_mitigation(pHddCtx->parent_dev ,hddDevTmLevelChangedHandler); |
| 567 | |
| 568 | /* Set Default TM Level as Lowest, do nothing */ |
| 569 | pHddCtx->tmInfo.currentTmLevel = WLAN_HDD_TM_LEVEL_0; |
| 570 | vos_mem_zero(&pHddCtx->tmInfo.tmAction, sizeof(hdd_tmLevelAction_t)); |
| 571 | vos_timer_init(&pHddCtx->tmInfo.txSleepTimer, |
| 572 | VOS_TIMER_TYPE_SW, |
| 573 | hddDevTmTxBlockTimeoutHandler, |
| 574 | (void *)pHddCtx); |
| 575 | mutex_init(&pHddCtx->tmInfo.tmOperationLock); |
| 576 | pHddCtx->tmInfo.txFrameCount = 0; |
| 577 | pHddCtx->tmInfo.blockedQueue = NULL; |
Leo Chang | 50bbd25 | 2013-04-25 14:58:01 -0700 | [diff] [blame^] | 578 | pHddCtx->tmInfo.qBlocked = VOS_FALSE; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 579 | return VOS_STATUS_SUCCESS; |
| 580 | } |
| 581 | |
| 582 | /*---------------------------------------------------------------------------- |
| 583 | |
| 584 | @brief Un-Register function |
| 585 | Un-Register Thermal Mitigation Level Changed handle callback function |
| 586 | |
| 587 | @param hdd_context_t pHddCtx |
| 588 | Global hdd context |
| 589 | |
| 590 | @return General status code |
| 591 | VOS_STATUS_SUCCESS Un-Registration Success |
| 592 | VOS_STATUS_E_FAILURE Un-Registration Fail |
| 593 | |
| 594 | ----------------------------------------------------------------------------*/ |
| 595 | VOS_STATUS hddDevTmUnregisterNotifyCallback(hdd_context_t *pHddCtx) |
| 596 | { |
Jeff Johnson | 04dd8a8 | 2012-06-29 20:41:40 -0700 | [diff] [blame] | 597 | VOS_STATUS vosStatus = VOS_STATUS_SUCCESS; |
| 598 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 599 | wcnss_unregister_thermal_mitigation(hddDevTmLevelChangedHandler); |
Jeff Johnson | 04dd8a8 | 2012-06-29 20:41:40 -0700 | [diff] [blame] | 600 | |
| 601 | if(VOS_TIMER_STATE_RUNNING == |
| 602 | vos_timer_getCurrentState(&pHddCtx->tmInfo.txSleepTimer)) |
| 603 | { |
| 604 | vosStatus = vos_timer_stop(&pHddCtx->tmInfo.txSleepTimer); |
| 605 | if(!VOS_IS_STATUS_SUCCESS(vosStatus)) |
| 606 | { |
| 607 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 608 | "%s: Timer stop fail", __func__); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // Destroy the vos timer... |
| 613 | vosStatus = vos_timer_destroy(&pHddCtx->tmInfo.txSleepTimer); |
| 614 | if (!VOS_IS_STATUS_SUCCESS(vosStatus)) |
| 615 | { |
| 616 | VOS_TRACE(VOS_MODULE_ID_HDD,VOS_TRACE_LEVEL_ERROR, |
| 617 | "%s: Fail to destroy timer", __func__); |
| 618 | } |
| 619 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 620 | return VOS_STATUS_SUCCESS; |
| 621 | } |
| 622 | |