blob: 71e4b88aa320411aced37aa92e09669321d66636 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * 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 Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
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 @file vos_sched.c
44 @brief VOS Scheduler Implementation
45
46 Copyright (c) 2011 QUALCOMM Incorporated.
47 All Rights Reserved.
48 Qualcomm Confidential and Proprietary
49===========================================================================*/
50/*===========================================================================
51 EDIT HISTORY FOR FILE
52
53 This section contains comments describing changes made to the module.
54 Notice that changes are listed in reverse chronological order.
55
56 $Header:$ $DateTime: $ $Author: $
57
58 when who what, where, why
59 -------- --- --------------------------------------------------------
60===========================================================================*/
61/*---------------------------------------------------------------------------
62 * Include Files
63 * ------------------------------------------------------------------------*/
64#include <vos_mq.h>
65#include <vos_api.h>
66#include <aniGlobal.h>
67#include <sirTypes.h>
68#include <halTypes.h>
69#include <limApi.h>
70#include <sme_Api.h>
71#ifndef FEATURE_WLAN_INTEGRATED_SOC
72#include <wlan_qct_ssc.h>
73#endif
74#include <wlan_qct_sys.h>
75#include <wlan_qct_tl.h>
76#include "vos_sched.h"
77#include <wlan_hdd_power.h>
78#ifdef FEATURE_WLAN_INTEGRATED_SOC
79#include "wlan_qct_wda.h"
80#include "wlan_qct_pal_msg.h"
81#endif
82#include <linux/spinlock.h>
83#include <linux/kthread.h>
84#ifndef FEATURE_WLAN_INTEGRATED_SOC
85#include <libra_sdioif.h>
86#include <wlan_sal_misc.h>
87#endif
88/*---------------------------------------------------------------------------
89 * Preprocessor Definitions and Constants
90 * ------------------------------------------------------------------------*/
91#define VOS_SCHED_THREAD_HEART_BEAT INFINITE
92/*---------------------------------------------------------------------------
93 * Type Declarations
94 * ------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------
96 * Data definitions
97 * ------------------------------------------------------------------------*/
98static pVosSchedContext gpVosSchedContext;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070099static pVosWatchdogContext gpVosWatchdogContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700100
101/*---------------------------------------------------------------------------
102 * Forward declaration
103 * ------------------------------------------------------------------------*/
104static int VosMCThread(void * Arg);
105static int VosWDThread(void * Arg);
106#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
107/* Integrated SOC will have single BIN for FTM driver and Production Driver
108 * So, anycase this must be compiled
109 * None integrated SOC will compile this part only for FTM Driver */
110static int VosTXThread(void * Arg);
111#ifdef FEATURE_WLAN_INTEGRATED_SOC
112static int VosRXThread(void* Arg);
113void vos_sched_flush_rx_mqs(pVosSchedContext SchedContext);
114#endif
115#endif
116extern v_VOID_t vos_core_return_msg(v_PVOID_t pVContext, pVosMsgWrapper pMsgWrapper);
117/*---------------------------------------------------------------------------
118 * External Function implementation
119 * ------------------------------------------------------------------------*/
120
121/*---------------------------------------------------------------------------
122 \brief vos_sched_open() - initialize the vOSS Scheduler
123 The \a vos_sched_open() function initializes the vOSS Scheduler
124 Upon successful initialization:
125 - All the message queues are initialized
126 - The Main Controller thread is created and ready to receive and
127 dispatch messages.
128 - The Tx thread is created and ready to receive and dispatch messages
129
130 \param pVosContext - pointer to the global vOSS Context
131 \param pVosSchedContext - pointer to a previously allocated buffer big
132 enough to hold a scheduler context.
133 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
134 is ready to be used.
135 VOS_STATUS_E_RESOURCES - System resources (other than memory)
136 are unavailable to initilize the scheduler
137 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
138 the scheduler
139 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
140 function
141 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
142 \sa vos_sched_open()
143 -------------------------------------------------------------------------*/
144VOS_STATUS
145vos_sched_open
146(
147 v_PVOID_t pVosContext,
148 pVosSchedContext pSchedContext,
149 v_SIZE_t SchedCtxSize
150)
151{
152 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
153/*-------------------------------------------------------------------------*/
154 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
155 "%s: Opening the VOSS Scheduler",__func__);
156 // Sanity checks
157 if ((pVosContext == NULL) || (pSchedContext == NULL)) {
158 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
159 "%s: Null params being passed",__func__);
160 return VOS_STATUS_E_FAILURE;
161 }
162 if (sizeof(VosSchedContext) != SchedCtxSize)
163 {
164 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
165 "%s: Incorrect VOS Sched Context size passed",__func__);
166 return VOS_STATUS_E_INVAL;
167 }
168 vos_mem_zero(pSchedContext, sizeof(VosSchedContext));
169 pSchedContext->pVContext = pVosContext;
170 vStatus = vos_sched_init_mqs(pSchedContext);
171 if (!VOS_IS_STATUS_SUCCESS(vStatus))
172 {
173 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
174 "%s: Failed to initialize VOS Scheduler MQs",__func__);
175 return vStatus;
176 }
177 // Initialize the helper events and event queues
178 init_completion(&pSchedContext->McStartEvent);
179 init_completion(&pSchedContext->TxStartEvent);
180#ifdef FEATURE_WLAN_INTEGRATED_SOC
181 init_completion(&pSchedContext->RxStartEvent);
182#endif
183 init_completion(&pSchedContext->McShutdown);
184 init_completion(&pSchedContext->TxShutdown);
185#ifdef FEATURE_WLAN_INTEGRATED_SOC
186 init_completion(&pSchedContext->RxShutdown);
187#endif
188 init_completion(&pSchedContext->ResumeMcEvent);
189 init_completion(&pSchedContext->ResumeTxEvent);
190#ifdef FEATURE_WLAN_INTEGRATED_SOC
191 init_completion(&pSchedContext->ResumeRxEvent);
192#endif
193
194 spin_lock_init(&pSchedContext->McThreadLock);
195 spin_lock_init(&pSchedContext->TxThreadLock);
196 spin_lock_init(&pSchedContext->RxThreadLock);
197
198 init_waitqueue_head(&pSchedContext->mcWaitQueue);
199 pSchedContext->mcEventFlag = 0;
200 init_waitqueue_head(&pSchedContext->txWaitQueue);
201 pSchedContext->txEventFlag= 0;
202#ifdef FEATURE_WLAN_INTEGRATED_SOC
203 init_waitqueue_head(&pSchedContext->rxWaitQueue);
204 pSchedContext->rxEventFlag= 0;
205#endif
206 /*
207 ** This initialization is critical as the threads will latter access the
208 ** global contexts normally,
209 **
210 ** I shall put some memory barrier here after the next piece of code but
211 ** I am keeping it simple for now.
212 */
213 gpVosSchedContext = pSchedContext;
214
215 //Create the VOSS Main Controller thread
216 pSchedContext->McThread = kthread_create(VosMCThread, pSchedContext,
217 "VosMCThread");
218 if (IS_ERR(pSchedContext->McThread))
219 {
220 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
221 "%s: Could not Create VOSS Main Thread Controller",__func__);
222 goto MC_THREAD_START_FAILURE;
223 }
224 wake_up_process(pSchedContext->McThread);
225 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
226 "%s: VOSS Main Controller thread Created",__func__);
227
228#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
229 pSchedContext->TxThread = kthread_create(VosTXThread, pSchedContext,
230 "VosTXThread");
231 if (IS_ERR(pSchedContext->TxThread))
232 {
233 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
234 "%s: Could not Create VOSS TX Thread",__func__);
235 goto TX_THREAD_START_FAILURE;
236 }
237 wake_up_process(pSchedContext->TxThread);
238 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
239 ("VOSS TX thread Created\n"));
240
241#ifdef FEATURE_WLAN_INTEGRATED_SOC
242 pSchedContext->RxThread = kthread_create(VosRXThread, pSchedContext,
243 "VosRXThread");
244 if (IS_ERR(pSchedContext->RxThread))
245 {
246
247 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
248 "%s: Could not Create VOSS RX Thread",__func__);
249 goto RX_THREAD_START_FAILURE;
250
251 }
252 wake_up_process(pSchedContext->RxThread);
253 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
254 ("VOSS RX thread Created\n"));
255#endif
256#endif
257
258 /*
259 ** Now make sure all threads have started before we exit.
260 ** Each thread should normally ACK back when it starts.
261 */
262 wait_for_completion_interruptible(&pSchedContext->McStartEvent);
263 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
264 "%s: VOSS MC Thread has started",__func__);
265#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
266 wait_for_completion_interruptible(&pSchedContext->TxStartEvent);
267 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
268 "%s: VOSS Tx Thread has started",__func__);
269#ifdef FEATURE_WLAN_INTEGRATED_SOC
270 wait_for_completion_interruptible(&pSchedContext->RxStartEvent);
271 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
272 "%s: VOSS Rx Thread has started",__func__);
273#endif
274
275 /*
276 ** We're good now: Let's get the ball rolling!!!
277 */
278 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
279 "%s: VOSS Scheduler successfully Opened",__func__);
280 #endif
281 return VOS_STATUS_SUCCESS;
282
283#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
284
285#ifdef FEATURE_WLAN_INTEGRATED_SOC
286RX_THREAD_START_FAILURE:
287 //Try and force the Tx thread controller to exit
288 set_bit(MC_SHUTDOWN_EVENT_MASK, &pSchedContext->txEventFlag);
289 set_bit(MC_POST_EVENT_MASK, &pSchedContext->txEventFlag);
290 wake_up_interruptible(&pSchedContext->txWaitQueue);
291 //Wait for TX to exit
292 wait_for_completion_interruptible(&pSchedContext->TxShutdown);
293#endif
294
295TX_THREAD_START_FAILURE:
296 //Try and force the Main thread controller to exit
297 set_bit(MC_SHUTDOWN_EVENT_MASK, &pSchedContext->mcEventFlag);
298 set_bit(MC_POST_EVENT_MASK, &pSchedContext->mcEventFlag);
299 wake_up_interruptible(&pSchedContext->mcWaitQueue);
300 //Wait for MC to exit
301 wait_for_completion_interruptible(&pSchedContext->McShutdown);
302
303#endif
304MC_THREAD_START_FAILURE:
305 //De-initialize all the message queues
306 vos_sched_deinit_mqs(pSchedContext);
307 return VOS_STATUS_E_RESOURCES;
308
309} /* vos_sched_open() */
310
311VOS_STATUS vos_watchdog_open
312(
313 v_PVOID_t pVosContext,
314 pVosWatchdogContext pWdContext,
315 v_SIZE_t wdCtxSize
316)
317{
318/*-------------------------------------------------------------------------*/
319 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
320 "%s: Opening the VOSS Watchdog module",__func__);
321 //Sanity checks
322 if ((pVosContext == NULL) || (pWdContext == NULL)) {
323 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
324 "%s: Null params being passed",__func__);
325 return VOS_STATUS_E_FAILURE;
326 }
327 if (sizeof(VosWatchdogContext) != wdCtxSize)
328 {
329 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
330 "%s: Incorrect VOS Watchdog Context size passed",__func__);
331 return VOS_STATUS_E_INVAL;
332 }
333 vos_mem_zero(pWdContext, sizeof(VosWatchdogContext));
334 pWdContext->pVContext = pVosContext;
335 gpVosWatchdogContext = pWdContext;
336
337 //Initialize the helper events and event queues
338 init_completion(&pWdContext->WdStartEvent);
339 init_completion(&pWdContext->WdShutdown);
340 init_waitqueue_head(&pWdContext->wdWaitQueue);
341 pWdContext->wdEventFlag = 0;
342
343 // Initialize the lock
344 spin_lock_init(&pWdContext->wdLock);
345
346 //Create the Watchdog thread
347 pWdContext->WdThread = kthread_create(VosWDThread, pWdContext,"VosWDThread");
348
349 if (IS_ERR(pWdContext->WdThread))
350 {
351 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
352 "%s: Could not Create Watchdog thread",__func__);
353 return VOS_STATUS_E_RESOURCES;
354 }
355 else
356 {
357 wake_up_process(pWdContext->WdThread);
358 }
359 /*
360 ** Now make sure thread has started before we exit.
361 ** Each thread should normally ACK back when it starts.
362 */
363 wait_for_completion_interruptible(&pWdContext->WdStartEvent);
364 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
365 "%s: VOSS Watchdog Thread has started",__func__);
366 return VOS_STATUS_SUCCESS;
367} /* vos_watchdog_open() */
368/*---------------------------------------------------------------------------
369 \brief VosMcThread() - The VOSS Main Controller thread
370 The \a VosMcThread() is the VOSS main controller thread:
371 \param Arg - pointer to the global vOSS Sched Context
372 \return Thread exit code
373 \sa VosMcThread()
374 -------------------------------------------------------------------------*/
375static int
376VosMCThread
377(
378 void * Arg
379)
380{
381 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
382 pVosMsgWrapper pMsgWrapper = NULL;
383 tpAniSirGlobal pMacContext = NULL;
384 tSirRetStatus macStatus = eSIR_SUCCESS;
385 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
386 int retWaitStatus = 0;
387 v_BOOL_t shutdown = VOS_FALSE;
388 hdd_context_t *pHddCtx = NULL;
389 v_CONTEXT_t pVosContext = NULL;
390
391 if (Arg == NULL)
392 {
393 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700394 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700395 return 0;
396 }
397 set_user_nice(current, -2);
398
399 daemonize("MC_Thread");
400 /*
401 ** Ack back to the context from which the main controller thread has been
402 ** created.
403 */
404 complete(&pSchedContext->McStartEvent);
405 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
406 "%s: MC Thread %d (%s) starting up",__func__, current->pid, current->comm);
407
408 /* Get the Global VOSS Context */
409 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
410 if(!pVosContext) {
411 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
412 return 0;
413 }
414
415 /* Get the HDD context */
416 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
417 if(!pHddCtx) {
418 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
419 return 0;
420 }
421
422 while(!shutdown)
423 {
424 // This implements the execution model algorithm
425 retWaitStatus = wait_event_interruptible(pSchedContext->mcWaitQueue,
426 test_bit(MC_POST_EVENT_MASK, &pSchedContext->mcEventFlag) ||
427 test_bit(MC_SUSPEND_EVENT_MASK, &pSchedContext->mcEventFlag));
428
429 if(retWaitStatus == -ERESTARTSYS)
430 {
431 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700432 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700433 break;
434 }
435 clear_bit(MC_POST_EVENT_MASK, &pSchedContext->mcEventFlag);
436
437 while(1)
438 {
439 // Check if MC needs to shutdown
440 if(test_bit(MC_SHUTDOWN_EVENT_MASK, &pSchedContext->mcEventFlag))
441 {
442 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
443 "%s: MC thread signaled to shutdown", __func__);
444 shutdown = VOS_TRUE;
445 /* Check for any Suspend Indication */
446 if(test_bit(MC_SUSPEND_EVENT_MASK, &pSchedContext->mcEventFlag))
447 {
448 clear_bit(MC_SUSPEND_EVENT_MASK, &pSchedContext->mcEventFlag);
449
450 /* Unblock anyone waiting on suspend */
451 complete(&pHddCtx->mc_sus_event_var);
452 }
453 break;
454 }
455#ifdef FEATURE_WLAN_INTEGRATED_SOC
456 /*
457 ** Check the WDI queue
458 ** Service it till the entire queue is empty
459 */
460 if (!vos_is_mq_empty(&pSchedContext->wdiMcMq))
461 {
462 wpt_msg *pWdiMsg;
463 /*
464 ** Service the WDI message queue
465 */
466 VOS_TRACE(VOS_MODULE_ID_WDI, VOS_TRACE_LEVEL_INFO,
467 ("Servicing the VOS MC WDI Message queue"));
468
469 pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700470
471 if (pMsgWrapper == NULL)
472 {
473 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700474 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700475 VOS_ASSERT(0);
476 break;
477 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700478
479 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnsond13512a2012-07-17 11:42:19 -0700480
481 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
482 {
483 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700484 "%s: WDI Msg or Callback is NULL", __func__);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700485 VOS_ASSERT(0);
486 break;
487 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700488
489 pWdiMsg->callback(pWdiMsg);
490
491 /*
492 ** return message to the Core
493 */
494 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
495
496 continue;
497 }
498
499#endif
500 // Check the SYS queue first
501 if (!vos_is_mq_empty(&pSchedContext->sysMcMq))
502 {
503 // Service the SYS message queue
504 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
505 "%s: Servicing the VOS SYS MC Message queue",__func__);
506 pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq);
507 if (pMsgWrapper == NULL)
508 {
509 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700510 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700511 VOS_ASSERT(0);
512 break;
513 }
514 vStatus = sysMcProcessMsg(pSchedContext->pVContext,
515 pMsgWrapper->pVosMsg);
516 if (!VOS_IS_STATUS_SUCCESS(vStatus))
517 {
518 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
519 "%s: Issue Processing SYS message",__func__);
520 }
521 //return message to the Core
522 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
523 continue;
524 }
525#ifdef FEATURE_WLAN_INTEGRATED_SOC
526 // Check the WDA queue
527 if (!vos_is_mq_empty(&pSchedContext->wdaMcMq))
528 {
529 // Service the WDA message queue
530 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
531 "%s: Servicing the VOS WDA MC Message queue",__func__);
532 pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq);
533 if (pMsgWrapper == NULL)
534 {
535 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700536 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700537 VOS_ASSERT(0);
538 break;
539 }
540 vStatus = WDA_McProcessMsg( pSchedContext->pVContext, pMsgWrapper->pVosMsg);
541 if (!VOS_IS_STATUS_SUCCESS(vStatus))
542 {
543 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
544 "%s: Issue Processing WDA message",__func__);
545 }
546 // return message to the Core
547 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
548 continue;
549 }
550#else
551
552 // Check the HAL queue
553 if (!vos_is_mq_empty(&pSchedContext->halMcMq))
554 {
555 /* Need some optimization*/
556 pMacContext = vos_get_context(VOS_MODULE_ID_HAL, pSchedContext->pVContext);
557
558 if(pMacContext == NULL)
559 {
560 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700561 "%s: pMacContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700562 VOS_ASSERT(0);
563 break;
564 }
565
566 // Service the HAL message queue
567 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
568 "%s: Servicing the VOS HAL MC Message queue",__func__);
569 pMsgWrapper = vos_mq_get(&pSchedContext->halMcMq);
570 if (pMsgWrapper == NULL)
571 {
572 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700573 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700574 VOS_ASSERT(0);
575 break;
576 }
577
578 macStatus = halProcessMsg( pMacContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
579 if (eSIR_SUCCESS != macStatus)
580 {
581 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
582 "%s: Issue Processing HAL message",__func__);
583 }
584 // return message to the Core
585 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
586 continue;
587 }
588#endif
589#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
590 // Check the PE queue
591 if (!vos_is_mq_empty(&pSchedContext->peMcMq))
592 {
593 // Service the PE message queue
594 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
595 "%s: Servicing the VOS PE MC Message queue",__func__);
596 pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq);
597 if (NULL == pMsgWrapper)
598 {
599 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700600 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700601 VOS_ASSERT(0);
602 break;
603 }
604
605 /* Need some optimization*/
606 pMacContext = vos_get_context(VOS_MODULE_ID_PE, pSchedContext->pVContext);
607 if (NULL == pMacContext)
608 {
609 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
610 "MAC Context not ready yet");
611 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
612 continue;
613 }
614
615 macStatus = peProcessMessages( pMacContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
616 if (eSIR_SUCCESS != macStatus)
617 {
618 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
619 "%s: Issue Processing PE message",__func__);
620 }
621 // return message to the Core
622 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
623 continue;
624 }
625 /** Check the SME queue **/
626 if (!vos_is_mq_empty(&pSchedContext->smeMcMq))
627 {
628 /* Service the SME message queue */
629 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
630 "%s: Servicing the VOS SME MC Message queue",__func__);
631 pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq);
632 if (NULL == pMsgWrapper)
633 {
634 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700635 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700636 VOS_ASSERT(0);
637 break;
638 }
639
640 /* Need some optimization*/
641 pMacContext = vos_get_context(VOS_MODULE_ID_SME, pSchedContext->pVContext);
642 if (NULL == pMacContext)
643 {
644 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
645 "MAC Context not ready yet");
646 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
647 continue;
648 }
649
650 vStatus = sme_ProcessMsg( (tHalHandle)pMacContext, pMsgWrapper->pVosMsg);
651 if (!VOS_IS_STATUS_SUCCESS(vStatus))
652 {
653 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
654 "%s: Issue Processing SME message",__func__);
655 }
656 // return message to the Core
657 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
658 continue;
659 }
660 /** Check the TL queue **/
661 if (!vos_is_mq_empty(&pSchedContext->tlMcMq))
662 {
663 // Service the TL message queue
664 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
665 ("Servicing the VOS TL MC Message queue"));
666 pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq);
667 if (pMsgWrapper == NULL)
668 {
669 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700670 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700671 VOS_ASSERT(0);
672 break;
673 }
674 vStatus = WLANTL_McProcessMsg( pSchedContext->pVContext,
675 pMsgWrapper->pVosMsg);
676 if (!VOS_IS_STATUS_SUCCESS(vStatus))
677 {
678 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
679 "%s: Issue Processing TL message",__func__);
680 }
681 // return message to the Core
682 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
683 continue;
684 }
685 /* Check for any Suspend Indication */
686 if(test_bit(MC_SUSPEND_EVENT_MASK, &pSchedContext->mcEventFlag))
687 {
688 clear_bit(MC_SUSPEND_EVENT_MASK, &pSchedContext->mcEventFlag);
689 spin_lock(&pSchedContext->McThreadLock);
690
691 /* Mc Thread Suspended */
692 complete(&pHddCtx->mc_sus_event_var);
693
694 INIT_COMPLETION(pSchedContext->ResumeMcEvent);
695 spin_unlock(&pSchedContext->McThreadLock);
696
697 /* Wait foe Resume Indication */
698 wait_for_completion_interruptible(&pSchedContext->ResumeMcEvent);
699 }
700#endif /* ANI_MANF_DIAG */
701 break; //All queues are empty now
702 } // while message loop processing
703 } // while TRUE
704 // If we get here the MC thread must exit
705 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700706 "%s: MC Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700707 complete_and_exit(&pSchedContext->McShutdown, 0);
708} /* VosMCThread() */
709int isWDresetInProgress(void)
710{
711 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
712 "%s: Reset is in Progress...",__func__);
713#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
714 if(gpVosWatchdogContext!=NULL)
715 {
716 return gpVosWatchdogContext->resetInProgress;
717 }
718 else
719 {
720 return 0;
721 }
722#else
723 return 0;
724#endif
725}
726/*---------------------------------------------------------------------------
727 \brief VosWdThread() - The VOSS Watchdog thread
728 The \a VosWdThread() is the Watchdog thread:
729 \param Arg - pointer to the global vOSS Sched Context
730 \return Thread exit code
731 \sa VosMcThread()
732 -------------------------------------------------------------------------*/
733static int
734VosWDThread
735(
736 void * Arg
737)
738{
739 pVosWatchdogContext pWdContext = (pVosWatchdogContext)Arg;
740 int retWaitStatus = 0;
741 v_BOOL_t shutdown = VOS_FALSE;
742 VOS_STATUS vosStatus = VOS_STATUS_SUCCESS;
743 set_user_nice(current, -3);
744
745 if (Arg == NULL)
746 {
747 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700748 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700749 return 0;
750 }
751 daemonize("WD_Thread");
752 /*
753 ** Ack back to the context from which the Watchdog thread has been
754 ** created.
755 */
756 complete(&pWdContext->WdStartEvent);
757 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
758 "%s: Watchdog Thread %d (%s) starting up",__func__, current->pid, current->comm);
759
760 while(!shutdown)
761 {
762 // This implements the Watchdog execution model algorithm
763 retWaitStatus = wait_event_interruptible(pWdContext->wdWaitQueue,
764 test_bit(WD_POST_EVENT_MASK, &pWdContext->wdEventFlag));
765 if(retWaitStatus == -ERESTARTSYS)
766 {
767 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700768 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700769 break;
770 }
771 clear_bit(WD_POST_EVENT_MASK, &pWdContext->wdEventFlag);
772 while(1)
773 {
774 // Check if Watchdog needs to shutdown
775 if(test_bit(WD_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag))
776 {
777 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
778 "%s: Watchdog thread signaled to shutdown", __func__);
779
780 clear_bit(WD_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag);
781 shutdown = VOS_TRUE;
782 break;
783 }
784 /* subsystem restart: shutdown event handler */
785 else if(test_bit(WD_WLAN_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag))
786 {
787 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
788 "%s: Watchdog thread signaled to perform WLAN shutdown",__func__);
789 clear_bit(WD_WLAN_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag);
790
791 //Perform WLAN shutdown
792 if(!pWdContext->resetInProgress)
793 {
794 pWdContext->resetInProgress = true;
795 vosStatus = hdd_wlan_shutdown();
796
797 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
798 {
799 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
800 "%s: Failed to shutdown WLAN",__func__);
801 VOS_ASSERT(0);
802 goto err_reset;
803 }
804 }
805 }
806 /* subsystem restart: re-init event handler */
807 else if(test_bit(WD_WLAN_REINIT_EVENT_MASK, &pWdContext->wdEventFlag))
808 {
809 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
810 "%s: Watchdog thread signaled to perform WLAN re-init",__func__);
811 clear_bit(WD_WLAN_REINIT_EVENT_MASK, &pWdContext->wdEventFlag);
812
813 //Perform WLAN re-init
814 if(!pWdContext->resetInProgress)
815 {
816 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
817 "%s: Trying to do WLAN re-init when it is not shutdown !!",__func__);
818 }
819 vosStatus = hdd_wlan_re_init();
820
821 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
822 {
823 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
824 "%s: Failed to re-init WLAN",__func__);
825 VOS_ASSERT(0);
826 goto err_reset;
827 }
828 pWdContext->resetInProgress = false;
829 }
830 else
831 {
832 //Unnecessary wakeup - Should never happen!!
833 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
834 "%s: Watchdog thread woke up unnecessarily",__func__);
835 }
836 break;
837 } // while message loop processing
838 } // while shutdown
839
840 // If we get here the Watchdog thread must exit
841 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700842 "%s: Watchdog Thread exiting !!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700843 complete_and_exit(&pWdContext->WdShutdown, 0);
844
845err_reset:
846 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700847 "%s: Watchdog Thread Failed to Reset, Exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700848 return 0;
849
850} /* VosMCThread() */
851
852/*---------------------------------------------------------------------------
853 \brief VosTXThread() - The VOSS Main Tx thread
854 The \a VosTxThread() is the VOSS main controller thread:
855 \param Arg - pointer to the global vOSS Sched Context
856
857 \return Thread exit code
858 \sa VosTxThread()
859 -------------------------------------------------------------------------*/
860#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
861static int VosTXThread ( void * Arg )
862{
863 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
864 pVosMsgWrapper pMsgWrapper = NULL;
865 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
866 int retWaitStatus = 0;
867 v_BOOL_t shutdown = VOS_FALSE;
868 hdd_context_t *pHddCtx = NULL;
869 v_CONTEXT_t pVosContext = NULL;
870
871 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -0700872
873#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -0700874 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -0700875#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700876
877 if (Arg == NULL)
878 {
879 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700880 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700881 return 0;
882 }
883 daemonize("TX_Thread");
884 /*
885 ** Ack back to the context from which the main controller thread has been
886 ** created.
887 */
888 complete(&pSchedContext->TxStartEvent);
889 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
890 "%s: TX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
891
892 /* Get the Global VOSS Context */
893 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
894 if(!pVosContext) {
895 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
896 return 0;
897 }
898
899 /* Get the HDD context */
900 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
901 if(!pHddCtx) {
902 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
903 return 0;
904 }
905
906
907 while(!shutdown)
908 {
909 // This implements the execution model algorithm
910 retWaitStatus = wait_event_interruptible(pSchedContext->txWaitQueue,
911 test_bit(TX_POST_EVENT_MASK, &pSchedContext->txEventFlag) ||
912 test_bit(TX_SUSPEND_EVENT_MASK, &pSchedContext->txEventFlag));
913
914
915 if(retWaitStatus == -ERESTARTSYS)
916 {
917 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700918 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700919 break;
920 }
921 clear_bit(TX_POST_EVENT_MASK, &pSchedContext->txEventFlag);
922
923 while(1)
924 {
925 if(test_bit(TX_SHUTDOWN_EVENT_MASK, &pSchedContext->txEventFlag))
926 {
927 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
928 "%s: TX thread signaled to shutdown", __func__);
929 shutdown = VOS_TRUE;
930 /* Check for any Suspend Indication */
931 if(test_bit(TX_SUSPEND_EVENT_MASK, &pSchedContext->txEventFlag))
932 {
933 clear_bit(TX_SUSPEND_EVENT_MASK, &pSchedContext->txEventFlag);
934
935 /* Unblock anyone waiting on suspend */
936 complete(&pHddCtx->tx_sus_event_var);
937 }
938 break;
939 }
940 // Check the SYS queue first
941 if (!vos_is_mq_empty(&pSchedContext->sysTxMq))
942 {
943 // Service the SYS message queue
944 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
945 "%s: Servicing the VOS SYS TX Message queue",__func__);
946 pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq);
947 if (pMsgWrapper == NULL)
948 {
949 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700950 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700951 VOS_ASSERT(0);
952 break;
953 }
954 vStatus = sysTxProcessMsg( pSchedContext->pVContext,
955 pMsgWrapper->pVosMsg);
956 if (!VOS_IS_STATUS_SUCCESS(vStatus))
957 {
958 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
959 "%s: Issue Processing TX SYS message",__func__);
960 }
961 // return message to the Core
962 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
963 continue;
964 }
965 // Check now the TL queue
966 if (!vos_is_mq_empty(&pSchedContext->tlTxMq))
967 {
968 // Service the TL message queue
969 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
970 "%s: Servicing the VOS TL TX Message queue",__func__);
971 pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq);
972 if (pMsgWrapper == NULL)
973 {
974 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700975 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700976 VOS_ASSERT(0);
977 break;
978 }
979 vStatus = WLANTL_TxProcessMsg( pSchedContext->pVContext,
980 pMsgWrapper->pVosMsg);
981 if (!VOS_IS_STATUS_SUCCESS(vStatus))
982 {
983 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
984 "%s: Issue Processing TX TL message",__func__);
985 }
986 // return message to the Core
987 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
988 continue;
989 }
990#ifdef FEATURE_WLAN_INTEGRATED_SOC
991 // Check the WDI queue
992 if (!vos_is_mq_empty(&pSchedContext->wdiTxMq))
993 {
994 wpt_msg *pWdiMsg;
995 VOS_TRACE(VOS_MODULE_ID_WDI, VOS_TRACE_LEVEL_INFO,
996 "%s: Servicing the VOS TX WDI Message queue",__func__);
997
998 pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700999
1000 if (pMsgWrapper == NULL)
1001 {
1002 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001003 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001004 VOS_ASSERT(0);
1005 break;
1006 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001007
1008 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07001009
Jeff Johnsond13512a2012-07-17 11:42:19 -07001010 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
1011 {
1012 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001013 "%s: WDI Msg or Callback is NULL", __func__);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001014 VOS_ASSERT(0);
1015 break;
1016 }
1017
Jeff Johnson295189b2012-06-20 16:38:30 -07001018 pWdiMsg->callback(pWdiMsg);
1019
1020 // return message to the Core
1021 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1022
1023 continue;
1024 }
1025#else
1026 // Check the SSC queue
1027 if (!vos_is_mq_empty(&pSchedContext->sscTxMq))
1028 {
1029 // Service the PE message queue
1030 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1031 "%s: Servicing the VOS TX SSC Message queue",__func__);
1032 pMsgWrapper = vos_mq_get(&pSchedContext->sscTxMq);
1033 if (pMsgWrapper == NULL)
1034 {
1035 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001036 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001037 VOS_ASSERT(0);
1038 break;
1039 }
1040 vStatus = WLANSSC_ProcessMsg( pSchedContext->pVContext,
1041 pMsgWrapper->pVosMsg);
1042 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1043 {
1044 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1045 "%s: Issue Processing TX TL message",__func__);
1046 }
1047 // return message to the Core
1048 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1049 continue;
1050 }
1051
1052#endif
1053 /* Check for any Suspend Indication */
1054 if(test_bit(TX_SUSPEND_EVENT_MASK, &pSchedContext->txEventFlag))
1055 {
1056 clear_bit(TX_SUSPEND_EVENT_MASK, &pSchedContext->txEventFlag);
1057 spin_lock(&pSchedContext->TxThreadLock);
1058
1059 /* Tx Thread Suspended */
1060 complete(&pHddCtx->tx_sus_event_var);
1061
1062 INIT_COMPLETION(pSchedContext->ResumeTxEvent);
1063 spin_unlock(&pSchedContext->TxThreadLock);
1064
1065 /* Wait foe Resume Indication */
1066 wait_for_completion_interruptible(&pSchedContext->ResumeTxEvent);
1067 }
1068
1069 break; //All queues are empty now
1070 } // while message loop processing
1071 } // while TRUE
1072 // If we get here the TX thread must exit
1073 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001074 "%s: TX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001075 complete_and_exit(&pSchedContext->TxShutdown, 0);
1076} /* VosTxThread() */
1077
1078#ifdef FEATURE_WLAN_INTEGRATED_SOC
1079/*---------------------------------------------------------------------------
1080 \brief VosRXThread() - The VOSS Main Rx thread
1081 The \a VosRxThread() is the VOSS Rx controller thread:
1082 \param Arg - pointer to the global vOSS Sched Context
1083
1084 \return Thread exit code
1085 \sa VosRxThread()
1086 -------------------------------------------------------------------------*/
1087
1088static int VosRXThread ( void * Arg )
1089{
1090 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
1091 pVosMsgWrapper pMsgWrapper = NULL;
1092 int retWaitStatus = 0;
1093 v_BOOL_t shutdown = VOS_FALSE;
1094 hdd_context_t *pHddCtx = NULL;
1095 v_CONTEXT_t pVosContext = NULL;
1096 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1097
1098 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001099
1100#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -07001101 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001102#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001103
1104 if (Arg == NULL)
1105 {
1106 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001107 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001108 return 0;
1109 }
1110 daemonize("RX_Thread");
1111 /*
1112 ** Ack back to the context from which the main controller thread has been
1113 ** created.
1114 */
1115 complete(&pSchedContext->RxStartEvent);
1116 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1117 "%s: RX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
1118
1119 /* Get the Global VOSS Context */
1120 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
1121 if(!pVosContext) {
1122 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
1123 return 0;
1124 }
1125
1126 /* Get the HDD context */
1127 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1128 if(!pHddCtx) {
1129 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
1130 return 0;
1131 }
1132
1133 while(!shutdown)
1134 {
1135 // This implements the execution model algorithm
1136 retWaitStatus = wait_event_interruptible(pSchedContext->rxWaitQueue,
1137 test_bit(RX_POST_EVENT_MASK, &pSchedContext->rxEventFlag) ||
1138 test_bit(RX_SUSPEND_EVENT_MASK, &pSchedContext->rxEventFlag));
1139
1140
1141 if(retWaitStatus == -ERESTARTSYS)
1142 {
1143 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001144 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001145 break;
1146 }
1147 clear_bit(RX_POST_EVENT_MASK, &pSchedContext->rxEventFlag);
1148
1149 while(1)
1150 {
1151 if(test_bit(RX_SHUTDOWN_EVENT_MASK, &pSchedContext->rxEventFlag))
1152 {
1153 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1154 "%s: RX thread signaled to shutdown", __func__);
1155 shutdown = VOS_TRUE;
1156 /* Check for any Suspend Indication */
1157 if(test_bit(RX_SUSPEND_EVENT_MASK, &pSchedContext->rxEventFlag))
1158 {
1159 clear_bit(RX_SUSPEND_EVENT_MASK, &pSchedContext->rxEventFlag);
1160
1161 /* Unblock anyone waiting on suspend */
1162 complete(&pHddCtx->rx_sus_event_var);
1163 }
1164 break;
1165 }
1166
1167
1168 // Check the SYS queue first
1169 if (!vos_is_mq_empty(&pSchedContext->sysRxMq))
1170 {
1171 // Service the SYS message queue
1172 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1173 "%s: Servicing the VOS SYS RX Message queue",__func__);
1174 pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq);
1175 if (pMsgWrapper == NULL)
1176 {
1177 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001178 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001179 VOS_ASSERT(0);
1180 break;
1181 }
1182 vStatus = sysRxProcessMsg( pSchedContext->pVContext,
1183 pMsgWrapper->pVosMsg);
1184 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1185 {
1186 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1187 "%s: Issue Processing TX SYS message",__func__);
1188 }
1189 // return message to the Core
1190 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1191 continue;
1192 }
1193
1194 // Check the WDI queue
1195 if (!vos_is_mq_empty(&pSchedContext->wdiRxMq))
1196 {
1197 wpt_msg *pWdiMsg;
1198 VOS_TRACE(VOS_MODULE_ID_WDI, VOS_TRACE_LEVEL_INFO,
1199 "%s: Servicing the VOS RX WDI Message queue",__func__);
1200
1201 pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq);
1202 if ((NULL == pMsgWrapper) || (NULL == pMsgWrapper->pVosMsg))
1203 {
1204 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001205 "%s: wdiRxMq message is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001206 VOS_ASSERT(0);
1207 // we won't return this wrapper since it is corrupt
1208 }
1209 else
1210 {
1211 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
1212 if ((NULL == pWdiMsg) || (NULL == pWdiMsg->callback))
1213 {
1214 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001215 "%s: WDI Msg or callback is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001216 VOS_ASSERT(0);
1217 }
1218 else
1219 {
1220 // invoke the message handler
1221 pWdiMsg->callback(pWdiMsg);
1222 }
1223
1224 // return message to the Core
1225 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1226 }
1227 continue;
1228 }
1229
1230 /* Check for any Suspend Indication */
1231 if(test_bit(RX_SUSPEND_EVENT_MASK, &pSchedContext->rxEventFlag))
1232 {
1233 clear_bit(RX_SUSPEND_EVENT_MASK, &pSchedContext->rxEventFlag);
1234 spin_lock(&pSchedContext->RxThreadLock);
1235
1236 /* Rx Thread Suspended */
1237 complete(&pHddCtx->rx_sus_event_var);
1238
1239 init_completion(&pSchedContext->ResumeRxEvent);
1240 spin_unlock(&pSchedContext->RxThreadLock);
1241
1242 /* Wait for Resume Indication */
1243 wait_for_completion_interruptible(&pSchedContext->ResumeRxEvent);
1244 }
1245
1246 break; //All queues are empty now
1247 } // while message loop processing
1248 } // while TRUE
1249 // If we get here the RX thread must exit
1250 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001251 "%s: RX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001252 complete_and_exit(&pSchedContext->RxShutdown, 0);
1253} /* VosRxThread() */
1254#endif
1255
1256#endif
1257/*---------------------------------------------------------------------------
1258 \brief vos_sched_close() - Close the vOSS Scheduler
1259 The \a vos_sched_closes() function closes the vOSS Scheduler
1260 Upon successful closing:
1261 - All the message queues are flushed
1262 - The Main Controller thread is closed
1263 - The Tx thread is closed
1264
1265 \param pVosContext - pointer to the global vOSS Context
1266 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1267 is ready to be used.
1268 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
1269 function
1270 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
1271 \sa vos_sched_close()
1272---------------------------------------------------------------------------*/
1273VOS_STATUS vos_sched_close ( v_PVOID_t pVosContext )
1274{
1275 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001276 "%s: invoked", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001277 if (gpVosSchedContext == NULL)
1278 {
1279 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001280 "%s: gpVosSchedContext == NULL\n",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001281 return VOS_STATUS_E_FAILURE;
1282 }
1283
1284 // shut down MC Thread
1285 set_bit(MC_SHUTDOWN_EVENT_MASK, &gpVosSchedContext->mcEventFlag);
1286 set_bit(MC_POST_EVENT_MASK, &gpVosSchedContext->mcEventFlag);
1287 wake_up_interruptible(&gpVosSchedContext->mcWaitQueue);
1288 //Wait for MC to exit
1289 wait_for_completion_interruptible(&gpVosSchedContext->McShutdown);
1290 gpVosSchedContext->McThread = 0;
1291
1292#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1293 // shut down TX Thread
1294 set_bit(TX_SHUTDOWN_EVENT_MASK, &gpVosSchedContext->txEventFlag);
1295 set_bit(TX_POST_EVENT_MASK, &gpVosSchedContext->txEventFlag);
1296 wake_up_interruptible(&gpVosSchedContext->txWaitQueue);
1297 //Wait for TX to exit
1298 wait_for_completion_interruptible(&gpVosSchedContext->TxShutdown);
1299 gpVosSchedContext->TxThread = 0;
1300
1301#ifdef FEATURE_WLAN_INTEGRATED_SOC
1302 // shut down RX Thread
1303 set_bit(RX_SHUTDOWN_EVENT_MASK, &gpVosSchedContext->rxEventFlag);
1304 set_bit(RX_POST_EVENT_MASK, &gpVosSchedContext->rxEventFlag);
1305 wake_up_interruptible(&gpVosSchedContext->rxWaitQueue);
1306 //Wait for RX to exit
1307 wait_for_completion_interruptible(&gpVosSchedContext->RxShutdown);
1308 gpVosSchedContext->RxThread = 0;
1309#endif // FEATURE_WLAN_INTEGRATED_SOC
1310#endif // !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1311
1312 //Clean up message queues of TX and MC thread
1313 vos_sched_flush_mc_mqs(gpVosSchedContext);
1314#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1315 vos_sched_flush_tx_mqs(gpVosSchedContext);
1316#ifdef FEATURE_WLAN_INTEGRATED_SOC
1317 vos_sched_flush_rx_mqs(gpVosSchedContext);
1318#endif // FEATURE_WLAN_INTEGRATED_SOC
1319#endif // !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1320
1321 //Deinit all the queues
1322 vos_sched_deinit_mqs(gpVosSchedContext);
1323
1324 return VOS_STATUS_SUCCESS;
1325} /* vox_sched_close() */
1326
1327VOS_STATUS vos_watchdog_close ( v_PVOID_t pVosContext )
1328{
1329 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001330 "%s: vos_watchdog closing now", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001331 if (gpVosWatchdogContext == NULL)
1332 {
1333 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001334 "%s: gpVosWatchdogContext is NULL\n",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001335 return VOS_STATUS_E_FAILURE;
1336 }
1337 set_bit(WD_SHUTDOWN_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1338 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1339 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1340 //Wait for Watchdog thread to exit
1341 wait_for_completion_interruptible(&gpVosWatchdogContext->WdShutdown);
1342 return VOS_STATUS_SUCCESS;
1343} /* vos_watchdog_close() */
1344
1345VOS_STATUS vos_watchdog_chip_reset ( vos_chip_reset_reason_type reason )
1346{
1347#ifdef FEATURE_WLAN_NON_INTEGRATED_SOC
1348 v_CONTEXT_t pVosContext = NULL;
1349 hdd_context_t *pHddCtx = NULL;
1350 hdd_chip_reset_stats_t *pResetStats;
1351 struct sdio_func *sdio_func_dev = NULL;
1352
1353 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001354 "%s: vos_watchdog resetting WLAN", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001355 if (gpVosWatchdogContext == NULL)
1356 {
1357 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001358 "%s: Watchdog not enabled. LOGP ignored.",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001359 return VOS_STATUS_E_FAILURE;
1360 }
1361
1362 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
1363 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1364
1365 hdd_reset_all_adapters(pHddCtx);
1366
1367 sdio_func_dev = libra_getsdio_funcdev();
1368
1369 if(sdio_func_dev == NULL)
1370 {
1371 /* Our card got removed before LOGP. Continue with reset anyways */
1372 hddLog(VOS_TRACE_LEVEL_FATAL, "%s: sdio_func_dev is NULL!",__func__);
1373 return VOS_STATUS_SUCCESS;
1374 }
1375
1376 sd_claim_host(sdio_func_dev);
1377
1378 /* Disable SDIO IRQ since we are in LOGP state */
1379 libra_disable_sdio_irq_capability(sdio_func_dev, 1);
1380 libra_enable_sdio_irq(sdio_func_dev, 0);
1381
1382 sd_release_host(sdio_func_dev);
1383
1384 /* Take the lock here */
1385 spin_lock(&gpVosWatchdogContext->wdLock);
1386
1387 if (gpVosWatchdogContext->resetInProgress)
1388 {
1389 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1390 "%s: Reset already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001391 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001392 /* Release the lock here */
1393 spin_unlock(&gpVosWatchdogContext->wdLock);
1394 return VOS_STATUS_E_FAILURE;
1395 }
1396 else if (pHddCtx->isLogpInProgress)
1397 {
1398 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1399 "%s: LOGP already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001400 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001401 /* Release the lock here */
1402 spin_unlock(&gpVosWatchdogContext->wdLock);
1403 return VOS_STATUS_E_FAILURE;
1404 }
1405
1406 VOS_ASSERT(0);
1407
1408 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
1409 pAdapter = (hdd_adapter_t *)vos_get_context(VOS_MODULE_ID_HDD,pVosContext);
1410
1411 /* Set the flags so that all future CMD53 and Wext commands get blocked right away */
1412 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, TRUE);
1413 pHddCtx->isLogpInProgress = TRUE;
1414
1415 /* Release the lock here */
1416 spin_unlock(&gpVosWatchdogContext->wdLock);
1417
1418 if (pHddCtx->isLoadUnloadInProgress)
1419 {
1420 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1421 "%s: Load/unload in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001422 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001423 return VOS_STATUS_E_FAILURE;
1424 }
1425
1426#ifdef CONFIG_HAS_EARLYSUSPEND
1427 if(VOS_STATUS_SUCCESS != hdd_wlan_reset_initialization())
1428 {
1429 /* This can fail if card got removed by SDCC during resume */
1430 VOS_ASSERT(0);
1431 }
1432#endif
1433
1434 /* Update Reset Statistics */
1435 pResetStats = &pHddCtx->hddChipResetStats;
1436 pResetStats->totalLogpResets++;
1437
1438 switch (reason)
1439 {
1440 case VOS_CHIP_RESET_CMD53_FAILURE:
1441 pResetStats->totalCMD53Failures++;
1442 break;
1443 case VOS_CHIP_RESET_FW_EXCEPTION:
1444 pResetStats->totalFWHearbeatFailures++;
1445 break;
1446 case VOS_CHIP_RESET_MUTEX_READ_FAILURE:
1447 pResetStats->totalMutexReadFailures++;
1448 break;
1449 case VOS_CHIP_RESET_MIF_EXCEPTION:
1450 pResetStats->totalMIFErrorFailures++;
1451 break;
1452 default:
1453 pResetStats->totalUnknownExceptions++;
1454 break;
1455 }
1456
1457 set_bit(WD_CHIP_RESET_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1458 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1459 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1460#endif
1461 return VOS_STATUS_SUCCESS;
1462} /* vos_watchdog_chip_reset() */
1463
1464/*---------------------------------------------------------------------------
1465 \brief vos_sched_init_mqs: Initialize the vOSS Scheduler message queues
1466 The \a vos_sched_init_mqs() function initializes the vOSS Scheduler
1467 message queues.
1468 \param pVosSchedContext - pointer to the Scheduler Context.
1469 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1470 is ready to be used.
1471 VOS_STATUS_E_RESOURCES - System resources (other than memory)
1472 are unavailable to initilize the scheduler
1473
1474 \sa vos_sched_init_mqs()
1475 -------------------------------------------------------------------------*/
1476VOS_STATUS vos_sched_init_mqs ( pVosSchedContext pSchedContext )
1477{
1478 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1479 // Now intialize all the message queues
1480#ifdef FEATURE_WLAN_INTEGRATED_SOC
1481 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1482 "%s: Initializing the WDA MC Message queue",__func__);
1483 vStatus = vos_mq_init(&pSchedContext->wdaMcMq);
1484 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1485 {
1486 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1487 "%s: Failed to init WDA MC Message queue",__func__);
1488 VOS_ASSERT(0);
1489 return vStatus;
1490 }
1491#else
1492 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1493 "%s: Initializing the HAL MC Message queue",__func__);
1494 vStatus = vos_mq_init(&pSchedContext->halMcMq);
1495 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1496 {
1497 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1498 "%s: Failed to init HAL MC Message queue",__func__);
1499 VOS_ASSERT(0);
1500 return vStatus;
1501 }
1502#endif
1503#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1504 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1505 "%s: Initializing the PE MC Message queue",__func__);
1506 vStatus = vos_mq_init(&pSchedContext->peMcMq);
1507 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1508 {
1509 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1510 "%s: Failed to init PE MC Message queue",__func__);
1511 VOS_ASSERT(0);
1512 return vStatus;
1513 }
1514 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1515 "%s: Initializing the SME MC Message queue", __func__);
1516 vStatus = vos_mq_init(&pSchedContext->smeMcMq);
1517 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1518 {
1519 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1520 "%s: Failed to init SME MC Message queue",__func__);
1521 VOS_ASSERT(0);
1522 return vStatus;
1523 }
1524 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1525 "%s: Initializing the TL MC Message queue",__func__);
1526 vStatus = vos_mq_init(&pSchedContext->tlMcMq);
1527 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1528 {
1529 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1530 "%s: Failed to init TL MC Message queue",__func__);
1531 VOS_ASSERT(0);
1532 return vStatus;
1533 }
1534#endif
1535 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1536 "%s: Initializing the SYS MC Message queue",__func__);
1537 vStatus = vos_mq_init(&pSchedContext->sysMcMq);
1538 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1539 {
1540 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1541 "%s: Failed to init SYS MC Message queue",__func__);
1542 VOS_ASSERT(0);
1543 return vStatus;
1544 }
1545#ifdef FEATURE_WLAN_INTEGRATED_SOC
1546 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1547 "%s: Initializing the WDI MC Message queue",__func__);
1548
1549 vStatus = vos_mq_init(&pSchedContext->wdiMcMq);
1550 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1551 {
1552 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1553 "%s: Failed to init WDI MC Message queue",__func__);
1554 VOS_ASSERT(0);
1555 return vStatus;
1556 }
1557#endif
1558
1559#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1560 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1561 "%s: Initializing the TL Tx Message queue",__func__);
1562 vStatus = vos_mq_init(&pSchedContext->tlTxMq);
1563 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1564 {
1565 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1566 "%s: Failed to init TL TX Message queue",__func__);
1567 VOS_ASSERT(0);
1568 return vStatus;
1569 }
1570#ifndef FEATURE_WLAN_INTEGRATED_SOC
1571 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1572 "%s: Initializing the SSC Tx Message queue",__func__);
1573 vStatus = vos_mq_init(&pSchedContext->sscTxMq);
1574 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1575 {
1576 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1577 "%s: Failed to init SSC TX Message queue",__func__);
1578 VOS_ASSERT(0);
1579 return vStatus;
1580 }
1581#else
1582 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1583 "%s: Initializing the WDI Tx Message queue",__func__);
1584 vStatus = vos_mq_init(&pSchedContext->wdiTxMq);
1585 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1586 {
1587 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1588 "%s: Failed to init WDI TX Message queue",__func__);
1589 VOS_ASSERT(0);
1590 return vStatus;
1591 }
1592
1593 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1594 "%s: Initializing the WDI Rx Message queue",__func__);
1595
1596 vStatus = vos_mq_init(&pSchedContext->wdiRxMq);
1597 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1598 {
1599 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1600 "%s: Failed to init WDI RX Message queue",__func__);
1601 VOS_ASSERT(0);
1602 return vStatus;
1603 }
1604
1605#endif
1606 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1607 "%s: Initializing the SYS Tx Message queue",__func__);
1608 vStatus = vos_mq_init(&pSchedContext->sysTxMq);
1609 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1610 {
1611 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1612 "%s: Failed to init SYS TX Message queue",__func__);
1613 VOS_ASSERT(0);
1614 return vStatus;
1615 }
1616
1617 vStatus = vos_mq_init(&pSchedContext->sysRxMq);
1618 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1619 {
1620 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1621 "%s: Failed to init SYS RX Message queue",__func__);
1622 VOS_ASSERT(0);
1623 return vStatus;
1624 }
1625#endif
1626 return VOS_STATUS_SUCCESS;
1627} /* vos_sched_init_mqs() */
1628
1629/*---------------------------------------------------------------------------
1630 \brief vos_sched_deinit_mqs: Deinitialize the vOSS Scheduler message queues
1631 The \a vos_sched_init_mqs() function deinitializes the vOSS Scheduler
1632 message queues.
1633 \param pVosSchedContext - pointer to the Scheduler Context.
1634 \return None
1635 \sa vos_sched_deinit_mqs()
1636 -------------------------------------------------------------------------*/
1637void vos_sched_deinit_mqs ( pVosSchedContext pSchedContext )
1638{
1639 // Now de-intialize all message queues
1640#ifndef FEATURE_WLAN_INTEGRATED_SOC
1641 // MC HAL
1642 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1643 "%s De-Initializing the HAL MC Message queue",__func__);
1644 vos_mq_deinit(&pSchedContext->halMcMq);
1645#else
1646 // MC WDA
1647 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1648 "%s De-Initializing the WDA MC Message queue",__func__);
1649 vos_mq_deinit(&pSchedContext->wdaMcMq);
1650#endif
1651#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1652 //MC PE
1653 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1654 "%s De-Initializing the PE MC Message queue",__func__);
1655 vos_mq_deinit(&pSchedContext->peMcMq);
1656 //MC SME
1657 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1658 "%s De-Initializing the SME MC Message queue",__func__);
1659 vos_mq_deinit(&pSchedContext->smeMcMq);
1660 //MC TL
1661 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1662 "%s De-Initializing the TL MC Message queue",__func__);
1663 vos_mq_deinit(&pSchedContext->tlMcMq);
1664#endif
1665 //MC SYS
1666 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1667 "%s De-Initializing the SYS MC Message queue",__func__);
1668 vos_mq_deinit(&pSchedContext->sysMcMq);
1669#ifdef FEATURE_WLAN_INTEGRATED_SOC
1670 // MC WDI
1671 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1672 "%s De-Initializing the WDI MC Message queue",__func__);
1673 vos_mq_deinit(&pSchedContext->wdiMcMq);
1674#endif
1675
1676#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1677 //Tx TL
1678 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1679 "%s De-Initializing the TL Tx Message queue",__func__);
1680 vos_mq_deinit(&pSchedContext->tlTxMq);
1681#ifndef FEATURE_WLAN_INTEGRATED_SOC
1682 //Tx SSC
1683 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1684 "%s: DeInitializing the SSC Tx Message queue",__func__);
1685 vos_mq_deinit(&pSchedContext->sscTxMq);
1686
1687#else
1688 //Tx WDI
1689 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1690 "%s: DeInitializing the WDI Tx Message queue",__func__);
1691 vos_mq_deinit(&pSchedContext->wdiTxMq);
1692
1693
1694 //Rx WDI
1695 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1696 "%s: DeInitializing the WDI Rx Message queue",__func__);
1697 vos_mq_deinit(&pSchedContext->wdiRxMq);
1698#endif
1699
1700 //Tx SYS
1701 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1702 "%s: DeInitializing the SYS Tx Message queue",__func__);
1703 vos_mq_deinit(&pSchedContext->sysTxMq);
1704
1705 //Rx SYS
1706 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1707 "%s: DeInitializing the SYS Rx Message queue",__func__);
1708 vos_mq_deinit(&pSchedContext->sysRxMq);
1709
1710#endif
1711} /* vos_sched_deinit_mqs() */
1712
1713/*-------------------------------------------------------------------------
1714 this helper function flushes all the MC message queues
1715 -------------------------------------------------------------------------*/
1716void vos_sched_flush_mc_mqs ( pVosSchedContext pSchedContext )
1717{
1718 pVosMsgWrapper pMsgWrapper = NULL;
1719 pVosContextType vosCtx;
1720
1721 /*
1722 ** Here each of the MC thread MQ shall be drained and returned to the
1723 ** Core. Before returning a wrapper to the Core, the VOS message shall be
1724 ** freed first
1725 */
1726 VOS_TRACE( VOS_MODULE_ID_VOSS,
1727 VOS_TRACE_LEVEL_INFO,
1728 ("Flushing the MC Thread message queue\n") );
1729
1730 if (NULL == pSchedContext)
1731 {
1732 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001733 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001734 return;
1735 }
1736
1737 vosCtx = (pVosContextType)(pSchedContext->pVContext);
1738 if (NULL == vosCtx)
1739 {
1740 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001741 "%s: vosCtx is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001742 return;
1743 }
1744
1745 /* Flush the SYS Mq */
1746 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq) ))
1747 {
1748 VOS_TRACE( VOS_MODULE_ID_VOSS,
1749 VOS_TRACE_LEVEL_INFO,
1750 "%s: Freeing MC SYS message type %d ",__func__,
1751 pMsgWrapper->pVosMsg->type );
1752 sysMcFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1753 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1754 }
1755#ifndef FEATURE_WLAN_INTEGRATED_SOC
1756 /* Flush the HAL Mq */
1757 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->halMcMq) ))
1758 {
1759 VOS_TRACE( VOS_MODULE_ID_VOSS,
1760 VOS_TRACE_LEVEL_INFO,
1761 "%s: Freeing MC HAL MSG message type %d",__func__,
1762 pMsgWrapper->pVosMsg->type );
1763 halFreeMsg(vosCtx->pMACContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
1764 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1765 }
1766#else
1767 /* Flush the WDA Mq */
1768 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq) ))
1769 {
1770 if(pMsgWrapper->pVosMsg != NULL)
1771 {
1772 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1773 "%s: Freeing MC WDA MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001774 __func__, pMsgWrapper->pVosMsg->type );
Jeff Johnson295189b2012-06-20 16:38:30 -07001775 if (pMsgWrapper->pVosMsg->bodyptr) {
1776 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1777 }
1778
1779 pMsgWrapper->pVosMsg->bodyptr = NULL;
1780 pMsgWrapper->pVosMsg->bodyval = 0;
1781 pMsgWrapper->pVosMsg->type = 0;
1782 }
1783 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1784 }
1785
1786 /* Flush the WDI Mq */
1787 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq) ))
1788 {
1789 if(pMsgWrapper->pVosMsg != NULL)
1790 {
1791 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1792 "%s: Freeing MC WDI MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001793 __func__, pMsgWrapper->pVosMsg->type );
Jeff Johnson295189b2012-06-20 16:38:30 -07001794 if (pMsgWrapper->pVosMsg->bodyptr) {
1795 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1796 }
1797
1798 pMsgWrapper->pVosMsg->bodyptr = NULL;
1799 pMsgWrapper->pVosMsg->bodyval = 0;
1800 pMsgWrapper->pVosMsg->type = 0;
1801 }
1802 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1803 }
1804
1805#endif
1806#if !defined(ANI_MANF_DIAG) || defined(FEATURE_WLAN_INTEGRATED_SOC)
1807 /* Flush the PE Mq */
1808 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq) ))
1809 {
1810 VOS_TRACE( VOS_MODULE_ID_VOSS,
1811 VOS_TRACE_LEVEL_INFO,
1812 "%s: Freeing MC PE MSG message type %d",__func__,
1813 pMsgWrapper->pVosMsg->type );
1814 peFreeMsg(vosCtx->pMACContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
1815 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1816 }
1817 /* Flush the SME Mq */
1818 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq) ))
1819 {
1820 VOS_TRACE( VOS_MODULE_ID_VOSS,
1821 VOS_TRACE_LEVEL_INFO,
1822 "%s: Freeing MC SME MSG message type %d", __func__,
1823 pMsgWrapper->pVosMsg->type );
1824 sme_FreeMsg(vosCtx->pMACContext, pMsgWrapper->pVosMsg);
1825 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1826 }
1827 /* Flush the TL Mq */
1828 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq) ))
1829 {
1830 VOS_TRACE( VOS_MODULE_ID_VOSS,
1831 VOS_TRACE_LEVEL_INFO,
1832 "%s: Freeing MC TL message type %d",__func__,
1833 pMsgWrapper->pVosMsg->type );
1834 WLANTL_McFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1835 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1836 }
1837#endif
1838} /* vos_sched_flush_mc_mqs() */
1839
1840/*-------------------------------------------------------------------------
1841 This helper function flushes all the TX message queues
1842 ------------------------------------------------------------------------*/
1843void vos_sched_flush_tx_mqs ( pVosSchedContext pSchedContext )
1844{
1845 pVosMsgWrapper pMsgWrapper = NULL;
1846 /*
1847 ** Here each of the TX thread MQ shall be drained and returned to the
1848 ** Core. Before returning a wrapper to the Core, the VOS message shall
1849 ** be freed first
1850 */
1851 VOS_TRACE( VOS_MODULE_ID_VOSS,
1852 VOS_TRACE_LEVEL_INFO,
1853 "%s: Flushing the TX Thread message queue",__func__);
1854
1855 if (NULL == pSchedContext)
1856 {
1857 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001858 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001859 return;
1860 }
1861
1862 /* Flush the SYS Mq */
1863 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq) ))
1864 {
1865 VOS_TRACE( VOS_MODULE_ID_VOSS,
1866 VOS_TRACE_LEVEL_INFO,
1867 "%s: Freeing TX SYS message type %d",__func__,
1868 pMsgWrapper->pVosMsg->type );
1869 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1870 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1871 }
1872 /* Flush the TL Mq */
1873 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq) ))
1874 {
1875 VOS_TRACE( VOS_MODULE_ID_VOSS,
1876 VOS_TRACE_LEVEL_INFO,
1877 "%s: Freeing TX TL MSG message type %d",__func__,
1878 pMsgWrapper->pVosMsg->type );
1879 WLANTL_TxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1880 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1881 }
1882#ifndef FEATURE_WLAN_INTEGRATED_SOC
1883 /* Flush the SSC Mq */
1884 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sscTxMq) ))
1885 {
1886 VOS_TRACE( VOS_MODULE_ID_VOSS,
1887 VOS_TRACE_LEVEL_INFO,
1888 "%s: Freeing TX SSC MSG message type %d",__func__,
1889 pMsgWrapper->pVosMsg->type );
1890 WLANSSC_FreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1891 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1892 }
1893#else
1894 /* Flush the WDI Mq */
1895 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq) ))
1896 {
1897 VOS_TRACE( VOS_MODULE_ID_VOSS,
1898 VOS_TRACE_LEVEL_INFO,
1899 "%s: Freeing TX WDI MSG message type %d",__func__,
1900 pMsgWrapper->pVosMsg->type );
1901 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1902 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1903 }
1904 #endif
1905} /* vos_sched_flush_tx_mqs() */
1906#ifdef FEATURE_WLAN_INTEGRATED_SOC
1907/*-------------------------------------------------------------------------
1908 This helper function flushes all the RX message queues
1909 ------------------------------------------------------------------------*/
1910void vos_sched_flush_rx_mqs ( pVosSchedContext pSchedContext )
1911{
1912 pVosMsgWrapper pMsgWrapper = NULL;
1913 /*
1914 ** Here each of the RX thread MQ shall be drained and returned to the
1915 ** Core. Before returning a wrapper to the Core, the VOS message shall
1916 ** be freed first
1917 */
1918 VOS_TRACE( VOS_MODULE_ID_VOSS,
1919 VOS_TRACE_LEVEL_INFO,
1920 "%s: Flushing the RX Thread message queue",__func__);
1921
1922 if (NULL == pSchedContext)
1923 {
1924 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001925 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001926 return;
1927 }
1928
1929 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq) ))
1930 {
1931 VOS_TRACE( VOS_MODULE_ID_VOSS,
1932 VOS_TRACE_LEVEL_INFO,
1933 "%s: Freeing RX WDI MSG message type %d",__func__,
1934 pMsgWrapper->pVosMsg->type );
1935 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1936 }
1937
1938 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq) ))
1939 {
1940 VOS_TRACE( VOS_MODULE_ID_VOSS,
1941 VOS_TRACE_LEVEL_INFO,
1942 "%s: Freeing RX SYS MSG message type %d",__func__,
1943 pMsgWrapper->pVosMsg->type );
1944 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1945 }
1946
1947}/* vos_sched_flush_rx_mqs() */
1948#endif
1949
1950/*-------------------------------------------------------------------------
1951 This helper function helps determine if thread id is of TX thread
1952 ------------------------------------------------------------------------*/
1953int vos_sched_is_tx_thread(int threadID)
1954{
1955 // Make sure that Vos Scheduler context has been initialized
1956 VOS_ASSERT( NULL != gpVosSchedContext);
1957 if (gpVosSchedContext == NULL)
1958 {
1959 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001960 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001961 return 0;
1962 }
1963 return ((gpVosSchedContext->TxThread) && (threadID == gpVosSchedContext->TxThread->pid));
1964}
1965#ifdef FEATURE_WLAN_INTEGRATED_SOC
1966/*-------------------------------------------------------------------------
1967 This helper function helps determine if thread id is of RX thread
1968 ------------------------------------------------------------------------*/
1969int vos_sched_is_rx_thread(int threadID)
1970{
1971 // Make sure that Vos Scheduler context has been initialized
1972 VOS_ASSERT( NULL != gpVosSchedContext);
1973 if (gpVosSchedContext == NULL)
1974 {
1975 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001976 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001977 return 0;
1978 }
1979 return ((gpVosSchedContext->RxThread) && (threadID == gpVosSchedContext->RxThread->pid));
1980}
1981#endif
1982/*-------------------------------------------------------------------------
1983 Helper function to get the scheduler context
1984 ------------------------------------------------------------------------*/
1985pVosSchedContext get_vos_sched_ctxt(void)
1986{
1987 //Make sure that Vos Scheduler context has been initialized
1988 if (gpVosSchedContext == NULL)
1989 {
1990 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001991 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001992 }
1993 return (gpVosSchedContext);
1994}
1995/*-------------------------------------------------------------------------
1996 Helper function to get the watchdog context
1997 ------------------------------------------------------------------------*/
1998pVosWatchdogContext get_vos_watchdog_ctxt(void)
1999{
2000 //Make sure that Vos Scheduler context has been initialized
2001 if (gpVosWatchdogContext == NULL)
2002 {
2003 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002004 "%s: gpVosWatchdogContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002005 }
2006 return (gpVosWatchdogContext);
2007}
2008/**
2009 @brief vos_watchdog_wlan_shutdown()
2010
2011 This function is called to shutdown WLAN driver during SSR.
2012 Adapters are disabled, and the watchdog task will be signalled
2013 to shutdown WLAN driver.
2014
2015 @param
2016 NONE
2017 @return
2018 VOS_STATUS_SUCCESS - Operation completed successfully.
2019 VOS_STATUS_E_FAILURE - Operation failed.
2020
2021*/
2022VOS_STATUS vos_watchdog_wlan_shutdown(void)
2023{
2024 v_CONTEXT_t pVosContext = NULL;
2025 hdd_context_t *pHddCtx = NULL;
2026
2027 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002028 "%s: WLAN driver is shutting down ", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002029 if (NULL == gpVosWatchdogContext)
2030 {
2031 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002032 "%s: Watchdog not enabled. LOGP ignored.", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002033 return VOS_STATUS_E_FAILURE;
2034 }
2035
2036 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
2037 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
2038 if (NULL == pHddCtx)
2039 {
2040 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002041 "%s: Invalid HDD Context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002042 return VOS_STATUS_E_FAILURE;
2043 }
2044
2045 /* Take the lock here */
2046 spin_lock(&gpVosWatchdogContext->wdLock);
2047
2048 /* reuse the existing 'reset in progress' */
2049 if (gpVosWatchdogContext->resetInProgress)
2050 {
2051 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2052 "%s: Shutdown already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002053 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002054 /* Release the lock here */
2055 spin_unlock(&gpVosWatchdogContext->wdLock);
2056 return VOS_STATUS_E_FAILURE;
2057 }
2058 /* reuse the existing 'logp in progress', eventhough it is not
2059 * exactly the same */
2060 else if (pHddCtx->isLogpInProgress)
2061 {
2062 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2063 "%s: shutdown/re-init already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002064 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002065 /* Release the lock here */
2066 spin_unlock(&gpVosWatchdogContext->wdLock);
2067 return VOS_STATUS_E_FAILURE;
2068 }
2069
2070 /* Set the flags so that all future CMD53 and Wext commands get blocked right away */
2071 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, TRUE);
2072 pHddCtx->isLogpInProgress = TRUE;
2073
2074 /* Release the lock here */
2075 spin_unlock(&gpVosWatchdogContext->wdLock);
2076
2077 if (pHddCtx->isLoadUnloadInProgress)
2078 {
2079 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2080 "%s: Load/unload in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002081 __func__);
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002082 /* wcnss has crashed, and SSR has alredy been started by Kernel driver.
2083 * So disable SSR from WLAN driver */
2084 hdd_set_ssr_required( HDD_SSR_DISABLED );
Jeff Johnson295189b2012-06-20 16:38:30 -07002085 return VOS_STATUS_E_FAILURE;
2086 }
2087 /* Update Riva Reset Statistics */
2088 pHddCtx->hddRivaResetStats++;
2089#ifdef CONFIG_HAS_EARLYSUSPEND
2090 if(VOS_STATUS_SUCCESS != hdd_wlan_reset_initialization())
2091 {
2092 VOS_ASSERT(0);
2093 }
2094#endif
2095
2096 set_bit(WD_WLAN_SHUTDOWN_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
2097 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
2098 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
2099
2100 return VOS_STATUS_SUCCESS;
2101}
2102
2103/**
2104 @brief vos_watchdog_wlan_re_init()
2105
2106 This function is called to re-initialize WLAN driver, and this is
2107 called when Riva SS reboots.
2108
2109 @param
2110 NONE
2111 @return
2112 VOS_STATUS_SUCCESS - Operation completed successfully.
2113 VOS_STATUS_E_FAILURE - Operation failed.
2114
2115*/
2116VOS_STATUS vos_watchdog_wlan_re_init(void)
2117{
2118 /* watchdog task is still running, it is not closed in shutdown */
2119 set_bit(WD_WLAN_REINIT_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
2120 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
2121 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
2122
2123 return VOS_STATUS_SUCCESS;
2124}