blob: 0e5d612a5a981cc3a98e59d6d194fac56c798311 [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>
86
Jeff Johnson295189b2012-06-20 16:38:30 -070087
Mahesh A Saptasagar8b42b272016-02-24 16:22:45 +053088#define TX_POST_EVENT 0x000
89#define TX_SUSPEND_EVENT 0x001
90#define MC_POST_EVENT 0x000
91#define MC_SUSPEND_EVENT 0x001
92#define RX_POST_EVENT 0x000
93#define RX_SUSPEND_EVENT 0x001
94#define TX_SHUTDOWN_EVENT 0x002
95#define MC_SHUTDOWN_EVENT 0x002
96#define RX_SHUTDOWN_EVENT 0x002
97
98#define WD_POST_EVENT 0x000
99#define WD_SHUTDOWN_EVENT 0x001
100#define WD_CHIP_RESET_EVENT 0x002
101#define WD_WLAN_SHUTDOWN_EVENT 0x003
102#define WD_WLAN_REINIT_EVENT 0x004
103#define WD_WLAN_DETECT_THREAD_STUCK 0x005
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530104
Jeff Johnson295189b2012-06-20 16:38:30 -0700105
106
107
108/*
109** Maximum number of messages in the system
110** These are buffers to account for all current messages
111** with some accounting of what we think is a
112** worst-case scenario. Must be able to handle all
113** incoming frames, as well as overhead for internal
114** messaging
115*/
116#define VOS_CORE_MAX_MESSAGES (VPKT_NUM_RX_RAW_PACKETS + 32)
117
118
119/*
120** vOSS Message queue definition.
121*/
122typedef struct _VosMqType
123{
124 /* Lock use to synchronize access to this message queue */
125 spinlock_t mqLock;
126
127 /* List of vOS Messages waiting on this queue */
128 struct list_head mqList;
129
130} VosMqType, *pVosMqType;
131
132
133/*
134** vOSS Scheduler context
135** The scheduler context contains the following:
136** ** the messages queues
137** ** the handle to the tread
138** ** pointer to the events that gracefully shutdown the MC and Tx threads
139**
140*/
141typedef struct _VosSchedContext
142{
143 /* Place holder to the VOSS Context */
144 v_PVOID_t pVContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700145 /* WDA Message queue on the Main thread*/
146 VosMqType wdaMcMq;
Jeff Johnson295189b2012-06-20 16:38:30 -0700147
148
149
150 /* PE Message queue on the Main thread*/
151 VosMqType peMcMq;
152
153 /* SME Message queue on the Main thread*/
154 VosMqType smeMcMq;
155
156 /* TL Message queue on the Main thread */
157 VosMqType tlMcMq;
158
159 /* SYS Message queue on the Main thread */
160 VosMqType sysMcMq;
161
Jeff Johnson295189b2012-06-20 16:38:30 -0700162 /* WDI Message queue on the Main thread*/
163 VosMqType wdiMcMq;
164
165 /* WDI Message queue on the Tx Thread*/
166 VosMqType wdiTxMq;
167
168 /* WDI Message queue on the Rx Thread*/
169 VosMqType wdiRxMq;
Jeff Johnson295189b2012-06-20 16:38:30 -0700170
171 /* TL Message queue on the Tx thread */
172 VosMqType tlTxMq;
173
Katya Nigam664f5032014-05-05 12:24:32 +0530174 /* TL Message queue on the Rx thread */
175 VosMqType tlRxMq;
176
Jeff Johnson295189b2012-06-20 16:38:30 -0700177 /* SYS Message queue on the Tx thread */
178 VosMqType sysTxMq;
179
Jeff Johnson295189b2012-06-20 16:38:30 -0700180 VosMqType sysRxMq;
Jeff Johnson295189b2012-06-20 16:38:30 -0700181
182 /* Handle of Event for MC thread to signal startup */
183 struct completion McStartEvent;
184
185 /* Handle of Event for Tx thread to signal startup */
186 struct completion TxStartEvent;
187
Jeff Johnson295189b2012-06-20 16:38:30 -0700188 /* Handle of Event for Rx thread to signal startup */
189 struct completion RxStartEvent;
Jeff Johnson295189b2012-06-20 16:38:30 -0700190
191 struct task_struct* McThread;
192
193 /* TX Thread handle */
194
195 struct task_struct* TxThread;
196
Jeff Johnson295189b2012-06-20 16:38:30 -0700197 /* RX Thread handle */
198 struct task_struct* RxThread;
Jeff Johnson295189b2012-06-20 16:38:30 -0700199
200
201 /* completion object for MC thread shutdown */
202 struct completion McShutdown;
203
204 /* completion object for Tx thread shutdown */
205 struct completion TxShutdown;
206
Jeff Johnson295189b2012-06-20 16:38:30 -0700207 /* completion object for Rx thread shutdown */
208 struct completion RxShutdown;
Jeff Johnson295189b2012-06-20 16:38:30 -0700209
210 /* Wait queue for MC thread */
211 wait_queue_head_t mcWaitQueue;
212
213 unsigned long mcEventFlag;
214
215 /* Wait queue for Tx thread */
216 wait_queue_head_t txWaitQueue;
217
218 unsigned long txEventFlag;
219
Jeff Johnson295189b2012-06-20 16:38:30 -0700220 /* Wait queue for Rx thread */
221 wait_queue_head_t rxWaitQueue;
222
223 unsigned long rxEventFlag;
Jeff Johnson295189b2012-06-20 16:38:30 -0700224
225 /* Completion object to resume Mc thread */
226 struct completion ResumeMcEvent;
227
228 /* Completion object to resume Tx thread */
229 struct completion ResumeTxEvent;
230
Jeff Johnson295189b2012-06-20 16:38:30 -0700231 /* Completion object to resume Rx thread */
232 struct completion ResumeRxEvent;
Jeff Johnson295189b2012-06-20 16:38:30 -0700233
234 /* lock to make sure that McThread and TxThread Suspend/resume mechanism is in sync*/
235 spinlock_t McThreadLock;
236 spinlock_t TxThreadLock;
237 spinlock_t RxThreadLock;
238
239} VosSchedContext, *pVosSchedContext;
240
241/*
242** VOSS watchdog context
243** The watchdog context contains the following:
244** The messages queues and events
245** The handle to the thread
246**
247*/
248typedef struct _VosWatchdogContext
249{
250
251 /* Place holder to the VOSS Context */
252 v_PVOID_t pVContext;
253
254 /* Handle of Event for Watchdog thread to signal startup */
255 struct completion WdStartEvent;
256
257 /* Watchdog Thread handle */
258
259 struct task_struct* WdThread;
260
261 /* completion object for Watchdog thread shutdown */
262 struct completion WdShutdown;
263
264 /* Wait queue for Watchdog thread */
265 wait_queue_head_t wdWaitQueue;
266
267 /* Event flag for events handled by Watchdog */
268 unsigned long wdEventFlag;
269
270 v_BOOL_t resetInProgress;
271
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530272 v_BOOL_t isFatalError;
273
Jeff Johnson295189b2012-06-20 16:38:30 -0700274 /* Lock for preventing multiple reset being triggered simultaneously */
275 spinlock_t wdLock;
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530276 /* Timer to detect thread stuck issue */
277 vos_timer_t threadStuckTimer;
278 /* Count for each thread to determine thread stuck */
279 unsigned int mcThreadStuckCount;
280 unsigned int txThreadStuckCount;
281 unsigned int rxThreadStuckCount;
282 /* lock to synchronize access to the thread stuck counts */
283 spinlock_t thread_stuck_lock;
Jeff Johnson295189b2012-06-20 16:38:30 -0700284
285} VosWatchdogContext, *pVosWatchdogContext;
286
287/*
288** vOSS Sched Msg Wrapper
289** Wrapper messages so that they can be chained to their respective queue
290** in the scheduler.
291*/
292typedef struct _VosMsgWrapper
293{
294 /* Message node */
295 struct list_head msgNode;
296
297 /* the Vos message it is associated to */
298 vos_msg_t *pVosMsg;
299
300} VosMsgWrapper, *pVosMsgWrapper;
301
302
Mahesh A Saptasagara67b86d2016-04-26 21:20:41 +0530303typedef struct vos_wdthread_timer_work {
304 vos_timer_callback_t callback;
305 v_PVOID_t userData;
306 struct list_head node;
307}vos_wdthread_timer_work_t;
Jeff Johnson295189b2012-06-20 16:38:30 -0700308
309typedef struct _VosContextType
310{
311 /* Messages buffers */
312 vos_msg_t aMsgBuffers[VOS_CORE_MAX_MESSAGES];
313
314 VosMsgWrapper aMsgWrappers[VOS_CORE_MAX_MESSAGES];
315
316 /* Free Message queue*/
317 VosMqType freeVosMq;
318
319 /* Scheduler Context */
320 VosSchedContext vosSched;
321
322 /* Watchdog Context */
323 VosWatchdogContext vosWatchdog;
324
325 /* HDD Module Context */
326 v_VOID_t *pHDDContext;
327
Jeff Johnson295189b2012-06-20 16:38:30 -0700328 /* HDD SoftAP Module Context */
329 v_VOID_t *pHDDSoftAPContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700330
331 /* TL Module Context */
332 v_VOID_t *pTLContext;
333
334 /* MAC Module Context */
335 v_VOID_t *pMACContext;
336
Jeff Johnson295189b2012-06-20 16:38:30 -0700337 /* BAP Context */
338 v_VOID_t *pBAPContext;
339
Jeff Johnson295189b2012-06-20 16:38:30 -0700340 /* SAP Context */
341 v_VOID_t *pSAPContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700342
343 /* VOS Packet Context */
344 vos_pkt_context_t vosPacket;
345
346 vos_event_t ProbeEvent;
347
348 volatile v_U8_t isLogpInProgress;
349
Jeff Johnson295189b2012-06-20 16:38:30 -0700350 vos_event_t wdaCompleteEvent;
351
352 /* WDA Context */
353 v_VOID_t *pWDAContext;
Jeff Johnson295189b2012-06-20 16:38:30 -0700354
355 volatile v_U8_t isLoadUnloadInProgress;
356
Sameer Thalappil9ab2fe52013-10-22 12:50:24 -0700357 /* SSR re-init in progress */
358 volatile v_U8_t isReInitInProgress;
359
Leo Chang80de3c22013-11-26 10:52:12 -0800360 /* NV BIN Version */
361 eNvVersionType nvVersion;
362
Girish Gowlia33f0372015-01-19 15:39:04 +0530363 /* Roam delay statistic enabled in ini*/
364 v_U8_t roamDelayStatsEnabled;
Sachin Ahuja715aafc2015-07-21 23:35:10 +0530365
366 /*Fw log complete Event*/
367 vos_event_t fwLogsComplete;
Sushant Kaushik8e644982015-09-23 12:18:54 +0530368 v_U32_t wakelock_log_level;
369 v_U32_t connectivity_log_level;
370 v_U32_t packet_stats_log_level;
Abhishek Singh837adf22015-10-01 17:37:37 +0530371 v_U8_t vosWrapperFullReported;
Mahesh A Saptasagara67b86d2016-04-26 21:20:41 +0530372 vos_wdthread_timer_work_t wdthread_timer_work;
373 struct list_head wdthread_timer_work_list;
374 struct work_struct wdthread_work;
375 spinlock_t wdthread_work_lock;
Abhishek Singh8a3e4dc2017-01-02 10:39:18 +0530376 bool snoc_high_freq_voting;
377 spinlock_t freq_voting_lock;
Jeff Johnson295189b2012-06-20 16:38:30 -0700378} VosContextType, *pVosContextType;
379
380
381
382/*---------------------------------------------------------------------------
383 Function declarations and documenation
384---------------------------------------------------------------------------*/
385
386int vos_sched_is_tx_thread(int threadID);
Jeff Johnson295189b2012-06-20 16:38:30 -0700387int vos_sched_is_rx_thread(int threadID);
Abhishek Singh880d7122015-08-26 16:23:04 +0530388int vos_sched_is_mc_thread(int threadID);
Hanumanth Reddy Pothula146bca42016-11-08 12:01:07 +0530389void vos_thread_stuck_timer_init(pVosWatchdogContext pWdContext);
390
Jeff Johnson295189b2012-06-20 16:38:30 -0700391/*---------------------------------------------------------------------------
392
393 \brief vos_sched_open() - initialize the vOSS Scheduler
394
395 The \a vos_sched_open() function initializes the vOSS Scheduler
396 Upon successful initialization:
397
398 - All the message queues are initialized
399
400 - The Main Controller thread is created and ready to receive and
401 dispatch messages.
402
403 - The Tx thread is created and ready to receive and dispatch messages
404
405
406 \param pVosContext - pointer to the global vOSS Context
407
408 \param pVosSchedContext - pointer to a previously allocated buffer big
409 enough to hold a scheduler context.
410 \
411
412 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
413 is ready to be used.
414
415 VOS_STATUS_E_RESOURCES - System resources (other than memory)
416 are unavailable to initilize the scheduler
417
418 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
419 the scheduler
420
421 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
422 function
423
424 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
425
426 \sa vos_sched_open()
427
428 -------------------------------------------------------------------------*/
429VOS_STATUS vos_sched_open( v_PVOID_t pVosContext,
430 pVosSchedContext pSchedCxt,
431 v_SIZE_t SchedCtxSize);
432
433/*---------------------------------------------------------------------------
434
435 \brief vos_watchdog_open() - initialize the vOSS watchdog
436
437 The \a vos_watchdog_open() function initializes the vOSS watchdog. Upon successful
438 initialization, the watchdog thread is created and ready to receive and process messages.
439
440
441 \param pVosContext - pointer to the global vOSS Context
442
443 \param pWdContext - pointer to a previously allocated buffer big
444 enough to hold a watchdog context.
445
446 \return VOS_STATUS_SUCCESS - Watchdog was successfully initialized and
447 is ready to be used.
448
449 VOS_STATUS_E_RESOURCES - System resources (other than memory)
450 are unavailable to initilize the Watchdog
451
452 VOS_STATUS_E_NOMEM - insufficient memory exists to initialize
453 the Watchdog
454
455 VOS_STATUS_E_INVAL - Invalid parameter passed to the Watchdog Open
456 function
457
458 VOS_STATUS_E_FAILURE - Failure to initialize the Watchdog/
459
460 \sa vos_watchdog_open()
461
462 -------------------------------------------------------------------------*/
463
464VOS_STATUS vos_watchdog_open
465
466(
467 v_PVOID_t pVosContext,
468 pVosWatchdogContext pWdContext,
469 v_SIZE_t wdCtxSize
470);
471
472/*---------------------------------------------------------------------------
473
474 \brief vos_sched_close() - Close the vOSS Scheduler
475
476 The \a vos_sched_closes() function closes the vOSS Scheduler
477 Upon successful closing:
478
479 - All the message queues are flushed
480
481 - The Main Controller thread is closed
482
483 - The Tx thread is closed
484
485
486 \param pVosContext - pointer to the global vOSS Context
487
488 \return VOS_STATUS_SUCCESS - Scheduler was successfully initialized and
489 is ready to be used.
490
491 VOS_STATUS_E_INVAL - Invalid parameter passed to the scheduler Open
492 function
493
494 VOS_STATUS_E_FAILURE - Failure to initialize the scheduler/
495
496 \sa vos_sched_close()
497
498---------------------------------------------------------------------------*/
499VOS_STATUS vos_sched_close( v_PVOID_t pVosContext);
500
501/*---------------------------------------------------------------------------
502
503 \brief vos_watchdog_close() - Close the vOSS Watchdog
504
505 The \a vos_watchdog_close() function closes the vOSS Watchdog
506 Upon successful closing:
507
508 - The Watchdog thread is closed
509
510
511 \param pVosContext - pointer to the global vOSS Context
512
513 \return VOS_STATUS_SUCCESS - Watchdog was successfully initialized and
514 is ready to be used.
515
516 VOS_STATUS_E_INVAL - Invalid parameter passed
517
518 VOS_STATUS_E_FAILURE - Failure to initialize the Watchdog/
519
520 \sa vos_watchdog_close()
521
522---------------------------------------------------------------------------*/
523VOS_STATUS vos_watchdog_close ( v_PVOID_t pVosContext );
524
525/* Helper routines provided to other VOS API's */
526VOS_STATUS vos_mq_init(pVosMqType pMq);
527void vos_mq_deinit(pVosMqType pMq);
528void vos_mq_put(pVosMqType pMq, pVosMsgWrapper pMsgWrapper);
Padma, Santhosh Kumarb036fc72015-11-13 16:22:23 +0530529void vos_mq_put_front(pVosMqType pMq, pVosMsgWrapper pMsgWrapper);
Jeff Johnson295189b2012-06-20 16:38:30 -0700530pVosMsgWrapper vos_mq_get(pVosMqType pMq);
531v_BOOL_t vos_is_mq_empty(pVosMqType pMq);
532pVosSchedContext get_vos_sched_ctxt(void);
533pVosWatchdogContext get_vos_watchdog_ctxt(void);
534VOS_STATUS vos_sched_init_mqs (pVosSchedContext pSchedContext);
535void vos_sched_deinit_mqs (pVosSchedContext pSchedContext);
536void vos_sched_flush_mc_mqs (pVosSchedContext pSchedContext);
537void vos_sched_flush_tx_mqs (pVosSchedContext pSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -0700538void vos_sched_flush_rx_mqs (pVosSchedContext pSchedContext);
Jeff Johnson295189b2012-06-20 16:38:30 -0700539void clearWlanResetReason(void);
540
541void vos_timer_module_init( void );
542VOS_STATUS vos_watchdog_wlan_shutdown(void);
543VOS_STATUS vos_watchdog_wlan_re_init(void);
Pradeep Kumar Goudagunta22d8e4d2014-07-17 15:03:51 +0530544v_BOOL_t isSsrPanicOnFailure(void);
Mahesh A Saptasagar96395ab2014-04-08 12:48:39 +0530545void vos_ssr_protect(const char *caller_func);
546void vos_ssr_unprotect(const char *caller_func);
Abhishek Singhe7ea25c2015-11-23 16:23:24 +0530547void vos_wd_reset_thread_stuck_count(int threadId);
548bool vos_is_wd_thread(int threadId);
Padma, Santhosh Kumar166597b2015-11-24 17:46:28 +0530549void vos_dump_stack(uint8_t value);
Arunk Khandavalliaf6c3af2017-01-16 11:44:46 +0530550void vos_dump_thread_stacks(int threadId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700551
552#endif // #if !defined __VOSS_SCHED_H