xref: /freebsd/sys/dev/pms/RefTisa/sat/src/smtimer.c (revision f4f56ff43dbd30930f4b018e39ba2b9abf84551f)
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 __FBSDID("$FreeBSD$");
24 #include <dev/pms/config.h>
25 
26 #include <dev/pms/freebsd/driver/common/osenv.h>
27 #include <dev/pms/freebsd/driver/common/ostypes.h>
28 #include <dev/pms/freebsd/driver/common/osdebug.h>
29 
30 #include <dev/pms/RefTisa/tisa/api/titypes.h>
31 
32 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
33 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
34 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
35 
36 #include <dev/pms/RefTisa/sat/api/sm.h>
37 #include <dev/pms/RefTisa/sat/api/smapi.h>
38 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
39 
40 #include <dev/pms/RefTisa/sat/src/smdefs.h>
41 #include <dev/pms/RefTisa/sat/src/smproto.h>
42 #include <dev/pms/RefTisa/sat/src/smtypes.h>
43 
44 osGLOBAL void
45 smTimerTick(smRoot_t 		*smRoot )
46 {
47   SM_DBG6(("smTimerTick: start\n"));
48 
49   smProcessTimers(smRoot);
50 
51   return;
52 }
53 
54 osGLOBAL void
55 smInitTimerRequest(
56                      smRoot_t                *smRoot,
57                      smTimerRequest_t        *timerRequest
58                      )
59 {
60   timerRequest->timeout       = 0;
61   timerRequest->timerCBFunc   = agNULL;
62   timerRequest->timerData1     = agNULL;
63   timerRequest->timerData2     = agNULL;
64   timerRequest->timerData3     = agNULL;
65   SMLIST_INIT_ELEMENT((&timerRequest->timerLink));
66 }
67 
68 osGLOBAL void
69 smSetTimerRequest(
70                   smRoot_t            *smRoot,
71                   smTimerRequest_t    *timerRequest,
72                   bit32               timeout,
73                   smTimerCBFunc_t     CBFunc,
74                   void                *timerData1,
75                   void                *timerData2,
76                   void                *timerData3
77                   )
78 {
79   timerRequest->timeout     = timeout;
80   timerRequest->timerCBFunc = CBFunc;
81   timerRequest->timerData1   = timerData1;
82   timerRequest->timerData2   = timerData2;
83   timerRequest->timerData3   = timerData3;
84 }
85 
86 osGLOBAL void
87 smAddTimer(
88            smRoot_t            *smRoot,
89            smList_t            *timerListHdr,
90            smTimerRequest_t    *timerRequest
91           )
92 {
93   tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
94   SMLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr);
95   timerRequest->timerRunning = agTRUE;
96   tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
97 }
98 
99 osGLOBAL void
100 smKillTimer(
101             smRoot_t            *smRoot,
102             smTimerRequest_t    *timerRequest
103            )
104 {
105   tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
106   timerRequest->timerRunning = agFALSE;
107   SMLIST_DEQUEUE_THIS(&(timerRequest->timerLink));
108   tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
109 }
110 
111 osGLOBAL void
112 smProcessTimers(
113                 smRoot_t *smRoot
114                 )
115 {
116   smIntRoot_t               *smIntRoot    = (smIntRoot_t *)smRoot->smData;
117   smIntContext_t            *smAllShared = (smIntContext_t *)&smIntRoot->smAllShared;
118   smTimerRequest_t          *timerRequest_to_process = agNULL;
119   smList_t                  *timerlist_to_process, *nexttimerlist = agNULL;
120 
121 
122   timerlist_to_process = &smAllShared->timerlist;
123 
124   timerlist_to_process = timerlist_to_process->flink;
125 
126   while ((timerlist_to_process != agNULL) && (timerlist_to_process != &smAllShared->timerlist))
127   {
128     nexttimerlist = timerlist_to_process->flink;
129 
130     tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
131     timerRequest_to_process = SMLIST_OBJECT_BASE(smTimerRequest_t, timerLink, timerlist_to_process);
132     tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
133 
134     if (timerRequest_to_process == agNULL)
135     {
136       SM_DBG1(("smProcessTimers: timerRequest_to_process is NULL! Error!!!\n"));
137       return;
138     }
139 
140     timerRequest_to_process->timeout--;
141 
142     if (timerRequest_to_process->timeout == 0)
143     {
144       timerRequest_to_process->timerRunning = agFALSE;
145 
146       tdsmSingleThreadedEnter(smRoot, SM_TIMER_LOCK);
147       SMLIST_DEQUEUE_THIS(timerlist_to_process);
148       tdsmSingleThreadedLeave(smRoot, SM_TIMER_LOCK);
149       /* calling call back function */
150       (timerRequest_to_process->timerCBFunc)(smRoot,
151                                              timerRequest_to_process->timerData1,
152                                              timerRequest_to_process->timerData2,
153                                              timerRequest_to_process->timerData3
154                                              );
155     }
156     timerlist_to_process = nexttimerlist;
157   }
158 
159  return;
160 }
161 
162