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