blob: 27a4dbe63d12f0d6539cab23bc7967f913607d36 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lam1ed83fc2014-02-19 01:15:45 -08002 * Copyright (c) 2012-2014 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.
Gopichand Nakkala92f07d82013-01-08 21:16:34 -080020 */
Kiet Lam1ed83fc2014-02-19 01:15:45 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028/*===========================================================================
29 @file vos_sched.c
30 @brief VOS Scheduler Implementation
31
Jeff Johnson295189b2012-06-20 16:38:30 -070032===========================================================================*/
33/*===========================================================================
34 EDIT HISTORY FOR FILE
35
36 This section contains comments describing changes made to the module.
37 Notice that changes are listed in reverse chronological order.
38
39 $Header:$ $DateTime: $ $Author: $
40
41 when who what, where, why
42 -------- --- --------------------------------------------------------
43===========================================================================*/
44/*---------------------------------------------------------------------------
45 * Include Files
46 * ------------------------------------------------------------------------*/
47#include <vos_mq.h>
48#include <vos_api.h>
49#include <aniGlobal.h>
50#include <sirTypes.h>
51#include <halTypes.h>
52#include <limApi.h>
53#include <sme_Api.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070054#include <wlan_qct_sys.h>
55#include <wlan_qct_tl.h>
56#include "vos_sched.h"
57#include <wlan_hdd_power.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070058#include "wlan_qct_wda.h"
59#include "wlan_qct_pal_msg.h"
Jeff Johnson295189b2012-06-20 16:38:30 -070060#include <linux/spinlock.h>
61#include <linux/kthread.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070062/*---------------------------------------------------------------------------
63 * Preprocessor Definitions and Constants
64 * ------------------------------------------------------------------------*/
65#define VOS_SCHED_THREAD_HEART_BEAT INFINITE
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +053066/* Milli seconds to delay SSR thread when an Entry point is Active */
67#define SSR_WAIT_SLEEP_TIME 100
68/* MAX iteration count to wait for Entry point to exit before
69 * we proceed with SSR in WD Thread
70 */
Pradeep Kumar Goudagunta21c08c42014-07-14 15:59:43 +053071#define MAX_SSR_WAIT_ITERATIONS 200
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +053072
73static atomic_t ssr_protect_entry_count;
74
Jeff Johnson295189b2012-06-20 16:38:30 -070075/*---------------------------------------------------------------------------
76 * Type Declarations
77 * ------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------
79 * Data definitions
80 * ------------------------------------------------------------------------*/
81static pVosSchedContext gpVosSchedContext;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070082static pVosWatchdogContext gpVosWatchdogContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070083
84/*---------------------------------------------------------------------------
85 * Forward declaration
86 * ------------------------------------------------------------------------*/
Jeff Johnson2f5cfec2013-02-22 21:25:10 -080087static int VosMCThread(void *Arg);
88static int VosWDThread(void *Arg);
89static int VosTXThread(void *Arg);
90static int VosRXThread(void *Arg);
Jeff Johnson295189b2012-06-20 16:38:30 -070091void vos_sched_flush_rx_mqs(pVosSchedContext SchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -070092extern v_VOID_t vos_core_return_msg(v_PVOID_t pVContext, pVosMsgWrapper pMsgWrapper);
93/*---------------------------------------------------------------------------
94 * External Function implementation
95 * ------------------------------------------------------------------------*/
96
97/*---------------------------------------------------------------------------
98 \brief vos_sched_open() - initialize the vOSS Scheduler
99 The \a vos_sched_open() function initializes the vOSS Scheduler
100 Upon successful initialization:
101 - All the message queues are initialized
102 - The Main Controller thread is created and ready to receive and
103 dispatch messages.
104 - The Tx thread is created and ready to receive and dispatch messages
105
106 \param pVosContext - pointer to the global vOSS Context
107 \param pVosSchedContext - pointer to a previously allocated buffer big
108 enough to hold a scheduler context.
109 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
110 is ready to be used.
111 VOS_STATUS_E_RESOURCES - System resources (other than memory)
112 are unavailable to initilize the scheduler
113 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
114 the scheduler
115 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
116 function
117 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
118 \sa vos_sched_open()
119 -------------------------------------------------------------------------*/
120VOS_STATUS
121vos_sched_open
122(
123 v_PVOID_t pVosContext,
124 pVosSchedContext pSchedContext,
125 v_SIZE_t SchedCtxSize
126)
127{
128 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
129/*-------------------------------------------------------------------------*/
130 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
131 "%s: Opening the VOSS Scheduler",__func__);
132 // Sanity checks
133 if ((pVosContext == NULL) || (pSchedContext == NULL)) {
134 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
135 "%s: Null params being passed",__func__);
136 return VOS_STATUS_E_FAILURE;
137 }
138 if (sizeof(VosSchedContext) != SchedCtxSize)
139 {
140 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
141 "%s: Incorrect VOS Sched Context size passed",__func__);
142 return VOS_STATUS_E_INVAL;
143 }
144 vos_mem_zero(pSchedContext, sizeof(VosSchedContext));
145 pSchedContext->pVContext = pVosContext;
146 vStatus = vos_sched_init_mqs(pSchedContext);
147 if (!VOS_IS_STATUS_SUCCESS(vStatus))
148 {
149 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
150 "%s: Failed to initialize VOS Scheduler MQs",__func__);
151 return vStatus;
152 }
153 // Initialize the helper events and event queues
154 init_completion(&pSchedContext->McStartEvent);
155 init_completion(&pSchedContext->TxStartEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700156 init_completion(&pSchedContext->RxStartEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700157 init_completion(&pSchedContext->McShutdown);
158 init_completion(&pSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700159 init_completion(&pSchedContext->RxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700160 init_completion(&pSchedContext->ResumeMcEvent);
161 init_completion(&pSchedContext->ResumeTxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700162 init_completion(&pSchedContext->ResumeRxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700163
164 spin_lock_init(&pSchedContext->McThreadLock);
165 spin_lock_init(&pSchedContext->TxThreadLock);
166 spin_lock_init(&pSchedContext->RxThreadLock);
167
168 init_waitqueue_head(&pSchedContext->mcWaitQueue);
169 pSchedContext->mcEventFlag = 0;
170 init_waitqueue_head(&pSchedContext->txWaitQueue);
171 pSchedContext->txEventFlag= 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700172 init_waitqueue_head(&pSchedContext->rxWaitQueue);
173 pSchedContext->rxEventFlag= 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700174 /*
Jeff Johnson2f5cfec2013-02-22 21:25:10 -0800175 ** This initialization is critical as the threads will later access the
Jeff Johnson295189b2012-06-20 16:38:30 -0700176 ** global contexts normally,
177 **
178 ** I shall put some memory barrier here after the next piece of code but
179 ** I am keeping it simple for now.
180 */
181 gpVosSchedContext = pSchedContext;
182
183 //Create the VOSS Main Controller thread
184 pSchedContext->McThread = kthread_create(VosMCThread, pSchedContext,
185 "VosMCThread");
186 if (IS_ERR(pSchedContext->McThread))
187 {
188 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
189 "%s: Could not Create VOSS Main Thread Controller",__func__);
190 goto MC_THREAD_START_FAILURE;
191 }
192 wake_up_process(pSchedContext->McThread);
193 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
194 "%s: VOSS Main Controller thread Created",__func__);
195
Jeff Johnson295189b2012-06-20 16:38:30 -0700196 pSchedContext->TxThread = kthread_create(VosTXThread, pSchedContext,
197 "VosTXThread");
198 if (IS_ERR(pSchedContext->TxThread))
199 {
200 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
201 "%s: Could not Create VOSS TX Thread",__func__);
202 goto TX_THREAD_START_FAILURE;
203 }
204 wake_up_process(pSchedContext->TxThread);
205 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussain02882402013-11-17 21:55:29 -0800206 ("VOSS TX thread Created"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700207
Jeff Johnson295189b2012-06-20 16:38:30 -0700208 pSchedContext->RxThread = kthread_create(VosRXThread, pSchedContext,
209 "VosRXThread");
210 if (IS_ERR(pSchedContext->RxThread))
211 {
212
213 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
214 "%s: Could not Create VOSS RX Thread",__func__);
215 goto RX_THREAD_START_FAILURE;
216
217 }
218 wake_up_process(pSchedContext->RxThread);
219 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussain02882402013-11-17 21:55:29 -0800220 ("VOSS RX thread Created"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700221
222 /*
223 ** Now make sure all threads have started before we exit.
224 ** Each thread should normally ACK back when it starts.
225 */
226 wait_for_completion_interruptible(&pSchedContext->McStartEvent);
227 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
228 "%s: VOSS MC Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700229 wait_for_completion_interruptible(&pSchedContext->TxStartEvent);
230 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
231 "%s: VOSS Tx Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700232 wait_for_completion_interruptible(&pSchedContext->RxStartEvent);
233 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
234 "%s: VOSS Rx Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700235
236 /*
237 ** We're good now: Let's get the ball rolling!!!
238 */
239 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
240 "%s: VOSS Scheduler successfully Opened",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700241 return VOS_STATUS_SUCCESS;
242
Jeff Johnson295189b2012-06-20 16:38:30 -0700243
Jeff Johnson295189b2012-06-20 16:38:30 -0700244RX_THREAD_START_FAILURE:
245 //Try and force the Tx thread controller to exit
246 set_bit(MC_SHUTDOWN_EVENT_MASK, &pSchedContext->txEventFlag);
247 set_bit(MC_POST_EVENT_MASK, &pSchedContext->txEventFlag);
248 wake_up_interruptible(&pSchedContext->txWaitQueue);
249 //Wait for TX to exit
250 wait_for_completion_interruptible(&pSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700251
252TX_THREAD_START_FAILURE:
253 //Try and force the Main thread controller to exit
254 set_bit(MC_SHUTDOWN_EVENT_MASK, &pSchedContext->mcEventFlag);
255 set_bit(MC_POST_EVENT_MASK, &pSchedContext->mcEventFlag);
256 wake_up_interruptible(&pSchedContext->mcWaitQueue);
257 //Wait for MC to exit
258 wait_for_completion_interruptible(&pSchedContext->McShutdown);
259
Jeff Johnson295189b2012-06-20 16:38:30 -0700260MC_THREAD_START_FAILURE:
261 //De-initialize all the message queues
262 vos_sched_deinit_mqs(pSchedContext);
263 return VOS_STATUS_E_RESOURCES;
264
265} /* vos_sched_open() */
266
267VOS_STATUS vos_watchdog_open
268(
269 v_PVOID_t pVosContext,
270 pVosWatchdogContext pWdContext,
271 v_SIZE_t wdCtxSize
272)
273{
274/*-------------------------------------------------------------------------*/
275 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
276 "%s: Opening the VOSS Watchdog module",__func__);
277 //Sanity checks
278 if ((pVosContext == NULL) || (pWdContext == NULL)) {
279 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
280 "%s: Null params being passed",__func__);
281 return VOS_STATUS_E_FAILURE;
282 }
283 if (sizeof(VosWatchdogContext) != wdCtxSize)
284 {
285 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
286 "%s: Incorrect VOS Watchdog Context size passed",__func__);
287 return VOS_STATUS_E_INVAL;
288 }
289 vos_mem_zero(pWdContext, sizeof(VosWatchdogContext));
290 pWdContext->pVContext = pVosContext;
291 gpVosWatchdogContext = pWdContext;
292
293 //Initialize the helper events and event queues
294 init_completion(&pWdContext->WdStartEvent);
295 init_completion(&pWdContext->WdShutdown);
296 init_waitqueue_head(&pWdContext->wdWaitQueue);
297 pWdContext->wdEventFlag = 0;
298
299 // Initialize the lock
300 spin_lock_init(&pWdContext->wdLock);
301
302 //Create the Watchdog thread
303 pWdContext->WdThread = kthread_create(VosWDThread, pWdContext,"VosWDThread");
304
305 if (IS_ERR(pWdContext->WdThread))
306 {
307 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
308 "%s: Could not Create Watchdog thread",__func__);
309 return VOS_STATUS_E_RESOURCES;
310 }
311 else
312 {
313 wake_up_process(pWdContext->WdThread);
314 }
315 /*
316 ** Now make sure thread has started before we exit.
317 ** Each thread should normally ACK back when it starts.
318 */
319 wait_for_completion_interruptible(&pWdContext->WdStartEvent);
320 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
321 "%s: VOSS Watchdog Thread has started",__func__);
322 return VOS_STATUS_SUCCESS;
323} /* vos_watchdog_open() */
324/*---------------------------------------------------------------------------
325 \brief VosMcThread() - The VOSS Main Controller thread
326 The \a VosMcThread() is the VOSS main controller thread:
327 \param Arg - pointer to the global vOSS Sched Context
328 \return Thread exit code
329 \sa VosMcThread()
330 -------------------------------------------------------------------------*/
331static int
332VosMCThread
333(
334 void * Arg
335)
336{
337 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
338 pVosMsgWrapper pMsgWrapper = NULL;
339 tpAniSirGlobal pMacContext = NULL;
340 tSirRetStatus macStatus = eSIR_SUCCESS;
341 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
342 int retWaitStatus = 0;
343 v_BOOL_t shutdown = VOS_FALSE;
344 hdd_context_t *pHddCtx = NULL;
345 v_CONTEXT_t pVosContext = NULL;
346
347 if (Arg == NULL)
348 {
349 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700350 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700351 return 0;
352 }
353 set_user_nice(current, -2);
354
Yue Maf49ba872013-08-19 12:04:25 -0700355#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700356 daemonize("MC_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700357#endif
358
Jeff Johnson295189b2012-06-20 16:38:30 -0700359 /*
360 ** Ack back to the context from which the main controller thread has been
361 ** created.
362 */
363 complete(&pSchedContext->McStartEvent);
364 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
365 "%s: MC Thread %d (%s) starting up",__func__, current->pid, current->comm);
366
367 /* Get the Global VOSS Context */
368 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
369 if(!pVosContext) {
370 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
371 return 0;
372 }
373
374 /* Get the HDD context */
375 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
376 if(!pHddCtx) {
377 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
378 return 0;
379 }
380
381 while(!shutdown)
382 {
383 // This implements the execution model algorithm
384 retWaitStatus = wait_event_interruptible(pSchedContext->mcWaitQueue,
385 test_bit(MC_POST_EVENT_MASK, &pSchedContext->mcEventFlag) ||
386 test_bit(MC_SUSPEND_EVENT_MASK, &pSchedContext->mcEventFlag));
387
388 if(retWaitStatus == -ERESTARTSYS)
389 {
390 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700391 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700392 break;
393 }
394 clear_bit(MC_POST_EVENT_MASK, &pSchedContext->mcEventFlag);
395
396 while(1)
397 {
398 // Check if MC needs to shutdown
399 if(test_bit(MC_SHUTDOWN_EVENT_MASK, &pSchedContext->mcEventFlag))
400 {
401 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
402 "%s: MC thread signaled to shutdown", __func__);
403 shutdown = VOS_TRUE;
404 /* Check for any Suspend Indication */
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530405 if (test_and_clear_bit(MC_SUSPEND_EVENT_MASK,
406 &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700407 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700408 /* Unblock anyone waiting on suspend */
409 complete(&pHddCtx->mc_sus_event_var);
410 }
411 break;
412 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700413 /*
414 ** Check the WDI queue
415 ** Service it till the entire queue is empty
416 */
417 if (!vos_is_mq_empty(&pSchedContext->wdiMcMq))
418 {
419 wpt_msg *pWdiMsg;
420 /*
421 ** Service the WDI message queue
422 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700423 pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700424
425 if (pMsgWrapper == NULL)
426 {
427 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700428 "%s: pMsgWrapper is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530429 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700430 break;
431 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700432
433 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnsond13512a2012-07-17 11:42:19 -0700434
435 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
436 {
437 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700438 "%s: WDI Msg or Callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530439 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700440 break;
441 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700442
443 pWdiMsg->callback(pWdiMsg);
444
445 /*
446 ** return message to the Core
447 */
448 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
449
450 continue;
451 }
452
Jeff Johnson295189b2012-06-20 16:38:30 -0700453 // Check the SYS queue first
454 if (!vos_is_mq_empty(&pSchedContext->sysMcMq))
455 {
456 // Service the SYS message queue
457 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
458 "%s: Servicing the VOS SYS MC Message queue",__func__);
459 pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq);
460 if (pMsgWrapper == NULL)
461 {
462 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700463 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700464 VOS_ASSERT(0);
465 break;
466 }
467 vStatus = sysMcProcessMsg(pSchedContext->pVContext,
468 pMsgWrapper->pVosMsg);
469 if (!VOS_IS_STATUS_SUCCESS(vStatus))
470 {
471 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
472 "%s: Issue Processing SYS message",__func__);
473 }
474 //return message to the Core
475 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
476 continue;
477 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700478 // Check the WDA queue
479 if (!vos_is_mq_empty(&pSchedContext->wdaMcMq))
480 {
481 // Service the WDA message queue
482 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
483 "%s: Servicing the VOS WDA MC Message queue",__func__);
484 pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq);
485 if (pMsgWrapper == NULL)
486 {
487 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700488 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700489 VOS_ASSERT(0);
490 break;
491 }
492 vStatus = WDA_McProcessMsg( pSchedContext->pVContext, pMsgWrapper->pVosMsg);
493 if (!VOS_IS_STATUS_SUCCESS(vStatus))
494 {
495 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
496 "%s: Issue Processing WDA message",__func__);
497 }
498 // return message to the Core
499 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
500 continue;
501 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700502 // Check the PE queue
503 if (!vos_is_mq_empty(&pSchedContext->peMcMq))
504 {
505 // Service the PE message queue
506 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
507 "%s: Servicing the VOS PE MC Message queue",__func__);
508 pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq);
509 if (NULL == pMsgWrapper)
510 {
511 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700512 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700513 VOS_ASSERT(0);
514 break;
515 }
516
517 /* Need some optimization*/
518 pMacContext = vos_get_context(VOS_MODULE_ID_PE, pSchedContext->pVContext);
519 if (NULL == pMacContext)
520 {
521 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
522 "MAC Context not ready yet");
523 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
524 continue;
525 }
526
527 macStatus = peProcessMessages( pMacContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
528 if (eSIR_SUCCESS != macStatus)
529 {
530 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
531 "%s: Issue Processing PE message",__func__);
532 }
533 // return message to the Core
534 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
535 continue;
536 }
537 /** Check the SME queue **/
538 if (!vos_is_mq_empty(&pSchedContext->smeMcMq))
539 {
540 /* Service the SME message queue */
541 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
542 "%s: Servicing the VOS SME MC Message queue",__func__);
543 pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq);
544 if (NULL == pMsgWrapper)
545 {
546 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700547 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700548 VOS_ASSERT(0);
549 break;
550 }
551
552 /* Need some optimization*/
553 pMacContext = vos_get_context(VOS_MODULE_ID_SME, pSchedContext->pVContext);
554 if (NULL == pMacContext)
555 {
556 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
557 "MAC Context not ready yet");
558 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
559 continue;
560 }
561
562 vStatus = sme_ProcessMsg( (tHalHandle)pMacContext, pMsgWrapper->pVosMsg);
563 if (!VOS_IS_STATUS_SUCCESS(vStatus))
564 {
565 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
566 "%s: Issue Processing SME message",__func__);
567 }
568 // return message to the Core
569 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
570 continue;
571 }
572 /** Check the TL queue **/
573 if (!vos_is_mq_empty(&pSchedContext->tlMcMq))
574 {
575 // Service the TL message queue
576 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
577 ("Servicing the VOS TL MC Message queue"));
578 pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq);
579 if (pMsgWrapper == NULL)
580 {
581 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700582 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700583 VOS_ASSERT(0);
584 break;
585 }
586 vStatus = WLANTL_McProcessMsg( pSchedContext->pVContext,
587 pMsgWrapper->pVosMsg);
588 if (!VOS_IS_STATUS_SUCCESS(vStatus))
589 {
590 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
591 "%s: Issue Processing TL message",__func__);
592 }
593 // return message to the Core
594 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
595 continue;
596 }
597 /* Check for any Suspend Indication */
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530598 if (test_and_clear_bit(MC_SUSPEND_EVENT_MASK,
599 &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700600 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700601 spin_lock(&pSchedContext->McThreadLock);
602
603 /* Mc Thread Suspended */
604 complete(&pHddCtx->mc_sus_event_var);
605
606 INIT_COMPLETION(pSchedContext->ResumeMcEvent);
607 spin_unlock(&pSchedContext->McThreadLock);
608
609 /* Wait foe Resume Indication */
610 wait_for_completion_interruptible(&pSchedContext->ResumeMcEvent);
611 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700612 break; //All queues are empty now
613 } // while message loop processing
614 } // while TRUE
615 // If we get here the MC thread must exit
616 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700617 "%s: MC Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700618 complete_and_exit(&pSchedContext->McShutdown, 0);
619} /* VosMCThread() */
Wilson Yang68349dd2014-02-06 17:30:38 -0800620
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530621v_BOOL_t isSsrPanicOnFailure(void)
622{
623 hdd_context_t *pHddCtx = NULL;
624 v_CONTEXT_t pVosContext = NULL;
625
626 /* Get the Global VOSS Context */
627 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
628 if(!pVosContext)
629 {
630 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
631 return FALSE;
632 }
633
634 /* Get the HDD context */
635 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
636 if((NULL == pHddCtx) || (NULL == pHddCtx->cfg_ini))
637 {
638 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null", __func__);
639 return FALSE;
640 }
641
642 return (pHddCtx->cfg_ini->fIsSsrPanicOnFailure);
643}
644
Jeff Johnson295189b2012-06-20 16:38:30 -0700645/*---------------------------------------------------------------------------
646 \brief VosWdThread() - The VOSS Watchdog thread
647 The \a VosWdThread() is the Watchdog thread:
648 \param Arg - pointer to the global vOSS Sched Context
649 \return Thread exit code
650 \sa VosMcThread()
651 -------------------------------------------------------------------------*/
652static int
653VosWDThread
654(
655 void * Arg
656)
657{
658 pVosWatchdogContext pWdContext = (pVosWatchdogContext)Arg;
659 int retWaitStatus = 0;
660 v_BOOL_t shutdown = VOS_FALSE;
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530661 int count = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700662 VOS_STATUS vosStatus = VOS_STATUS_SUCCESS;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530663 hdd_context_t *pHddCtx = NULL;
664 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700665 set_user_nice(current, -3);
666
667 if (Arg == NULL)
668 {
669 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700670 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700671 return 0;
672 }
Yue Maf49ba872013-08-19 12:04:25 -0700673
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530674 /* Get the Global VOSS Context */
675 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
676
677 if(!pVosContext)
678 {
679 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
680 return 0;
681 }
682
683 /* Get the HDD context */
684 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
685
686 if(!pHddCtx)
687 {
688 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
689 return 0;
690 }
691
Yue Maf49ba872013-08-19 12:04:25 -0700692#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700693 daemonize("WD_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700694#endif
695
Jeff Johnson295189b2012-06-20 16:38:30 -0700696 /*
697 ** Ack back to the context from which the Watchdog thread has been
698 ** created.
699 */
700 complete(&pWdContext->WdStartEvent);
701 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
702 "%s: Watchdog Thread %d (%s) starting up",__func__, current->pid, current->comm);
703
704 while(!shutdown)
705 {
706 // This implements the Watchdog execution model algorithm
707 retWaitStatus = wait_event_interruptible(pWdContext->wdWaitQueue,
708 test_bit(WD_POST_EVENT_MASK, &pWdContext->wdEventFlag));
709 if(retWaitStatus == -ERESTARTSYS)
710 {
711 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700712 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700713 break;
714 }
715 clear_bit(WD_POST_EVENT_MASK, &pWdContext->wdEventFlag);
716 while(1)
717 {
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530718 /* Check for any Active Entry Points
719 * If active, delay SSR until no entry point is active or
720 * delay until count is decremented to ZERO
721 */
722 count = MAX_SSR_WAIT_ITERATIONS;
723 while (count)
724 {
725 if (!atomic_read(&ssr_protect_entry_count))
726 {
727 /* no external threads are executing */
728 break;
729 }
730 /* at least one external thread is executing */
731 if (--count)
732 {
733 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
734 "%s: Waiting for active entry points to exit", __func__);
735 msleep(SSR_WAIT_SLEEP_TIME);
736 }
737 }
738 /* at least one external thread is executing */
739 if (!count)
740 {
741 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
742 "%s: Continuing SSR when %d Entry points are still active",
743 __func__, atomic_read(&ssr_protect_entry_count));
744 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700745 // Check if Watchdog needs to shutdown
746 if(test_bit(WD_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag))
747 {
748 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
749 "%s: Watchdog thread signaled to shutdown", __func__);
750
751 clear_bit(WD_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag);
752 shutdown = VOS_TRUE;
753 break;
754 }
755 /* subsystem restart: shutdown event handler */
756 else if(test_bit(WD_WLAN_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag))
757 {
758 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
759 "%s: Watchdog thread signaled to perform WLAN shutdown",__func__);
760 clear_bit(WD_WLAN_SHUTDOWN_EVENT_MASK, &pWdContext->wdEventFlag);
761
762 //Perform WLAN shutdown
763 if(!pWdContext->resetInProgress)
764 {
765 pWdContext->resetInProgress = true;
766 vosStatus = hdd_wlan_shutdown();
767
768 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
769 {
770 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
771 "%s: Failed to shutdown WLAN",__func__);
772 VOS_ASSERT(0);
773 goto err_reset;
774 }
775 }
776 }
777 /* subsystem restart: re-init event handler */
778 else if(test_bit(WD_WLAN_REINIT_EVENT_MASK, &pWdContext->wdEventFlag))
779 {
780 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
781 "%s: Watchdog thread signaled to perform WLAN re-init",__func__);
782 clear_bit(WD_WLAN_REINIT_EVENT_MASK, &pWdContext->wdEventFlag);
783
784 //Perform WLAN re-init
785 if(!pWdContext->resetInProgress)
786 {
787 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Katya Nigamb37c7812014-06-19 14:45:16 +0530788 "%s: Do WLAN re-init only when it is shutdown !!",__func__);
789 break;
Jeff Johnson295189b2012-06-20 16:38:30 -0700790 }
791 vosStatus = hdd_wlan_re_init();
792
793 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
794 {
795 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
796 "%s: Failed to re-init WLAN",__func__);
797 VOS_ASSERT(0);
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530798 pWdContext->isFatalError = true;
799 }
800 else
801 {
802 pWdContext->isFatalError = false;
Mukul Sharmae74e42c2015-08-06 23:55:49 +0530803 pHddCtx->isLogpInProgress = FALSE;
804 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700805 }
Mihir Shetefd528652014-06-23 19:07:50 +0530806 atomic_set(&pHddCtx->isRestartInProgress, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700807 pWdContext->resetInProgress = false;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530808 complete(&pHddCtx->ssr_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700809 }
810 else
811 {
812 //Unnecessary wakeup - Should never happen!!
813 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
814 "%s: Watchdog thread woke up unnecessarily",__func__);
815 }
816 break;
817 } // while message loop processing
818 } // while shutdown
819
820 // If we get here the Watchdog thread must exit
821 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700822 "%s: Watchdog Thread exiting !!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700823 complete_and_exit(&pWdContext->WdShutdown, 0);
824
825err_reset:
826 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700827 "%s: Watchdog Thread Failed to Reset, Exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700828 return 0;
829
830} /* VosMCThread() */
831
832/*---------------------------------------------------------------------------
833 \brief VosTXThread() - The VOSS Main Tx thread
834 The \a VosTxThread() is the VOSS main controller thread:
835 \param Arg - pointer to the global vOSS Sched Context
836
837 \return Thread exit code
838 \sa VosTxThread()
839 -------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -0700840static int VosTXThread ( void * Arg )
841{
842 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
843 pVosMsgWrapper pMsgWrapper = NULL;
844 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
845 int retWaitStatus = 0;
846 v_BOOL_t shutdown = VOS_FALSE;
847 hdd_context_t *pHddCtx = NULL;
848 v_CONTEXT_t pVosContext = NULL;
849
850 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -0700851
852#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -0700853 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -0700854#endif
Jeff Johnson295189b2012-06-20 16:38:30 -0700855
856 if (Arg == NULL)
857 {
858 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700859 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700860 return 0;
861 }
Yue Maf49ba872013-08-19 12:04:25 -0700862
863#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700864 daemonize("TX_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700865#endif
866
Jeff Johnson295189b2012-06-20 16:38:30 -0700867 /*
868 ** Ack back to the context from which the main controller thread has been
869 ** created.
870 */
871 complete(&pSchedContext->TxStartEvent);
872 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
873 "%s: TX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
874
875 /* Get the Global VOSS Context */
876 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
877 if(!pVosContext) {
878 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
879 return 0;
880 }
881
882 /* Get the HDD context */
883 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
884 if(!pHddCtx) {
885 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
886 return 0;
887 }
888
889
890 while(!shutdown)
891 {
892 // This implements the execution model algorithm
893 retWaitStatus = wait_event_interruptible(pSchedContext->txWaitQueue,
894 test_bit(TX_POST_EVENT_MASK, &pSchedContext->txEventFlag) ||
895 test_bit(TX_SUSPEND_EVENT_MASK, &pSchedContext->txEventFlag));
896
897
898 if(retWaitStatus == -ERESTARTSYS)
899 {
900 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700901 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700902 break;
903 }
904 clear_bit(TX_POST_EVENT_MASK, &pSchedContext->txEventFlag);
905
906 while(1)
907 {
908 if(test_bit(TX_SHUTDOWN_EVENT_MASK, &pSchedContext->txEventFlag))
909 {
910 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
911 "%s: TX thread signaled to shutdown", __func__);
912 shutdown = VOS_TRUE;
913 /* Check for any Suspend Indication */
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530914 if (test_and_clear_bit(TX_SUSPEND_EVENT_MASK,
915 &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700916 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700917 /* Unblock anyone waiting on suspend */
918 complete(&pHddCtx->tx_sus_event_var);
919 }
920 break;
921 }
922 // Check the SYS queue first
923 if (!vos_is_mq_empty(&pSchedContext->sysTxMq))
924 {
925 // Service the SYS message queue
926 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
927 "%s: Servicing the VOS SYS TX Message queue",__func__);
928 pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq);
929 if (pMsgWrapper == NULL)
930 {
931 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700932 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700933 VOS_ASSERT(0);
934 break;
935 }
936 vStatus = sysTxProcessMsg( pSchedContext->pVContext,
937 pMsgWrapper->pVosMsg);
938 if (!VOS_IS_STATUS_SUCCESS(vStatus))
939 {
940 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
941 "%s: Issue Processing TX SYS message",__func__);
942 }
943 // return message to the Core
944 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
945 continue;
946 }
947 // Check now the TL queue
948 if (!vos_is_mq_empty(&pSchedContext->tlTxMq))
949 {
950 // Service the TL message queue
951 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
952 "%s: Servicing the VOS TL TX Message queue",__func__);
953 pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq);
954 if (pMsgWrapper == NULL)
955 {
956 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700957 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700958 VOS_ASSERT(0);
959 break;
960 }
961 vStatus = WLANTL_TxProcessMsg( pSchedContext->pVContext,
962 pMsgWrapper->pVosMsg);
963 if (!VOS_IS_STATUS_SUCCESS(vStatus))
964 {
965 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
966 "%s: Issue Processing TX TL message",__func__);
967 }
968 // return message to the Core
969 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
970 continue;
971 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700972 // Check the WDI queue
973 if (!vos_is_mq_empty(&pSchedContext->wdiTxMq))
974 {
975 wpt_msg *pWdiMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -0700976 pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700977
978 if (pMsgWrapper == NULL)
979 {
980 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700981 "%s: pMsgWrapper is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530982 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700983 break;
984 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700985
986 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnson295189b2012-06-20 16:38:30 -0700987
Jeff Johnsond13512a2012-07-17 11:42:19 -0700988 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
989 {
990 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700991 "%s: WDI Msg or Callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530992 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700993 break;
994 }
995
Jeff Johnson295189b2012-06-20 16:38:30 -0700996 pWdiMsg->callback(pWdiMsg);
997
998 // return message to the Core
999 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1000
1001 continue;
1002 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001003 /* Check for any Suspend Indication */
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301004 if (test_and_clear_bit(TX_SUSPEND_EVENT_MASK,
1005 &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001006 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001007 spin_lock(&pSchedContext->TxThreadLock);
1008
1009 /* Tx Thread Suspended */
1010 complete(&pHddCtx->tx_sus_event_var);
1011
1012 INIT_COMPLETION(pSchedContext->ResumeTxEvent);
1013 spin_unlock(&pSchedContext->TxThreadLock);
1014
1015 /* Wait foe Resume Indication */
1016 wait_for_completion_interruptible(&pSchedContext->ResumeTxEvent);
1017 }
1018
1019 break; //All queues are empty now
1020 } // while message loop processing
1021 } // while TRUE
1022 // If we get here the TX thread must exit
1023 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001024 "%s: TX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001025 complete_and_exit(&pSchedContext->TxShutdown, 0);
1026} /* VosTxThread() */
1027
Jeff Johnson295189b2012-06-20 16:38:30 -07001028/*---------------------------------------------------------------------------
1029 \brief VosRXThread() - The VOSS Main Rx thread
1030 The \a VosRxThread() is the VOSS Rx controller thread:
1031 \param Arg - pointer to the global vOSS Sched Context
1032
1033 \return Thread exit code
1034 \sa VosRxThread()
1035 -------------------------------------------------------------------------*/
1036
1037static int VosRXThread ( void * Arg )
1038{
1039 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
1040 pVosMsgWrapper pMsgWrapper = NULL;
1041 int retWaitStatus = 0;
1042 v_BOOL_t shutdown = VOS_FALSE;
1043 hdd_context_t *pHddCtx = NULL;
1044 v_CONTEXT_t pVosContext = NULL;
1045 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1046
1047 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001048
1049#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -07001050 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001051#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001052
1053 if (Arg == NULL)
1054 {
1055 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001056 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001057 return 0;
1058 }
Yue Maf49ba872013-08-19 12:04:25 -07001059
1060#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001061 daemonize("RX_Thread");
Yue Maf49ba872013-08-19 12:04:25 -07001062#endif
1063
Jeff Johnson295189b2012-06-20 16:38:30 -07001064 /*
1065 ** Ack back to the context from which the main controller thread has been
1066 ** created.
1067 */
1068 complete(&pSchedContext->RxStartEvent);
1069 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1070 "%s: RX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
1071
1072 /* Get the Global VOSS Context */
1073 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
1074 if(!pVosContext) {
1075 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
1076 return 0;
1077 }
1078
1079 /* Get the HDD context */
1080 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1081 if(!pHddCtx) {
1082 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
1083 return 0;
1084 }
1085
1086 while(!shutdown)
1087 {
1088 // This implements the execution model algorithm
1089 retWaitStatus = wait_event_interruptible(pSchedContext->rxWaitQueue,
1090 test_bit(RX_POST_EVENT_MASK, &pSchedContext->rxEventFlag) ||
1091 test_bit(RX_SUSPEND_EVENT_MASK, &pSchedContext->rxEventFlag));
1092
1093
1094 if(retWaitStatus == -ERESTARTSYS)
1095 {
1096 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001097 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001098 break;
1099 }
1100 clear_bit(RX_POST_EVENT_MASK, &pSchedContext->rxEventFlag);
1101
1102 while(1)
1103 {
1104 if(test_bit(RX_SHUTDOWN_EVENT_MASK, &pSchedContext->rxEventFlag))
1105 {
1106 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1107 "%s: RX thread signaled to shutdown", __func__);
1108 shutdown = VOS_TRUE;
1109 /* Check for any Suspend Indication */
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301110 if (test_and_clear_bit(RX_SUSPEND_EVENT_MASK,
1111 &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001112 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001113 /* Unblock anyone waiting on suspend */
1114 complete(&pHddCtx->rx_sus_event_var);
1115 }
1116 break;
1117 }
1118
1119
1120 // Check the SYS queue first
1121 if (!vos_is_mq_empty(&pSchedContext->sysRxMq))
1122 {
1123 // Service the SYS message queue
1124 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1125 "%s: Servicing the VOS SYS RX Message queue",__func__);
1126 pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq);
1127 if (pMsgWrapper == NULL)
1128 {
1129 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001130 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001131 VOS_ASSERT(0);
1132 break;
1133 }
1134 vStatus = sysRxProcessMsg( pSchedContext->pVContext,
1135 pMsgWrapper->pVosMsg);
1136 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1137 {
1138 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1139 "%s: Issue Processing TX SYS message",__func__);
1140 }
1141 // return message to the Core
1142 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1143 continue;
1144 }
1145
Katya Nigam664f5032014-05-05 12:24:32 +05301146 // Check now the TL queue
1147 if (!vos_is_mq_empty(&pSchedContext->tlRxMq))
1148 {
1149 // Service the TL message queue
1150 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1151 "%s: Servicing the VOS TL RX Message queue",__func__);
1152 pMsgWrapper = vos_mq_get(&pSchedContext->tlRxMq);
1153 if (pMsgWrapper == NULL)
1154 {
1155 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1156 "%s: pMsgWrapper is NULL", __func__);
1157 VOS_ASSERT(0);
1158 break;
1159 }
1160 vStatus = WLANTL_RxProcessMsg( pSchedContext->pVContext,
1161 pMsgWrapper->pVosMsg);
1162 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1163 {
1164 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1165 "%s: Issue Processing RX TL message",__func__);
1166 }
1167 // return message to the Core
1168 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1169 continue;
1170 }
1171
Jeff Johnson295189b2012-06-20 16:38:30 -07001172 // Check the WDI queue
1173 if (!vos_is_mq_empty(&pSchedContext->wdiRxMq))
1174 {
1175 wpt_msg *pWdiMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07001176 pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq);
1177 if ((NULL == pMsgWrapper) || (NULL == pMsgWrapper->pVosMsg))
1178 {
1179 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001180 "%s: wdiRxMq message is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301181 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001182 // we won't return this wrapper since it is corrupt
1183 }
1184 else
1185 {
1186 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
1187 if ((NULL == pWdiMsg) || (NULL == pWdiMsg->callback))
1188 {
1189 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001190 "%s: WDI Msg or callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301191 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001192 }
1193 else
1194 {
1195 // invoke the message handler
1196 pWdiMsg->callback(pWdiMsg);
1197 }
1198
1199 // return message to the Core
1200 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1201 }
1202 continue;
1203 }
1204
1205 /* Check for any Suspend Indication */
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301206 if (test_and_clear_bit(RX_SUSPEND_EVENT_MASK,
1207 &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001208 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001209 spin_lock(&pSchedContext->RxThreadLock);
1210
1211 /* Rx Thread Suspended */
1212 complete(&pHddCtx->rx_sus_event_var);
1213
Gopichand Nakkala05621412013-06-19 19:37:38 +05301214 INIT_COMPLETION(pSchedContext->ResumeRxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -07001215 spin_unlock(&pSchedContext->RxThreadLock);
1216
1217 /* Wait for Resume Indication */
1218 wait_for_completion_interruptible(&pSchedContext->ResumeRxEvent);
1219 }
1220
1221 break; //All queues are empty now
1222 } // while message loop processing
1223 } // while TRUE
1224 // If we get here the RX thread must exit
1225 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001226 "%s: RX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001227 complete_and_exit(&pSchedContext->RxShutdown, 0);
1228} /* VosRxThread() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001229
Jeff Johnson295189b2012-06-20 16:38:30 -07001230/*---------------------------------------------------------------------------
1231 \brief vos_sched_close() - Close the vOSS Scheduler
1232 The \a vos_sched_closes() function closes the vOSS Scheduler
1233 Upon successful closing:
1234 - All the message queues are flushed
1235 - The Main Controller thread is closed
1236 - The Tx thread is closed
1237
1238 \param pVosContext - pointer to the global vOSS Context
1239 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1240 is ready to be used.
1241 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
1242 function
1243 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
1244 \sa vos_sched_close()
1245---------------------------------------------------------------------------*/
1246VOS_STATUS vos_sched_close ( v_PVOID_t pVosContext )
1247{
1248 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001249 "%s: invoked", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001250 if (gpVosSchedContext == NULL)
1251 {
1252 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Arif Hussain02882402013-11-17 21:55:29 -08001253 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001254 return VOS_STATUS_E_FAILURE;
1255 }
1256
1257 // shut down MC Thread
1258 set_bit(MC_SHUTDOWN_EVENT_MASK, &gpVosSchedContext->mcEventFlag);
1259 set_bit(MC_POST_EVENT_MASK, &gpVosSchedContext->mcEventFlag);
1260 wake_up_interruptible(&gpVosSchedContext->mcWaitQueue);
1261 //Wait for MC to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301262 wait_for_completion(&gpVosSchedContext->McShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001263 gpVosSchedContext->McThread = 0;
1264
Jeff Johnson295189b2012-06-20 16:38:30 -07001265 // shut down TX Thread
1266 set_bit(TX_SHUTDOWN_EVENT_MASK, &gpVosSchedContext->txEventFlag);
1267 set_bit(TX_POST_EVENT_MASK, &gpVosSchedContext->txEventFlag);
1268 wake_up_interruptible(&gpVosSchedContext->txWaitQueue);
1269 //Wait for TX to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301270 wait_for_completion(&gpVosSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001271 gpVosSchedContext->TxThread = 0;
1272
Jeff Johnson295189b2012-06-20 16:38:30 -07001273 // shut down RX Thread
1274 set_bit(RX_SHUTDOWN_EVENT_MASK, &gpVosSchedContext->rxEventFlag);
1275 set_bit(RX_POST_EVENT_MASK, &gpVosSchedContext->rxEventFlag);
1276 wake_up_interruptible(&gpVosSchedContext->rxWaitQueue);
1277 //Wait for RX to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301278 wait_for_completion(&gpVosSchedContext->RxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001279 gpVosSchedContext->RxThread = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001280
1281 //Clean up message queues of TX and MC thread
1282 vos_sched_flush_mc_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001283 vos_sched_flush_tx_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001284 vos_sched_flush_rx_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001285
1286 //Deinit all the queues
1287 vos_sched_deinit_mqs(gpVosSchedContext);
1288
1289 return VOS_STATUS_SUCCESS;
1290} /* vox_sched_close() */
1291
1292VOS_STATUS vos_watchdog_close ( v_PVOID_t pVosContext )
1293{
1294 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001295 "%s: vos_watchdog closing now", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001296 if (gpVosWatchdogContext == NULL)
1297 {
1298 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Arif Hussain02882402013-11-17 21:55:29 -08001299 "%s: gpVosWatchdogContext is NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 return VOS_STATUS_E_FAILURE;
1301 }
1302 set_bit(WD_SHUTDOWN_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1303 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1304 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1305 //Wait for Watchdog thread to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301306 wait_for_completion(&gpVosWatchdogContext->WdShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001307 return VOS_STATUS_SUCCESS;
1308} /* vos_watchdog_close() */
1309
Jeff Johnson295189b2012-06-20 16:38:30 -07001310/*---------------------------------------------------------------------------
1311 \brief vos_sched_init_mqs: Initialize the vOSS Scheduler message queues
1312 The \a vos_sched_init_mqs() function initializes the vOSS Scheduler
1313 message queues.
1314 \param pVosSchedContext - pointer to the Scheduler Context.
1315 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1316 is ready to be used.
1317 VOS_STATUS_E_RESOURCES - System resources (other than memory)
1318 are unavailable to initilize the scheduler
1319
1320 \sa vos_sched_init_mqs()
1321 -------------------------------------------------------------------------*/
1322VOS_STATUS vos_sched_init_mqs ( pVosSchedContext pSchedContext )
1323{
1324 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1325 // Now intialize all the message queues
Jeff Johnson295189b2012-06-20 16:38:30 -07001326 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1327 "%s: Initializing the WDA MC Message queue",__func__);
1328 vStatus = vos_mq_init(&pSchedContext->wdaMcMq);
1329 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1330 {
1331 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1332 "%s: Failed to init WDA MC Message queue",__func__);
1333 VOS_ASSERT(0);
1334 return vStatus;
1335 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001336 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1337 "%s: Initializing the PE MC Message queue",__func__);
1338 vStatus = vos_mq_init(&pSchedContext->peMcMq);
1339 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1340 {
1341 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1342 "%s: Failed to init PE MC Message queue",__func__);
1343 VOS_ASSERT(0);
1344 return vStatus;
1345 }
1346 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1347 "%s: Initializing the SME MC Message queue", __func__);
1348 vStatus = vos_mq_init(&pSchedContext->smeMcMq);
1349 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1350 {
1351 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1352 "%s: Failed to init SME MC Message queue",__func__);
1353 VOS_ASSERT(0);
1354 return vStatus;
1355 }
1356 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1357 "%s: Initializing the TL MC Message queue",__func__);
1358 vStatus = vos_mq_init(&pSchedContext->tlMcMq);
1359 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1360 {
1361 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1362 "%s: Failed to init TL MC Message queue",__func__);
1363 VOS_ASSERT(0);
1364 return vStatus;
1365 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001366 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1367 "%s: Initializing the SYS MC Message queue",__func__);
1368 vStatus = vos_mq_init(&pSchedContext->sysMcMq);
1369 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1370 {
1371 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1372 "%s: Failed to init SYS MC Message queue",__func__);
1373 VOS_ASSERT(0);
1374 return vStatus;
1375 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001376 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1377 "%s: Initializing the WDI MC Message queue",__func__);
1378
1379 vStatus = vos_mq_init(&pSchedContext->wdiMcMq);
1380 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1381 {
1382 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1383 "%s: Failed to init WDI MC Message queue",__func__);
1384 VOS_ASSERT(0);
1385 return vStatus;
1386 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001387
Jeff Johnson295189b2012-06-20 16:38:30 -07001388 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1389 "%s: Initializing the TL Tx Message queue",__func__);
1390 vStatus = vos_mq_init(&pSchedContext->tlTxMq);
1391 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1392 {
1393 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1394 "%s: Failed to init TL TX Message queue",__func__);
1395 VOS_ASSERT(0);
1396 return vStatus;
1397 }
Katya Nigam664f5032014-05-05 12:24:32 +05301398
1399 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1400 "%s: Initializing the TL Rx Message queue",__func__);
1401 vStatus = vos_mq_init(&pSchedContext->tlRxMq);
1402 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1403 {
1404 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1405 "%s: Failed to init TL RX Message queue",__func__);
1406 VOS_ASSERT(0);
1407 return vStatus;
1408 }
1409
Jeff Johnson295189b2012-06-20 16:38:30 -07001410 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1411 "%s: Initializing the WDI Tx Message queue",__func__);
1412 vStatus = vos_mq_init(&pSchedContext->wdiTxMq);
1413 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1414 {
1415 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1416 "%s: Failed to init WDI TX Message queue",__func__);
1417 VOS_ASSERT(0);
1418 return vStatus;
1419 }
1420
1421 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1422 "%s: Initializing the WDI Rx Message queue",__func__);
1423
1424 vStatus = vos_mq_init(&pSchedContext->wdiRxMq);
1425 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1426 {
1427 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1428 "%s: Failed to init WDI RX Message queue",__func__);
1429 VOS_ASSERT(0);
1430 return vStatus;
1431 }
1432
Jeff Johnson295189b2012-06-20 16:38:30 -07001433 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1434 "%s: Initializing the SYS Tx Message queue",__func__);
1435 vStatus = vos_mq_init(&pSchedContext->sysTxMq);
1436 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1437 {
1438 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1439 "%s: Failed to init SYS TX Message queue",__func__);
1440 VOS_ASSERT(0);
1441 return vStatus;
1442 }
1443
1444 vStatus = vos_mq_init(&pSchedContext->sysRxMq);
1445 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1446 {
1447 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1448 "%s: Failed to init SYS RX Message queue",__func__);
1449 VOS_ASSERT(0);
1450 return vStatus;
1451 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001452 return VOS_STATUS_SUCCESS;
1453} /* vos_sched_init_mqs() */
1454
1455/*---------------------------------------------------------------------------
1456 \brief vos_sched_deinit_mqs: Deinitialize the vOSS Scheduler message queues
1457 The \a vos_sched_init_mqs() function deinitializes the vOSS Scheduler
1458 message queues.
1459 \param pVosSchedContext - pointer to the Scheduler Context.
1460 \return None
1461 \sa vos_sched_deinit_mqs()
1462 -------------------------------------------------------------------------*/
1463void vos_sched_deinit_mqs ( pVosSchedContext pSchedContext )
1464{
1465 // Now de-intialize all message queues
Jeff Johnson295189b2012-06-20 16:38:30 -07001466 // MC WDA
1467 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1468 "%s De-Initializing the WDA MC Message queue",__func__);
1469 vos_mq_deinit(&pSchedContext->wdaMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001470 //MC PE
1471 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1472 "%s De-Initializing the PE MC Message queue",__func__);
1473 vos_mq_deinit(&pSchedContext->peMcMq);
1474 //MC SME
1475 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1476 "%s De-Initializing the SME MC Message queue",__func__);
1477 vos_mq_deinit(&pSchedContext->smeMcMq);
1478 //MC TL
1479 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1480 "%s De-Initializing the TL MC Message queue",__func__);
1481 vos_mq_deinit(&pSchedContext->tlMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001482 //MC SYS
1483 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1484 "%s De-Initializing the SYS MC Message queue",__func__);
1485 vos_mq_deinit(&pSchedContext->sysMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001486 // MC WDI
1487 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1488 "%s De-Initializing the WDI MC Message queue",__func__);
1489 vos_mq_deinit(&pSchedContext->wdiMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001490
Jeff Johnson295189b2012-06-20 16:38:30 -07001491 //Tx TL
1492 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1493 "%s De-Initializing the TL Tx Message queue",__func__);
1494 vos_mq_deinit(&pSchedContext->tlTxMq);
Katya Nigam664f5032014-05-05 12:24:32 +05301495
1496 //Rx TL
1497 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1498 "%s De-Initializing the TL Rx Message queue",__func__);
1499 vos_mq_deinit(&pSchedContext->tlRxMq);
1500
Jeff Johnson295189b2012-06-20 16:38:30 -07001501 //Tx WDI
1502 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1503 "%s: DeInitializing the WDI Tx Message queue",__func__);
1504 vos_mq_deinit(&pSchedContext->wdiTxMq);
1505
1506
1507 //Rx WDI
1508 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1509 "%s: DeInitializing the WDI Rx Message queue",__func__);
1510 vos_mq_deinit(&pSchedContext->wdiRxMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001511
1512 //Tx SYS
1513 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1514 "%s: DeInitializing the SYS Tx Message queue",__func__);
1515 vos_mq_deinit(&pSchedContext->sysTxMq);
1516
1517 //Rx SYS
1518 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1519 "%s: DeInitializing the SYS Rx Message queue",__func__);
1520 vos_mq_deinit(&pSchedContext->sysRxMq);
1521
Jeff Johnson295189b2012-06-20 16:38:30 -07001522} /* vos_sched_deinit_mqs() */
1523
1524/*-------------------------------------------------------------------------
1525 this helper function flushes all the MC message queues
1526 -------------------------------------------------------------------------*/
1527void vos_sched_flush_mc_mqs ( pVosSchedContext pSchedContext )
1528{
1529 pVosMsgWrapper pMsgWrapper = NULL;
1530 pVosContextType vosCtx;
1531
1532 /*
1533 ** Here each of the MC thread MQ shall be drained and returned to the
1534 ** Core. Before returning a wrapper to the Core, the VOS message shall be
1535 ** freed first
1536 */
1537 VOS_TRACE( VOS_MODULE_ID_VOSS,
1538 VOS_TRACE_LEVEL_INFO,
Arif Hussain02882402013-11-17 21:55:29 -08001539 ("Flushing the MC Thread message queue") );
Jeff Johnson295189b2012-06-20 16:38:30 -07001540
1541 if (NULL == pSchedContext)
1542 {
1543 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001544 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001545 return;
1546 }
1547
1548 vosCtx = (pVosContextType)(pSchedContext->pVContext);
1549 if (NULL == vosCtx)
1550 {
1551 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001552 "%s: vosCtx is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001553 return;
1554 }
1555
1556 /* Flush the SYS Mq */
1557 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq) ))
1558 {
1559 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301560 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001561 "%s: Freeing MC SYS message type %d ",__func__,
1562 pMsgWrapper->pVosMsg->type );
1563 sysMcFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1564 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1565 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001566 /* Flush the WDA Mq */
1567 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq) ))
1568 {
1569 if(pMsgWrapper->pVosMsg != NULL)
1570 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301571 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001572 "%s: Freeing MC WDA MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001573 __func__, pMsgWrapper->pVosMsg->type );
Jeff Johnson295189b2012-06-20 16:38:30 -07001574 if (pMsgWrapper->pVosMsg->bodyptr) {
1575 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1576 }
1577
1578 pMsgWrapper->pVosMsg->bodyptr = NULL;
1579 pMsgWrapper->pVosMsg->bodyval = 0;
1580 pMsgWrapper->pVosMsg->type = 0;
1581 }
1582 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1583 }
1584
1585 /* Flush the WDI Mq */
1586 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq) ))
1587 {
1588 if(pMsgWrapper->pVosMsg != NULL)
1589 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301590 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001591 "%s: Freeing MC WDI MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001592 __func__, pMsgWrapper->pVosMsg->type );
Leo Chang0f24ca12013-12-17 13:35:00 -08001593
1594 /* MSG body pointer is not NULL
1595 * and MSG type is 0
1596 * This MSG is not posted by SMD NOTIFY
1597 * We have to free MSG body */
1598 if ((pMsgWrapper->pVosMsg->bodyptr) && (!pMsgWrapper->pVosMsg->type))
1599 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001600 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1601 }
Leo Chang0f24ca12013-12-17 13:35:00 -08001602 /* MSG body pointer is not NULL
1603 * and MSG type is not 0
1604 * This MSG is posted by SMD NOTIFY
1605 * We should not free MSG body */
1606 else if ((pMsgWrapper->pVosMsg->bodyptr) && pMsgWrapper->pVosMsg->type)
1607 {
1608 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1609 "%s: SMD NOTIFY MSG, do not free body",
1610 __func__);
1611 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001612 pMsgWrapper->pVosMsg->bodyptr = NULL;
1613 pMsgWrapper->pVosMsg->bodyval = 0;
1614 pMsgWrapper->pVosMsg->type = 0;
1615 }
1616 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1617 }
1618
Jeff Johnson295189b2012-06-20 16:38:30 -07001619 /* Flush the PE Mq */
1620 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq) ))
1621 {
1622 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301623 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001624 "%s: Freeing MC PE MSG message type %d",__func__,
1625 pMsgWrapper->pVosMsg->type );
1626 peFreeMsg(vosCtx->pMACContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
1627 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1628 }
1629 /* Flush the SME Mq */
1630 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq) ))
1631 {
1632 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301633 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001634 "%s: Freeing MC SME MSG message type %d", __func__,
1635 pMsgWrapper->pVosMsg->type );
1636 sme_FreeMsg(vosCtx->pMACContext, pMsgWrapper->pVosMsg);
1637 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1638 }
1639 /* Flush the TL Mq */
1640 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq) ))
1641 {
1642 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301643 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001644 "%s: Freeing MC TL message type %d",__func__,
1645 pMsgWrapper->pVosMsg->type );
1646 WLANTL_McFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1647 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1648 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001649} /* vos_sched_flush_mc_mqs() */
1650
1651/*-------------------------------------------------------------------------
1652 This helper function flushes all the TX message queues
1653 ------------------------------------------------------------------------*/
1654void vos_sched_flush_tx_mqs ( pVosSchedContext pSchedContext )
1655{
1656 pVosMsgWrapper pMsgWrapper = NULL;
1657 /*
1658 ** Here each of the TX thread MQ shall be drained and returned to the
1659 ** Core. Before returning a wrapper to the Core, the VOS message shall
1660 ** be freed first
1661 */
1662 VOS_TRACE( VOS_MODULE_ID_VOSS,
1663 VOS_TRACE_LEVEL_INFO,
1664 "%s: Flushing the TX Thread message queue",__func__);
1665
1666 if (NULL == pSchedContext)
1667 {
1668 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001669 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001670 return;
1671 }
1672
1673 /* Flush the SYS Mq */
1674 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq) ))
1675 {
1676 VOS_TRACE( VOS_MODULE_ID_VOSS,
1677 VOS_TRACE_LEVEL_INFO,
1678 "%s: Freeing TX SYS message type %d",__func__,
1679 pMsgWrapper->pVosMsg->type );
1680 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1681 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1682 }
1683 /* Flush the TL Mq */
1684 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq) ))
1685 {
1686 VOS_TRACE( VOS_MODULE_ID_VOSS,
1687 VOS_TRACE_LEVEL_INFO,
1688 "%s: Freeing TX TL MSG message type %d",__func__,
1689 pMsgWrapper->pVosMsg->type );
1690 WLANTL_TxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1691 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1692 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001693 /* Flush the WDI Mq */
1694 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq) ))
1695 {
1696 VOS_TRACE( VOS_MODULE_ID_VOSS,
1697 VOS_TRACE_LEVEL_INFO,
1698 "%s: Freeing TX WDI MSG message type %d",__func__,
1699 pMsgWrapper->pVosMsg->type );
1700 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1701 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1702 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001703} /* vos_sched_flush_tx_mqs() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001704/*-------------------------------------------------------------------------
1705 This helper function flushes all the RX message queues
1706 ------------------------------------------------------------------------*/
1707void vos_sched_flush_rx_mqs ( pVosSchedContext pSchedContext )
1708{
1709 pVosMsgWrapper pMsgWrapper = NULL;
1710 /*
1711 ** Here each of the RX thread MQ shall be drained and returned to the
1712 ** Core. Before returning a wrapper to the Core, the VOS message shall
1713 ** be freed first
1714 */
1715 VOS_TRACE( VOS_MODULE_ID_VOSS,
1716 VOS_TRACE_LEVEL_INFO,
1717 "%s: Flushing the RX Thread message queue",__func__);
1718
1719 if (NULL == pSchedContext)
1720 {
1721 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001722 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001723 return;
1724 }
1725
1726 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq) ))
1727 {
1728 VOS_TRACE( VOS_MODULE_ID_VOSS,
1729 VOS_TRACE_LEVEL_INFO,
1730 "%s: Freeing RX WDI MSG message type %d",__func__,
1731 pMsgWrapper->pVosMsg->type );
1732 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1733 }
1734
Katya Nigam664f5032014-05-05 12:24:32 +05301735 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlRxMq) ))
1736 {
1737 VOS_TRACE( VOS_MODULE_ID_VOSS,
1738 VOS_TRACE_LEVEL_INFO,
1739 "%s: Freeing RX TL MSG message type %d",__func__,
1740 pMsgWrapper->pVosMsg->type );
1741 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1742 }
1743
Jeff Johnson295189b2012-06-20 16:38:30 -07001744 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq) ))
1745 {
1746 VOS_TRACE( VOS_MODULE_ID_VOSS,
1747 VOS_TRACE_LEVEL_INFO,
1748 "%s: Freeing RX SYS MSG message type %d",__func__,
1749 pMsgWrapper->pVosMsg->type );
1750 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1751 }
1752
1753}/* vos_sched_flush_rx_mqs() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001754
1755/*-------------------------------------------------------------------------
1756 This helper function helps determine if thread id is of TX thread
1757 ------------------------------------------------------------------------*/
1758int vos_sched_is_tx_thread(int threadID)
1759{
1760 // Make sure that Vos Scheduler context has been initialized
1761 VOS_ASSERT( NULL != gpVosSchedContext);
1762 if (gpVosSchedContext == NULL)
1763 {
1764 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001765 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 return 0;
1767 }
1768 return ((gpVosSchedContext->TxThread) && (threadID == gpVosSchedContext->TxThread->pid));
1769}
Jeff Johnson295189b2012-06-20 16:38:30 -07001770/*-------------------------------------------------------------------------
1771 This helper function helps determine if thread id is of RX thread
1772 ------------------------------------------------------------------------*/
1773int vos_sched_is_rx_thread(int threadID)
1774{
1775 // Make sure that Vos Scheduler context has been initialized
1776 VOS_ASSERT( NULL != gpVosSchedContext);
1777 if (gpVosSchedContext == NULL)
1778 {
1779 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001780 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001781 return 0;
1782 }
1783 return ((gpVosSchedContext->RxThread) && (threadID == gpVosSchedContext->RxThread->pid));
1784}
Jeff Johnson295189b2012-06-20 16:38:30 -07001785/*-------------------------------------------------------------------------
1786 Helper function to get the scheduler context
1787 ------------------------------------------------------------------------*/
1788pVosSchedContext get_vos_sched_ctxt(void)
1789{
1790 //Make sure that Vos Scheduler context has been initialized
1791 if (gpVosSchedContext == NULL)
1792 {
1793 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001794 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001795 }
1796 return (gpVosSchedContext);
1797}
1798/*-------------------------------------------------------------------------
1799 Helper function to get the watchdog context
1800 ------------------------------------------------------------------------*/
1801pVosWatchdogContext get_vos_watchdog_ctxt(void)
1802{
1803 //Make sure that Vos Scheduler context has been initialized
1804 if (gpVosWatchdogContext == NULL)
1805 {
1806 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001807 "%s: gpVosWatchdogContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001808 }
1809 return (gpVosWatchdogContext);
1810}
1811/**
1812 @brief vos_watchdog_wlan_shutdown()
1813
1814 This function is called to shutdown WLAN driver during SSR.
1815 Adapters are disabled, and the watchdog task will be signalled
1816 to shutdown WLAN driver.
1817
1818 @param
1819 NONE
1820 @return
1821 VOS_STATUS_SUCCESS - Operation completed successfully.
1822 VOS_STATUS_E_FAILURE - Operation failed.
1823
1824*/
1825VOS_STATUS vos_watchdog_wlan_shutdown(void)
1826{
1827 v_CONTEXT_t pVosContext = NULL;
1828 hdd_context_t *pHddCtx = NULL;
1829
Jeff Johnson295189b2012-06-20 16:38:30 -07001830 if (NULL == gpVosWatchdogContext)
1831 {
1832 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001833 "%s: Watchdog not enabled. LOGP ignored.", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001834 return VOS_STATUS_E_FAILURE;
1835 }
1836
Siddharth Bhalb9a1ae32014-08-27 14:53:55 +05301837 if (gpVosWatchdogContext->isFatalError)
1838 {
1839 /* If we hit this, it means wlan driver is in bad state and needs
1840 * driver unload and load.
1841 */
1842 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1843 "%s: Driver in bad state and need unload and load", __func__);
1844 return VOS_STATUS_E_FAILURE;
1845 }
1846
1847 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1848 "%s: WLAN driver is shutting down ", __func__);
1849
Jeff Johnson295189b2012-06-20 16:38:30 -07001850 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
1851 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1852 if (NULL == pHddCtx)
1853 {
1854 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001855 "%s: Invalid HDD Context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001856 return VOS_STATUS_E_FAILURE;
1857 }
1858
1859 /* Take the lock here */
1860 spin_lock(&gpVosWatchdogContext->wdLock);
1861
1862 /* reuse the existing 'reset in progress' */
1863 if (gpVosWatchdogContext->resetInProgress)
1864 {
1865 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1866 "%s: Shutdown already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001867 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001868 /* Release the lock here */
1869 spin_unlock(&gpVosWatchdogContext->wdLock);
1870 return VOS_STATUS_E_FAILURE;
1871 }
1872 /* reuse the existing 'logp in progress', eventhough it is not
1873 * exactly the same */
1874 else if (pHddCtx->isLogpInProgress)
1875 {
1876 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1877 "%s: shutdown/re-init already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001878 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001879 /* Release the lock here */
1880 spin_unlock(&gpVosWatchdogContext->wdLock);
1881 return VOS_STATUS_E_FAILURE;
Siddharth Bhal1ab61052014-09-15 14:39:37 +05301882 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001883
Mihir Shete18156292014-03-11 15:38:30 +05301884 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Jeff Johnson295189b2012-06-20 16:38:30 -07001885 {
1886 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
1887 "%s: Load/unload in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001888 __func__);
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07001889 /* wcnss has crashed, and SSR has alredy been started by Kernel driver.
1890 * So disable SSR from WLAN driver */
1891 hdd_set_ssr_required( HDD_SSR_DISABLED );
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +05301892
Siddharth Bhal1ab61052014-09-15 14:39:37 +05301893 /* Release the lock here before returning */
1894 spin_unlock(&gpVosWatchdogContext->wdLock);
Jeff Johnson295189b2012-06-20 16:38:30 -07001895 return VOS_STATUS_E_FAILURE;
1896 }
Siddharth Bhal1ab61052014-09-15 14:39:37 +05301897 /* Set the flags so that all commands from userspace get blocked right away */
1898 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, TRUE);
1899 vos_set_reinit_in_progress(VOS_MODULE_ID_VOSS, FALSE);
1900 pHddCtx->isLogpInProgress = TRUE;
1901
1902 /* Release the lock here */
1903 spin_unlock(&gpVosWatchdogContext->wdLock);
1904
Jeff Johnson295189b2012-06-20 16:38:30 -07001905 /* Update Riva Reset Statistics */
1906 pHddCtx->hddRivaResetStats++;
1907#ifdef CONFIG_HAS_EARLYSUSPEND
1908 if(VOS_STATUS_SUCCESS != hdd_wlan_reset_initialization())
1909 {
1910 VOS_ASSERT(0);
1911 }
1912#endif
1913
1914 set_bit(WD_WLAN_SHUTDOWN_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1915 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1916 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1917
1918 return VOS_STATUS_SUCCESS;
1919}
1920
1921/**
1922 @brief vos_watchdog_wlan_re_init()
1923
1924 This function is called to re-initialize WLAN driver, and this is
1925 called when Riva SS reboots.
1926
1927 @param
1928 NONE
1929 @return
1930 VOS_STATUS_SUCCESS - Operation completed successfully.
1931 VOS_STATUS_E_FAILURE - Operation failed.
1932
1933*/
1934VOS_STATUS vos_watchdog_wlan_re_init(void)
1935{
1936 /* watchdog task is still running, it is not closed in shutdown */
1937 set_bit(WD_WLAN_REINIT_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1938 set_bit(WD_POST_EVENT_MASK, &gpVosWatchdogContext->wdEventFlag);
1939 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1940
1941 return VOS_STATUS_SUCCESS;
1942}
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05301943
1944/**
1945 @brief vos_ssr_protect()
1946
1947 This function is called to keep track of active driver entry points
1948
1949 @param
1950 caller_func - Name of calling function.
1951 @return
1952 void
1953*/
1954void vos_ssr_protect(const char *caller_func)
1955{
1956 int count;
1957 count = atomic_inc_return(&ssr_protect_entry_count);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05301958}
1959
1960/**
1961 @brief vos_ssr_unprotect()
1962
1963 @param
1964 caller_func - Name of calling function.
1965 @return
1966 void
1967*/
1968void vos_ssr_unprotect(const char *caller_func)
1969{
1970 int count;
1971 count = atomic_dec_return(&ssr_protect_entry_count);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05301972}