blob: 558fd2db03d13529d289e3da5e33059bcf0bd9e9 [file] [log] [blame]
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -07001/*****************************************************************************
2
3 (c) Cambridge Silicon Radio Limited 2011
4 All rights reserved and confidential information of CSR
5
6 Refer to LICENSE.txt included with this source for details
7 on the license terms.
8
9*****************************************************************************/
10
11#ifndef CSR_WIFI_FSM_TYPES_H
12#define CSR_WIFI_FSM_TYPES_H
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include "csr_types.h"
19#include "csr_util.h"
20#include "csr_pmem.h"
21#include "csr_panic.h"
22#include "csr_sched.h"
23
24#ifdef CSR_WIFI_FSM_MUTEX_ENABLE
25#include "csr_framework_ext.h"
26#endif
27
28#include "csr_wifi_fsm.h"
29
30#define CSR_WIFI_FSM_MAX_TRANSITION_HISTORY 10
31
32/**
33 * @brief
34 * FSM event list header.
35 *
36 * @par Description
37 * Singly linked list of events.
38 */
39typedef struct CsrWifiFsmEventList
40{
41 CsrWifiFsmEvent *first;
42 CsrWifiFsmEvent *last;
43} CsrWifiFsmEventList;
44
45
46/**
47 * @brief
48 * FSM timer id.
49 *
50 * @par Description
51 * Composite Id made up of the type, dest and a unique id so
52 * CsrWifiFsmRemoveTimer knows where to look when removing the timer
53 */
54typedef struct CsrWifiFsmTimerId
55{
56 CsrPrim type;
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -070057 u16 primtype;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -070058 CsrSchedQid destination;
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -070059 u16 uniqueid;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -070060} CsrWifiFsmTimerId;
61
62/**
63 * @brief
64 * FSM timer header.
65 *
66 * @par Description
67 * All timer MUST have this struct as the FIRST member.
68 * The first members of the structure MUST remain compatable
69 * with the CsrWifiFsmEvent so that timers are just specialised events
70 */
71typedef struct CsrWifiFsmTimer
72{
73 CsrPrim type;
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -070074 u16 primtype;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -070075 CsrSchedQid destination;
76 CsrSchedQid source;
77
78 /* Private pointer to allow an optimal Event list */
79 struct CsrWifiFsmTimer *next;
80
81 CsrWifiFsmTimerId timerid;
Greg Kroah-Hartman26a6b2e2012-07-20 12:05:42 -070082 u32 timeoutTimeMs;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -070083} CsrWifiFsmTimer;
84
85
86/**
87 * @brief
88 * Fsm Alien Event
89 *
90 * @par Description
91 * Allows the wrapping of alien events that do not use CsrWifiFsmEvent
92 * as the first member of the Event struct
93 */
94typedef struct
95{
96 CsrWifiFsmEvent event;
97 void *alienEvent;
98} CsrWifiFsmAlienEvent;
99
100
101/**
102 * @brief
103 * FSM timer list header.
104 *
105 * @par Description
106 * Singly linked list of timers.
107 */
108typedef struct CsrWifiFsmTimerList
109{
110 CsrWifiFsmTimer *first;
111 CsrWifiFsmTimer *last;
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700112 u16 nexttimerid;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700113} CsrWifiFsmTimerList;
114
115/**
116 * @brief
117 * Process Entry Function Pointer
118 *
119 * @par Description
120 * Defines the entry function for a processes.
121 * Called at process initialisation.
122 *
123 * @param[in] context : FSM context
124 *
125 * @return
126 * void
127 */
128typedef void (*CsrWifiFsmProcEntryFnPtr)(CsrWifiFsmContext *context);
129
130/**
131 * @brief
132 * Process Transition Function Pointer
133 *
134 * @par Description
135 * Defines a transition function for a processes.
136 * Called when an event causes a transition on a process
137 *
138 * @param[in] CsrWifiFsmContext* : FSM context
139 * @param[in] void* : FSM data (can be NULL)
140 * @param[in] const CsrWifiFsmEvent* : event to process
141 *
142 * @return
143 * void
144 */
145typedef void (*CsrWifiFsmTransitionFnPtr)(CsrWifiFsmContext *context, void *fsmData, const CsrWifiFsmEvent *event);
146
147/**
148 * @brief
149 * Process reset/shutdown Function Pointer
150 *
151 * @par Description
152 * Defines the reset/shutdown function for a processes.
153 * Called to reset or shutdown an fsm.
154 *
155 * @param[in] context : FSM context
156 *
157 * @return
158 * void
159 */
160typedef void (*CsrWifiFsmProcResetFnPtr)(CsrWifiFsmContext *context);
161
162/**
163 * @brief
164 * FSM Default Destination CallbackFunction Pointer
165 *
166 * @par Description
167 * Defines the default destination function for the FSM
168 * to call when an event does not have a valid destination.
169 * This
170 *
171 * @param[in] context : External context
172 *
173 * @return
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700174 * u16 a valid destination OR CSR_WIFI_FSM_ENV
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700175 */
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700176typedef u16 (*CsrWifiFsmDestLookupCallbackPtr)(void *context, const CsrWifiFsmEvent *event);
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700177
178
179#ifdef CSR_WIFI_FSM_DUMP_ENABLE
180/**
181 * @brief
182 * Trace Dump Function Pointer
183 *
184 * @par Description
185 * Called when we want to trace the FSM
186 *
187 * @param[in] context : FSM context
188 * @param[in] id : fsm id
189 *
190 * @return
191 * void
192 */
193typedef void (*CsrWifiFsmDumpFnPtr)(CsrWifiFsmContext *context, void *fsmData);
194#endif
195
196/**
197 * @brief
198 * Event ID to transition function entry
199 *
200 * @par Description
201 * Event ID to Transition Entry in a state table.
202 */
203typedef struct
204{
Greg Kroah-Hartman26a6b2e2012-07-20 12:05:42 -0700205 u32 eventid;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700206 CsrWifiFsmTransitionFnPtr transition;
207#ifdef CSR_LOG_ENABLE
Greg Kroah-Hartmanc781b962012-07-20 12:22:32 -0700208 const char *transitionName;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700209#endif
210} CsrWifiFsmEventEntry;
211
212/**
213 * @brief
214 * Single State's Transition Table
215 *
216 * @par Description
217 * Stores Data for a single State's event to
218 * transition functions mapping
219 */
220typedef struct
221{
Greg Kroah-Hartman7e6f579442012-07-20 11:51:01 -0700222 const u8 numEntries;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700223 const CsrBool saveAll;
224 const CsrWifiFsmEventEntry *eventEntryArray; /* array of transition function pointers for state */
225#ifdef CSR_LOG_ENABLE
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700226 u16 stateNumber;
Greg Kroah-Hartmanc781b962012-07-20 12:22:32 -0700227 const char *stateName;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700228#endif
229} CsrWifiFsmTableEntry;
230
231/**
232 * @brief
233 * Process State Transtion table
234 *
235 * @par Description
236 * Stores Data for a processes State to transition table
237 */
238typedef struct
239{
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700240 u16 numStates; /* number of states */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700241 const CsrWifiFsmTableEntry *aStateEventMatrix; /* state event matrix */
242} CsrWifiFsmTransitionFunctionTable;
243
244/**
245 * @brief
246 * Const Process definition
247 *
248 * @par Description
249 * Constant process specification.
250 * This is ALL the non dynamic data that defines
251 * a process.
252 */
253typedef struct
254{
Greg Kroah-Hartmanc781b962012-07-20 12:22:32 -0700255 const char *processName;
Greg Kroah-Hartman26a6b2e2012-07-20 12:05:42 -0700256 const u32 processId;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700257 const CsrWifiFsmTransitionFunctionTable transitionTable;
258 const CsrWifiFsmTableEntry unhandledTransitions;
259 const CsrWifiFsmTableEntry ignoreFunctions;
260 const CsrWifiFsmProcEntryFnPtr entryFn;
261 const CsrWifiFsmProcResetFnPtr resetFn;
262#ifdef CSR_WIFI_FSM_DUMP_ENABLE
263 const CsrWifiFsmDumpFnPtr dumpFn; /* Called to dump fsm specific trace if not NULL */
264#endif
265} CsrWifiFsmProcessStateMachine;
266
267#ifdef CSR_WIFI_FSM_DUMP_ENABLE
268/**
269 * @brief
270 * Storage for state transition info
271 */
272typedef struct
273{
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700274 u16 transitionNumber;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700275 CsrWifiFsmEvent event;
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700276 u16 fromState;
277 u16 toState;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700278 CsrWifiFsmTransitionFnPtr transitionFn;
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700279 u16 transitionCount; /* number consecutive of times this transition was seen */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700280#ifdef CSR_LOG_ENABLE
Greg Kroah-Hartmanc781b962012-07-20 12:22:32 -0700281 const char *transitionName;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700282#endif
283} CsrWifiFsmTransitionRecord;
284
285/**
286 * @brief
287 * Storage for the last state X transitions
288 */
289typedef struct
290{
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700291 u16 numTransitions;
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700292 CsrWifiFsmTransitionRecord records[CSR_WIFI_FSM_MAX_TRANSITION_HISTORY];
293} CsrWifiFsmTransitionRecords;
294#endif
295
296/**
297 * @brief
298 * Dynamic Process data
299 *
300 * @par Description
301 * Dynamic process data that is used to keep track of the
302 * state and data for a process instance
303 */
304typedef struct
305{
306 const CsrWifiFsmProcessStateMachine *fsmInfo; /* state machine info that is constant regardless of context */
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700307 u16 instanceId; /* Runtime process id */
308 u16 state; /* Current state */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700309 void *params; /* Instance user data */
310 CsrWifiFsmEventList savedEventQueue; /* The saved event queue */
311 struct CsrWifiFsmInstanceEntry *subFsm; /* Sub Fsm instance data */
312 struct CsrWifiFsmInstanceEntry *subFsmCaller; /* The Fsm instance that created the SubFsm and should be used for callbacks*/
313#ifdef CSR_WIFI_FSM_DUMP_ENABLE
314 CsrWifiFsmTransitionRecords transitionRecords; /* Last X transitions in the FSM */
315#endif
316} CsrWifiFsmInstanceEntry;
317
318/**
319 * @brief
320 * OnCreate Callback Function Pointer
321 *
322 * @par Description
323 * Called when an fsm is created.
324 *
325 * @param[in] extContext : External context
326 * @param[in] instance : FSM instance
327 *
328 * @return
329 * void
330 */
331typedef void (*CsrWifiFsmOnCreateFnPtr)(void *extContext, const CsrWifiFsmInstanceEntry *instance);
332
333/**
334 * @brief
335 * OnTransition Callback Function Pointer
336 *
337 * @par Description
338 * Called when an event is processed by a fsm
339 *
340 * @param[in] extContext : External context
341 * @param[in] eventEntryArray : Entry data
342 * @param[in] event : Event
343 *
344 * @return
345 * void
346 */
347typedef void (*CsrWifiFsmOnTransitionFnPtr)(void *extContext, const CsrWifiFsmEventEntry *eventEntryArray, const CsrWifiFsmEvent *event);
348
349/**
350 * @brief
351 * OnStateChange Callback Function Pointer
352 *
353 * @par Description
354 * Called when CsrWifiFsmNextState is called
355 *
356 * @param[in] extContext : External context
357 *
358 * @return
359 * void
360 */
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700361typedef void (*CsrWifiFsmOnStateChangeFnPtr)(void *extContext, u16 nextstate);
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700362
363/**
364 * @brief
365 * OnIgnore,OnError or OnInvalid Callback Function Pointer
366 *
367 * @par Description
368 * Called when an event is processed by a fsm
369 *
370 * @param[in] extContext : External context
371 * @param[in] event : Event
372 *
373 * @return
374 * void
375 */
376typedef void (*CsrWifiFsmOnEventFnPtr)(void *extContext, const CsrWifiFsmEvent *event);
377
378/**
379 * @brief
380 * Toplevel FSM context data
381 *
382 * @par Description
383 * Holds ALL FSM static and dynamic data for a FSM
384 */
385struct CsrWifiFsmContext
386{
387 CsrWifiFsmEventList eventQueue; /* The internal event queue */
388 CsrWifiFsmEventList externalEventQueue; /* The external event queue */
389#ifdef CSR_WIFI_FSM_MUTEX_ENABLE
390 CsrMutexHandle externalEventQueueLock; /* The external event queue mutex */
391#endif
Greg Kroah-Hartman26a6b2e2012-07-20 12:05:42 -0700392 u32 timeOffset; /* Amount to adjust the TimeOfDayMs by */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700393 CsrWifiFsmTimerList timerQueue; /* The internal timer queue */
394 CsrBool useTempSaveList; /* Should the temp save list be used */
395 CsrWifiFsmEventList tempSaveList; /* The temp save event queue */
396 CsrWifiFsmEvent *eventForwardedOrSaved; /* The event that was forwarded or Saved */
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700397 u16 maxProcesses; /* Size of instanceArray */
398 u16 numProcesses; /* Current number allocated in instanceArray */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700399 CsrWifiFsmInstanceEntry *instanceArray; /* Array of processes for this component */
400 CsrWifiFsmInstanceEntry *ownerInstance; /* The Process that owns currentInstance (SubFsm support) */
401 CsrWifiFsmInstanceEntry *currentInstance; /* Current Process that is executing */
402 CsrWifiFsmExternalWakupCallbackPtr externalEventFn; /* External event Callback */
403 CsrWifiFsmOnEventFnPtr appIgnoreCallback; /* Application Ignore event Callback */
404 CsrWifiFsmDestLookupCallbackPtr appEvtDstCallback; /* Application Lookup event Destination Function*/
405
406 void *applicationContext; /* Internal fsm application context */
407 void *externalContext; /* External context (set by the user of the fsm)*/
408 CsrLogTextTaskId loggingTaskId; /* Task Id to use in any logging output */
409
410#ifndef CSR_WIFI_FSM_SCHEDULER_DISABLED
411 CsrSchedTid schedTimerId; /* Scheduler TimerId for use in Scheduler Tasks */
Greg Kroah-Hartman26a6b2e2012-07-20 12:05:42 -0700412 u32 schedTimerNexttimeoutMs; /* Next timeout time for the current timer */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700413#endif
414
415#ifdef CSR_WIFI_FSM_MUTEX_ENABLE
416#ifdef CSR_WIFI_FSM_TRANSITION_LOCK
417 CsrMutexHandle transitionLock; /* Lock when calling transition functions */
418#endif
419#endif
420
421#ifdef CSR_LOG_ENABLE
422 CsrWifiFsmOnCreateFnPtr onCreate; /* Debug Transition Callback */
423 CsrWifiFsmOnTransitionFnPtr onTransition; /* Debug Transition Callback */
424 CsrWifiFsmOnTransitionFnPtr onUnhandedCallback; /* Unhanded event Callback */
425 CsrWifiFsmOnStateChangeFnPtr onStateChange; /* Debug State Change Callback */
426 CsrWifiFsmOnEventFnPtr onIgnoreCallback; /* Ignore event Callback */
427 CsrWifiFsmOnEventFnPtr onSaveCallback; /* Save event Callback */
428 CsrWifiFsmOnEventFnPtr onErrorCallback; /* Error event Callback */
429 CsrWifiFsmOnEventFnPtr onInvalidCallback; /* Invalid event Callback */
430#endif
431#ifdef CSR_WIFI_FSM_DUMP_ENABLE
Greg Kroah-Hartman8c87f692012-07-20 12:00:10 -0700432 u16 masterTransitionNumber; /* Increments on every transition */
Greg Kroah-Hartman635d2b02012-06-19 16:15:42 -0700433#endif
434};
435
436
437#ifdef __cplusplus
438}
439#endif
440
441#endif /* CSR_WIFI_FSM_TYPES_H */