xref: /freebsd/sys/dev/pms/RefTisa/sat/src/smtimer.c (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3 *
4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5 *that the following conditions are met:
6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7 *following disclaimer.
8 *2. Redistributions in binary form must reproduce the above copyright notice,
9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10 *with the distribution.
11 *
12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20 
21 ********************************************************************************/
22 #include <sys/cdefs.h>
23 #include <dev/pms/config.h>
24 
25 #include <dev/pms/freebsd/driver/common/osenv.h>
26 #include <dev/pms/freebsd/driver/common/ostypes.h>
27 #include <dev/pms/freebsd/driver/common/osdebug.h>
28 
29 #include <dev/pms/RefTisa/tisa/api/titypes.h>
30 
31 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
32 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
33 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
34 
35 #include <dev/pms/RefTisa/sat/api/sm.h>
36 #include <dev/pms/RefTisa/sat/api/smapi.h>
37 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
38 
39 #include <dev/pms/RefTisa/sat/src/smdefs.h>
40 #include <dev/pms/RefTisa/sat/src/smproto.h>
41 #include <dev/pms/RefTisa/sat/src/smtypes.h>
42 
43 osGLOBAL void
44 smTimerTick(smRoot_t 		*smRoot )
45 {
46   SM_DBG6(("smTimerTick: start\n"));
47 
48   smProcessTimers(smRoot);
49 
50   return;
51 }
52 
53 osGLOBAL void
54 smInitTimerRequest(
55                      smRoot_t                *smRoot,
56                      smTimerRequest_t        *timerRequest
57                      )
58 {
59   timerRequest->timeout       = 0;
60   timerRequest->timerCBFunc   = agNULL;
61   timerRequest->timerData1     = agNULL;
62   timerRequest->timerData2     = agNULL;
63   timerRequest->timerData3     = agNULL;
64   SMLIST_INIT_ELEMENT((&timerRequest->timerLink));
65 }
66 
67 osGLOBAL void
68 smSetTimerRequest(
69                   smRoot_t            *smRoot,
70                   smTimerRequest_t    *timerRequest,
71                   bit32               timeout,
72                   smTimerCBFunc_t     CBFunc,
73                   void                *timerData1,
74                   void                *timerData2,
75                   void                *timerData3
76                   )
77 {
78   timerRequest->timeout     = timeout;
79   timerRequest->timerCBFunc = CBFunc;
80   timerRequest->timerData1   = timerData1;
81   timerRequest->timerData2   = timerData2;
82   timerRequest->timerData3   = timerData3;
83 }
84 
85 osGLOBAL void
86 smAddTimer(
87            smRoot_t            *smRoot,
88            smList_t            *timerListHdr,
89            smTimerRequest_t    *timerRequest
90           )
91 {
92   tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
93   SMLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr);
94   timerRequest->timerRunning = agTRUE;
95   tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
96 }
97 
98 osGLOBAL void
99 smKillTimer(
100             smRoot_t            *smRoot,
101             smTimerRequest_t    *timerRequest
102            )
103 {
104   tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
105   timerRequest->timerRunning = agFALSE;
106   SMLIST_DEQUEUE_THIS(&(timerRequest->timerLink));
107   tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
108 }
109 
110 osGLOBAL void
111 smProcessTimers(
112                 smRoot_t *smRoot
113                 )
114 {
115   smIntRoot_t               *smIntRoot    = (smIntRoot_t *)smRoot->smData;
116   smIntContext_t            *smAllShared = (smIntContext_t *)&smIntRoot->smAllShared;
117   smTimerRequest_t          *timerRequest_to_process = agNULL;
118   smList_t                  *timerlist_to_process, *nexttimerlist = agNULL;
119 
120 
121   timerlist_to_process = &smAllShared->timerlist;
122 
123   timerlist_to_process = timerlist_to_process->flink;
124 
125   while ((timerlist_to_process != agNULL) && (timerlist_to_process != &smAllShared->timerlist))
126   {
127     nexttimerlist = timerlist_to_process->flink;
128 
129     tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
130     timerRequest_to_process = SMLIST_OBJECT_BASE(smTimerRequest_t, timerLink, timerlist_to_process);
131     tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
132 
133     if (timerRequest_to_process == agNULL)
134     {
135       SM_DBG1(("smProcessTimers: timerRequest_to_process is NULL! Error!!!\n"));
136       return;
137     }
138 
139     timerRequest_to_process->timeout--;
140 
141     if (timerRequest_to_process->timeout == 0)
142     {
143       timerRequest_to_process->timerRunning = agFALSE;
144 
145       tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
146       SMLIST_DEQUEUE_THIS(timerlist_to_process);
147       tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
148       /* calling call back function */
149       (timerRequest_to_process->timerCBFunc)(smRoot,
150                                              timerRequest_to_process->timerData1,
151                                              timerRequest_to_process->timerData2,
152                                              timerRequest_to_process->timerData3
153                                              );
154     }
155     timerlist_to_process = nexttimerlist;
156   }
157 
158  return;
159 }
160 
161