]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/dev/pms/RefTisa/discovery/dm/dmtimer.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / dev / pms / RefTisa / discovery / dm / dmtimer.c
1 /*******************************************************************************
2 **
3 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved. 
4 *
5 *Redistribution and use in source and binary forms, with or without modification, are permitted provided 
6 *that the following conditions are met: 
7 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8 *following disclaimer. 
9 *2. Redistributions in binary form must reproduce the above copyright notice, 
10 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
11 *with the distribution. 
12 *
13 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED 
14 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
17 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
18 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
19 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
20 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
21
22 **
23 ********************************************************************************/
24 #include <sys/cdefs.h>
25 __FBSDID("$FreeBSD$");
26 #include <dev/pms/config.h>
27
28 #include <dev/pms/freebsd/driver/common/osenv.h>
29 #include <dev/pms/freebsd/driver/common/ostypes.h>
30 #include <dev/pms/freebsd/driver/common/osdebug.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 #ifdef FDS_DM
37 #include <dev/pms/RefTisa/discovery/api/dm.h>
38 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
39 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
40
41 #include <dev/pms/RefTisa/discovery/dm/dmdefs.h>
42 #include <dev/pms/RefTisa/discovery/dm/dmtypes.h>
43 #include <dev/pms/RefTisa/discovery/dm/dmproto.h>
44
45 osGLOBAL void   
46 dmTimerTick(dmRoot_t            *dmRoot )
47 {
48   DM_DBG6(("dmTimerTick: start\n"));
49   
50   dmProcessTimers(dmRoot);
51
52   return;
53 }                                                                                                                                       
54                                 
55 osGLOBAL void
56 dmInitTimerRequest(
57                      dmRoot_t                *dmRoot, 
58                      dmTimerRequest_t        *timerRequest
59                      )
60 {
61   timerRequest->timeout       = 0;
62   timerRequest->timerCBFunc   = agNULL;
63   timerRequest->timerData1     = agNULL;
64   timerRequest->timerData2     = agNULL;
65   timerRequest->timerData3     = agNULL;
66   DMLIST_INIT_ELEMENT((&timerRequest->timerLink));
67 }
68
69 osGLOBAL void
70 dmSetTimerRequest(
71                   dmRoot_t            *dmRoot,
72                   dmTimerRequest_t    *timerRequest,
73                   bit32               timeout,
74                   dmTimerCBFunc_t     CBFunc,
75                   void                *timerData1,
76                   void                *timerData2,
77                   void                *timerData3
78                   )
79 {
80   timerRequest->timeout     = timeout;
81   timerRequest->timerCBFunc = CBFunc;
82   timerRequest->timerData1   = timerData1;
83   timerRequest->timerData2   = timerData2;
84   timerRequest->timerData3   = timerData3;
85 }
86
87 osGLOBAL void
88 dmAddTimer(
89            dmRoot_t            *dmRoot,
90            dmList_t            *timerListHdr, 
91            dmTimerRequest_t    *timerRequest
92           )
93 {
94   tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
95   DMLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr);
96   timerRequest->timerRunning = agTRUE;
97   tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
98 }
99
100 osGLOBAL void
101 dmKillTimer(
102             dmRoot_t            *dmRoot,
103             dmTimerRequest_t    *timerRequest
104            )
105 {
106   tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
107   timerRequest->timerRunning = agFALSE;
108   DMLIST_DEQUEUE_THIS(&(timerRequest->timerLink));
109   tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
110 }
111
112
113 osGLOBAL void 
114 dmProcessTimers(
115                 dmRoot_t *dmRoot
116                 )
117 {
118   dmIntRoot_t               *dmIntRoot    = (dmIntRoot_t *)dmRoot->dmData;
119   dmIntContext_t            *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
120   dmTimerRequest_t          *timerRequest_to_process = agNULL;
121   dmList_t                  *timerlist_to_process, *nexttimerlist = agNULL;
122
123   
124   timerlist_to_process = &dmAllShared->timerlist;
125   
126   timerlist_to_process = timerlist_to_process->flink;
127
128   while ((timerlist_to_process != agNULL) && (timerlist_to_process != &dmAllShared->timerlist))
129   {
130     nexttimerlist = timerlist_to_process->flink;
131     
132     tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
133     timerRequest_to_process = DMLIST_OBJECT_BASE(dmTimerRequest_t, timerLink, timerlist_to_process);
134     tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
135     
136     if (timerRequest_to_process == agNULL)
137     {
138       DM_DBG1(("dmProcessTimers: timerRequest_to_process is NULL! Error!!!\n"));
139       return;      
140     }
141     
142     timerRequest_to_process->timeout--;
143     
144     if (timerRequest_to_process->timeout == 0)
145     {      
146       tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
147       timerRequest_to_process->timerRunning = agFALSE;
148       DMLIST_DEQUEUE_THIS(timerlist_to_process);
149       tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
150       /* calling call back function */
151       (timerRequest_to_process->timerCBFunc)(dmRoot, 
152                                              timerRequest_to_process->timerData1, 
153                                              timerRequest_to_process->timerData2, 
154                                              timerRequest_to_process->timerData3 
155                                              );
156     }
157     timerlist_to_process = nexttimerlist;
158   }
159
160  return;
161 }
162 #endif /* FDS_ DM */
163