blob: 2fa2b6a4d8e15ccba02ec4886755fe0136864c44 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Arunk Khandavalliaf6c3af2017-01-16 11:44:46 +05302 * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
Kiet Lam1ed83fc2014-02-19 01:15:45 -08003 *
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>
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +053062#include <linux/wcnss_wlan.h>
63
Jeff Johnson295189b2012-06-20 16:38:30 -070064/*---------------------------------------------------------------------------
65 * Preprocessor Definitions and Constants
66 * ------------------------------------------------------------------------*/
67#define VOS_SCHED_THREAD_HEART_BEAT INFINITE
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +053068/* Milli seconds to delay SSR thread when an Entry point is Active */
69#define SSR_WAIT_SLEEP_TIME 100
70/* MAX iteration count to wait for Entry point to exit before
71 * we proceed with SSR in WD Thread
72 */
Pradeep Kumar Goudagunta21c08c42014-07-14 15:59:43 +053073#define MAX_SSR_WAIT_ITERATIONS 200
Abhishek Singhe7ea25c2015-11-23 16:23:24 +053074/* Timer value for detecting thread stuck issues */
75#define THREAD_STUCK_TIMER_VAL 5000 // 5 seconds
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +053076#define THREAD_STUCK_COUNT 6
Abhishek Singhe7ea25c2015-11-23 16:23:24 +053077
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +053078#define MC_Thread 0
79#define TX_Thread 1
80#define RX_Thread 2
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +053081
82static atomic_t ssr_protect_entry_count;
83
Jeff Johnson295189b2012-06-20 16:38:30 -070084/*---------------------------------------------------------------------------
85 * Type Declarations
86 * ------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------
88 * Data definitions
89 * ------------------------------------------------------------------------*/
90static pVosSchedContext gpVosSchedContext;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070091static pVosWatchdogContext gpVosWatchdogContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070092
93/*---------------------------------------------------------------------------
94 * Forward declaration
95 * ------------------------------------------------------------------------*/
Jeff Johnson2f5cfec2013-02-22 21:25:10 -080096static int VosMCThread(void *Arg);
97static int VosWDThread(void *Arg);
98static int VosTXThread(void *Arg);
99static int VosRXThread(void *Arg);
Jeff Johnson295189b2012-06-20 16:38:30 -0700100void vos_sched_flush_rx_mqs(pVosSchedContext SchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -0700101extern v_VOID_t vos_core_return_msg(v_PVOID_t pVContext, pVosMsgWrapper pMsgWrapper);
102/*---------------------------------------------------------------------------
103 * External Function implementation
104 * ------------------------------------------------------------------------*/
105
106/*---------------------------------------------------------------------------
107 \brief vos_sched_open() - initialize the vOSS Scheduler
108 The \a vos_sched_open() function initializes the vOSS Scheduler
109 Upon successful initialization:
110 - All the message queues are initialized
111 - The Main Controller thread is created and ready to receive and
112 dispatch messages.
113 - The Tx thread is created and ready to receive and dispatch messages
114
115 \param pVosContext - pointer to the global vOSS Context
116 \param pVosSchedContext - pointer to a previously allocated buffer big
117 enough to hold a scheduler context.
118 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
119 is ready to be used.
120 VOS_STATUS_E_RESOURCES - System resources (other than memory)
121 are unavailable to initilize the scheduler
122 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
123 the scheduler
124 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
125 function
126 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
127 \sa vos_sched_open()
128 -------------------------------------------------------------------------*/
129VOS_STATUS
130vos_sched_open
131(
132 v_PVOID_t pVosContext,
133 pVosSchedContext pSchedContext,
134 v_SIZE_t SchedCtxSize
135)
136{
137 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
138/*-------------------------------------------------------------------------*/
139 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
140 "%s: Opening the VOSS Scheduler",__func__);
141 // Sanity checks
142 if ((pVosContext == NULL) || (pSchedContext == NULL)) {
143 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
144 "%s: Null params being passed",__func__);
145 return VOS_STATUS_E_FAILURE;
146 }
147 if (sizeof(VosSchedContext) != SchedCtxSize)
148 {
149 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
150 "%s: Incorrect VOS Sched Context size passed",__func__);
151 return VOS_STATUS_E_INVAL;
152 }
153 vos_mem_zero(pSchedContext, sizeof(VosSchedContext));
154 pSchedContext->pVContext = pVosContext;
155 vStatus = vos_sched_init_mqs(pSchedContext);
156 if (!VOS_IS_STATUS_SUCCESS(vStatus))
157 {
158 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
159 "%s: Failed to initialize VOS Scheduler MQs",__func__);
160 return vStatus;
161 }
162 // Initialize the helper events and event queues
163 init_completion(&pSchedContext->McStartEvent);
164 init_completion(&pSchedContext->TxStartEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700165 init_completion(&pSchedContext->RxStartEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700166 init_completion(&pSchedContext->McShutdown);
167 init_completion(&pSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700168 init_completion(&pSchedContext->RxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700169 init_completion(&pSchedContext->ResumeMcEvent);
170 init_completion(&pSchedContext->ResumeTxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700171 init_completion(&pSchedContext->ResumeRxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700172
173 spin_lock_init(&pSchedContext->McThreadLock);
174 spin_lock_init(&pSchedContext->TxThreadLock);
175 spin_lock_init(&pSchedContext->RxThreadLock);
176
177 init_waitqueue_head(&pSchedContext->mcWaitQueue);
178 pSchedContext->mcEventFlag = 0;
179 init_waitqueue_head(&pSchedContext->txWaitQueue);
180 pSchedContext->txEventFlag= 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700181 init_waitqueue_head(&pSchedContext->rxWaitQueue);
182 pSchedContext->rxEventFlag= 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700183 /*
Jeff Johnson2f5cfec2013-02-22 21:25:10 -0800184 ** This initialization is critical as the threads will later access the
Jeff Johnson295189b2012-06-20 16:38:30 -0700185 ** global contexts normally,
186 **
187 ** I shall put some memory barrier here after the next piece of code but
188 ** I am keeping it simple for now.
189 */
190 gpVosSchedContext = pSchedContext;
191
192 //Create the VOSS Main Controller thread
193 pSchedContext->McThread = kthread_create(VosMCThread, pSchedContext,
194 "VosMCThread");
195 if (IS_ERR(pSchedContext->McThread))
196 {
197 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
198 "%s: Could not Create VOSS Main Thread Controller",__func__);
199 goto MC_THREAD_START_FAILURE;
200 }
201 wake_up_process(pSchedContext->McThread);
202 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
203 "%s: VOSS Main Controller thread Created",__func__);
204
Jeff Johnson295189b2012-06-20 16:38:30 -0700205 pSchedContext->TxThread = kthread_create(VosTXThread, pSchedContext,
206 "VosTXThread");
207 if (IS_ERR(pSchedContext->TxThread))
208 {
209 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
210 "%s: Could not Create VOSS TX Thread",__func__);
211 goto TX_THREAD_START_FAILURE;
212 }
213 wake_up_process(pSchedContext->TxThread);
214 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussain02882402013-11-17 21:55:29 -0800215 ("VOSS TX thread Created"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700216
Jeff Johnson295189b2012-06-20 16:38:30 -0700217 pSchedContext->RxThread = kthread_create(VosRXThread, pSchedContext,
218 "VosRXThread");
219 if (IS_ERR(pSchedContext->RxThread))
220 {
221
222 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
223 "%s: Could not Create VOSS RX Thread",__func__);
224 goto RX_THREAD_START_FAILURE;
225
226 }
227 wake_up_process(pSchedContext->RxThread);
228 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussain02882402013-11-17 21:55:29 -0800229 ("VOSS RX thread Created"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700230
231 /*
232 ** Now make sure all threads have started before we exit.
233 ** Each thread should normally ACK back when it starts.
234 */
235 wait_for_completion_interruptible(&pSchedContext->McStartEvent);
236 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
237 "%s: VOSS MC Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700238 wait_for_completion_interruptible(&pSchedContext->TxStartEvent);
239 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
240 "%s: VOSS Tx Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700241 wait_for_completion_interruptible(&pSchedContext->RxStartEvent);
242 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
243 "%s: VOSS Rx Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700244
245 /*
246 ** We're good now: Let's get the ball rolling!!!
247 */
248 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
249 "%s: VOSS Scheduler successfully Opened",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700250 return VOS_STATUS_SUCCESS;
251
Jeff Johnson295189b2012-06-20 16:38:30 -0700252
Jeff Johnson295189b2012-06-20 16:38:30 -0700253RX_THREAD_START_FAILURE:
254 //Try and force the Tx thread controller to exit
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530255 set_bit(MC_SHUTDOWN_EVENT, &pSchedContext->txEventFlag);
256 set_bit(MC_POST_EVENT, &pSchedContext->txEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700257 wake_up_interruptible(&pSchedContext->txWaitQueue);
258 //Wait for TX to exit
259 wait_for_completion_interruptible(&pSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700260
261TX_THREAD_START_FAILURE:
262 //Try and force the Main thread controller to exit
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530263 set_bit(MC_SHUTDOWN_EVENT, &pSchedContext->mcEventFlag);
264 set_bit(MC_POST_EVENT, &pSchedContext->mcEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700265 wake_up_interruptible(&pSchedContext->mcWaitQueue);
266 //Wait for MC to exit
267 wait_for_completion_interruptible(&pSchedContext->McShutdown);
268
Jeff Johnson295189b2012-06-20 16:38:30 -0700269MC_THREAD_START_FAILURE:
270 //De-initialize all the message queues
271 vos_sched_deinit_mqs(pSchedContext);
272 return VOS_STATUS_E_RESOURCES;
273
274} /* vos_sched_open() */
275
276VOS_STATUS vos_watchdog_open
277(
278 v_PVOID_t pVosContext,
279 pVosWatchdogContext pWdContext,
280 v_SIZE_t wdCtxSize
281)
282{
283/*-------------------------------------------------------------------------*/
284 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
285 "%s: Opening the VOSS Watchdog module",__func__);
286 //Sanity checks
287 if ((pVosContext == NULL) || (pWdContext == NULL)) {
288 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
289 "%s: Null params being passed",__func__);
290 return VOS_STATUS_E_FAILURE;
291 }
292 if (sizeof(VosWatchdogContext) != wdCtxSize)
293 {
294 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
295 "%s: Incorrect VOS Watchdog Context size passed",__func__);
296 return VOS_STATUS_E_INVAL;
297 }
298 vos_mem_zero(pWdContext, sizeof(VosWatchdogContext));
299 pWdContext->pVContext = pVosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700300
301 //Initialize the helper events and event queues
302 init_completion(&pWdContext->WdStartEvent);
303 init_completion(&pWdContext->WdShutdown);
304 init_waitqueue_head(&pWdContext->wdWaitQueue);
305 pWdContext->wdEventFlag = 0;
306
307 // Initialize the lock
308 spin_lock_init(&pWdContext->wdLock);
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530309 spin_lock_init(&pWdContext->thread_stuck_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -0700310
311 //Create the Watchdog thread
312 pWdContext->WdThread = kthread_create(VosWDThread, pWdContext,"VosWDThread");
313
314 if (IS_ERR(pWdContext->WdThread))
315 {
316 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
317 "%s: Could not Create Watchdog thread",__func__);
318 return VOS_STATUS_E_RESOURCES;
319 }
320 else
321 {
Ashish Kumar Dhanotiya532bdef2017-05-09 17:31:59 +0530322 gpVosWatchdogContext = pWdContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700323 wake_up_process(pWdContext->WdThread);
324 }
325 /*
326 ** Now make sure thread has started before we exit.
327 ** Each thread should normally ACK back when it starts.
328 */
329 wait_for_completion_interruptible(&pWdContext->WdStartEvent);
330 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
331 "%s: VOSS Watchdog Thread has started",__func__);
332 return VOS_STATUS_SUCCESS;
333} /* vos_watchdog_open() */
334/*---------------------------------------------------------------------------
335 \brief VosMcThread() - The VOSS Main Controller thread
336 The \a VosMcThread() is the VOSS main controller thread:
337 \param Arg - pointer to the global vOSS Sched Context
338 \return Thread exit code
339 \sa VosMcThread()
340 -------------------------------------------------------------------------*/
341static int
342VosMCThread
343(
344 void * Arg
345)
346{
347 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
348 pVosMsgWrapper pMsgWrapper = NULL;
349 tpAniSirGlobal pMacContext = NULL;
350 tSirRetStatus macStatus = eSIR_SUCCESS;
351 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
352 int retWaitStatus = 0;
353 v_BOOL_t shutdown = VOS_FALSE;
354 hdd_context_t *pHddCtx = NULL;
355 v_CONTEXT_t pVosContext = NULL;
356
357 if (Arg == NULL)
358 {
359 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700360 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700361 return 0;
362 }
363 set_user_nice(current, -2);
364
Yue Maf49ba872013-08-19 12:04:25 -0700365#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700366 daemonize("MC_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700367#endif
368
Jeff Johnson295189b2012-06-20 16:38:30 -0700369 /*
370 ** Ack back to the context from which the main controller thread has been
371 ** created.
372 */
373 complete(&pSchedContext->McStartEvent);
374 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
375 "%s: MC Thread %d (%s) starting up",__func__, current->pid, current->comm);
376
377 /* Get the Global VOSS Context */
378 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
379 if(!pVosContext) {
380 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
381 return 0;
382 }
383
384 /* Get the HDD context */
385 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
386 if(!pHddCtx) {
387 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
388 return 0;
389 }
390
391 while(!shutdown)
392 {
393 // This implements the execution model algorithm
394 retWaitStatus = wait_event_interruptible(pSchedContext->mcWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530395 test_bit(MC_POST_EVENT, &pSchedContext->mcEventFlag) ||
396 test_bit(MC_SUSPEND_EVENT, &pSchedContext->mcEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -0700397
398 if(retWaitStatus == -ERESTARTSYS)
399 {
400 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700401 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700402 break;
403 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530404 clear_bit(MC_POST_EVENT, &pSchedContext->mcEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700405
406 while(1)
407 {
408 // Check if MC needs to shutdown
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530409 if(test_bit(MC_SHUTDOWN_EVENT, &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700410 {
411 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
412 "%s: MC thread signaled to shutdown", __func__);
413 shutdown = VOS_TRUE;
414 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530415 if (test_and_clear_bit(MC_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530416 &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700417 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700418 /* Unblock anyone waiting on suspend */
419 complete(&pHddCtx->mc_sus_event_var);
420 }
421 break;
422 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700423 /*
424 ** Check the WDI queue
425 ** Service it till the entire queue is empty
426 */
427 if (!vos_is_mq_empty(&pSchedContext->wdiMcMq))
428 {
429 wpt_msg *pWdiMsg;
430 /*
431 ** Service the WDI message queue
432 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700433 pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700434
435 if (pMsgWrapper == NULL)
436 {
437 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700438 "%s: pMsgWrapper 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 = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnsond13512a2012-07-17 11:42:19 -0700444
445 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
446 {
447 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700448 "%s: WDI Msg or Callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530449 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700450 break;
451 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700452
453 pWdiMsg->callback(pWdiMsg);
454
455 /*
456 ** return message to the Core
457 */
458 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
459
460 continue;
461 }
462
Jeff Johnson295189b2012-06-20 16:38:30 -0700463 // Check the SYS queue first
464 if (!vos_is_mq_empty(&pSchedContext->sysMcMq))
465 {
466 // Service the SYS message queue
467 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
468 "%s: Servicing the VOS SYS MC Message queue",__func__);
469 pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq);
470 if (pMsgWrapper == NULL)
471 {
472 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700473 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700474 VOS_ASSERT(0);
475 break;
476 }
477 vStatus = sysMcProcessMsg(pSchedContext->pVContext,
478 pMsgWrapper->pVosMsg);
479 if (!VOS_IS_STATUS_SUCCESS(vStatus))
480 {
481 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
482 "%s: Issue Processing SYS message",__func__);
483 }
484 //return message to the Core
485 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
486 continue;
487 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700488 // Check the WDA queue
489 if (!vos_is_mq_empty(&pSchedContext->wdaMcMq))
490 {
491 // Service the WDA message queue
492 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
493 "%s: Servicing the VOS WDA MC Message queue",__func__);
494 pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq);
495 if (pMsgWrapper == NULL)
496 {
497 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700498 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700499 VOS_ASSERT(0);
500 break;
501 }
502 vStatus = WDA_McProcessMsg( pSchedContext->pVContext, pMsgWrapper->pVosMsg);
503 if (!VOS_IS_STATUS_SUCCESS(vStatus))
504 {
505 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
506 "%s: Issue Processing WDA message",__func__);
507 }
508 // return message to the Core
509 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
510 continue;
511 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700512 // Check the PE queue
513 if (!vos_is_mq_empty(&pSchedContext->peMcMq))
514 {
515 // Service the PE message queue
516 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
517 "%s: Servicing the VOS PE MC Message queue",__func__);
518 pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq);
519 if (NULL == pMsgWrapper)
520 {
521 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700522 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700523 VOS_ASSERT(0);
524 break;
525 }
526
527 /* Need some optimization*/
528 pMacContext = vos_get_context(VOS_MODULE_ID_PE, pSchedContext->pVContext);
529 if (NULL == pMacContext)
530 {
531 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
532 "MAC Context not ready yet");
533 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
534 continue;
535 }
536
537 macStatus = peProcessMessages( pMacContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
538 if (eSIR_SUCCESS != macStatus)
539 {
540 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
541 "%s: Issue Processing PE message",__func__);
542 }
543 // return message to the Core
544 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
545 continue;
546 }
547 /** Check the SME queue **/
548 if (!vos_is_mq_empty(&pSchedContext->smeMcMq))
549 {
550 /* Service the SME message queue */
551 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
552 "%s: Servicing the VOS SME MC Message queue",__func__);
553 pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq);
554 if (NULL == pMsgWrapper)
555 {
556 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700557 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700558 VOS_ASSERT(0);
559 break;
560 }
561
562 /* Need some optimization*/
563 pMacContext = vos_get_context(VOS_MODULE_ID_SME, pSchedContext->pVContext);
564 if (NULL == pMacContext)
565 {
566 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
567 "MAC Context not ready yet");
568 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
569 continue;
570 }
571
572 vStatus = sme_ProcessMsg( (tHalHandle)pMacContext, pMsgWrapper->pVosMsg);
573 if (!VOS_IS_STATUS_SUCCESS(vStatus))
574 {
575 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
576 "%s: Issue Processing SME message",__func__);
577 }
578 // return message to the Core
579 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
580 continue;
581 }
582 /** Check the TL queue **/
583 if (!vos_is_mq_empty(&pSchedContext->tlMcMq))
584 {
585 // Service the TL message queue
586 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
587 ("Servicing the VOS TL MC Message queue"));
588 pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq);
589 if (pMsgWrapper == NULL)
590 {
591 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700592 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700593 VOS_ASSERT(0);
594 break;
595 }
596 vStatus = WLANTL_McProcessMsg( pSchedContext->pVContext,
597 pMsgWrapper->pVosMsg);
598 if (!VOS_IS_STATUS_SUCCESS(vStatus))
599 {
600 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
601 "%s: Issue Processing TL message",__func__);
602 }
603 // return message to the Core
604 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
605 continue;
606 }
607 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530608 if (test_and_clear_bit(MC_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530609 &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700610 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700611 spin_lock(&pSchedContext->McThreadLock);
Abhishek Singhbff18d22016-02-04 18:05:32 +0530612 INIT_COMPLETION(pSchedContext->ResumeMcEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700613 /* Mc Thread Suspended */
614 complete(&pHddCtx->mc_sus_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700615 spin_unlock(&pSchedContext->McThreadLock);
616
617 /* Wait foe Resume Indication */
618 wait_for_completion_interruptible(&pSchedContext->ResumeMcEvent);
619 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700620 break; //All queues are empty now
621 } // while message loop processing
622 } // while TRUE
623 // If we get here the MC thread must exit
624 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700625 "%s: MC Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700626 complete_and_exit(&pSchedContext->McShutdown, 0);
627} /* VosMCThread() */
Wilson Yang68349dd2014-02-06 17:30:38 -0800628
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530629v_BOOL_t isSsrPanicOnFailure(void)
630{
631 hdd_context_t *pHddCtx = NULL;
632 v_CONTEXT_t pVosContext = NULL;
633
634 /* Get the Global VOSS Context */
635 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
636 if(!pVosContext)
637 {
638 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
639 return FALSE;
640 }
641
642 /* Get the HDD context */
643 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
644 if((NULL == pHddCtx) || (NULL == pHddCtx->cfg_ini))
645 {
646 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null", __func__);
647 return FALSE;
648 }
649
650 return (pHddCtx->cfg_ini->fIsSsrPanicOnFailure);
651}
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530652/**
653 * vos_wd_detect_thread_stuck()- Detect thread stuck
654 * by probing the MC, TX, RX threads and take action if
655 * Thread doesnt respond.
656 *
657 * This function is called to detect thread stuck
658 * and probe threads.
659 *
660 * Return: void
661 */
662static void vos_wd_detect_thread_stuck(void)
663{
664 unsigned long flags;
665
666 spin_lock_irqsave(&gpVosWatchdogContext->thread_stuck_lock, flags);
667
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +0530668 if ((gpVosWatchdogContext->mcThreadStuckCount == THREAD_STUCK_COUNT) ||
669 (gpVosWatchdogContext->txThreadStuckCount == THREAD_STUCK_COUNT) ||
670 (gpVosWatchdogContext->rxThreadStuckCount == THREAD_STUCK_COUNT))
671 {
672 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
673 hddLog(LOGE, FL("Thread Stuck count reached threshold!!!"
674 "MC Count %d RX count %d TX count %d"),
675 gpVosWatchdogContext->mcThreadStuckCount,
676 gpVosWatchdogContext->rxThreadStuckCount,
677 gpVosWatchdogContext->txThreadStuckCount);
678 return;
679 }
680
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530681 if (gpVosWatchdogContext->mcThreadStuckCount ||
682 gpVosWatchdogContext->txThreadStuckCount ||
683 gpVosWatchdogContext->rxThreadStuckCount)
684 {
685 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
686
687 hddLog(LOG1, FL("MC Count %d RX count %d TX count %d"),
688 gpVosWatchdogContext->mcThreadStuckCount,
689 gpVosWatchdogContext->rxThreadStuckCount,
690 gpVosWatchdogContext->txThreadStuckCount);
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +0530691
692 if (gpVosWatchdogContext->mcThreadStuckCount)
693 {
694 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
695 "%s: Invoking dump stack for MC thread",__func__);
696 vos_dump_stack(MC_Thread);
697 }
698 if (gpVosWatchdogContext->txThreadStuckCount)
699 {
700 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
701 "%s: Invoking dump stack for TX thread",__func__);
702 vos_dump_stack(TX_Thread);
703 }
704 if (gpVosWatchdogContext->rxThreadStuckCount)
705 {
706 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
707 "%s: Invoking dump stack for RX thread",__func__);
708 vos_dump_stack(RX_Thread);
709 }
710
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530711 vos_fatal_event_logs_req(WLAN_LOG_TYPE_FATAL,
712 WLAN_LOG_INDICATOR_HOST_ONLY,
713 WLAN_LOG_REASON_THREAD_STUCK,
714 FALSE, TRUE);
715
716 spin_lock_irqsave(&gpVosWatchdogContext->thread_stuck_lock, flags);
717 }
718
719 /* Increment the thread stuck count for all threads */
720 gpVosWatchdogContext->mcThreadStuckCount++;
721 gpVosWatchdogContext->txThreadStuckCount++;
722 gpVosWatchdogContext->rxThreadStuckCount++;
723
724 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
725 vos_probe_threads();
726
727 /* Restart the timer */
728 if (VOS_STATUS_SUCCESS !=
729 vos_timer_start(&gpVosWatchdogContext->threadStuckTimer,
730 THREAD_STUCK_TIMER_VAL))
731 hddLog(LOGE, FL("Unable to start thread stuck timer"));
732}
733
734/**
735 * wlan_wd_detect_thread_stuck_cb()- Call back of the
736 * thread stuck timer.
737 * @priv: timer data.
738 * This function is called when the thread stuck timer
739 * expire to detect thread stuck and probe threads.
740 *
741 * Return: void
742 */
743static void vos_wd_detect_thread_stuck_cb(void *priv)
744{
745 if (!(vos_is_logp_in_progress(VOS_MODULE_ID_SYS, NULL) ||
746 vos_is_load_unload_in_progress(VOS_MODULE_ID_SYS, NULL)))
747 {
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530748 set_bit(WD_WLAN_DETECT_THREAD_STUCK,
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530749 &gpVosWatchdogContext->wdEventFlag);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530750 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530751 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
752 }
753}
754
755/**
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +0530756 * vos_thread_stuck_timer_init - Initialize thread stuck timer
757 *
758 * @pWdContext: watchdog context.
759 *
760 * Return: void
761 */
762void vos_thread_stuck_timer_init(pVosWatchdogContext pWdContext)
763{
764 if (vos_timer_init_deferrable(&pWdContext->threadStuckTimer,
765 VOS_TIMER_TYPE_SW,
766 vos_wd_detect_thread_stuck_cb, NULL))
767 hddLog(LOGE, FL("Unable to initialize thread stuck timer"));
768 else
769 {
770 if (VOS_STATUS_SUCCESS !=
771 vos_timer_start(&pWdContext->threadStuckTimer,
772 THREAD_STUCK_TIMER_VAL))
773 hddLog(LOGE, FL("Unable to start thread stuck timer"));
774 else
775 hddLog(LOG1, FL("Successfully started thread stuck timer"));
776 }
777
778}
779
780/**
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530781 * wlan_logging_reset_thread_stuck_count()- Callback to
782 * probe msg sent to Threads.
783 *
784 * @threadId: passed threadid
785 *
786 * This function is called to by the thread after
787 * processing the probe msg, with their own thread id.
788 *
789 * Return: void.
790 */
791void vos_wd_reset_thread_stuck_count(int threadId)
792{
793 unsigned long flags;
794
795 spin_lock_irqsave(&gpVosWatchdogContext->thread_stuck_lock, flags);
796 if (vos_sched_is_mc_thread(threadId))
797 gpVosWatchdogContext->mcThreadStuckCount = 0;
798 else if (vos_sched_is_tx_thread(threadId))
799 gpVosWatchdogContext->txThreadStuckCount = 0;
800 else if (vos_sched_is_rx_thread(threadId))
801 gpVosWatchdogContext->rxThreadStuckCount = 0;
802 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
803}
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530804
Jeff Johnson295189b2012-06-20 16:38:30 -0700805/*---------------------------------------------------------------------------
806 \brief VosWdThread() - The VOSS Watchdog thread
807 The \a VosWdThread() is the Watchdog thread:
808 \param Arg - pointer to the global vOSS Sched Context
809 \return Thread exit code
810 \sa VosMcThread()
811 -------------------------------------------------------------------------*/
812static int
813VosWDThread
814(
815 void * Arg
816)
817{
818 pVosWatchdogContext pWdContext = (pVosWatchdogContext)Arg;
819 int retWaitStatus = 0;
820 v_BOOL_t shutdown = VOS_FALSE;
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530821 int count = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700822 VOS_STATUS vosStatus = VOS_STATUS_SUCCESS;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530823 hdd_context_t *pHddCtx = NULL;
824 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700825 set_user_nice(current, -3);
826
827 if (Arg == NULL)
828 {
829 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700830 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700831 return 0;
832 }
Yue Maf49ba872013-08-19 12:04:25 -0700833
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530834 /* Get the Global VOSS Context */
835 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
836
837 if(!pVosContext)
838 {
839 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
840 return 0;
841 }
842
843 /* Get the HDD context */
844 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
845
846 if(!pHddCtx)
847 {
848 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
849 return 0;
850 }
851
Yue Maf49ba872013-08-19 12:04:25 -0700852#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700853 daemonize("WD_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700854#endif
855
Jeff Johnson295189b2012-06-20 16:38:30 -0700856 /*
857 ** Ack back to the context from which the Watchdog thread has been
858 ** created.
859 */
860 complete(&pWdContext->WdStartEvent);
861 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
862 "%s: Watchdog Thread %d (%s) starting up",__func__, current->pid, current->comm);
863
864 while(!shutdown)
865 {
866 // This implements the Watchdog execution model algorithm
867 retWaitStatus = wait_event_interruptible(pWdContext->wdWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530868 test_bit(WD_POST_EVENT, &pWdContext->wdEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -0700869 if(retWaitStatus == -ERESTARTSYS)
870 {
871 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700872 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700873 break;
874 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530875 clear_bit(WD_POST_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700876 while(1)
877 {
Abhishek Singh58749d62016-02-03 15:27:20 +0530878
879 /* Post Msg to detect thread stuck. */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530880 if (test_and_clear_bit(WD_WLAN_DETECT_THREAD_STUCK,
Abhishek Singh58749d62016-02-03 15:27:20 +0530881 &pWdContext->wdEventFlag))
882 {
883 vos_wd_detect_thread_stuck();
884 /*
885 * Process here and return without processing any SSR
886 * related logic.
887 */
888 break;
889 }
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530890 /* Check for any Active Entry Points
891 * If active, delay SSR until no entry point is active or
892 * delay until count is decremented to ZERO
893 */
894 count = MAX_SSR_WAIT_ITERATIONS;
895 while (count)
896 {
897 if (!atomic_read(&ssr_protect_entry_count))
898 {
899 /* no external threads are executing */
900 break;
901 }
902 /* at least one external thread is executing */
903 if (--count)
904 {
905 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
906 "%s: Waiting for active entry points to exit", __func__);
907 msleep(SSR_WAIT_SLEEP_TIME);
908 }
909 }
910 /* at least one external thread is executing */
911 if (!count)
912 {
913 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
914 "%s: Continuing SSR when %d Entry points are still active",
915 __func__, atomic_read(&ssr_protect_entry_count));
916 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700917 // Check if Watchdog needs to shutdown
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530918 if(test_bit(WD_SHUTDOWN_EVENT, &pWdContext->wdEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700919 {
920 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
921 "%s: Watchdog thread signaled to shutdown", __func__);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530922 clear_bit(WD_SHUTDOWN_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700923 shutdown = VOS_TRUE;
924 break;
925 }
926 /* subsystem restart: shutdown event handler */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530927 else if(test_bit(WD_WLAN_SHUTDOWN_EVENT, &pWdContext->wdEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700928 {
929 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
930 "%s: Watchdog thread signaled to perform WLAN shutdown",__func__);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530931 clear_bit(WD_WLAN_SHUTDOWN_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700932
933 //Perform WLAN shutdown
934 if(!pWdContext->resetInProgress)
935 {
936 pWdContext->resetInProgress = true;
937 vosStatus = hdd_wlan_shutdown();
938
939 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
940 {
941 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
942 "%s: Failed to shutdown WLAN",__func__);
943 VOS_ASSERT(0);
944 goto err_reset;
945 }
946 }
947 }
948 /* subsystem restart: re-init event handler */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530949 else if(test_bit(WD_WLAN_REINIT_EVENT, &pWdContext->wdEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700950 {
951 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
952 "%s: Watchdog thread signaled to perform WLAN re-init",__func__);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530953 clear_bit(WD_WLAN_REINIT_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700954
955 //Perform WLAN re-init
956 if(!pWdContext->resetInProgress)
957 {
958 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Katya Nigamb37c7812014-06-19 14:45:16 +0530959 "%s: Do WLAN re-init only when it is shutdown !!",__func__);
960 break;
Jeff Johnson295189b2012-06-20 16:38:30 -0700961 }
962 vosStatus = hdd_wlan_re_init();
963
964 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
965 {
966 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
967 "%s: Failed to re-init WLAN",__func__);
968 VOS_ASSERT(0);
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530969 pWdContext->isFatalError = true;
970 }
971 else
972 {
973 pWdContext->isFatalError = false;
Mukul Sharmae74e42c2015-08-06 23:55:49 +0530974 pHddCtx->isLogpInProgress = FALSE;
975 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, FALSE);
Jeff Johnson295189b2012-06-20 16:38:30 -0700976 }
Mihir Shetefd528652014-06-23 19:07:50 +0530977 atomic_set(&pHddCtx->isRestartInProgress, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700978 pWdContext->resetInProgress = false;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530979 complete(&pHddCtx->ssr_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700980 }
981 else
982 {
983 //Unnecessary wakeup - Should never happen!!
984 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
985 "%s: Watchdog thread woke up unnecessarily",__func__);
986 }
987 break;
988 } // while message loop processing
989 } // while shutdown
990
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530991 vos_timer_destroy(&pWdContext->threadStuckTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700992 // If we get here the Watchdog thread must exit
993 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700994 "%s: Watchdog Thread exiting !!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700995 complete_and_exit(&pWdContext->WdShutdown, 0);
996
997err_reset:
998 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700999 "%s: Watchdog Thread Failed to Reset, Exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001000 return 0;
1001
1002} /* VosMCThread() */
1003
1004/*---------------------------------------------------------------------------
1005 \brief VosTXThread() - The VOSS Main Tx thread
1006 The \a VosTxThread() is the VOSS main controller thread:
1007 \param Arg - pointer to the global vOSS Sched Context
1008
1009 \return Thread exit code
1010 \sa VosTxThread()
1011 -------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -07001012static int VosTXThread ( void * Arg )
1013{
1014 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
1015 pVosMsgWrapper pMsgWrapper = NULL;
1016 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1017 int retWaitStatus = 0;
1018 v_BOOL_t shutdown = VOS_FALSE;
1019 hdd_context_t *pHddCtx = NULL;
1020 v_CONTEXT_t pVosContext = NULL;
1021
1022 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001023
1024#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -07001025 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001026#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001027
1028 if (Arg == NULL)
1029 {
1030 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001031 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001032 return 0;
1033 }
Yue Maf49ba872013-08-19 12:04:25 -07001034
1035#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001036 daemonize("TX_Thread");
Yue Maf49ba872013-08-19 12:04:25 -07001037#endif
1038
Jeff Johnson295189b2012-06-20 16:38:30 -07001039 /*
1040 ** Ack back to the context from which the main controller thread has been
1041 ** created.
1042 */
1043 complete(&pSchedContext->TxStartEvent);
1044 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1045 "%s: TX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
1046
1047 /* Get the Global VOSS Context */
1048 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
1049 if(!pVosContext) {
1050 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
1051 return 0;
1052 }
1053
1054 /* Get the HDD context */
1055 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1056 if(!pHddCtx) {
1057 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
1058 return 0;
1059 }
1060
1061
1062 while(!shutdown)
1063 {
1064 // This implements the execution model algorithm
1065 retWaitStatus = wait_event_interruptible(pSchedContext->txWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301066 test_bit(TX_POST_EVENT, &pSchedContext->txEventFlag) ||
1067 test_bit(TX_SUSPEND_EVENT, &pSchedContext->txEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -07001068
1069
1070 if(retWaitStatus == -ERESTARTSYS)
1071 {
1072 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001073 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001074 break;
1075 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301076 clear_bit(TX_POST_EVENT, &pSchedContext->txEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001077
1078 while(1)
1079 {
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301080 if(test_bit(TX_SHUTDOWN_EVENT, &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001081 {
1082 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1083 "%s: TX thread signaled to shutdown", __func__);
1084 shutdown = VOS_TRUE;
1085 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301086 if (test_and_clear_bit(TX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301087 &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001088 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001089 /* Unblock anyone waiting on suspend */
1090 complete(&pHddCtx->tx_sus_event_var);
1091 }
1092 break;
1093 }
1094 // Check the SYS queue first
1095 if (!vos_is_mq_empty(&pSchedContext->sysTxMq))
1096 {
1097 // Service the SYS message queue
1098 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1099 "%s: Servicing the VOS SYS TX Message queue",__func__);
1100 pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq);
1101 if (pMsgWrapper == NULL)
1102 {
1103 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001104 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001105 VOS_ASSERT(0);
1106 break;
1107 }
1108 vStatus = sysTxProcessMsg( pSchedContext->pVContext,
1109 pMsgWrapper->pVosMsg);
1110 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1111 {
1112 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1113 "%s: Issue Processing TX SYS message",__func__);
1114 }
1115 // return message to the Core
1116 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1117 continue;
1118 }
1119 // Check now the TL queue
1120 if (!vos_is_mq_empty(&pSchedContext->tlTxMq))
1121 {
1122 // Service the TL message queue
1123 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1124 "%s: Servicing the VOS TL TX Message queue",__func__);
1125 pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq);
1126 if (pMsgWrapper == NULL)
1127 {
1128 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001129 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001130 VOS_ASSERT(0);
1131 break;
1132 }
1133 vStatus = WLANTL_TxProcessMsg( pSchedContext->pVContext,
1134 pMsgWrapper->pVosMsg);
1135 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1136 {
1137 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1138 "%s: Issue Processing TX TL message",__func__);
1139 }
1140 // return message to the Core
1141 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1142 continue;
1143 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001144 // Check the WDI queue
1145 if (!vos_is_mq_empty(&pSchedContext->wdiTxMq))
1146 {
1147 wpt_msg *pWdiMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07001148 pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001149
1150 if (pMsgWrapper == NULL)
1151 {
1152 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001153 "%s: pMsgWrapper is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301154 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001155 break;
1156 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001157
1158 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07001159
Jeff Johnsond13512a2012-07-17 11:42:19 -07001160 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
1161 {
1162 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001163 "%s: WDI Msg or Callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301164 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001165 break;
1166 }
1167
Jeff Johnson295189b2012-06-20 16:38:30 -07001168 pWdiMsg->callback(pWdiMsg);
1169
1170 // return message to the Core
1171 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1172
1173 continue;
1174 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001175 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301176 if (test_and_clear_bit(TX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301177 &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001178 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001179 spin_lock(&pSchedContext->TxThreadLock);
Abhishek Singhbff18d22016-02-04 18:05:32 +05301180 INIT_COMPLETION(pSchedContext->ResumeTxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -07001181 /* Tx Thread Suspended */
1182 complete(&pHddCtx->tx_sus_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07001183 spin_unlock(&pSchedContext->TxThreadLock);
Jeff Johnson295189b2012-06-20 16:38:30 -07001184 /* Wait foe Resume Indication */
1185 wait_for_completion_interruptible(&pSchedContext->ResumeTxEvent);
1186 }
1187
1188 break; //All queues are empty now
1189 } // while message loop processing
1190 } // while TRUE
1191 // If we get here the TX thread must exit
1192 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001193 "%s: TX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001194 complete_and_exit(&pSchedContext->TxShutdown, 0);
1195} /* VosTxThread() */
1196
Jeff Johnson295189b2012-06-20 16:38:30 -07001197/*---------------------------------------------------------------------------
1198 \brief VosRXThread() - The VOSS Main Rx thread
1199 The \a VosRxThread() is the VOSS Rx controller thread:
1200 \param Arg - pointer to the global vOSS Sched Context
1201
1202 \return Thread exit code
1203 \sa VosRxThread()
1204 -------------------------------------------------------------------------*/
1205
1206static int VosRXThread ( void * Arg )
1207{
1208 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
1209 pVosMsgWrapper pMsgWrapper = NULL;
1210 int retWaitStatus = 0;
1211 v_BOOL_t shutdown = VOS_FALSE;
1212 hdd_context_t *pHddCtx = NULL;
1213 v_CONTEXT_t pVosContext = NULL;
1214 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1215
1216 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001217
1218#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -07001219 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001220#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001221
1222 if (Arg == NULL)
1223 {
1224 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001225 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001226 return 0;
1227 }
Yue Maf49ba872013-08-19 12:04:25 -07001228
1229#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001230 daemonize("RX_Thread");
Yue Maf49ba872013-08-19 12:04:25 -07001231#endif
1232
Jeff Johnson295189b2012-06-20 16:38:30 -07001233 /*
1234 ** Ack back to the context from which the main controller thread has been
1235 ** created.
1236 */
1237 complete(&pSchedContext->RxStartEvent);
1238 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1239 "%s: RX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
1240
1241 /* Get the Global VOSS Context */
1242 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
1243 if(!pVosContext) {
1244 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
1245 return 0;
1246 }
1247
1248 /* Get the HDD context */
1249 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1250 if(!pHddCtx) {
1251 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
1252 return 0;
1253 }
1254
1255 while(!shutdown)
1256 {
1257 // This implements the execution model algorithm
1258 retWaitStatus = wait_event_interruptible(pSchedContext->rxWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301259 test_bit(RX_POST_EVENT, &pSchedContext->rxEventFlag) ||
1260 test_bit(RX_SUSPEND_EVENT, &pSchedContext->rxEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -07001261
1262
1263 if(retWaitStatus == -ERESTARTSYS)
1264 {
1265 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001266 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001267 break;
1268 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301269 clear_bit(RX_POST_EVENT, &pSchedContext->rxEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001270
1271 while(1)
1272 {
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301273 if(test_bit(RX_SHUTDOWN_EVENT, &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001274 {
1275 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1276 "%s: RX thread signaled to shutdown", __func__);
1277 shutdown = VOS_TRUE;
1278 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301279 if (test_and_clear_bit(RX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301280 &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001281 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001282 /* Unblock anyone waiting on suspend */
1283 complete(&pHddCtx->rx_sus_event_var);
1284 }
1285 break;
1286 }
1287
1288
1289 // Check the SYS queue first
1290 if (!vos_is_mq_empty(&pSchedContext->sysRxMq))
1291 {
1292 // Service the SYS message queue
1293 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1294 "%s: Servicing the VOS SYS RX Message queue",__func__);
1295 pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq);
1296 if (pMsgWrapper == NULL)
1297 {
1298 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001299 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001300 VOS_ASSERT(0);
1301 break;
1302 }
1303 vStatus = sysRxProcessMsg( pSchedContext->pVContext,
1304 pMsgWrapper->pVosMsg);
1305 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1306 {
1307 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1308 "%s: Issue Processing TX SYS message",__func__);
1309 }
1310 // return message to the Core
1311 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1312 continue;
1313 }
1314
Katya Nigam664f5032014-05-05 12:24:32 +05301315 // Check now the TL queue
1316 if (!vos_is_mq_empty(&pSchedContext->tlRxMq))
1317 {
1318 // Service the TL message queue
1319 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1320 "%s: Servicing the VOS TL RX Message queue",__func__);
1321 pMsgWrapper = vos_mq_get(&pSchedContext->tlRxMq);
1322 if (pMsgWrapper == NULL)
1323 {
1324 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1325 "%s: pMsgWrapper is NULL", __func__);
1326 VOS_ASSERT(0);
1327 break;
1328 }
1329 vStatus = WLANTL_RxProcessMsg( pSchedContext->pVContext,
1330 pMsgWrapper->pVosMsg);
1331 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1332 {
1333 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1334 "%s: Issue Processing RX TL message",__func__);
1335 }
1336 // return message to the Core
1337 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1338 continue;
1339 }
1340
Jeff Johnson295189b2012-06-20 16:38:30 -07001341 // Check the WDI queue
1342 if (!vos_is_mq_empty(&pSchedContext->wdiRxMq))
1343 {
1344 wpt_msg *pWdiMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07001345 pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq);
1346 if ((NULL == pMsgWrapper) || (NULL == pMsgWrapper->pVosMsg))
1347 {
1348 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001349 "%s: wdiRxMq message is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301350 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001351 // we won't return this wrapper since it is corrupt
1352 }
1353 else
1354 {
1355 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
1356 if ((NULL == pWdiMsg) || (NULL == pWdiMsg->callback))
1357 {
1358 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001359 "%s: WDI Msg or callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301360 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001361 }
1362 else
1363 {
1364 // invoke the message handler
1365 pWdiMsg->callback(pWdiMsg);
1366 }
1367
1368 // return message to the Core
1369 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1370 }
1371 continue;
1372 }
1373
1374 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301375 if (test_and_clear_bit(RX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301376 &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001377 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001378 spin_lock(&pSchedContext->RxThreadLock);
Abhishek Singhbff18d22016-02-04 18:05:32 +05301379 INIT_COMPLETION(pSchedContext->ResumeRxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -07001380 /* Rx Thread Suspended */
1381 complete(&pHddCtx->rx_sus_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07001382 spin_unlock(&pSchedContext->RxThreadLock);
1383
1384 /* Wait for Resume Indication */
1385 wait_for_completion_interruptible(&pSchedContext->ResumeRxEvent);
1386 }
1387
1388 break; //All queues are empty now
1389 } // while message loop processing
1390 } // while TRUE
1391 // If we get here the RX thread must exit
1392 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001393 "%s: RX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001394 complete_and_exit(&pSchedContext->RxShutdown, 0);
1395} /* VosRxThread() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001396
Jeff Johnson295189b2012-06-20 16:38:30 -07001397/*---------------------------------------------------------------------------
1398 \brief vos_sched_close() - Close the vOSS Scheduler
1399 The \a vos_sched_closes() function closes the vOSS Scheduler
1400 Upon successful closing:
1401 - All the message queues are flushed
1402 - The Main Controller thread is closed
1403 - The Tx thread is closed
1404
1405 \param pVosContext - pointer to the global vOSS Context
1406 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1407 is ready to be used.
1408 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
1409 function
1410 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
1411 \sa vos_sched_close()
1412---------------------------------------------------------------------------*/
1413VOS_STATUS vos_sched_close ( v_PVOID_t pVosContext )
1414{
1415 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001416 "%s: invoked", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001417 if (gpVosSchedContext == NULL)
1418 {
1419 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Arif Hussain02882402013-11-17 21:55:29 -08001420 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001421 return VOS_STATUS_E_FAILURE;
1422 }
1423
1424 // shut down MC Thread
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301425 set_bit(MC_SHUTDOWN_EVENT, &gpVosSchedContext->mcEventFlag);
1426 set_bit(MC_POST_EVENT, &gpVosSchedContext->mcEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001427 wake_up_interruptible(&gpVosSchedContext->mcWaitQueue);
1428 //Wait for MC to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301429 wait_for_completion(&gpVosSchedContext->McShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001430 gpVosSchedContext->McThread = 0;
1431
Jeff Johnson295189b2012-06-20 16:38:30 -07001432 // shut down TX Thread
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301433 set_bit(TX_SHUTDOWN_EVENT, &gpVosSchedContext->txEventFlag);
1434 set_bit(TX_POST_EVENT, &gpVosSchedContext->txEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001435 wake_up_interruptible(&gpVosSchedContext->txWaitQueue);
1436 //Wait for TX to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301437 wait_for_completion(&gpVosSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001438 gpVosSchedContext->TxThread = 0;
1439
Jeff Johnson295189b2012-06-20 16:38:30 -07001440 // shut down RX Thread
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301441 set_bit(RX_SHUTDOWN_EVENT, &gpVosSchedContext->rxEventFlag);
1442 set_bit(RX_POST_EVENT, &gpVosSchedContext->rxEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001443 wake_up_interruptible(&gpVosSchedContext->rxWaitQueue);
1444 //Wait for RX to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301445 wait_for_completion(&gpVosSchedContext->RxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001446 gpVosSchedContext->RxThread = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001447
1448 //Clean up message queues of TX and MC thread
1449 vos_sched_flush_mc_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001450 vos_sched_flush_tx_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001451 vos_sched_flush_rx_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001452
1453 //Deinit all the queues
1454 vos_sched_deinit_mqs(gpVosSchedContext);
1455
1456 return VOS_STATUS_SUCCESS;
1457} /* vox_sched_close() */
1458
1459VOS_STATUS vos_watchdog_close ( v_PVOID_t pVosContext )
1460{
1461 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001462 "%s: vos_watchdog closing now", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001463 if (gpVosWatchdogContext == NULL)
1464 {
1465 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Arif Hussain02882402013-11-17 21:55:29 -08001466 "%s: gpVosWatchdogContext is NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001467 return VOS_STATUS_E_FAILURE;
1468 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301469 set_bit(WD_SHUTDOWN_EVENT, &gpVosWatchdogContext->wdEventFlag);
1470 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001471 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1472 //Wait for Watchdog thread to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301473 wait_for_completion(&gpVosWatchdogContext->WdShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001474 return VOS_STATUS_SUCCESS;
1475} /* vos_watchdog_close() */
1476
Jeff Johnson295189b2012-06-20 16:38:30 -07001477/*---------------------------------------------------------------------------
1478 \brief vos_sched_init_mqs: Initialize the vOSS Scheduler message queues
1479 The \a vos_sched_init_mqs() function initializes the vOSS Scheduler
1480 message queues.
1481 \param pVosSchedContext - pointer to the Scheduler Context.
1482 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1483 is ready to be used.
1484 VOS_STATUS_E_RESOURCES - System resources (other than memory)
1485 are unavailable to initilize the scheduler
1486
1487 \sa vos_sched_init_mqs()
1488 -------------------------------------------------------------------------*/
1489VOS_STATUS vos_sched_init_mqs ( pVosSchedContext pSchedContext )
1490{
1491 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1492 // Now intialize all the message queues
Jeff Johnson295189b2012-06-20 16:38:30 -07001493 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1494 "%s: Initializing the WDA MC Message queue",__func__);
1495 vStatus = vos_mq_init(&pSchedContext->wdaMcMq);
1496 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1497 {
1498 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1499 "%s: Failed to init WDA MC Message queue",__func__);
1500 VOS_ASSERT(0);
1501 return vStatus;
1502 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001503 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1504 "%s: Initializing the PE MC Message queue",__func__);
1505 vStatus = vos_mq_init(&pSchedContext->peMcMq);
1506 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1507 {
1508 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1509 "%s: Failed to init PE MC Message queue",__func__);
1510 VOS_ASSERT(0);
1511 return vStatus;
1512 }
1513 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1514 "%s: Initializing the SME MC Message queue", __func__);
1515 vStatus = vos_mq_init(&pSchedContext->smeMcMq);
1516 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1517 {
1518 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1519 "%s: Failed to init SME MC Message queue",__func__);
1520 VOS_ASSERT(0);
1521 return vStatus;
1522 }
1523 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1524 "%s: Initializing the TL MC Message queue",__func__);
1525 vStatus = vos_mq_init(&pSchedContext->tlMcMq);
1526 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1527 {
1528 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1529 "%s: Failed to init TL MC Message queue",__func__);
1530 VOS_ASSERT(0);
1531 return vStatus;
1532 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001533 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1534 "%s: Initializing the SYS MC Message queue",__func__);
1535 vStatus = vos_mq_init(&pSchedContext->sysMcMq);
1536 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1537 {
1538 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1539 "%s: Failed to init SYS MC Message queue",__func__);
1540 VOS_ASSERT(0);
1541 return vStatus;
1542 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001543 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1544 "%s: Initializing the WDI MC Message queue",__func__);
1545
1546 vStatus = vos_mq_init(&pSchedContext->wdiMcMq);
1547 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1548 {
1549 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1550 "%s: Failed to init WDI MC Message queue",__func__);
1551 VOS_ASSERT(0);
1552 return vStatus;
1553 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001554
Jeff Johnson295189b2012-06-20 16:38:30 -07001555 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1556 "%s: Initializing the TL Tx Message queue",__func__);
1557 vStatus = vos_mq_init(&pSchedContext->tlTxMq);
1558 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1559 {
1560 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1561 "%s: Failed to init TL TX Message queue",__func__);
1562 VOS_ASSERT(0);
1563 return vStatus;
1564 }
Katya Nigam664f5032014-05-05 12:24:32 +05301565
1566 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1567 "%s: Initializing the TL Rx Message queue",__func__);
1568 vStatus = vos_mq_init(&pSchedContext->tlRxMq);
1569 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1570 {
1571 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1572 "%s: Failed to init TL RX Message queue",__func__);
1573 VOS_ASSERT(0);
1574 return vStatus;
1575 }
1576
Jeff Johnson295189b2012-06-20 16:38:30 -07001577 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1578 "%s: Initializing the WDI Tx Message queue",__func__);
1579 vStatus = vos_mq_init(&pSchedContext->wdiTxMq);
1580 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1581 {
1582 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1583 "%s: Failed to init WDI TX Message queue",__func__);
1584 VOS_ASSERT(0);
1585 return vStatus;
1586 }
1587
1588 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1589 "%s: Initializing the WDI Rx Message queue",__func__);
1590
1591 vStatus = vos_mq_init(&pSchedContext->wdiRxMq);
1592 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1593 {
1594 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1595 "%s: Failed to init WDI RX Message queue",__func__);
1596 VOS_ASSERT(0);
1597 return vStatus;
1598 }
1599
Jeff Johnson295189b2012-06-20 16:38:30 -07001600 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1601 "%s: Initializing the SYS Tx Message queue",__func__);
1602 vStatus = vos_mq_init(&pSchedContext->sysTxMq);
1603 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1604 {
1605 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1606 "%s: Failed to init SYS TX Message queue",__func__);
1607 VOS_ASSERT(0);
1608 return vStatus;
1609 }
1610
1611 vStatus = vos_mq_init(&pSchedContext->sysRxMq);
1612 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1613 {
1614 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1615 "%s: Failed to init SYS RX Message queue",__func__);
1616 VOS_ASSERT(0);
1617 return vStatus;
1618 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001619 return VOS_STATUS_SUCCESS;
1620} /* vos_sched_init_mqs() */
1621
1622/*---------------------------------------------------------------------------
1623 \brief vos_sched_deinit_mqs: Deinitialize the vOSS Scheduler message queues
1624 The \a vos_sched_init_mqs() function deinitializes the vOSS Scheduler
1625 message queues.
1626 \param pVosSchedContext - pointer to the Scheduler Context.
1627 \return None
1628 \sa vos_sched_deinit_mqs()
1629 -------------------------------------------------------------------------*/
1630void vos_sched_deinit_mqs ( pVosSchedContext pSchedContext )
1631{
1632 // Now de-intialize all message queues
Jeff Johnson295189b2012-06-20 16:38:30 -07001633 // MC WDA
1634 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1635 "%s De-Initializing the WDA MC Message queue",__func__);
1636 vos_mq_deinit(&pSchedContext->wdaMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001637 //MC PE
1638 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1639 "%s De-Initializing the PE MC Message queue",__func__);
1640 vos_mq_deinit(&pSchedContext->peMcMq);
1641 //MC SME
1642 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1643 "%s De-Initializing the SME MC Message queue",__func__);
1644 vos_mq_deinit(&pSchedContext->smeMcMq);
1645 //MC TL
1646 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1647 "%s De-Initializing the TL MC Message queue",__func__);
1648 vos_mq_deinit(&pSchedContext->tlMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001649 //MC SYS
1650 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1651 "%s De-Initializing the SYS MC Message queue",__func__);
1652 vos_mq_deinit(&pSchedContext->sysMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001653 // MC WDI
1654 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1655 "%s De-Initializing the WDI MC Message queue",__func__);
1656 vos_mq_deinit(&pSchedContext->wdiMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001657
Jeff Johnson295189b2012-06-20 16:38:30 -07001658 //Tx TL
1659 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1660 "%s De-Initializing the TL Tx Message queue",__func__);
1661 vos_mq_deinit(&pSchedContext->tlTxMq);
Katya Nigam664f5032014-05-05 12:24:32 +05301662
1663 //Rx TL
1664 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1665 "%s De-Initializing the TL Rx Message queue",__func__);
1666 vos_mq_deinit(&pSchedContext->tlRxMq);
1667
Jeff Johnson295189b2012-06-20 16:38:30 -07001668 //Tx WDI
1669 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1670 "%s: DeInitializing the WDI Tx Message queue",__func__);
1671 vos_mq_deinit(&pSchedContext->wdiTxMq);
1672
1673
1674 //Rx WDI
1675 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1676 "%s: DeInitializing the WDI Rx Message queue",__func__);
1677 vos_mq_deinit(&pSchedContext->wdiRxMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001678
1679 //Tx SYS
1680 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1681 "%s: DeInitializing the SYS Tx Message queue",__func__);
1682 vos_mq_deinit(&pSchedContext->sysTxMq);
1683
1684 //Rx SYS
1685 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1686 "%s: DeInitializing the SYS Rx Message queue",__func__);
1687 vos_mq_deinit(&pSchedContext->sysRxMq);
1688
Jeff Johnson295189b2012-06-20 16:38:30 -07001689} /* vos_sched_deinit_mqs() */
1690
1691/*-------------------------------------------------------------------------
1692 this helper function flushes all the MC message queues
1693 -------------------------------------------------------------------------*/
1694void vos_sched_flush_mc_mqs ( pVosSchedContext pSchedContext )
1695{
1696 pVosMsgWrapper pMsgWrapper = NULL;
1697 pVosContextType vosCtx;
1698
1699 /*
1700 ** Here each of the MC thread MQ shall be drained and returned to the
1701 ** Core. Before returning a wrapper to the Core, the VOS message shall be
1702 ** freed first
1703 */
1704 VOS_TRACE( VOS_MODULE_ID_VOSS,
1705 VOS_TRACE_LEVEL_INFO,
Arif Hussain02882402013-11-17 21:55:29 -08001706 ("Flushing the MC Thread message queue") );
Jeff Johnson295189b2012-06-20 16:38:30 -07001707
1708 if (NULL == pSchedContext)
1709 {
1710 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001711 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001712 return;
1713 }
1714
1715 vosCtx = (pVosContextType)(pSchedContext->pVContext);
1716 if (NULL == vosCtx)
1717 {
1718 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001719 "%s: vosCtx is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001720 return;
1721 }
1722
1723 /* Flush the SYS Mq */
1724 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq) ))
1725 {
1726 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301727 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001728 "%s: Freeing MC SYS message type %d ",__func__,
1729 pMsgWrapper->pVosMsg->type );
1730 sysMcFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1731 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1732 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001733 /* Flush the WDA Mq */
1734 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq) ))
1735 {
1736 if(pMsgWrapper->pVosMsg != NULL)
1737 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301738 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001739 "%s: Freeing MC WDA MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001740 __func__, pMsgWrapper->pVosMsg->type );
Jeff Johnson295189b2012-06-20 16:38:30 -07001741 if (pMsgWrapper->pVosMsg->bodyptr) {
1742 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1743 }
1744
1745 pMsgWrapper->pVosMsg->bodyptr = NULL;
1746 pMsgWrapper->pVosMsg->bodyval = 0;
1747 pMsgWrapper->pVosMsg->type = 0;
1748 }
1749 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1750 }
1751
1752 /* Flush the WDI Mq */
1753 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq) ))
1754 {
1755 if(pMsgWrapper->pVosMsg != NULL)
1756 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301757 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001758 "%s: Freeing MC WDI MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001759 __func__, pMsgWrapper->pVosMsg->type );
Leo Chang0f24ca12013-12-17 13:35:00 -08001760
1761 /* MSG body pointer is not NULL
1762 * and MSG type is 0
1763 * This MSG is not posted by SMD NOTIFY
1764 * We have to free MSG body */
1765 if ((pMsgWrapper->pVosMsg->bodyptr) && (!pMsgWrapper->pVosMsg->type))
1766 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001767 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1768 }
Leo Chang0f24ca12013-12-17 13:35:00 -08001769 /* MSG body pointer is not NULL
1770 * and MSG type is not 0
1771 * This MSG is posted by SMD NOTIFY
1772 * We should not free MSG body */
1773 else if ((pMsgWrapper->pVosMsg->bodyptr) && pMsgWrapper->pVosMsg->type)
1774 {
1775 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1776 "%s: SMD NOTIFY MSG, do not free body",
1777 __func__);
1778 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001779 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
Jeff Johnson295189b2012-06-20 16:38:30 -07001786 /* Flush the PE Mq */
1787 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq) ))
1788 {
1789 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301790 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001791 "%s: Freeing MC PE MSG message type %d",__func__,
1792 pMsgWrapper->pVosMsg->type );
1793 peFreeMsg(vosCtx->pMACContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
1794 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1795 }
1796 /* Flush the SME Mq */
1797 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq) ))
1798 {
1799 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301800 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001801 "%s: Freeing MC SME MSG message type %d", __func__,
1802 pMsgWrapper->pVosMsg->type );
1803 sme_FreeMsg(vosCtx->pMACContext, pMsgWrapper->pVosMsg);
1804 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1805 }
1806 /* Flush the TL Mq */
1807 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq) ))
1808 {
1809 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301810 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001811 "%s: Freeing MC TL message type %d",__func__,
1812 pMsgWrapper->pVosMsg->type );
1813 WLANTL_McFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1814 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1815 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001816} /* vos_sched_flush_mc_mqs() */
1817
1818/*-------------------------------------------------------------------------
1819 This helper function flushes all the TX message queues
1820 ------------------------------------------------------------------------*/
1821void vos_sched_flush_tx_mqs ( pVosSchedContext pSchedContext )
1822{
1823 pVosMsgWrapper pMsgWrapper = NULL;
1824 /*
1825 ** Here each of the TX thread MQ shall be drained and returned to the
1826 ** Core. Before returning a wrapper to the Core, the VOS message shall
1827 ** be freed first
1828 */
1829 VOS_TRACE( VOS_MODULE_ID_VOSS,
1830 VOS_TRACE_LEVEL_INFO,
1831 "%s: Flushing the TX Thread message queue",__func__);
1832
1833 if (NULL == pSchedContext)
1834 {
1835 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001836 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001837 return;
1838 }
1839
1840 /* Flush the SYS Mq */
1841 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq) ))
1842 {
1843 VOS_TRACE( VOS_MODULE_ID_VOSS,
1844 VOS_TRACE_LEVEL_INFO,
1845 "%s: Freeing TX SYS message type %d",__func__,
1846 pMsgWrapper->pVosMsg->type );
1847 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1848 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1849 }
1850 /* Flush the TL Mq */
1851 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq) ))
1852 {
1853 VOS_TRACE( VOS_MODULE_ID_VOSS,
1854 VOS_TRACE_LEVEL_INFO,
1855 "%s: Freeing TX TL MSG message type %d",__func__,
1856 pMsgWrapper->pVosMsg->type );
1857 WLANTL_TxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1858 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1859 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001860 /* Flush the WDI Mq */
1861 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq) ))
1862 {
1863 VOS_TRACE( VOS_MODULE_ID_VOSS,
1864 VOS_TRACE_LEVEL_INFO,
1865 "%s: Freeing TX WDI MSG message type %d",__func__,
1866 pMsgWrapper->pVosMsg->type );
1867 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1868 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1869 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001870} /* vos_sched_flush_tx_mqs() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001871/*-------------------------------------------------------------------------
1872 This helper function flushes all the RX message queues
1873 ------------------------------------------------------------------------*/
1874void vos_sched_flush_rx_mqs ( pVosSchedContext pSchedContext )
1875{
1876 pVosMsgWrapper pMsgWrapper = NULL;
1877 /*
1878 ** Here each of the RX thread MQ shall be drained and returned to the
1879 ** Core. Before returning a wrapper to the Core, the VOS message shall
1880 ** be freed first
1881 */
1882 VOS_TRACE( VOS_MODULE_ID_VOSS,
1883 VOS_TRACE_LEVEL_INFO,
1884 "%s: Flushing the RX Thread message queue",__func__);
1885
1886 if (NULL == pSchedContext)
1887 {
1888 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001889 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001890 return;
1891 }
1892
1893 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq) ))
1894 {
1895 VOS_TRACE( VOS_MODULE_ID_VOSS,
1896 VOS_TRACE_LEVEL_INFO,
1897 "%s: Freeing RX WDI MSG message type %d",__func__,
1898 pMsgWrapper->pVosMsg->type );
1899 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1900 }
1901
Katya Nigam664f5032014-05-05 12:24:32 +05301902 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlRxMq) ))
1903 {
1904 VOS_TRACE( VOS_MODULE_ID_VOSS,
1905 VOS_TRACE_LEVEL_INFO,
1906 "%s: Freeing RX TL MSG message type %d",__func__,
1907 pMsgWrapper->pVosMsg->type );
1908 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1909 }
1910
Jeff Johnson295189b2012-06-20 16:38:30 -07001911 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq) ))
1912 {
1913 VOS_TRACE( VOS_MODULE_ID_VOSS,
1914 VOS_TRACE_LEVEL_INFO,
1915 "%s: Freeing RX SYS MSG message type %d",__func__,
1916 pMsgWrapper->pVosMsg->type );
1917 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1918 }
1919
1920}/* vos_sched_flush_rx_mqs() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001921
1922/*-------------------------------------------------------------------------
1923 This helper function helps determine if thread id is of TX thread
1924 ------------------------------------------------------------------------*/
1925int vos_sched_is_tx_thread(int threadID)
1926{
1927 // Make sure that Vos Scheduler context has been initialized
1928 VOS_ASSERT( NULL != gpVosSchedContext);
1929 if (gpVosSchedContext == NULL)
1930 {
1931 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001932 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001933 return 0;
1934 }
1935 return ((gpVosSchedContext->TxThread) && (threadID == gpVosSchedContext->TxThread->pid));
1936}
Jeff Johnson295189b2012-06-20 16:38:30 -07001937/*-------------------------------------------------------------------------
1938 This helper function helps determine if thread id is of RX thread
1939 ------------------------------------------------------------------------*/
1940int vos_sched_is_rx_thread(int threadID)
1941{
1942 // Make sure that Vos Scheduler context has been initialized
1943 VOS_ASSERT( NULL != gpVosSchedContext);
1944 if (gpVosSchedContext == NULL)
1945 {
1946 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001947 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001948 return 0;
1949 }
1950 return ((gpVosSchedContext->RxThread) && (threadID == gpVosSchedContext->RxThread->pid));
1951}
Abhishek Singh880d7122015-08-26 16:23:04 +05301952
1953/*-------------------------------------------------------------------------
1954 This helper function helps determine if thread id is of MC thread
1955 ------------------------------------------------------------------------*/
1956int vos_sched_is_mc_thread(int threadID)
1957{
1958 // Make sure that Vos Scheduler context has been initialized
1959 VOS_ASSERT( NULL != gpVosSchedContext);
1960 if (gpVosSchedContext == NULL)
1961 {
1962 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1963 "%s: gpVosSchedContext == NULL",__func__);
1964 return 0;
1965 }
1966 return ((gpVosSchedContext->McThread) &&
1967 (threadID == gpVosSchedContext->McThread->pid));
1968}
1969
Jeff Johnson295189b2012-06-20 16:38:30 -07001970/*-------------------------------------------------------------------------
1971 Helper function to get the scheduler context
1972 ------------------------------------------------------------------------*/
1973pVosSchedContext get_vos_sched_ctxt(void)
1974{
1975 //Make sure that Vos Scheduler context has been initialized
1976 if (gpVosSchedContext == NULL)
1977 {
1978 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001979 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001980 }
1981 return (gpVosSchedContext);
1982}
1983/*-------------------------------------------------------------------------
1984 Helper function to get the watchdog context
1985 ------------------------------------------------------------------------*/
1986pVosWatchdogContext get_vos_watchdog_ctxt(void)
1987{
1988 //Make sure that Vos Scheduler context has been initialized
1989 if (gpVosWatchdogContext == NULL)
1990 {
1991 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001992 "%s: gpVosWatchdogContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001993 }
1994 return (gpVosWatchdogContext);
1995}
1996/**
1997 @brief vos_watchdog_wlan_shutdown()
1998
1999 This function is called to shutdown WLAN driver during SSR.
2000 Adapters are disabled, and the watchdog task will be signalled
2001 to shutdown WLAN driver.
2002
2003 @param
2004 NONE
2005 @return
2006 VOS_STATUS_SUCCESS - Operation completed successfully.
2007 VOS_STATUS_E_FAILURE - Operation failed.
2008
2009*/
2010VOS_STATUS vos_watchdog_wlan_shutdown(void)
2011{
2012 v_CONTEXT_t pVosContext = NULL;
2013 hdd_context_t *pHddCtx = NULL;
2014
Jeff Johnson295189b2012-06-20 16:38:30 -07002015 if (NULL == gpVosWatchdogContext)
2016 {
2017 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002018 "%s: Watchdog not enabled. LOGP ignored.", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002019 return VOS_STATUS_E_FAILURE;
2020 }
2021
Siddharth Bhalb9a1ae32014-08-27 14:53:55 +05302022 if (gpVosWatchdogContext->isFatalError)
2023 {
2024 /* If we hit this, it means wlan driver is in bad state and needs
2025 * driver unload and load.
2026 */
2027 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2028 "%s: Driver in bad state and need unload and load", __func__);
2029 return VOS_STATUS_E_FAILURE;
2030 }
2031
Siddharth Bhalb9a1ae32014-08-27 14:53:55 +05302032
Jeff Johnson295189b2012-06-20 16:38:30 -07002033 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
2034 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
2035 if (NULL == pHddCtx)
2036 {
2037 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002038 "%s: Invalid HDD Context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002039 return VOS_STATUS_E_FAILURE;
2040 }
2041
2042 /* Take the lock here */
2043 spin_lock(&gpVosWatchdogContext->wdLock);
2044
2045 /* reuse the existing 'reset in progress' */
2046 if (gpVosWatchdogContext->resetInProgress)
2047 {
2048 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2049 "%s: Shutdown already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002050 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002051 /* Release the lock here */
2052 spin_unlock(&gpVosWatchdogContext->wdLock);
2053 return VOS_STATUS_E_FAILURE;
2054 }
2055 /* reuse the existing 'logp in progress', eventhough it is not
2056 * exactly the same */
2057 else if (pHddCtx->isLogpInProgress)
2058 {
2059 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2060 "%s: shutdown/re-init already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002061 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002062 /* Release the lock here */
2063 spin_unlock(&gpVosWatchdogContext->wdLock);
2064 return VOS_STATUS_E_FAILURE;
Siddharth Bhal1ab61052014-09-15 14:39:37 +05302065 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002066
Mihir Shete18156292014-03-11 15:38:30 +05302067 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Jeff Johnson295189b2012-06-20 16:38:30 -07002068 {
2069 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2070 "%s: Load/unload in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002071 __func__);
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002072 /* wcnss has crashed, and SSR has alredy been started by Kernel driver.
2073 * So disable SSR from WLAN driver */
2074 hdd_set_ssr_required( HDD_SSR_DISABLED );
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +05302075
Siddharth Bhal1ab61052014-09-15 14:39:37 +05302076 /* Release the lock here before returning */
2077 spin_unlock(&gpVosWatchdogContext->wdLock);
Jeff Johnson295189b2012-06-20 16:38:30 -07002078 return VOS_STATUS_E_FAILURE;
2079 }
Siddharth Bhal1ab61052014-09-15 14:39:37 +05302080 /* Set the flags so that all commands from userspace get blocked right away */
2081 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, TRUE);
2082 vos_set_reinit_in_progress(VOS_MODULE_ID_VOSS, FALSE);
2083 pHddCtx->isLogpInProgress = TRUE;
2084
2085 /* Release the lock here */
2086 spin_unlock(&gpVosWatchdogContext->wdLock);
2087
Manjeet Singhaf8d9af2016-01-04 17:56:25 +05302088 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2089 "%s: WLAN driver is shutting down ", __func__);
2090
Jeff Johnson295189b2012-06-20 16:38:30 -07002091 /* Update Riva Reset Statistics */
2092 pHddCtx->hddRivaResetStats++;
2093#ifdef CONFIG_HAS_EARLYSUSPEND
2094 if(VOS_STATUS_SUCCESS != hdd_wlan_reset_initialization())
2095 {
2096 VOS_ASSERT(0);
2097 }
2098#endif
2099
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05302100 set_bit(WD_WLAN_SHUTDOWN_EVENT, &gpVosWatchdogContext->wdEventFlag);
2101 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07002102 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
2103
2104 return VOS_STATUS_SUCCESS;
2105}
2106
2107/**
2108 @brief vos_watchdog_wlan_re_init()
2109
2110 This function is called to re-initialize WLAN driver, and this is
2111 called when Riva SS reboots.
2112
2113 @param
2114 NONE
2115 @return
2116 VOS_STATUS_SUCCESS - Operation completed successfully.
2117 VOS_STATUS_E_FAILURE - Operation failed.
2118
2119*/
2120VOS_STATUS vos_watchdog_wlan_re_init(void)
2121{
Gupta, Kapilcb2c2d72016-04-21 16:20:12 +05302122 /* Make sure that Vos Watchdog context has been initialized */
2123 if (gpVosWatchdogContext == NULL) {
2124 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
2125 "%s: gpVosWatchdogContext == NULL", __func__);
2126 return VOS_STATUS_E_FAILURE;
2127 }
2128
Jeff Johnson295189b2012-06-20 16:38:30 -07002129 /* watchdog task is still running, it is not closed in shutdown */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05302130 set_bit(WD_WLAN_REINIT_EVENT, &gpVosWatchdogContext->wdEventFlag);
2131 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07002132 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
2133
2134 return VOS_STATUS_SUCCESS;
2135}
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05302136
2137/**
2138 @brief vos_ssr_protect()
2139
2140 This function is called to keep track of active driver entry points
2141
2142 @param
2143 caller_func - Name of calling function.
2144 @return
2145 void
2146*/
2147void vos_ssr_protect(const char *caller_func)
2148{
2149 int count;
2150 count = atomic_inc_return(&ssr_protect_entry_count);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05302151}
2152
2153/**
2154 @brief vos_ssr_unprotect()
2155
2156 @param
2157 caller_func - Name of calling function.
2158 @return
2159 void
2160*/
2161void vos_ssr_unprotect(const char *caller_func)
2162{
2163 int count;
2164 count = atomic_dec_return(&ssr_protect_entry_count);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05302165}
Abhishek Singhe7ea25c2015-11-23 16:23:24 +05302166/**
2167 * vos_is_wd_thread()- Check if threadid is
2168 * of Watchdog thread
2169 *
2170 * @threadId: passed threadid
2171 *
2172 * This function is called to check if threadid is
2173 * of wd thread.
2174 *
2175 * Return: true if threadid is of wd thread.
2176 */
2177bool vos_is_wd_thread(int threadId)
2178{
Gupta, Kapilbd50b5c2015-12-04 18:57:02 +05302179 /* Make sure that Vos Watchdog context has been initialized */
2180 if (gpVosWatchdogContext == NULL)
2181 {
2182 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
2183 "%s: gpVosWatchdogContext == NULL", __func__);
2184 return false;
2185 }
2186
Abhishek Singhe7ea25c2015-11-23 16:23:24 +05302187 return ((gpVosWatchdogContext->WdThread) &&
2188 (threadId == gpVosWatchdogContext->WdThread->pid));
2189}
2190
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302191void vos_dump_stack(uint8_t thread_id)
2192{
2193 switch (thread_id)
2194 {
2195 case MC_Thread:
2196 wcnss_dump_stack(gpVosSchedContext->McThread);
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302197 break;
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302198 case TX_Thread:
2199 wcnss_dump_stack(gpVosSchedContext->TxThread);
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302200 break;
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302201 case RX_Thread:
2202 wcnss_dump_stack(gpVosSchedContext->RxThread);
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302203 break;
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302204 default:
2205 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302206 "%s: Invalid thread %d invoked",__func__, thread_id);
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302207 }
2208}
Arunk Khandavalliaf6c3af2017-01-16 11:44:46 +05302209
2210void vos_dump_thread_stacks(int threadId)
2211{
2212 /* Make sure that Vos Watchdog context has been initialized */
2213 if (gpVosWatchdogContext == NULL)
2214 {
2215 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2216 "%s: gpVosWatchdogContext == NULL", __func__);
2217 return;
2218 }
2219 hddLog(LOGE, FL("Thread Stuck count reached threshold!!!"
2220 "MC Count %d RX count %d TX count %d"),
2221 gpVosWatchdogContext->mcThreadStuckCount,
2222 gpVosWatchdogContext->rxThreadStuckCount,
2223 gpVosWatchdogContext->txThreadStuckCount);
2224
2225 vos_dump_stack(MC_Thread);
2226 vos_dump_stack(TX_Thread);
2227 vos_dump_stack(RX_Thread);
2228}
Abhinav Kumar118efd02019-08-07 16:41:07 +05302229
2230int vos_get_gfp_flags(void)
2231{
2232 int flags = GFP_KERNEL;
2233
2234 if (in_interrupt() || in_atomic() || irqs_disabled())
2235 flags = GFP_ATOMIC;
2236
2237 return flags;
2238}