blob: d5ee1d52446858c24ac9edc442e8108cf7c6d551 [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>
Dundi Raviteja18ce38e2020-08-04 16:32:14 +053063#include "wlan_qct_pal_device.h"
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +053064
Jeff Johnson295189b2012-06-20 16:38:30 -070065/*---------------------------------------------------------------------------
66 * Preprocessor Definitions and Constants
67 * ------------------------------------------------------------------------*/
68#define VOS_SCHED_THREAD_HEART_BEAT INFINITE
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +053069/* Milli seconds to delay SSR thread when an Entry point is Active */
70#define SSR_WAIT_SLEEP_TIME 100
71/* MAX iteration count to wait for Entry point to exit before
72 * we proceed with SSR in WD Thread
73 */
Pradeep Kumar Goudagunta21c08c42014-07-14 15:59:43 +053074#define MAX_SSR_WAIT_ITERATIONS 200
Abhishek Singhe7ea25c2015-11-23 16:23:24 +053075/* Timer value for detecting thread stuck issues */
76#define THREAD_STUCK_TIMER_VAL 5000 // 5 seconds
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +053077#define THREAD_STUCK_COUNT 6
Abhishek Singhe7ea25c2015-11-23 16:23:24 +053078
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +053079#define MC_Thread 0
80#define TX_Thread 1
81#define RX_Thread 2
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +053082
83static atomic_t ssr_protect_entry_count;
84
Jeff Johnson295189b2012-06-20 16:38:30 -070085/*---------------------------------------------------------------------------
86 * Type Declarations
87 * ------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------
89 * Data definitions
90 * ------------------------------------------------------------------------*/
91static pVosSchedContext gpVosSchedContext;
Madan Mohan Koyyalamudidfd6aa82012-10-18 20:18:43 -070092static pVosWatchdogContext gpVosWatchdogContext;
Jeff Johnson295189b2012-06-20 16:38:30 -070093
94/*---------------------------------------------------------------------------
95 * Forward declaration
96 * ------------------------------------------------------------------------*/
Jeff Johnson2f5cfec2013-02-22 21:25:10 -080097static int VosMCThread(void *Arg);
98static int VosWDThread(void *Arg);
99static int VosTXThread(void *Arg);
100static int VosRXThread(void *Arg);
Jeff Johnson295189b2012-06-20 16:38:30 -0700101void vos_sched_flush_rx_mqs(pVosSchedContext SchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -0700102extern v_VOID_t vos_core_return_msg(v_PVOID_t pVContext, pVosMsgWrapper pMsgWrapper);
103/*---------------------------------------------------------------------------
104 * External Function implementation
105 * ------------------------------------------------------------------------*/
106
107/*---------------------------------------------------------------------------
108 \brief vos_sched_open() - initialize the vOSS Scheduler
109 The \a vos_sched_open() function initializes the vOSS Scheduler
110 Upon successful initialization:
111 - All the message queues are initialized
112 - The Main Controller thread is created and ready to receive and
113 dispatch messages.
114 - The Tx thread is created and ready to receive and dispatch messages
115
116 \param pVosContext - pointer to the global vOSS Context
117 \param pVosSchedContext - pointer to a previously allocated buffer big
118 enough to hold a scheduler context.
119 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
120 is ready to be used.
121 VOS_STATUS_E_RESOURCES - System resources (other than memory)
122 are unavailable to initilize the scheduler
123 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
124 the scheduler
125 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
126 function
127 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
128 \sa vos_sched_open()
129 -------------------------------------------------------------------------*/
130VOS_STATUS
131vos_sched_open
132(
133 v_PVOID_t pVosContext,
134 pVosSchedContext pSchedContext,
135 v_SIZE_t SchedCtxSize
136)
137{
138 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
139/*-------------------------------------------------------------------------*/
140 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
141 "%s: Opening the VOSS Scheduler",__func__);
142 // Sanity checks
143 if ((pVosContext == NULL) || (pSchedContext == NULL)) {
144 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
145 "%s: Null params being passed",__func__);
146 return VOS_STATUS_E_FAILURE;
147 }
148 if (sizeof(VosSchedContext) != SchedCtxSize)
149 {
150 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
151 "%s: Incorrect VOS Sched Context size passed",__func__);
152 return VOS_STATUS_E_INVAL;
153 }
154 vos_mem_zero(pSchedContext, sizeof(VosSchedContext));
155 pSchedContext->pVContext = pVosContext;
156 vStatus = vos_sched_init_mqs(pSchedContext);
157 if (!VOS_IS_STATUS_SUCCESS(vStatus))
158 {
159 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
160 "%s: Failed to initialize VOS Scheduler MQs",__func__);
161 return vStatus;
162 }
163 // Initialize the helper events and event queues
164 init_completion(&pSchedContext->McStartEvent);
165 init_completion(&pSchedContext->TxStartEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700166 init_completion(&pSchedContext->RxStartEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700167 init_completion(&pSchedContext->McShutdown);
168 init_completion(&pSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700169 init_completion(&pSchedContext->RxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700170 init_completion(&pSchedContext->ResumeMcEvent);
171 init_completion(&pSchedContext->ResumeTxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700172 init_completion(&pSchedContext->ResumeRxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700173
174 spin_lock_init(&pSchedContext->McThreadLock);
175 spin_lock_init(&pSchedContext->TxThreadLock);
176 spin_lock_init(&pSchedContext->RxThreadLock);
177
178 init_waitqueue_head(&pSchedContext->mcWaitQueue);
179 pSchedContext->mcEventFlag = 0;
180 init_waitqueue_head(&pSchedContext->txWaitQueue);
181 pSchedContext->txEventFlag= 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700182 init_waitqueue_head(&pSchedContext->rxWaitQueue);
183 pSchedContext->rxEventFlag= 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700184 /*
Jeff Johnson2f5cfec2013-02-22 21:25:10 -0800185 ** This initialization is critical as the threads will later access the
Jeff Johnson295189b2012-06-20 16:38:30 -0700186 ** global contexts normally,
187 **
188 ** I shall put some memory barrier here after the next piece of code but
189 ** I am keeping it simple for now.
190 */
191 gpVosSchedContext = pSchedContext;
192
193 //Create the VOSS Main Controller thread
194 pSchedContext->McThread = kthread_create(VosMCThread, pSchedContext,
195 "VosMCThread");
196 if (IS_ERR(pSchedContext->McThread))
197 {
198 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
199 "%s: Could not Create VOSS Main Thread Controller",__func__);
200 goto MC_THREAD_START_FAILURE;
201 }
202 wake_up_process(pSchedContext->McThread);
203 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
204 "%s: VOSS Main Controller thread Created",__func__);
205
Jeff Johnson295189b2012-06-20 16:38:30 -0700206 pSchedContext->TxThread = kthread_create(VosTXThread, pSchedContext,
207 "VosTXThread");
208 if (IS_ERR(pSchedContext->TxThread))
209 {
210 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
211 "%s: Could not Create VOSS TX Thread",__func__);
212 goto TX_THREAD_START_FAILURE;
213 }
214 wake_up_process(pSchedContext->TxThread);
215 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussain02882402013-11-17 21:55:29 -0800216 ("VOSS TX thread Created"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700217
Jeff Johnson295189b2012-06-20 16:38:30 -0700218 pSchedContext->RxThread = kthread_create(VosRXThread, pSchedContext,
219 "VosRXThread");
220 if (IS_ERR(pSchedContext->RxThread))
221 {
222
223 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
224 "%s: Could not Create VOSS RX Thread",__func__);
225 goto RX_THREAD_START_FAILURE;
226
227 }
228 wake_up_process(pSchedContext->RxThread);
229 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Arif Hussain02882402013-11-17 21:55:29 -0800230 ("VOSS RX thread Created"));
Jeff Johnson295189b2012-06-20 16:38:30 -0700231
232 /*
233 ** Now make sure all threads have started before we exit.
234 ** Each thread should normally ACK back when it starts.
235 */
236 wait_for_completion_interruptible(&pSchedContext->McStartEvent);
237 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
238 "%s: VOSS MC Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700239 wait_for_completion_interruptible(&pSchedContext->TxStartEvent);
240 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
241 "%s: VOSS Tx Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700242 wait_for_completion_interruptible(&pSchedContext->RxStartEvent);
243 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
244 "%s: VOSS Rx Thread has started",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700245
246 /*
247 ** We're good now: Let's get the ball rolling!!!
248 */
249 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
250 "%s: VOSS Scheduler successfully Opened",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700251 return VOS_STATUS_SUCCESS;
252
Jeff Johnson295189b2012-06-20 16:38:30 -0700253
Jeff Johnson295189b2012-06-20 16:38:30 -0700254RX_THREAD_START_FAILURE:
255 //Try and force the Tx thread controller to exit
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530256 set_bit(MC_SHUTDOWN_EVENT, &pSchedContext->txEventFlag);
257 set_bit(MC_POST_EVENT, &pSchedContext->txEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700258 wake_up_interruptible(&pSchedContext->txWaitQueue);
259 //Wait for TX to exit
260 wait_for_completion_interruptible(&pSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -0700261
262TX_THREAD_START_FAILURE:
263 //Try and force the Main thread controller to exit
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530264 set_bit(MC_SHUTDOWN_EVENT, &pSchedContext->mcEventFlag);
265 set_bit(MC_POST_EVENT, &pSchedContext->mcEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700266 wake_up_interruptible(&pSchedContext->mcWaitQueue);
267 //Wait for MC to exit
268 wait_for_completion_interruptible(&pSchedContext->McShutdown);
269
Jeff Johnson295189b2012-06-20 16:38:30 -0700270MC_THREAD_START_FAILURE:
271 //De-initialize all the message queues
272 vos_sched_deinit_mqs(pSchedContext);
273 return VOS_STATUS_E_RESOURCES;
274
275} /* vos_sched_open() */
276
277VOS_STATUS vos_watchdog_open
278(
279 v_PVOID_t pVosContext,
280 pVosWatchdogContext pWdContext,
281 v_SIZE_t wdCtxSize
282)
283{
284/*-------------------------------------------------------------------------*/
285 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
286 "%s: Opening the VOSS Watchdog module",__func__);
287 //Sanity checks
288 if ((pVosContext == NULL) || (pWdContext == NULL)) {
289 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
290 "%s: Null params being passed",__func__);
291 return VOS_STATUS_E_FAILURE;
292 }
293 if (sizeof(VosWatchdogContext) != wdCtxSize)
294 {
295 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
296 "%s: Incorrect VOS Watchdog Context size passed",__func__);
297 return VOS_STATUS_E_INVAL;
298 }
299 vos_mem_zero(pWdContext, sizeof(VosWatchdogContext));
300 pWdContext->pVContext = pVosContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700301
302 //Initialize the helper events and event queues
303 init_completion(&pWdContext->WdStartEvent);
304 init_completion(&pWdContext->WdShutdown);
305 init_waitqueue_head(&pWdContext->wdWaitQueue);
306 pWdContext->wdEventFlag = 0;
307
308 // Initialize the lock
309 spin_lock_init(&pWdContext->wdLock);
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530310 spin_lock_init(&pWdContext->thread_stuck_lock);
Jeff Johnson295189b2012-06-20 16:38:30 -0700311
312 //Create the Watchdog thread
313 pWdContext->WdThread = kthread_create(VosWDThread, pWdContext,"VosWDThread");
314
315 if (IS_ERR(pWdContext->WdThread))
316 {
317 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
318 "%s: Could not Create Watchdog thread",__func__);
319 return VOS_STATUS_E_RESOURCES;
320 }
321 else
322 {
Ashish Kumar Dhanotiya532bdef2017-05-09 17:31:59 +0530323 gpVosWatchdogContext = pWdContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700324 wake_up_process(pWdContext->WdThread);
325 }
326 /*
327 ** Now make sure thread has started before we exit.
328 ** Each thread should normally ACK back when it starts.
329 */
330 wait_for_completion_interruptible(&pWdContext->WdStartEvent);
331 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
332 "%s: VOSS Watchdog Thread has started",__func__);
333 return VOS_STATUS_SUCCESS;
334} /* vos_watchdog_open() */
335/*---------------------------------------------------------------------------
336 \brief VosMcThread() - The VOSS Main Controller thread
337 The \a VosMcThread() is the VOSS main controller thread:
338 \param Arg - pointer to the global vOSS Sched Context
339 \return Thread exit code
340 \sa VosMcThread()
341 -------------------------------------------------------------------------*/
342static int
343VosMCThread
344(
345 void * Arg
346)
347{
348 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
349 pVosMsgWrapper pMsgWrapper = NULL;
350 tpAniSirGlobal pMacContext = NULL;
351 tSirRetStatus macStatus = eSIR_SUCCESS;
352 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
353 int retWaitStatus = 0;
354 v_BOOL_t shutdown = VOS_FALSE;
355 hdd_context_t *pHddCtx = NULL;
356 v_CONTEXT_t pVosContext = NULL;
357
358 if (Arg == NULL)
359 {
360 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700361 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700362 return 0;
363 }
364 set_user_nice(current, -2);
365
Yue Maf49ba872013-08-19 12:04:25 -0700366#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700367 daemonize("MC_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700368#endif
369
Jeff Johnson295189b2012-06-20 16:38:30 -0700370 /*
371 ** Ack back to the context from which the main controller thread has been
372 ** created.
373 */
374 complete(&pSchedContext->McStartEvent);
375 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
376 "%s: MC Thread %d (%s) starting up",__func__, current->pid, current->comm);
377
378 /* Get the Global VOSS Context */
379 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
380 if(!pVosContext) {
381 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
382 return 0;
383 }
384
385 /* Get the HDD context */
386 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
387 if(!pHddCtx) {
388 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
389 return 0;
390 }
391
392 while(!shutdown)
393 {
394 // This implements the execution model algorithm
395 retWaitStatus = wait_event_interruptible(pSchedContext->mcWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530396 test_bit(MC_POST_EVENT, &pSchedContext->mcEventFlag) ||
397 test_bit(MC_SUSPEND_EVENT, &pSchedContext->mcEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -0700398
399 if(retWaitStatus == -ERESTARTSYS)
400 {
401 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700402 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700403 break;
404 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530405 clear_bit(MC_POST_EVENT, &pSchedContext->mcEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700406
407 while(1)
408 {
409 // Check if MC needs to shutdown
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530410 if(test_bit(MC_SHUTDOWN_EVENT, &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700411 {
412 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
413 "%s: MC thread signaled to shutdown", __func__);
414 shutdown = VOS_TRUE;
415 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530416 if (test_and_clear_bit(MC_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530417 &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700418 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700419 /* Unblock anyone waiting on suspend */
420 complete(&pHddCtx->mc_sus_event_var);
421 }
422 break;
423 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700424 /*
425 ** Check the WDI queue
426 ** Service it till the entire queue is empty
427 */
428 if (!vos_is_mq_empty(&pSchedContext->wdiMcMq))
429 {
430 wpt_msg *pWdiMsg;
431 /*
432 ** Service the WDI message queue
433 */
Jeff Johnson295189b2012-06-20 16:38:30 -0700434 pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700435
436 if (pMsgWrapper == NULL)
437 {
438 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700439 "%s: pMsgWrapper is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530440 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700441 break;
442 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700443
444 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnsond13512a2012-07-17 11:42:19 -0700445
446 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
447 {
448 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700449 "%s: WDI Msg or Callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +0530450 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -0700451 break;
452 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700453
454 pWdiMsg->callback(pWdiMsg);
455
456 /*
457 ** return message to the Core
458 */
459 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
460
461 continue;
462 }
463
Jeff Johnson295189b2012-06-20 16:38:30 -0700464 // Check the SYS queue first
465 if (!vos_is_mq_empty(&pSchedContext->sysMcMq))
466 {
467 // Service the SYS message queue
468 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
469 "%s: Servicing the VOS SYS MC Message queue",__func__);
470 pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq);
471 if (pMsgWrapper == NULL)
472 {
473 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700474 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700475 VOS_ASSERT(0);
476 break;
477 }
478 vStatus = sysMcProcessMsg(pSchedContext->pVContext,
479 pMsgWrapper->pVosMsg);
480 if (!VOS_IS_STATUS_SUCCESS(vStatus))
481 {
482 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
483 "%s: Issue Processing SYS message",__func__);
484 }
485 //return message to the Core
486 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
487 continue;
488 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700489 // Check the WDA queue
490 if (!vos_is_mq_empty(&pSchedContext->wdaMcMq))
491 {
492 // Service the WDA message queue
493 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
494 "%s: Servicing the VOS WDA MC Message queue",__func__);
495 pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq);
496 if (pMsgWrapper == NULL)
497 {
498 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700499 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700500 VOS_ASSERT(0);
501 break;
502 }
503 vStatus = WDA_McProcessMsg( pSchedContext->pVContext, pMsgWrapper->pVosMsg);
504 if (!VOS_IS_STATUS_SUCCESS(vStatus))
505 {
506 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
507 "%s: Issue Processing WDA message",__func__);
508 }
509 // return message to the Core
510 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
511 continue;
512 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700513 // Check the PE queue
514 if (!vos_is_mq_empty(&pSchedContext->peMcMq))
515 {
516 // Service the PE message queue
517 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
518 "%s: Servicing the VOS PE MC Message queue",__func__);
519 pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq);
520 if (NULL == pMsgWrapper)
521 {
522 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700523 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700524 VOS_ASSERT(0);
525 break;
526 }
527
528 /* Need some optimization*/
529 pMacContext = vos_get_context(VOS_MODULE_ID_PE, pSchedContext->pVContext);
530 if (NULL == pMacContext)
531 {
532 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
533 "MAC Context not ready yet");
534 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
535 continue;
536 }
537
538 macStatus = peProcessMessages( pMacContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
539 if (eSIR_SUCCESS != macStatus)
540 {
541 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
542 "%s: Issue Processing PE message",__func__);
543 }
544 // return message to the Core
545 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
546 continue;
547 }
548 /** Check the SME queue **/
549 if (!vos_is_mq_empty(&pSchedContext->smeMcMq))
550 {
551 /* Service the SME message queue */
552 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
553 "%s: Servicing the VOS SME MC Message queue",__func__);
554 pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq);
555 if (NULL == pMsgWrapper)
556 {
557 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700558 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700559 VOS_ASSERT(0);
560 break;
561 }
562
563 /* Need some optimization*/
564 pMacContext = vos_get_context(VOS_MODULE_ID_SME, pSchedContext->pVContext);
565 if (NULL == pMacContext)
566 {
567 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
568 "MAC Context not ready yet");
569 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
570 continue;
571 }
572
573 vStatus = sme_ProcessMsg( (tHalHandle)pMacContext, pMsgWrapper->pVosMsg);
574 if (!VOS_IS_STATUS_SUCCESS(vStatus))
575 {
576 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
577 "%s: Issue Processing SME message",__func__);
578 }
579 // return message to the Core
580 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
581 continue;
582 }
583 /** Check the TL queue **/
584 if (!vos_is_mq_empty(&pSchedContext->tlMcMq))
585 {
586 // Service the TL message queue
587 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
588 ("Servicing the VOS TL MC Message queue"));
589 pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq);
590 if (pMsgWrapper == NULL)
591 {
592 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700593 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700594 VOS_ASSERT(0);
595 break;
596 }
597 vStatus = WLANTL_McProcessMsg( pSchedContext->pVContext,
598 pMsgWrapper->pVosMsg);
599 if (!VOS_IS_STATUS_SUCCESS(vStatus))
600 {
601 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
602 "%s: Issue Processing TL message",__func__);
603 }
604 // return message to the Core
605 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
606 continue;
607 }
608 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530609 if (test_and_clear_bit(MC_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +0530610 &pSchedContext->mcEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700611 {
Jeff Johnson295189b2012-06-20 16:38:30 -0700612 spin_lock(&pSchedContext->McThreadLock);
Abhishek Singhbff18d22016-02-04 18:05:32 +0530613 INIT_COMPLETION(pSchedContext->ResumeMcEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -0700614 /* Mc Thread Suspended */
615 complete(&pHddCtx->mc_sus_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700616 spin_unlock(&pSchedContext->McThreadLock);
617
618 /* Wait foe Resume Indication */
619 wait_for_completion_interruptible(&pSchedContext->ResumeMcEvent);
620 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700621 break; //All queues are empty now
622 } // while message loop processing
623 } // while TRUE
624 // If we get here the MC thread must exit
625 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700626 "%s: MC Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700627 complete_and_exit(&pSchedContext->McShutdown, 0);
628} /* VosMCThread() */
Wilson Yang68349dd2014-02-06 17:30:38 -0800629
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530630v_BOOL_t isSsrPanicOnFailure(void)
631{
632 hdd_context_t *pHddCtx = NULL;
633 v_CONTEXT_t pVosContext = NULL;
634
635 /* Get the Global VOSS Context */
636 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
637 if(!pVosContext)
638 {
639 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
640 return FALSE;
641 }
642
643 /* Get the HDD context */
644 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext);
645 if((NULL == pHddCtx) || (NULL == pHddCtx->cfg_ini))
646 {
647 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null", __func__);
648 return FALSE;
649 }
650
651 return (pHddCtx->cfg_ini->fIsSsrPanicOnFailure);
652}
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530653/**
654 * vos_wd_detect_thread_stuck()- Detect thread stuck
655 * by probing the MC, TX, RX threads and take action if
656 * Thread doesnt respond.
657 *
658 * This function is called to detect thread stuck
659 * and probe threads.
660 *
661 * Return: void
662 */
663static void vos_wd_detect_thread_stuck(void)
664{
665 unsigned long flags;
666
667 spin_lock_irqsave(&gpVosWatchdogContext->thread_stuck_lock, flags);
668
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +0530669 if ((gpVosWatchdogContext->mcThreadStuckCount == THREAD_STUCK_COUNT) ||
670 (gpVosWatchdogContext->txThreadStuckCount == THREAD_STUCK_COUNT) ||
671 (gpVosWatchdogContext->rxThreadStuckCount == THREAD_STUCK_COUNT))
672 {
673 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
674 hddLog(LOGE, FL("Thread Stuck count reached threshold!!!"
675 "MC Count %d RX count %d TX count %d"),
676 gpVosWatchdogContext->mcThreadStuckCount,
677 gpVosWatchdogContext->rxThreadStuckCount,
678 gpVosWatchdogContext->txThreadStuckCount);
679 return;
680 }
681
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530682 if (gpVosWatchdogContext->mcThreadStuckCount ||
683 gpVosWatchdogContext->txThreadStuckCount ||
684 gpVosWatchdogContext->rxThreadStuckCount)
685 {
686 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
687
688 hddLog(LOG1, FL("MC Count %d RX count %d TX count %d"),
689 gpVosWatchdogContext->mcThreadStuckCount,
690 gpVosWatchdogContext->rxThreadStuckCount,
691 gpVosWatchdogContext->txThreadStuckCount);
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +0530692
693 if (gpVosWatchdogContext->mcThreadStuckCount)
694 {
695 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
696 "%s: Invoking dump stack for MC thread",__func__);
697 vos_dump_stack(MC_Thread);
698 }
699 if (gpVosWatchdogContext->txThreadStuckCount)
700 {
701 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
702 "%s: Invoking dump stack for TX thread",__func__);
703 vos_dump_stack(TX_Thread);
704 }
705 if (gpVosWatchdogContext->rxThreadStuckCount)
706 {
707 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
708 "%s: Invoking dump stack for RX thread",__func__);
709 vos_dump_stack(RX_Thread);
710 }
711
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530712 vos_fatal_event_logs_req(WLAN_LOG_TYPE_FATAL,
713 WLAN_LOG_INDICATOR_HOST_ONLY,
714 WLAN_LOG_REASON_THREAD_STUCK,
715 FALSE, TRUE);
716
717 spin_lock_irqsave(&gpVosWatchdogContext->thread_stuck_lock, flags);
718 }
719
720 /* Increment the thread stuck count for all threads */
721 gpVosWatchdogContext->mcThreadStuckCount++;
722 gpVosWatchdogContext->txThreadStuckCount++;
723 gpVosWatchdogContext->rxThreadStuckCount++;
724
725 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
726 vos_probe_threads();
727
728 /* Restart the timer */
729 if (VOS_STATUS_SUCCESS !=
730 vos_timer_start(&gpVosWatchdogContext->threadStuckTimer,
731 THREAD_STUCK_TIMER_VAL))
732 hddLog(LOGE, FL("Unable to start thread stuck timer"));
733}
734
735/**
736 * wlan_wd_detect_thread_stuck_cb()- Call back of the
737 * thread stuck timer.
738 * @priv: timer data.
739 * This function is called when the thread stuck timer
740 * expire to detect thread stuck and probe threads.
741 *
742 * Return: void
743 */
744static void vos_wd_detect_thread_stuck_cb(void *priv)
745{
746 if (!(vos_is_logp_in_progress(VOS_MODULE_ID_SYS, NULL) ||
747 vos_is_load_unload_in_progress(VOS_MODULE_ID_SYS, NULL)))
748 {
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530749 set_bit(WD_WLAN_DETECT_THREAD_STUCK,
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530750 &gpVosWatchdogContext->wdEventFlag);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530751 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530752 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
753 }
754}
755
756/**
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +0530757 * vos_thread_stuck_timer_init - Initialize thread stuck timer
758 *
759 * @pWdContext: watchdog context.
760 *
761 * Return: void
762 */
763void vos_thread_stuck_timer_init(pVosWatchdogContext pWdContext)
764{
765 if (vos_timer_init_deferrable(&pWdContext->threadStuckTimer,
766 VOS_TIMER_TYPE_SW,
767 vos_wd_detect_thread_stuck_cb, NULL))
768 hddLog(LOGE, FL("Unable to initialize thread stuck timer"));
769 else
770 {
771 if (VOS_STATUS_SUCCESS !=
772 vos_timer_start(&pWdContext->threadStuckTimer,
773 THREAD_STUCK_TIMER_VAL))
774 hddLog(LOGE, FL("Unable to start thread stuck timer"));
775 else
776 hddLog(LOG1, FL("Successfully started thread stuck timer"));
777 }
778
779}
780
781/**
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530782 * wlan_logging_reset_thread_stuck_count()- Callback to
783 * probe msg sent to Threads.
784 *
785 * @threadId: passed threadid
786 *
787 * This function is called to by the thread after
788 * processing the probe msg, with their own thread id.
789 *
790 * Return: void.
791 */
792void vos_wd_reset_thread_stuck_count(int threadId)
793{
794 unsigned long flags;
795
796 spin_lock_irqsave(&gpVosWatchdogContext->thread_stuck_lock, flags);
797 if (vos_sched_is_mc_thread(threadId))
798 gpVosWatchdogContext->mcThreadStuckCount = 0;
799 else if (vos_sched_is_tx_thread(threadId))
800 gpVosWatchdogContext->txThreadStuckCount = 0;
801 else if (vos_sched_is_rx_thread(threadId))
802 gpVosWatchdogContext->rxThreadStuckCount = 0;
803 spin_unlock_irqrestore(&gpVosWatchdogContext->thread_stuck_lock, flags);
804}
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530805
Jeff Johnson295189b2012-06-20 16:38:30 -0700806/*---------------------------------------------------------------------------
807 \brief VosWdThread() - The VOSS Watchdog thread
808 The \a VosWdThread() is the Watchdog thread:
809 \param Arg - pointer to the global vOSS Sched Context
810 \return Thread exit code
811 \sa VosMcThread()
812 -------------------------------------------------------------------------*/
813static int
814VosWDThread
815(
816 void * Arg
817)
818{
819 pVosWatchdogContext pWdContext = (pVosWatchdogContext)Arg;
820 int retWaitStatus = 0;
821 v_BOOL_t shutdown = VOS_FALSE;
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530822 int count = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -0700823 VOS_STATUS vosStatus = VOS_STATUS_SUCCESS;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530824 hdd_context_t *pHddCtx = NULL;
825 v_CONTEXT_t pVosContext = NULL;
Jeff Johnson295189b2012-06-20 16:38:30 -0700826 set_user_nice(current, -3);
827
828 if (Arg == NULL)
829 {
830 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700831 "%s: Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700832 return 0;
833 }
Yue Maf49ba872013-08-19 12:04:25 -0700834
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530835 /* Get the Global VOSS Context */
836 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
837
838 if(!pVosContext)
839 {
840 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
841 return 0;
842 }
843
844 /* Get the HDD context */
845 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
846
847 if(!pHddCtx)
848 {
849 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
850 return 0;
851 }
852
Yue Maf49ba872013-08-19 12:04:25 -0700853#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -0700854 daemonize("WD_Thread");
Yue Maf49ba872013-08-19 12:04:25 -0700855#endif
856
Jeff Johnson295189b2012-06-20 16:38:30 -0700857 /*
858 ** Ack back to the context from which the Watchdog thread has been
859 ** created.
860 */
861 complete(&pWdContext->WdStartEvent);
862 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
863 "%s: Watchdog Thread %d (%s) starting up",__func__, current->pid, current->comm);
864
865 while(!shutdown)
866 {
867 // This implements the Watchdog execution model algorithm
868 retWaitStatus = wait_event_interruptible(pWdContext->wdWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530869 test_bit(WD_POST_EVENT, &pWdContext->wdEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -0700870 if(retWaitStatus == -ERESTARTSYS)
871 {
872 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700873 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700874 break;
875 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530876 clear_bit(WD_POST_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700877 while(1)
878 {
Abhishek Singh58749d62016-02-03 15:27:20 +0530879
880 /* Post Msg to detect thread stuck. */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530881 if (test_and_clear_bit(WD_WLAN_DETECT_THREAD_STUCK,
Abhishek Singh58749d62016-02-03 15:27:20 +0530882 &pWdContext->wdEventFlag))
883 {
884 vos_wd_detect_thread_stuck();
885 /*
886 * Process here and return without processing any SSR
887 * related logic.
888 */
889 break;
890 }
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530891 /* Check for any Active Entry Points
892 * If active, delay SSR until no entry point is active or
893 * delay until count is decremented to ZERO
894 */
895 count = MAX_SSR_WAIT_ITERATIONS;
896 while (count)
897 {
898 if (!atomic_read(&ssr_protect_entry_count))
899 {
900 /* no external threads are executing */
901 break;
902 }
903 /* at least one external thread is executing */
904 if (--count)
905 {
906 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
907 "%s: Waiting for active entry points to exit", __func__);
908 msleep(SSR_WAIT_SLEEP_TIME);
909 }
910 }
911 /* at least one external thread is executing */
912 if (!count)
913 {
914 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
915 "%s: Continuing SSR when %d Entry points are still active",
916 __func__, atomic_read(&ssr_protect_entry_count));
917 }
Jeff Johnson295189b2012-06-20 16:38:30 -0700918 // Check if Watchdog needs to shutdown
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530919 if(test_bit(WD_SHUTDOWN_EVENT, &pWdContext->wdEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700920 {
921 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
922 "%s: Watchdog thread signaled to shutdown", __func__);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530923 clear_bit(WD_SHUTDOWN_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700924 shutdown = VOS_TRUE;
925 break;
926 }
927 /* subsystem restart: shutdown event handler */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530928 else if(test_bit(WD_WLAN_SHUTDOWN_EVENT, &pWdContext->wdEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700929 {
930 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
931 "%s: Watchdog thread signaled to perform WLAN shutdown",__func__);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530932 clear_bit(WD_WLAN_SHUTDOWN_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700933
934 //Perform WLAN shutdown
935 if(!pWdContext->resetInProgress)
936 {
937 pWdContext->resetInProgress = true;
938 vosStatus = hdd_wlan_shutdown();
939
940 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
941 {
942 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
943 "%s: Failed to shutdown WLAN",__func__);
944 VOS_ASSERT(0);
945 goto err_reset;
946 }
947 }
948 }
949 /* subsystem restart: re-init event handler */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530950 else if(test_bit(WD_WLAN_REINIT_EVENT, &pWdContext->wdEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -0700951 {
952 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
953 "%s: Watchdog thread signaled to perform WLAN re-init",__func__);
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +0530954 clear_bit(WD_WLAN_REINIT_EVENT, &pWdContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -0700955
956 //Perform WLAN re-init
957 if(!pWdContext->resetInProgress)
958 {
959 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Katya Nigamb37c7812014-06-19 14:45:16 +0530960 "%s: Do WLAN re-init only when it is shutdown !!",__func__);
961 break;
Jeff Johnson295189b2012-06-20 16:38:30 -0700962 }
963 vosStatus = hdd_wlan_re_init();
964
965 if (! VOS_IS_STATUS_SUCCESS(vosStatus))
966 {
967 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
968 "%s: Failed to re-init WLAN",__func__);
969 VOS_ASSERT(0);
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530970 pWdContext->isFatalError = true;
971 }
972 else
973 {
974 pWdContext->isFatalError = false;
Jeff Johnson295189b2012-06-20 16:38:30 -0700975 }
Mihir Shetefd528652014-06-23 19:07:50 +0530976 atomic_set(&pHddCtx->isRestartInProgress, 0);
Jeff Johnson295189b2012-06-20 16:38:30 -0700977 pWdContext->resetInProgress = false;
Arun Kumar Khandavallie0b046d2014-03-01 21:54:25 +0530978 complete(&pHddCtx->ssr_comp_var);
Jeff Johnson295189b2012-06-20 16:38:30 -0700979 }
980 else
981 {
982 //Unnecessary wakeup - Should never happen!!
983 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
984 "%s: Watchdog thread woke up unnecessarily",__func__);
985 }
986 break;
987 } // while message loop processing
988 } // while shutdown
989
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530990 vos_timer_destroy(&pWdContext->threadStuckTimer);
Jeff Johnson295189b2012-06-20 16:38:30 -0700991 // If we get here the Watchdog thread must exit
992 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700993 "%s: Watchdog Thread exiting !!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700994 complete_and_exit(&pWdContext->WdShutdown, 0);
995
996err_reset:
997 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700998 "%s: Watchdog Thread Failed to Reset, Exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700999 return 0;
1000
1001} /* VosMCThread() */
1002
1003/*---------------------------------------------------------------------------
1004 \brief VosTXThread() - The VOSS Main Tx thread
1005 The \a VosTxThread() is the VOSS main controller thread:
1006 \param Arg - pointer to the global vOSS Sched Context
1007
1008 \return Thread exit code
1009 \sa VosTxThread()
1010 -------------------------------------------------------------------------*/
Jeff Johnson295189b2012-06-20 16:38:30 -07001011static int VosTXThread ( void * Arg )
1012{
1013 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
1014 pVosMsgWrapper pMsgWrapper = NULL;
1015 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1016 int retWaitStatus = 0;
1017 v_BOOL_t shutdown = VOS_FALSE;
1018 hdd_context_t *pHddCtx = NULL;
1019 v_CONTEXT_t pVosContext = NULL;
1020
1021 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001022
1023#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -07001024 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001025#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001026
1027 if (Arg == NULL)
1028 {
1029 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001030 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001031 return 0;
1032 }
Yue Maf49ba872013-08-19 12:04:25 -07001033
1034#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001035 daemonize("TX_Thread");
Yue Maf49ba872013-08-19 12:04:25 -07001036#endif
1037
Jeff Johnson295189b2012-06-20 16:38:30 -07001038 /*
1039 ** Ack back to the context from which the main controller thread has been
1040 ** created.
1041 */
1042 complete(&pSchedContext->TxStartEvent);
1043 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1044 "%s: TX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
1045
1046 /* Get the Global VOSS Context */
1047 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
1048 if(!pVosContext) {
1049 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
1050 return 0;
1051 }
1052
1053 /* Get the HDD context */
1054 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1055 if(!pHddCtx) {
1056 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
1057 return 0;
1058 }
1059
1060
1061 while(!shutdown)
1062 {
1063 // This implements the execution model algorithm
1064 retWaitStatus = wait_event_interruptible(pSchedContext->txWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301065 test_bit(TX_POST_EVENT, &pSchedContext->txEventFlag) ||
1066 test_bit(TX_SUSPEND_EVENT, &pSchedContext->txEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -07001067
1068
1069 if(retWaitStatus == -ERESTARTSYS)
1070 {
1071 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001072 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001073 break;
1074 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301075 clear_bit(TX_POST_EVENT, &pSchedContext->txEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001076
1077 while(1)
1078 {
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301079 if(test_bit(TX_SHUTDOWN_EVENT, &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001080 {
1081 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1082 "%s: TX thread signaled to shutdown", __func__);
1083 shutdown = VOS_TRUE;
1084 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301085 if (test_and_clear_bit(TX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301086 &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001087 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001088 /* Unblock anyone waiting on suspend */
1089 complete(&pHddCtx->tx_sus_event_var);
1090 }
1091 break;
1092 }
1093 // Check the SYS queue first
1094 if (!vos_is_mq_empty(&pSchedContext->sysTxMq))
1095 {
1096 // Service the SYS message queue
1097 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1098 "%s: Servicing the VOS SYS TX Message queue",__func__);
1099 pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq);
1100 if (pMsgWrapper == NULL)
1101 {
1102 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001103 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001104 VOS_ASSERT(0);
1105 break;
1106 }
1107 vStatus = sysTxProcessMsg( pSchedContext->pVContext,
1108 pMsgWrapper->pVosMsg);
1109 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1110 {
1111 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1112 "%s: Issue Processing TX SYS message",__func__);
1113 }
1114 // return message to the Core
1115 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1116 continue;
1117 }
1118 // Check now the TL queue
1119 if (!vos_is_mq_empty(&pSchedContext->tlTxMq))
1120 {
1121 // Service the TL message queue
1122 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1123 "%s: Servicing the VOS TL TX Message queue",__func__);
1124 pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq);
1125 if (pMsgWrapper == NULL)
1126 {
1127 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001128 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001129 VOS_ASSERT(0);
1130 break;
1131 }
1132 vStatus = WLANTL_TxProcessMsg( pSchedContext->pVContext,
1133 pMsgWrapper->pVosMsg);
1134 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1135 {
1136 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1137 "%s: Issue Processing TX TL message",__func__);
1138 }
1139 // return message to the Core
1140 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1141 continue;
1142 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001143 // Check the WDI queue
1144 if (!vos_is_mq_empty(&pSchedContext->wdiTxMq))
1145 {
1146 wpt_msg *pWdiMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07001147 pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001148
1149 if (pMsgWrapper == NULL)
1150 {
1151 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001152 "%s: pMsgWrapper is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301153 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001154 break;
1155 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001156
1157 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
Jeff Johnson295189b2012-06-20 16:38:30 -07001158
Jeff Johnsond13512a2012-07-17 11:42:19 -07001159 if(pWdiMsg == NULL || pWdiMsg->callback == NULL)
1160 {
1161 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001162 "%s: WDI Msg or Callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301163 VOS_BUG(0);
Jeff Johnsond13512a2012-07-17 11:42:19 -07001164 break;
1165 }
1166
Jeff Johnson295189b2012-06-20 16:38:30 -07001167 pWdiMsg->callback(pWdiMsg);
1168
1169 // return message to the Core
1170 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1171
1172 continue;
1173 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001174 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301175 if (test_and_clear_bit(TX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301176 &pSchedContext->txEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001177 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001178 spin_lock(&pSchedContext->TxThreadLock);
Abhishek Singhbff18d22016-02-04 18:05:32 +05301179 INIT_COMPLETION(pSchedContext->ResumeTxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -07001180 /* Tx Thread Suspended */
1181 complete(&pHddCtx->tx_sus_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07001182 spin_unlock(&pSchedContext->TxThreadLock);
Jeff Johnson295189b2012-06-20 16:38:30 -07001183 /* Wait foe Resume Indication */
1184 wait_for_completion_interruptible(&pSchedContext->ResumeTxEvent);
1185 }
1186
1187 break; //All queues are empty now
1188 } // while message loop processing
1189 } // while TRUE
1190 // If we get here the TX thread must exit
1191 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001192 "%s: TX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001193 complete_and_exit(&pSchedContext->TxShutdown, 0);
1194} /* VosTxThread() */
1195
Jeff Johnson295189b2012-06-20 16:38:30 -07001196/*---------------------------------------------------------------------------
1197 \brief VosRXThread() - The VOSS Main Rx thread
1198 The \a VosRxThread() is the VOSS Rx controller thread:
1199 \param Arg - pointer to the global vOSS Sched Context
1200
1201 \return Thread exit code
1202 \sa VosRxThread()
1203 -------------------------------------------------------------------------*/
1204
1205static int VosRXThread ( void * Arg )
1206{
1207 pVosSchedContext pSchedContext = (pVosSchedContext)Arg;
1208 pVosMsgWrapper pMsgWrapper = NULL;
1209 int retWaitStatus = 0;
1210 v_BOOL_t shutdown = VOS_FALSE;
1211 hdd_context_t *pHddCtx = NULL;
1212 v_CONTEXT_t pVosContext = NULL;
1213 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1214
1215 set_user_nice(current, -1);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001216
1217#ifdef WLAN_FEATURE_11AC_HIGH_TP
Madan Mohan Koyyalamudi893c77f2012-09-18 19:30:48 -07001218 set_wake_up_idle(true);
Madan Mohan Koyyalamudid68ecce2012-09-18 19:51:41 -07001219#endif
Jeff Johnson295189b2012-06-20 16:38:30 -07001220
1221 if (Arg == NULL)
1222 {
1223 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001224 "%s Bad Args passed", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001225 return 0;
1226 }
Yue Maf49ba872013-08-19 12:04:25 -07001227
1228#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0))
Jeff Johnson295189b2012-06-20 16:38:30 -07001229 daemonize("RX_Thread");
Yue Maf49ba872013-08-19 12:04:25 -07001230#endif
1231
Jeff Johnson295189b2012-06-20 16:38:30 -07001232 /*
1233 ** Ack back to the context from which the main controller thread has been
1234 ** created.
1235 */
1236 complete(&pSchedContext->RxStartEvent);
1237 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1238 "%s: RX Thread %d (%s) starting up!",__func__, current->pid, current->comm);
1239
1240 /* Get the Global VOSS Context */
1241 pVosContext = vos_get_global_context(VOS_MODULE_ID_SYS, NULL);
1242 if(!pVosContext) {
1243 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: Global VOS context is Null", __func__);
1244 return 0;
1245 }
1246
1247 /* Get the HDD context */
1248 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
1249 if(!pHddCtx) {
1250 hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD context is Null",__func__);
1251 return 0;
1252 }
1253
1254 while(!shutdown)
1255 {
1256 // This implements the execution model algorithm
1257 retWaitStatus = wait_event_interruptible(pSchedContext->rxWaitQueue,
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301258 test_bit(RX_POST_EVENT, &pSchedContext->rxEventFlag) ||
1259 test_bit(RX_SUSPEND_EVENT, &pSchedContext->rxEventFlag));
Jeff Johnson295189b2012-06-20 16:38:30 -07001260
1261
1262 if(retWaitStatus == -ERESTARTSYS)
1263 {
1264 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001265 "%s: wait_event_interruptible returned -ERESTARTSYS", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001266 break;
1267 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301268 clear_bit(RX_POST_EVENT, &pSchedContext->rxEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001269
1270 while(1)
1271 {
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301272 if(test_bit(RX_SHUTDOWN_EVENT, &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001273 {
1274 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1275 "%s: RX thread signaled to shutdown", __func__);
1276 shutdown = VOS_TRUE;
1277 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301278 if (test_and_clear_bit(RX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301279 &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001280 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001281 /* Unblock anyone waiting on suspend */
1282 complete(&pHddCtx->rx_sus_event_var);
1283 }
1284 break;
1285 }
1286
1287
1288 // Check the SYS queue first
1289 if (!vos_is_mq_empty(&pSchedContext->sysRxMq))
1290 {
1291 // Service the SYS message queue
1292 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1293 "%s: Servicing the VOS SYS RX Message queue",__func__);
1294 pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq);
1295 if (pMsgWrapper == NULL)
1296 {
1297 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001298 "%s: pMsgWrapper is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001299 VOS_ASSERT(0);
1300 break;
1301 }
1302 vStatus = sysRxProcessMsg( pSchedContext->pVContext,
1303 pMsgWrapper->pVosMsg);
1304 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1305 {
1306 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1307 "%s: Issue Processing TX SYS message",__func__);
1308 }
1309 // return message to the Core
1310 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1311 continue;
1312 }
1313
Katya Nigam664f5032014-05-05 12:24:32 +05301314 // Check now the TL queue
1315 if (!vos_is_mq_empty(&pSchedContext->tlRxMq))
1316 {
1317 // Service the TL message queue
1318 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
1319 "%s: Servicing the VOS TL RX Message queue",__func__);
1320 pMsgWrapper = vos_mq_get(&pSchedContext->tlRxMq);
1321 if (pMsgWrapper == NULL)
1322 {
1323 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1324 "%s: pMsgWrapper is NULL", __func__);
1325 VOS_ASSERT(0);
1326 break;
1327 }
1328 vStatus = WLANTL_RxProcessMsg( pSchedContext->pVContext,
1329 pMsgWrapper->pVosMsg);
1330 if (!VOS_IS_STATUS_SUCCESS(vStatus))
1331 {
1332 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1333 "%s: Issue Processing RX TL message",__func__);
1334 }
1335 // return message to the Core
1336 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1337 continue;
1338 }
1339
Jeff Johnson295189b2012-06-20 16:38:30 -07001340 // Check the WDI queue
1341 if (!vos_is_mq_empty(&pSchedContext->wdiRxMq))
1342 {
1343 wpt_msg *pWdiMsg;
Jeff Johnson295189b2012-06-20 16:38:30 -07001344 pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq);
1345 if ((NULL == pMsgWrapper) || (NULL == pMsgWrapper->pVosMsg))
1346 {
1347 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001348 "%s: wdiRxMq message is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301349 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001350 // we won't return this wrapper since it is corrupt
1351 }
1352 else
1353 {
1354 pWdiMsg = (wpt_msg *)pMsgWrapper->pVosMsg->bodyptr;
1355 if ((NULL == pWdiMsg) || (NULL == pWdiMsg->callback))
1356 {
1357 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001358 "%s: WDI Msg or callback is NULL", __func__);
Mihir Shetea71d91c2014-11-05 14:55:38 +05301359 VOS_BUG(0);
Jeff Johnson295189b2012-06-20 16:38:30 -07001360 }
1361 else
1362 {
1363 // invoke the message handler
1364 pWdiMsg->callback(pWdiMsg);
1365 }
1366
1367 // return message to the Core
1368 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1369 }
1370 continue;
1371 }
1372
1373 /* Check for any Suspend Indication */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301374 if (test_and_clear_bit(RX_SUSPEND_EVENT,
Mihir Shete5dfd9a52014-06-09 17:22:55 +05301375 &pSchedContext->rxEventFlag))
Jeff Johnson295189b2012-06-20 16:38:30 -07001376 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001377 spin_lock(&pSchedContext->RxThreadLock);
Abhishek Singhbff18d22016-02-04 18:05:32 +05301378 INIT_COMPLETION(pSchedContext->ResumeRxEvent);
Jeff Johnson295189b2012-06-20 16:38:30 -07001379 /* Rx Thread Suspended */
1380 complete(&pHddCtx->rx_sus_event_var);
Jeff Johnson295189b2012-06-20 16:38:30 -07001381 spin_unlock(&pSchedContext->RxThreadLock);
1382
1383 /* Wait for Resume Indication */
1384 wait_for_completion_interruptible(&pSchedContext->ResumeRxEvent);
1385 }
1386
1387 break; //All queues are empty now
1388 } // while message loop processing
1389 } // while TRUE
1390 // If we get here the RX thread must exit
1391 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001392 "%s: RX Thread exiting!!!!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001393 complete_and_exit(&pSchedContext->RxShutdown, 0);
1394} /* VosRxThread() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001395
Jeff Johnson295189b2012-06-20 16:38:30 -07001396/*---------------------------------------------------------------------------
1397 \brief vos_sched_close() - Close the vOSS Scheduler
1398 The \a vos_sched_closes() function closes the vOSS Scheduler
1399 Upon successful closing:
1400 - All the message queues are flushed
1401 - The Main Controller thread is closed
1402 - The Tx thread is closed
1403
1404 \param pVosContext - pointer to the global vOSS Context
1405 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1406 is ready to be used.
1407 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
1408 function
1409 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
1410 \sa vos_sched_close()
1411---------------------------------------------------------------------------*/
1412VOS_STATUS vos_sched_close ( v_PVOID_t pVosContext )
1413{
1414 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001415 "%s: invoked", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001416 if (gpVosSchedContext == NULL)
1417 {
1418 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Arif Hussain02882402013-11-17 21:55:29 -08001419 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001420 return VOS_STATUS_E_FAILURE;
1421 }
1422
1423 // shut down MC Thread
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301424 set_bit(MC_SHUTDOWN_EVENT, &gpVosSchedContext->mcEventFlag);
1425 set_bit(MC_POST_EVENT, &gpVosSchedContext->mcEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001426 wake_up_interruptible(&gpVosSchedContext->mcWaitQueue);
1427 //Wait for MC to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301428 wait_for_completion(&gpVosSchedContext->McShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001429 gpVosSchedContext->McThread = 0;
1430
Jeff Johnson295189b2012-06-20 16:38:30 -07001431 // shut down TX Thread
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301432 set_bit(TX_SHUTDOWN_EVENT, &gpVosSchedContext->txEventFlag);
1433 set_bit(TX_POST_EVENT, &gpVosSchedContext->txEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001434 wake_up_interruptible(&gpVosSchedContext->txWaitQueue);
1435 //Wait for TX to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301436 wait_for_completion(&gpVosSchedContext->TxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001437 gpVosSchedContext->TxThread = 0;
1438
Jeff Johnson295189b2012-06-20 16:38:30 -07001439 // shut down RX Thread
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301440 set_bit(RX_SHUTDOWN_EVENT, &gpVosSchedContext->rxEventFlag);
1441 set_bit(RX_POST_EVENT, &gpVosSchedContext->rxEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001442 wake_up_interruptible(&gpVosSchedContext->rxWaitQueue);
1443 //Wait for RX to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301444 wait_for_completion(&gpVosSchedContext->RxShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001445 gpVosSchedContext->RxThread = 0;
Jeff Johnson295189b2012-06-20 16:38:30 -07001446
1447 //Clean up message queues of TX and MC thread
1448 vos_sched_flush_mc_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001449 vos_sched_flush_tx_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001450 vos_sched_flush_rx_mqs(gpVosSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -07001451
1452 //Deinit all the queues
1453 vos_sched_deinit_mqs(gpVosSchedContext);
1454
1455 return VOS_STATUS_SUCCESS;
1456} /* vox_sched_close() */
1457
1458VOS_STATUS vos_watchdog_close ( v_PVOID_t pVosContext )
1459{
1460 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001461 "%s: vos_watchdog closing now", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001462 if (gpVosWatchdogContext == NULL)
1463 {
1464 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Arif Hussain02882402013-11-17 21:55:29 -08001465 "%s: gpVosWatchdogContext is NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001466 return VOS_STATUS_E_FAILURE;
1467 }
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05301468 set_bit(WD_SHUTDOWN_EVENT, &gpVosWatchdogContext->wdEventFlag);
1469 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07001470 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
1471 //Wait for Watchdog thread to exit
Mihir Shetede20c472013-11-28 11:02:38 +05301472 wait_for_completion(&gpVosWatchdogContext->WdShutdown);
Jeff Johnson295189b2012-06-20 16:38:30 -07001473 return VOS_STATUS_SUCCESS;
1474} /* vos_watchdog_close() */
1475
Jeff Johnson295189b2012-06-20 16:38:30 -07001476/*---------------------------------------------------------------------------
1477 \brief vos_sched_init_mqs: Initialize the vOSS Scheduler message queues
1478 The \a vos_sched_init_mqs() function initializes the vOSS Scheduler
1479 message queues.
1480 \param pVosSchedContext - pointer to the Scheduler Context.
1481 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
1482 is ready to be used.
1483 VOS_STATUS_E_RESOURCES - System resources (other than memory)
1484 are unavailable to initilize the scheduler
1485
1486 \sa vos_sched_init_mqs()
1487 -------------------------------------------------------------------------*/
1488VOS_STATUS vos_sched_init_mqs ( pVosSchedContext pSchedContext )
1489{
1490 VOS_STATUS vStatus = VOS_STATUS_SUCCESS;
1491 // Now intialize all the message queues
Jeff Johnson295189b2012-06-20 16:38:30 -07001492 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1493 "%s: Initializing the WDA MC Message queue",__func__);
1494 vStatus = vos_mq_init(&pSchedContext->wdaMcMq);
1495 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1496 {
1497 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1498 "%s: Failed to init WDA MC Message queue",__func__);
1499 VOS_ASSERT(0);
1500 return vStatus;
1501 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001502 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1503 "%s: Initializing the PE MC Message queue",__func__);
1504 vStatus = vos_mq_init(&pSchedContext->peMcMq);
1505 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1506 {
1507 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1508 "%s: Failed to init PE MC Message queue",__func__);
1509 VOS_ASSERT(0);
1510 return vStatus;
1511 }
1512 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1513 "%s: Initializing the SME MC Message queue", __func__);
1514 vStatus = vos_mq_init(&pSchedContext->smeMcMq);
1515 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1516 {
1517 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1518 "%s: Failed to init SME MC Message queue",__func__);
1519 VOS_ASSERT(0);
1520 return vStatus;
1521 }
1522 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1523 "%s: Initializing the TL MC Message queue",__func__);
1524 vStatus = vos_mq_init(&pSchedContext->tlMcMq);
1525 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1526 {
1527 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1528 "%s: Failed to init TL MC Message queue",__func__);
1529 VOS_ASSERT(0);
1530 return vStatus;
1531 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001532 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1533 "%s: Initializing the SYS MC Message queue",__func__);
1534 vStatus = vos_mq_init(&pSchedContext->sysMcMq);
1535 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1536 {
1537 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1538 "%s: Failed to init SYS MC Message queue",__func__);
1539 VOS_ASSERT(0);
1540 return vStatus;
1541 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001542 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1543 "%s: Initializing the WDI MC Message queue",__func__);
1544
1545 vStatus = vos_mq_init(&pSchedContext->wdiMcMq);
1546 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1547 {
1548 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1549 "%s: Failed to init WDI MC Message queue",__func__);
1550 VOS_ASSERT(0);
1551 return vStatus;
1552 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001553
Jeff Johnson295189b2012-06-20 16:38:30 -07001554 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1555 "%s: Initializing the TL Tx Message queue",__func__);
1556 vStatus = vos_mq_init(&pSchedContext->tlTxMq);
1557 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1558 {
1559 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1560 "%s: Failed to init TL TX Message queue",__func__);
1561 VOS_ASSERT(0);
1562 return vStatus;
1563 }
Katya Nigam664f5032014-05-05 12:24:32 +05301564
1565 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1566 "%s: Initializing the TL Rx Message queue",__func__);
1567 vStatus = vos_mq_init(&pSchedContext->tlRxMq);
1568 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1569 {
1570 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1571 "%s: Failed to init TL RX Message queue",__func__);
1572 VOS_ASSERT(0);
1573 return vStatus;
1574 }
1575
Jeff Johnson295189b2012-06-20 16:38:30 -07001576 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1577 "%s: Initializing the WDI Tx Message queue",__func__);
1578 vStatus = vos_mq_init(&pSchedContext->wdiTxMq);
1579 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1580 {
1581 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1582 "%s: Failed to init WDI TX Message queue",__func__);
1583 VOS_ASSERT(0);
1584 return vStatus;
1585 }
1586
1587 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1588 "%s: Initializing the WDI Rx Message queue",__func__);
1589
1590 vStatus = vos_mq_init(&pSchedContext->wdiRxMq);
1591 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1592 {
1593 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1594 "%s: Failed to init WDI RX Message queue",__func__);
1595 VOS_ASSERT(0);
1596 return vStatus;
1597 }
1598
Jeff Johnson295189b2012-06-20 16:38:30 -07001599 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1600 "%s: Initializing the SYS Tx Message queue",__func__);
1601 vStatus = vos_mq_init(&pSchedContext->sysTxMq);
1602 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1603 {
1604 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1605 "%s: Failed to init SYS TX Message queue",__func__);
1606 VOS_ASSERT(0);
1607 return vStatus;
1608 }
1609
1610 vStatus = vos_mq_init(&pSchedContext->sysRxMq);
1611 if (! VOS_IS_STATUS_SUCCESS(vStatus))
1612 {
1613 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1614 "%s: Failed to init SYS RX Message queue",__func__);
1615 VOS_ASSERT(0);
1616 return vStatus;
1617 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001618 return VOS_STATUS_SUCCESS;
1619} /* vos_sched_init_mqs() */
1620
1621/*---------------------------------------------------------------------------
1622 \brief vos_sched_deinit_mqs: Deinitialize the vOSS Scheduler message queues
1623 The \a vos_sched_init_mqs() function deinitializes the vOSS Scheduler
1624 message queues.
1625 \param pVosSchedContext - pointer to the Scheduler Context.
1626 \return None
1627 \sa vos_sched_deinit_mqs()
1628 -------------------------------------------------------------------------*/
1629void vos_sched_deinit_mqs ( pVosSchedContext pSchedContext )
1630{
1631 // Now de-intialize all message queues
Jeff Johnson295189b2012-06-20 16:38:30 -07001632 // MC WDA
1633 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1634 "%s De-Initializing the WDA MC Message queue",__func__);
1635 vos_mq_deinit(&pSchedContext->wdaMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001636 //MC PE
1637 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1638 "%s De-Initializing the PE MC Message queue",__func__);
1639 vos_mq_deinit(&pSchedContext->peMcMq);
1640 //MC SME
1641 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1642 "%s De-Initializing the SME MC Message queue",__func__);
1643 vos_mq_deinit(&pSchedContext->smeMcMq);
1644 //MC TL
1645 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1646 "%s De-Initializing the TL MC Message queue",__func__);
1647 vos_mq_deinit(&pSchedContext->tlMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001648 //MC SYS
1649 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1650 "%s De-Initializing the SYS MC Message queue",__func__);
1651 vos_mq_deinit(&pSchedContext->sysMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001652 // MC WDI
1653 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1654 "%s De-Initializing the WDI MC Message queue",__func__);
1655 vos_mq_deinit(&pSchedContext->wdiMcMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001656
Jeff Johnson295189b2012-06-20 16:38:30 -07001657 //Tx TL
1658 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1659 "%s De-Initializing the TL Tx Message queue",__func__);
1660 vos_mq_deinit(&pSchedContext->tlTxMq);
Katya Nigam664f5032014-05-05 12:24:32 +05301661
1662 //Rx TL
1663 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1664 "%s De-Initializing the TL Rx Message queue",__func__);
1665 vos_mq_deinit(&pSchedContext->tlRxMq);
1666
Jeff Johnson295189b2012-06-20 16:38:30 -07001667 //Tx WDI
1668 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1669 "%s: DeInitializing the WDI Tx Message queue",__func__);
1670 vos_mq_deinit(&pSchedContext->wdiTxMq);
1671
1672
1673 //Rx WDI
1674 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1675 "%s: DeInitializing the WDI Rx Message queue",__func__);
1676 vos_mq_deinit(&pSchedContext->wdiRxMq);
Jeff Johnson295189b2012-06-20 16:38:30 -07001677
1678 //Tx SYS
1679 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1680 "%s: DeInitializing the SYS Tx Message queue",__func__);
1681 vos_mq_deinit(&pSchedContext->sysTxMq);
1682
1683 //Rx SYS
1684 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO_HIGH,
1685 "%s: DeInitializing the SYS Rx Message queue",__func__);
1686 vos_mq_deinit(&pSchedContext->sysRxMq);
1687
Jeff Johnson295189b2012-06-20 16:38:30 -07001688} /* vos_sched_deinit_mqs() */
1689
1690/*-------------------------------------------------------------------------
1691 this helper function flushes all the MC message queues
1692 -------------------------------------------------------------------------*/
1693void vos_sched_flush_mc_mqs ( pVosSchedContext pSchedContext )
1694{
1695 pVosMsgWrapper pMsgWrapper = NULL;
1696 pVosContextType vosCtx;
1697
1698 /*
1699 ** Here each of the MC thread MQ shall be drained and returned to the
1700 ** Core. Before returning a wrapper to the Core, the VOS message shall be
1701 ** freed first
1702 */
1703 VOS_TRACE( VOS_MODULE_ID_VOSS,
1704 VOS_TRACE_LEVEL_INFO,
Arif Hussain02882402013-11-17 21:55:29 -08001705 ("Flushing the MC Thread message queue") );
Jeff Johnson295189b2012-06-20 16:38:30 -07001706
1707 if (NULL == pSchedContext)
1708 {
1709 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001710 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001711 return;
1712 }
1713
1714 vosCtx = (pVosContextType)(pSchedContext->pVContext);
1715 if (NULL == vosCtx)
1716 {
1717 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001718 "%s: vosCtx is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001719 return;
1720 }
1721
1722 /* Flush the SYS Mq */
1723 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysMcMq) ))
1724 {
1725 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301726 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001727 "%s: Freeing MC SYS message type %d ",__func__,
1728 pMsgWrapper->pVosMsg->type );
1729 sysMcFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1730 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1731 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001732 /* Flush the WDA Mq */
1733 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdaMcMq) ))
1734 {
1735 if(pMsgWrapper->pVosMsg != NULL)
1736 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301737 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001738 "%s: Freeing MC WDA MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001739 __func__, pMsgWrapper->pVosMsg->type );
Jeff Johnson295189b2012-06-20 16:38:30 -07001740 if (pMsgWrapper->pVosMsg->bodyptr) {
1741 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1742 }
1743
1744 pMsgWrapper->pVosMsg->bodyptr = NULL;
1745 pMsgWrapper->pVosMsg->bodyval = 0;
1746 pMsgWrapper->pVosMsg->type = 0;
1747 }
1748 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1749 }
1750
1751 /* Flush the WDI Mq */
1752 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiMcMq) ))
1753 {
1754 if(pMsgWrapper->pVosMsg != NULL)
1755 {
Ratheesh S P36dbc932015-08-07 14:28:57 +05301756 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001757 "%s: Freeing MC WDI MSG message type %d",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001758 __func__, pMsgWrapper->pVosMsg->type );
Leo Chang0f24ca12013-12-17 13:35:00 -08001759
1760 /* MSG body pointer is not NULL
1761 * and MSG type is 0
1762 * This MSG is not posted by SMD NOTIFY
1763 * We have to free MSG body */
1764 if ((pMsgWrapper->pVosMsg->bodyptr) && (!pMsgWrapper->pVosMsg->type))
1765 {
Jeff Johnson295189b2012-06-20 16:38:30 -07001766 vos_mem_free((v_VOID_t*)pMsgWrapper->pVosMsg->bodyptr);
1767 }
Leo Chang0f24ca12013-12-17 13:35:00 -08001768 /* MSG body pointer is not NULL
1769 * and MSG type is not 0
1770 * This MSG is posted by SMD NOTIFY
1771 * We should not free MSG body */
1772 else if ((pMsgWrapper->pVosMsg->bodyptr) && pMsgWrapper->pVosMsg->type)
1773 {
1774 VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1775 "%s: SMD NOTIFY MSG, do not free body",
1776 __func__);
1777 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001778 pMsgWrapper->pVosMsg->bodyptr = NULL;
1779 pMsgWrapper->pVosMsg->bodyval = 0;
1780 pMsgWrapper->pVosMsg->type = 0;
1781 }
1782 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1783 }
1784
Jeff Johnson295189b2012-06-20 16:38:30 -07001785 /* Flush the PE Mq */
1786 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->peMcMq) ))
1787 {
1788 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301789 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001790 "%s: Freeing MC PE MSG message type %d",__func__,
1791 pMsgWrapper->pVosMsg->type );
1792 peFreeMsg(vosCtx->pMACContext, (tSirMsgQ*)pMsgWrapper->pVosMsg);
1793 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1794 }
1795 /* Flush the SME Mq */
1796 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->smeMcMq) ))
1797 {
1798 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301799 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001800 "%s: Freeing MC SME MSG message type %d", __func__,
1801 pMsgWrapper->pVosMsg->type );
1802 sme_FreeMsg(vosCtx->pMACContext, pMsgWrapper->pVosMsg);
1803 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1804 }
1805 /* Flush the TL Mq */
1806 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlMcMq) ))
1807 {
1808 VOS_TRACE( VOS_MODULE_ID_VOSS,
Ratheesh S P36dbc932015-08-07 14:28:57 +05301809 VOS_TRACE_LEVEL_INFO,
Jeff Johnson295189b2012-06-20 16:38:30 -07001810 "%s: Freeing MC TL message type %d",__func__,
1811 pMsgWrapper->pVosMsg->type );
1812 WLANTL_McFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1813 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1814 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001815} /* vos_sched_flush_mc_mqs() */
1816
1817/*-------------------------------------------------------------------------
1818 This helper function flushes all the TX message queues
1819 ------------------------------------------------------------------------*/
1820void vos_sched_flush_tx_mqs ( pVosSchedContext pSchedContext )
1821{
1822 pVosMsgWrapper pMsgWrapper = NULL;
1823 /*
1824 ** Here each of the TX thread MQ shall be drained and returned to the
1825 ** Core. Before returning a wrapper to the Core, the VOS message shall
1826 ** be freed first
1827 */
1828 VOS_TRACE( VOS_MODULE_ID_VOSS,
1829 VOS_TRACE_LEVEL_INFO,
1830 "%s: Flushing the TX Thread message queue",__func__);
1831
1832 if (NULL == pSchedContext)
1833 {
1834 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001835 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001836 return;
1837 }
1838
1839 /* Flush the SYS Mq */
1840 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysTxMq) ))
1841 {
1842 VOS_TRACE( VOS_MODULE_ID_VOSS,
1843 VOS_TRACE_LEVEL_INFO,
1844 "%s: Freeing TX SYS message type %d",__func__,
1845 pMsgWrapper->pVosMsg->type );
1846 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1847 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1848 }
1849 /* Flush the TL Mq */
1850 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlTxMq) ))
1851 {
1852 VOS_TRACE( VOS_MODULE_ID_VOSS,
1853 VOS_TRACE_LEVEL_INFO,
1854 "%s: Freeing TX TL MSG message type %d",__func__,
1855 pMsgWrapper->pVosMsg->type );
1856 WLANTL_TxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1857 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1858 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001859 /* Flush the WDI Mq */
1860 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiTxMq) ))
1861 {
1862 VOS_TRACE( VOS_MODULE_ID_VOSS,
1863 VOS_TRACE_LEVEL_INFO,
1864 "%s: Freeing TX WDI MSG message type %d",__func__,
1865 pMsgWrapper->pVosMsg->type );
1866 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1867 vos_core_return_msg(pSchedContext->pVContext, pMsgWrapper);
1868 }
Jeff Johnson295189b2012-06-20 16:38:30 -07001869} /* vos_sched_flush_tx_mqs() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001870/*-------------------------------------------------------------------------
1871 This helper function flushes all the RX message queues
1872 ------------------------------------------------------------------------*/
1873void vos_sched_flush_rx_mqs ( pVosSchedContext pSchedContext )
1874{
1875 pVosMsgWrapper pMsgWrapper = NULL;
1876 /*
1877 ** Here each of the RX thread MQ shall be drained and returned to the
1878 ** Core. Before returning a wrapper to the Core, the VOS message shall
1879 ** be freed first
1880 */
1881 VOS_TRACE( VOS_MODULE_ID_VOSS,
1882 VOS_TRACE_LEVEL_INFO,
1883 "%s: Flushing the RX Thread message queue",__func__);
1884
1885 if (NULL == pSchedContext)
1886 {
1887 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001888 "%s: pSchedContext is NULL", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001889 return;
1890 }
1891
1892 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->wdiRxMq) ))
1893 {
1894 VOS_TRACE( VOS_MODULE_ID_VOSS,
1895 VOS_TRACE_LEVEL_INFO,
1896 "%s: Freeing RX WDI MSG message type %d",__func__,
1897 pMsgWrapper->pVosMsg->type );
1898 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1899 }
1900
Katya Nigam664f5032014-05-05 12:24:32 +05301901 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->tlRxMq) ))
1902 {
1903 VOS_TRACE( VOS_MODULE_ID_VOSS,
1904 VOS_TRACE_LEVEL_INFO,
1905 "%s: Freeing RX TL MSG message type %d",__func__,
1906 pMsgWrapper->pVosMsg->type );
1907 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1908 }
1909
Jeff Johnson295189b2012-06-20 16:38:30 -07001910 while( NULL != (pMsgWrapper = vos_mq_get(&pSchedContext->sysRxMq) ))
1911 {
1912 VOS_TRACE( VOS_MODULE_ID_VOSS,
1913 VOS_TRACE_LEVEL_INFO,
1914 "%s: Freeing RX SYS MSG message type %d",__func__,
1915 pMsgWrapper->pVosMsg->type );
1916 sysTxFreeMsg(pSchedContext->pVContext, pMsgWrapper->pVosMsg);
1917 }
1918
1919}/* vos_sched_flush_rx_mqs() */
Jeff Johnson295189b2012-06-20 16:38:30 -07001920
1921/*-------------------------------------------------------------------------
1922 This helper function helps determine if thread id is of TX thread
1923 ------------------------------------------------------------------------*/
1924int vos_sched_is_tx_thread(int threadID)
1925{
1926 // Make sure that Vos Scheduler context has been initialized
1927 VOS_ASSERT( NULL != gpVosSchedContext);
1928 if (gpVosSchedContext == NULL)
1929 {
1930 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001931 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001932 return 0;
1933 }
1934 return ((gpVosSchedContext->TxThread) && (threadID == gpVosSchedContext->TxThread->pid));
1935}
Jeff Johnson295189b2012-06-20 16:38:30 -07001936/*-------------------------------------------------------------------------
1937 This helper function helps determine if thread id is of RX thread
1938 ------------------------------------------------------------------------*/
1939int vos_sched_is_rx_thread(int threadID)
1940{
1941 // Make sure that Vos Scheduler context has been initialized
1942 VOS_ASSERT( NULL != gpVosSchedContext);
1943 if (gpVosSchedContext == NULL)
1944 {
1945 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001946 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001947 return 0;
1948 }
1949 return ((gpVosSchedContext->RxThread) && (threadID == gpVosSchedContext->RxThread->pid));
1950}
Abhishek Singh880d7122015-08-26 16:23:04 +05301951
1952/*-------------------------------------------------------------------------
1953 This helper function helps determine if thread id is of MC thread
1954 ------------------------------------------------------------------------*/
1955int vos_sched_is_mc_thread(int threadID)
1956{
1957 // Make sure that Vos Scheduler context has been initialized
1958 VOS_ASSERT( NULL != gpVosSchedContext);
1959 if (gpVosSchedContext == NULL)
1960 {
1961 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
1962 "%s: gpVosSchedContext == NULL",__func__);
1963 return 0;
1964 }
1965 return ((gpVosSchedContext->McThread) &&
1966 (threadID == gpVosSchedContext->McThread->pid));
1967}
1968
Jeff Johnson295189b2012-06-20 16:38:30 -07001969/*-------------------------------------------------------------------------
1970 Helper function to get the scheduler context
1971 ------------------------------------------------------------------------*/
1972pVosSchedContext get_vos_sched_ctxt(void)
1973{
1974 //Make sure that Vos Scheduler context has been initialized
1975 if (gpVosSchedContext == NULL)
1976 {
1977 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001978 "%s: gpVosSchedContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001979 }
1980 return (gpVosSchedContext);
1981}
1982/*-------------------------------------------------------------------------
1983 Helper function to get the watchdog context
1984 ------------------------------------------------------------------------*/
1985pVosWatchdogContext get_vos_watchdog_ctxt(void)
1986{
1987 //Make sure that Vos Scheduler context has been initialized
1988 if (gpVosWatchdogContext == NULL)
1989 {
1990 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07001991 "%s: gpVosWatchdogContext == NULL",__func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07001992 }
1993 return (gpVosWatchdogContext);
1994}
1995/**
1996 @brief vos_watchdog_wlan_shutdown()
1997
1998 This function is called to shutdown WLAN driver during SSR.
1999 Adapters are disabled, and the watchdog task will be signalled
2000 to shutdown WLAN driver.
2001
2002 @param
2003 NONE
2004 @return
2005 VOS_STATUS_SUCCESS - Operation completed successfully.
2006 VOS_STATUS_E_FAILURE - Operation failed.
2007
2008*/
2009VOS_STATUS vos_watchdog_wlan_shutdown(void)
2010{
2011 v_CONTEXT_t pVosContext = NULL;
2012 hdd_context_t *pHddCtx = NULL;
2013
Jeff Johnson295189b2012-06-20 16:38:30 -07002014 if (NULL == gpVosWatchdogContext)
2015 {
2016 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002017 "%s: Watchdog not enabled. LOGP ignored.", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002018 return VOS_STATUS_E_FAILURE;
2019 }
2020
Siddharth Bhalb9a1ae32014-08-27 14:53:55 +05302021 if (gpVosWatchdogContext->isFatalError)
2022 {
2023 /* If we hit this, it means wlan driver is in bad state and needs
2024 * driver unload and load.
2025 */
2026 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2027 "%s: Driver in bad state and need unload and load", __func__);
2028 return VOS_STATUS_E_FAILURE;
2029 }
2030
Siddharth Bhalb9a1ae32014-08-27 14:53:55 +05302031
Jeff Johnson295189b2012-06-20 16:38:30 -07002032 pVosContext = vos_get_global_context(VOS_MODULE_ID_HDD, NULL);
2033 pHddCtx = (hdd_context_t *)vos_get_context(VOS_MODULE_ID_HDD, pVosContext );
2034 if (NULL == pHddCtx)
2035 {
2036 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002037 "%s: Invalid HDD Context", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002038 return VOS_STATUS_E_FAILURE;
2039 }
2040
Ramanasarvesh Sadula918a5bc2020-09-25 12:14:09 +05302041#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0))
Dundi Raviteja18ce38e2020-08-04 16:32:14 +05302042 wpalUnRegisterInterrupt(DXE_INTERRUPT_RX_READY);
2043 wpalUnRegisterInterrupt(DXE_INTERRUPT_TX_COMPLE);
Ramanasarvesh Sadula918a5bc2020-09-25 12:14:09 +05302044#endif
Dundi Raviteja18ce38e2020-08-04 16:32:14 +05302045
Jeff Johnson295189b2012-06-20 16:38:30 -07002046 /* Take the lock here */
2047 spin_lock(&gpVosWatchdogContext->wdLock);
2048
2049 /* reuse the existing 'reset in progress' */
2050 if (gpVosWatchdogContext->resetInProgress)
2051 {
2052 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2053 "%s: Shutdown already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002054 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002055 /* Release the lock here */
2056 spin_unlock(&gpVosWatchdogContext->wdLock);
2057 return VOS_STATUS_E_FAILURE;
2058 }
2059 /* reuse the existing 'logp in progress', eventhough it is not
2060 * exactly the same */
2061 else if (pHddCtx->isLogpInProgress)
2062 {
2063 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2064 "%s: shutdown/re-init already in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002065 __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -07002066 /* Release the lock here */
2067 spin_unlock(&gpVosWatchdogContext->wdLock);
2068 return VOS_STATUS_E_FAILURE;
Siddharth Bhal1ab61052014-09-15 14:39:37 +05302069 }
Jeff Johnson295189b2012-06-20 16:38:30 -07002070
Mihir Shete18156292014-03-11 15:38:30 +05302071 if (WLAN_HDD_IS_LOAD_UNLOAD_IN_PROGRESS(pHddCtx))
Jeff Johnson295189b2012-06-20 16:38:30 -07002072 {
2073 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2074 "%s: Load/unload in Progress. Ignoring signaling Watchdog",
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -07002075 __func__);
Madan Mohan Koyyalamudib5da5332012-10-15 17:23:21 -07002076 /* wcnss has crashed, and SSR has alredy been started by Kernel driver.
2077 * So disable SSR from WLAN driver */
2078 hdd_set_ssr_required( HDD_SSR_DISABLED );
Hema Aparna Medicharla6b4d4f32015-06-23 04:09:12 +05302079
Siddharth Bhal1ab61052014-09-15 14:39:37 +05302080 /* Release the lock here before returning */
2081 spin_unlock(&gpVosWatchdogContext->wdLock);
Jeff Johnson295189b2012-06-20 16:38:30 -07002082 return VOS_STATUS_E_FAILURE;
2083 }
Siddharth Bhal1ab61052014-09-15 14:39:37 +05302084 /* Set the flags so that all commands from userspace get blocked right away */
2085 vos_set_logp_in_progress(VOS_MODULE_ID_VOSS, TRUE);
2086 vos_set_reinit_in_progress(VOS_MODULE_ID_VOSS, FALSE);
2087 pHddCtx->isLogpInProgress = TRUE;
2088
2089 /* Release the lock here */
2090 spin_unlock(&gpVosWatchdogContext->wdLock);
2091
Manjeet Singhaf8d9af2016-01-04 17:56:25 +05302092 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_FATAL,
2093 "%s: WLAN driver is shutting down ", __func__);
2094
Jeff Johnson295189b2012-06-20 16:38:30 -07002095 /* Update Riva Reset Statistics */
2096 pHddCtx->hddRivaResetStats++;
2097#ifdef CONFIG_HAS_EARLYSUSPEND
2098 if(VOS_STATUS_SUCCESS != hdd_wlan_reset_initialization())
2099 {
2100 VOS_ASSERT(0);
2101 }
2102#endif
2103
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05302104 set_bit(WD_WLAN_SHUTDOWN_EVENT, &gpVosWatchdogContext->wdEventFlag);
2105 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07002106 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
2107
2108 return VOS_STATUS_SUCCESS;
2109}
2110
2111/**
2112 @brief vos_watchdog_wlan_re_init()
2113
2114 This function is called to re-initialize WLAN driver, and this is
2115 called when Riva SS reboots.
2116
2117 @param
2118 NONE
2119 @return
2120 VOS_STATUS_SUCCESS - Operation completed successfully.
2121 VOS_STATUS_E_FAILURE - Operation failed.
2122
2123*/
2124VOS_STATUS vos_watchdog_wlan_re_init(void)
2125{
Gupta, Kapilcb2c2d72016-04-21 16:20:12 +05302126 /* Make sure that Vos Watchdog context has been initialized */
2127 if (gpVosWatchdogContext == NULL) {
2128 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
2129 "%s: gpVosWatchdogContext == NULL", __func__);
2130 return VOS_STATUS_E_FAILURE;
2131 }
2132
Jeff Johnson295189b2012-06-20 16:38:30 -07002133 /* watchdog task is still running, it is not closed in shutdown */
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +05302134 set_bit(WD_WLAN_REINIT_EVENT, &gpVosWatchdogContext->wdEventFlag);
2135 set_bit(WD_POST_EVENT, &gpVosWatchdogContext->wdEventFlag);
Jeff Johnson295189b2012-06-20 16:38:30 -07002136 wake_up_interruptible(&gpVosWatchdogContext->wdWaitQueue);
2137
2138 return VOS_STATUS_SUCCESS;
2139}
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05302140
2141/**
2142 @brief vos_ssr_protect()
2143
2144 This function is called to keep track of active driver entry points
2145
2146 @param
2147 caller_func - Name of calling function.
2148 @return
2149 void
2150*/
2151void vos_ssr_protect(const char *caller_func)
2152{
2153 int count;
2154 count = atomic_inc_return(&ssr_protect_entry_count);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05302155}
2156
2157/**
2158 @brief vos_ssr_unprotect()
2159
2160 @param
2161 caller_func - Name of calling function.
2162 @return
2163 void
2164*/
2165void vos_ssr_unprotect(const char *caller_func)
2166{
2167 int count;
2168 count = atomic_dec_return(&ssr_protect_entry_count);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +05302169}
Abhishek Singhe7ea25c2015-11-23 16:23:24 +05302170/**
2171 * vos_is_wd_thread()- Check if threadid is
2172 * of Watchdog thread
2173 *
2174 * @threadId: passed threadid
2175 *
2176 * This function is called to check if threadid is
2177 * of wd thread.
2178 *
2179 * Return: true if threadid is of wd thread.
2180 */
2181bool vos_is_wd_thread(int threadId)
2182{
Gupta, Kapilbd50b5c2015-12-04 18:57:02 +05302183 /* Make sure that Vos Watchdog context has been initialized */
2184 if (gpVosWatchdogContext == NULL)
2185 {
2186 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_INFO,
2187 "%s: gpVosWatchdogContext == NULL", __func__);
2188 return false;
2189 }
2190
Abhishek Singhe7ea25c2015-11-23 16:23:24 +05302191 return ((gpVosWatchdogContext->WdThread) &&
2192 (threadId == gpVosWatchdogContext->WdThread->pid));
2193}
2194
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302195void vos_dump_stack(uint8_t thread_id)
2196{
2197 switch (thread_id)
2198 {
2199 case MC_Thread:
2200 wcnss_dump_stack(gpVosSchedContext->McThread);
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302201 break;
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302202 case TX_Thread:
2203 wcnss_dump_stack(gpVosSchedContext->TxThread);
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302204 break;
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302205 case RX_Thread:
2206 wcnss_dump_stack(gpVosSchedContext->RxThread);
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302207 break;
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302208 default:
2209 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
Padma, Santhosh Kumar3fd3c192016-04-06 16:21:03 +05302210 "%s: Invalid thread %d invoked",__func__, thread_id);
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +05302211 }
2212}
Arunk Khandavalliaf6c3af2017-01-16 11:44:46 +05302213
2214void vos_dump_thread_stacks(int threadId)
2215{
2216 /* Make sure that Vos Watchdog context has been initialized */
2217 if (gpVosWatchdogContext == NULL)
2218 {
2219 VOS_TRACE(VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
2220 "%s: gpVosWatchdogContext == NULL", __func__);
2221 return;
2222 }
2223 hddLog(LOGE, FL("Thread Stuck count reached threshold!!!"
2224 "MC Count %d RX count %d TX count %d"),
2225 gpVosWatchdogContext->mcThreadStuckCount,
2226 gpVosWatchdogContext->rxThreadStuckCount,
2227 gpVosWatchdogContext->txThreadStuckCount);
2228
2229 vos_dump_stack(MC_Thread);
2230 vos_dump_stack(TX_Thread);
2231 vos_dump_stack(RX_Thread);
2232}
Abhinav Kumar118efd02019-08-07 16:41:07 +05302233
2234int vos_get_gfp_flags(void)
2235{
2236 int flags = GFP_KERNEL;
2237
2238 if (in_interrupt() || in_atomic() || irqs_disabled())
2239 flags = GFP_ATOMIC;
2240
2241 return flags;
2242}