blob: 8d75a8b96aac2af9650285b67ea252143c026d73 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +05302 * Copyright (c) 2012-2018 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#if !defined( __VOS_SCHED_H )
29#define __VOS_SCHED_H
30
31/**=========================================================================
32
33 \file vos_sched.h
34
35 \brief virtual Operating System Servies (vOSS)
36
37 Definitions for some of the internal data type that is internally used
38 by the vOSS scheduler on Windows Mobile.
39
40 This file defines a vOSS message queue on Win Mobile and give some
41 insights about how the scheduler implements the execution model supported
42 by vOSS.
43
44
Jeff Johnson295189b2012-06-20 16:38:30 -070045
46 ========================================================================*/
47
48/*===========================================================================
49
50 EDIT HISTORY FOR FILE
51
52
53 This section contains comments describing changes made to the module.
54 Notice that changes are listed in reverse chronological order.
55
56
57 $Header:$ $DateTime: $ $Author: $
58
59
60 when who what, where, why
61 -------- --- --------------------------------------------------------
62 09/15/08 lac Removed hardcoded #define for VOS_TRACE.
63 06/12/08 hba Created module.
64
65===========================================================================*/
66
67/*--------------------------------------------------------------------------
68 Include Files
69 ------------------------------------------------------------------------*/
70#include <vos_event.h>
Vinay Krishna Eranna2025d892014-09-18 16:51:42 +053071#include <vos_nvitem.h>
72#include <vos_mq.h>
Jeff Johnson295189b2012-06-20 16:38:30 -070073#include "i_vos_types.h"
74#include "i_vos_packet.h"
75#include <linux/wait.h>
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053076
77#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && \
78 defined(WLAN_OPEN_SOURCE)
79#include <linux/device.h>
80#include <linux/pm_wakeup.h>
81#else
Jeff Johnson295189b2012-06-20 16:38:30 -070082#include <linux/wakelock.h>
Rajeev Kumar Sirasanagandla5b21a9c2018-01-08 17:05:11 +053083#endif
84
Abhishek Singhe7ea25c2015-11-23 16:23:24 +053085#include <vos_timer.h>
Anurag Chouhanf0d0ba12018-02-09 15:13:43 +053086#include <vos_api.h>
Abhishek Singhe7ea25c2015-11-23 16:23:24 +053087
Jeff Johnson295189b2012-06-20 16:38:30 -070088
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +053089#define TX_POST_EVENT 0x000
90#define TX_SUSPEND_EVENT 0x001
91#define MC_POST_EVENT 0x000
92#define MC_SUSPEND_EVENT 0x001
93#define RX_POST_EVENT 0x000
94#define RX_SUSPEND_EVENT 0x001
95#define TX_SHUTDOWN_EVENT 0x002
96#define MC_SHUTDOWN_EVENT 0x002
97#define RX_SHUTDOWN_EVENT 0x002
98
99#define WD_POST_EVENT 0x000
100#define WD_SHUTDOWN_EVENT 0x001
101#define WD_CHIP_RESET_EVENT 0x002
102#define WD_WLAN_SHUTDOWN_EVENT 0x003
103#define WD_WLAN_REINIT_EVENT 0x004
104#define WD_WLAN_DETECT_THREAD_STUCK 0x005
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530105
Jeff Johnson295189b2012-06-20 16:38:30 -0700106
107
108
109/*
110** Maximum number of messages in the system
111** These are buffers to account for all current messages
112** with some accounting of what we think is a
113** worst-case scenario. Must be able to handle all
114** incoming frames, as well as overhead for internal
115** messaging
116*/
117#define VOS_CORE_MAX_MESSAGES (VPKT_NUM_RX_RAW_PACKETS + 32)
118
119
120/*
121** vOSS Message queue definition.
122*/
123typedef struct _VosMqType
124{
125 /* Lock use to synchronize access to this message queue */
126 spinlock_t mqLock;
127
128 /* List of vOS Messages waiting on this queue */
129 struct list_head mqList;
130
131} VosMqType, *pVosMqType;
132
133
134/*
135** vOSS Scheduler context
136** The scheduler context contains the following:
137** ** the messages queues
138** ** the handle to the tread
139** ** pointer to the events that gracefully shutdown the MC and Tx threads
140**
141*/
142typedef struct _VosSchedContext
143{
144 /* Place holder to the VOSS Context */
145 v_PVOID_t pVContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700146 /* WDA Message queue on the Main thread*/
147 VosMqType wdaMcMq;
Jeff Johnson295189b2012-06-20 16:38:30 -0700148
149
150
151 /* PE Message queue on the Main thread*/
152 VosMqType peMcMq;
153
154 /* SME Message queue on the Main thread*/
155 VosMqType smeMcMq;
156
157 /* TL Message queue on the Main thread */
158 VosMqType tlMcMq;
159
160 /* SYS Message queue on the Main thread */
161 VosMqType sysMcMq;
162
Jeff Johnson295189b2012-06-20 16:38:30 -0700163 /* WDI Message queue on the Main thread*/
164 VosMqType wdiMcMq;
165
166 /* WDI Message queue on the Tx Thread*/
167 VosMqType wdiTxMq;
168
169 /* WDI Message queue on the Rx Thread*/
170 VosMqType wdiRxMq;
Jeff Johnson295189b2012-06-20 16:38:30 -0700171
172 /* TL Message queue on the Tx thread */
173 VosMqType tlTxMq;
174
Katya Nigam664f5032014-05-05 12:24:32 +0530175 /* TL Message queue on the Rx thread */
176 VosMqType tlRxMq;
177
Jeff Johnson295189b2012-06-20 16:38:30 -0700178 /* SYS Message queue on the Tx thread */
179 VosMqType sysTxMq;
180
Jeff Johnson295189b2012-06-20 16:38:30 -0700181 VosMqType sysRxMq;
Jeff Johnson295189b2012-06-20 16:38:30 -0700182
183 /* Handle of Event for MC thread to signal startup */
184 struct completion McStartEvent;
185
186 /* Handle of Event for Tx thread to signal startup */
187 struct completion TxStartEvent;
188
Jeff Johnson295189b2012-06-20 16:38:30 -0700189 /* Handle of Event for Rx thread to signal startup */
190 struct completion RxStartEvent;
Jeff Johnson295189b2012-06-20 16:38:30 -0700191
192 struct task_struct* McThread;
193
194 /* TX Thread handle */
195
196 struct task_struct* TxThread;
197
Jeff Johnson295189b2012-06-20 16:38:30 -0700198 /* RX Thread handle */
199 struct task_struct* RxThread;
Jeff Johnson295189b2012-06-20 16:38:30 -0700200
201
202 /* completion object for MC thread shutdown */
203 struct completion McShutdown;
204
205 /* completion object for Tx thread shutdown */
206 struct completion TxShutdown;
207
Jeff Johnson295189b2012-06-20 16:38:30 -0700208 /* completion object for Rx thread shutdown */
209 struct completion RxShutdown;
Jeff Johnson295189b2012-06-20 16:38:30 -0700210
211 /* Wait queue for MC thread */
212 wait_queue_head_t mcWaitQueue;
213
214 unsigned long mcEventFlag;
215
216 /* Wait queue for Tx thread */
217 wait_queue_head_t txWaitQueue;
218
219 unsigned long txEventFlag;
220
Jeff Johnson295189b2012-06-20 16:38:30 -0700221 /* Wait queue for Rx thread */
222 wait_queue_head_t rxWaitQueue;
223
224 unsigned long rxEventFlag;
Jeff Johnson295189b2012-06-20 16:38:30 -0700225
226 /* Completion object to resume Mc thread */
227 struct completion ResumeMcEvent;
228
229 /* Completion object to resume Tx thread */
230 struct completion ResumeTxEvent;
231
Jeff Johnson295189b2012-06-20 16:38:30 -0700232 /* Completion object to resume Rx thread */
233 struct completion ResumeRxEvent;
Jeff Johnson295189b2012-06-20 16:38:30 -0700234
235 /* lock to make sure that McThread and TxThread Suspend/resume mechanism is in sync*/
236 spinlock_t McThreadLock;
237 spinlock_t TxThreadLock;
238 spinlock_t RxThreadLock;
239
240} VosSchedContext, *pVosSchedContext;
241
242/*
243** VOSS watchdog context
244** The watchdog context contains the following:
245** The messages queues and events
246** The handle to the thread
247**
248*/
249typedef struct _VosWatchdogContext
250{
251
252 /* Place holder to the VOSS Context */
253 v_PVOID_t pVContext;
254
255 /* Handle of Event for Watchdog thread to signal startup */
256 struct completion WdStartEvent;
257
258 /* Watchdog Thread handle */
259
260 struct task_struct* WdThread;
261
262 /* completion object for Watchdog thread shutdown */
263 struct completion WdShutdown;
264
265 /* Wait queue for Watchdog thread */
266 wait_queue_head_t wdWaitQueue;
267
268 /* Event flag for events handled by Watchdog */
269 unsigned long wdEventFlag;
270
271 v_BOOL_t resetInProgress;
272
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530273 v_BOOL_t isFatalError;
274
Jeff Johnson295189b2012-06-20 16:38:30 -0700275 /* Lock for preventing multiple reset being triggered simultaneously */
276 spinlock_t wdLock;
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530277 /* Timer to detect thread stuck issue */
278 vos_timer_t threadStuckTimer;
279 /* Count for each thread to determine thread stuck */
280 unsigned int mcThreadStuckCount;
281 unsigned int txThreadStuckCount;
282 unsigned int rxThreadStuckCount;
283 /* lock to synchronize access to the thread stuck counts */
284 spinlock_t thread_stuck_lock;
Jeff Johnson295189b2012-06-20 16:38:30 -0700285
286} VosWatchdogContext, *pVosWatchdogContext;
287
288/*
289** vOSS Sched Msg Wrapper
290** Wrapper messages so that they can be chained to their respective queue
291** in the scheduler.
292*/
293typedef struct _VosMsgWrapper
294{
295 /* Message node */
296 struct list_head msgNode;
297
298 /* the Vos message it is associated to */
299 vos_msg_t *pVosMsg;
300
301} VosMsgWrapper, *pVosMsgWrapper;
302
303
Mahesh A Saptasagara67b86d2016-04-26 21:20:41 +0530304typedef struct vos_wdthread_timer_work {
305 vos_timer_callback_t callback;
306 v_PVOID_t userData;
307 struct list_head node;
308}vos_wdthread_timer_work_t;
Jeff Johnson295189b2012-06-20 16:38:30 -0700309
310typedef struct _VosContextType
311{
312 /* Messages buffers */
313 vos_msg_t aMsgBuffers[VOS_CORE_MAX_MESSAGES];
314
315 VosMsgWrapper aMsgWrappers[VOS_CORE_MAX_MESSAGES];
316
317 /* Free Message queue*/
318 VosMqType freeVosMq;
319
320 /* Scheduler Context */
321 VosSchedContext vosSched;
322
323 /* Watchdog Context */
324 VosWatchdogContext vosWatchdog;
325
326 /* HDD Module Context */
327 v_VOID_t *pHDDContext;
328
Jeff Johnson295189b2012-06-20 16:38:30 -0700329 /* HDD SoftAP Module Context */
330 v_VOID_t *pHDDSoftAPContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700331
332 /* TL Module Context */
333 v_VOID_t *pTLContext;
334
335 /* MAC Module Context */
336 v_VOID_t *pMACContext;
337
Jeff Johnson295189b2012-06-20 16:38:30 -0700338 /* BAP Context */
339 v_VOID_t *pBAPContext;
340
Jeff Johnson295189b2012-06-20 16:38:30 -0700341 /* SAP Context */
342 v_VOID_t *pSAPContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700343
344 /* VOS Packet Context */
345 vos_pkt_context_t vosPacket;
346
347 vos_event_t ProbeEvent;
348
349 volatile v_U8_t isLogpInProgress;
350
Jeff Johnson295189b2012-06-20 16:38:30 -0700351 vos_event_t wdaCompleteEvent;
352
353 /* WDA Context */
354 v_VOID_t *pWDAContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700355
356 volatile v_U8_t isLoadUnloadInProgress;
357
Sameer Thalappil9ab2fe52013-10-22 12:50:24 -0700358 /* SSR re-init in progress */
359 volatile v_U8_t isReInitInProgress;
360
Leo Chang80de3c22013-11-26 10:52:12 -0800361 /* NV BIN Version */
362 eNvVersionType nvVersion;
363
Girish Gowlia33f0372015-01-19 15:39:04 +0530364 /* Roam delay statistic enabled in ini*/
365 v_U8_t roamDelayStatsEnabled;
Sachin Ahuja715aafc2015-07-21 23:35:10 +0530366
367 /*Fw log complete Event*/
368 vos_event_t fwLogsComplete;
Sushant Kaushik8e644982015-09-23 12:18:54 +0530369 v_U32_t wakelock_log_level;
370 v_U32_t connectivity_log_level;
371 v_U32_t packet_stats_log_level;
Abhishek Singh837adf22015-10-01 17:37:37 +0530372 v_U8_t vosWrapperFullReported;
Mahesh A Saptasagara67b86d2016-04-26 21:20:41 +0530373 vos_wdthread_timer_work_t wdthread_timer_work;
374 struct list_head wdthread_timer_work_list;
375 struct work_struct wdthread_work;
376 spinlock_t wdthread_work_lock;
Abhishek Singh8a3e4dc2017-01-02 10:39:18 +0530377 bool snoc_high_freq_voting;
378 spinlock_t freq_voting_lock;
Anurag Chouhanf0d0ba12018-02-09 15:13:43 +0530379 enum vos_hang_reason recovery_reason;
Jeff Johnson295189b2012-06-20 16:38:30 -0700380} VosContextType, *pVosContextType;
381
382
383
384/*---------------------------------------------------------------------------
385 Function declarations and documenation
386---------------------------------------------------------------------------*/
387
388int vos_sched_is_tx_thread(int threadID);
Jeff Johnson295189b2012-06-20 16:38:30 -0700389int vos_sched_is_rx_thread(int threadID);
Abhishek Singh880d7122015-08-26 16:23:04 +0530390int vos_sched_is_mc_thread(int threadID);
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +0530391void vos_thread_stuck_timer_init(pVosWatchdogContext pWdContext);
392
Jeff Johnson295189b2012-06-20 16:38:30 -0700393/*---------------------------------------------------------------------------
394
395 \brief vos_sched_open() - initialize the vOSS Scheduler
396
397 The \a vos_sched_open() function initializes the vOSS Scheduler
398 Upon successful initialization:
399
400 - All the message queues are initialized
401
402 - The Main Controller thread is created and ready to receive and
403 dispatch messages.
404
405 - The Tx thread is created and ready to receive and dispatch messages
406
407
408 \param pVosContext - pointer to the global vOSS Context
409
410 \param pVosSchedContext - pointer to a previously allocated buffer big
411 enough to hold a scheduler context.
412 \
413
414 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
415 is ready to be used.
416
417 VOS_STATUS_E_RESOURCES - System resources (other than memory)
418 are unavailable to initilize the scheduler
419
420 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
421 the scheduler
422
423 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
424 function
425
426 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
427
428 \sa vos_sched_open()
429
430 -------------------------------------------------------------------------*/
431VOS_STATUS vos_sched_open( v_PVOID_t pVosContext,
432 pVosSchedContext pSchedCxt,
433 v_SIZE_t SchedCtxSize);
434
435/*---------------------------------------------------------------------------
436
437 \brief vos_watchdog_open() - initialize the vOSS watchdog
438
439 The \a vos_watchdog_open() function initializes the vOSS watchdog. Upon successful
440 initialization, the watchdog thread is created and ready to receive and process messages.
441
442
443 \param pVosContext - pointer to the global vOSS Context
444
445 \param pWdContext - pointer to a previously allocated buffer big
446 enough to hold a watchdog context.
447
448 \return VOS_STATUS_SUCCESS - Watchdog was successfully initialized and
449 is ready to be used.
450
451 VOS_STATUS_E_RESOURCES - System resources (other than memory)
452 are unavailable to initilize the Watchdog
453
454 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
455 the Watchdog
456
457 VOS_STATUS_E_INVAL - Invalid parameter passed to the Watchdog Open
458 function
459
460 VOS_STATUS_E_FAILURE - Failure to initialize the Watchdog/
461
462 \sa vos_watchdog_open()
463
464 -------------------------------------------------------------------------*/
465
466VOS_STATUS vos_watchdog_open
467
468(
469 v_PVOID_t pVosContext,
470 pVosWatchdogContext pWdContext,
471 v_SIZE_t wdCtxSize
472);
473
474/*---------------------------------------------------------------------------
475
476 \brief vos_sched_close() - Close the vOSS Scheduler
477
478 The \a vos_sched_closes() function closes the vOSS Scheduler
479 Upon successful closing:
480
481 - All the message queues are flushed
482
483 - The Main Controller thread is closed
484
485 - The Tx thread is closed
486
487
488 \param pVosContext - pointer to the global vOSS Context
489
490 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
491 is ready to be used.
492
493 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
494 function
495
496 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
497
498 \sa vos_sched_close()
499
500---------------------------------------------------------------------------*/
501VOS_STATUS vos_sched_close( v_PVOID_t pVosContext);
502
503/*---------------------------------------------------------------------------
504
505 \brief vos_watchdog_close() - Close the vOSS Watchdog
506
507 The \a vos_watchdog_close() function closes the vOSS Watchdog
508 Upon successful closing:
509
510 - The Watchdog thread is closed
511
512
513 \param pVosContext - pointer to the global vOSS Context
514
515 \return VOS_STATUS_SUCCESS - Watchdog was successfully initialized and
516 is ready to be used.
517
518 VOS_STATUS_E_INVAL - Invalid parameter passed
519
520 VOS_STATUS_E_FAILURE - Failure to initialize the Watchdog/
521
522 \sa vos_watchdog_close()
523
524---------------------------------------------------------------------------*/
525VOS_STATUS vos_watchdog_close ( v_PVOID_t pVosContext );
526
527/* Helper routines provided to other VOS API's */
528VOS_STATUS vos_mq_init(pVosMqType pMq);
529void vos_mq_deinit(pVosMqType pMq);
530void vos_mq_put(pVosMqType pMq, pVosMsgWrapper pMsgWrapper);
Padma, Santhosh Kumarb036fc72015-11-13 16:22:23 +0530531void vos_mq_put_front(pVosMqType pMq, pVosMsgWrapper pMsgWrapper);
Jeff Johnson295189b2012-06-20 16:38:30 -0700532pVosMsgWrapper vos_mq_get(pVosMqType pMq);
533v_BOOL_t vos_is_mq_empty(pVosMqType pMq);
534pVosSchedContext get_vos_sched_ctxt(void);
535pVosWatchdogContext get_vos_watchdog_ctxt(void);
536VOS_STATUS vos_sched_init_mqs (pVosSchedContext pSchedContext);
537void vos_sched_deinit_mqs (pVosSchedContext pSchedContext);
538void vos_sched_flush_mc_mqs (pVosSchedContext pSchedContext);
539void vos_sched_flush_tx_mqs (pVosSchedContext pSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -0700540void vos_sched_flush_rx_mqs (pVosSchedContext pSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -0700541void clearWlanResetReason(void);
542
543void vos_timer_module_init( void );
544VOS_STATUS vos_watchdog_wlan_shutdown(void);
545VOS_STATUS vos_watchdog_wlan_re_init(void);
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530546v_BOOL_t isSsrPanicOnFailure(void);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530547void vos_ssr_protect(const char *caller_func);
548void vos_ssr_unprotect(const char *caller_func);
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530549void vos_wd_reset_thread_stuck_count(int threadId);
550bool vos_is_wd_thread(int threadId);
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +0530551void vos_dump_stack(uint8_t value);
Arunk Khandavalliaf6c3af2017-01-16 11:44:46 +0530552void vos_dump_thread_stacks(int threadId);
Abhinav Kumar118efd02019-08-07 16:41:07 +0530553/**
554 * vos_get_gfp_flags(): get GFP flags
555 *
556 * Based on the scheduled context, return GFP flags
557 * Return: gfp flags
558 */
559int vos_get_gfp_flags(void);
Jeff Johnson295189b2012-06-20 16:38:30 -0700560#endif // #if !defined __VOSS_SCHED_H