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 /*******************************************************************************/
23*4e1bc9a0SAchim Leubner /** \file
24*4e1bc9a0SAchim Leubner *
25*4e1bc9a0SAchim Leubner * This file contains timer functions in TD layer
26*4e1bc9a0SAchim Leubner *
27*4e1bc9a0SAchim Leubner */
28*4e1bc9a0SAchim Leubner #include <sys/cdefs.h>
29*4e1bc9a0SAchim Leubner #include <dev/pms/config.h>
30*4e1bc9a0SAchim Leubner
31*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/osenv.h>
32*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/ostypes.h>
33*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/osdebug.h>
34*4e1bc9a0SAchim Leubner
35*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sallsdk/api/sa.h>
36*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
37*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
38*4e1bc9a0SAchim Leubner
39*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/api/titypes.h>
40*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
41*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/api/tiapi.h>
42*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
43*4e1bc9a0SAchim Leubner
44*4e1bc9a0SAchim Leubner #ifdef FDS_SM
45*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/api/sm.h>
46*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/api/smapi.h>
47*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
48*4e1bc9a0SAchim Leubner #endif
49*4e1bc9a0SAchim Leubner
50*4e1bc9a0SAchim Leubner #ifdef FDS_DM
51*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/discovery/api/dm.h>
52*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/discovery/api/dmapi.h>
53*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
54*4e1bc9a0SAchim Leubner #endif
55*4e1bc9a0SAchim Leubner
56*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
57*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/osstring.h>
58*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
59*4e1bc9a0SAchim Leubner
60*4e1bc9a0SAchim Leubner #ifdef INITIATOR_DRIVER
61*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
62*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
63*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
64*4e1bc9a0SAchim Leubner #endif
65*4e1bc9a0SAchim Leubner
66*4e1bc9a0SAchim Leubner #ifdef TARGET_DRIVER
67*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
68*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
69*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
70*4e1bc9a0SAchim Leubner #endif
71*4e1bc9a0SAchim Leubner
72*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
73*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
74*4e1bc9a0SAchim Leubner
75*4e1bc9a0SAchim Leubner /*****************************************************************************
76*4e1bc9a0SAchim Leubner *! \brief tiCOMTimerTick
77*4e1bc9a0SAchim Leubner *
78*4e1bc9a0SAchim Leubner * Purpose: This function is called to every usecsPerTick interval
79*4e1bc9a0SAchim Leubner *
80*4e1bc9a0SAchim Leubner * \param tiRoot: Pointer to initiator specific root data structure for this
81*4e1bc9a0SAchim Leubner * instance of the driver.
82*4e1bc9a0SAchim Leubner *
83*4e1bc9a0SAchim Leubner * \return: None
84*4e1bc9a0SAchim Leubner *
85*4e1bc9a0SAchim Leubner *
86*4e1bc9a0SAchim Leubner *****************************************************************************/
87*4e1bc9a0SAchim Leubner osGLOBAL void
tiCOMTimerTick(tiRoot_t * tiRoot)88*4e1bc9a0SAchim Leubner tiCOMTimerTick (
89*4e1bc9a0SAchim Leubner tiRoot_t * tiRoot
90*4e1bc9a0SAchim Leubner )
91*4e1bc9a0SAchim Leubner {
92*4e1bc9a0SAchim Leubner tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData);
93*4e1bc9a0SAchim Leubner agsaRoot_t *agRoot = &tdsaRoot->tdsaAllShared.agRootNonInt;
94*4e1bc9a0SAchim Leubner #ifdef FDS_DM
95*4e1bc9a0SAchim Leubner dmRoot_t *dmRoot = &tdsaRoot->tdsaAllShared.dmRoot;
96*4e1bc9a0SAchim Leubner #endif
97*4e1bc9a0SAchim Leubner
98*4e1bc9a0SAchim Leubner #ifdef FDS_SM_NOT_YET
99*4e1bc9a0SAchim Leubner smRoot_t *smRoot = &tdsaRoot->tdsaAllShared.smRoot;
100*4e1bc9a0SAchim Leubner #endif
101*4e1bc9a0SAchim Leubner /* checking the lower layer */
102*4e1bc9a0SAchim Leubner saTimerTick(agRoot);
103*4e1bc9a0SAchim Leubner
104*4e1bc9a0SAchim Leubner #ifdef FDS_DM
105*4e1bc9a0SAchim Leubner /* checking the DM */
106*4e1bc9a0SAchim Leubner dmTimerTick(dmRoot);
107*4e1bc9a0SAchim Leubner #endif
108*4e1bc9a0SAchim Leubner
109*4e1bc9a0SAchim Leubner #ifdef FDS_SM_NOT_YET
110*4e1bc9a0SAchim Leubner /* checking the SM */
111*4e1bc9a0SAchim Leubner smTimerTick(smRoot);
112*4e1bc9a0SAchim Leubner #endif
113*4e1bc9a0SAchim Leubner
114*4e1bc9a0SAchim Leubner /*
115*4e1bc9a0SAchim Leubner timers for discovery
116*4e1bc9a0SAchim Leubner checking tdsaRoot_t timers
117*4e1bc9a0SAchim Leubner */
118*4e1bc9a0SAchim Leubner
119*4e1bc9a0SAchim Leubner tdsaProcessTimers(tiRoot);
120*4e1bc9a0SAchim Leubner
121*4e1bc9a0SAchim Leubner }
122*4e1bc9a0SAchim Leubner
123*4e1bc9a0SAchim Leubner /*****************************************************************************
124*4e1bc9a0SAchim Leubner *! \brief tdsaInitTimerRequest
125*4e1bc9a0SAchim Leubner *
126*4e1bc9a0SAchim Leubner * Purpose: This function initiallizes timer request
127*4e1bc9a0SAchim Leubner *
128*4e1bc9a0SAchim Leubner * \param tiRoot: Pointer to initiator specific root data structure
129*4e1bc9a0SAchim Leubner * for this instance of the driver.
130*4e1bc9a0SAchim Leubner * \param timerrequest Pointer to timer request
131*4e1bc9a0SAchim Leubner *
132*4e1bc9a0SAchim Leubner * \return: None
133*4e1bc9a0SAchim Leubner *
134*4e1bc9a0SAchim Leubner *
135*4e1bc9a0SAchim Leubner *****************************************************************************/
136*4e1bc9a0SAchim Leubner osGLOBAL void
tdsaInitTimerRequest(tiRoot_t * tiRoot,tdsaTimerRequest_t * timerRequest)137*4e1bc9a0SAchim Leubner tdsaInitTimerRequest(
138*4e1bc9a0SAchim Leubner tiRoot_t *tiRoot,
139*4e1bc9a0SAchim Leubner tdsaTimerRequest_t *timerRequest
140*4e1bc9a0SAchim Leubner )
141*4e1bc9a0SAchim Leubner {
142*4e1bc9a0SAchim Leubner timerRequest->timeout = 0;
143*4e1bc9a0SAchim Leubner timerRequest->timerCBFunc = agNULL;
144*4e1bc9a0SAchim Leubner timerRequest->timerData1 = agNULL;
145*4e1bc9a0SAchim Leubner timerRequest->timerData2 = agNULL;
146*4e1bc9a0SAchim Leubner timerRequest->timerData3 = agNULL;
147*4e1bc9a0SAchim Leubner TDLIST_INIT_ELEMENT((&timerRequest->timerLink));
148*4e1bc9a0SAchim Leubner }
149*4e1bc9a0SAchim Leubner
150*4e1bc9a0SAchim Leubner /*****************************************************************************
151*4e1bc9a0SAchim Leubner *! \brief tdsaSetTimerRequest
152*4e1bc9a0SAchim Leubner *
153*4e1bc9a0SAchim Leubner * Purpose: This function sets timer request
154*4e1bc9a0SAchim Leubner *
155*4e1bc9a0SAchim Leubner * \param tiRoot: Pointer to initiator specific root data structure
156*4e1bc9a0SAchim Leubner * for this instance of the driver.
157*4e1bc9a0SAchim Leubner * \param timerrequest Pointer to timer request
158*4e1bc9a0SAchim Leubner * \param timeout timeout value
159*4e1bc9a0SAchim Leubner * \param CBFunc timer CB function
160*4e1bc9a0SAchim Leubner * \param timerData1 Data associated with the timer
161*4e1bc9a0SAchim Leubner * \param timerData2 Data associated with the timer
162*4e1bc9a0SAchim Leubner * \param timerData3 Data associated with the timer
163*4e1bc9a0SAchim Leubner *
164*4e1bc9a0SAchim Leubner * \return: None
165*4e1bc9a0SAchim Leubner *
166*4e1bc9a0SAchim Leubner *
167*4e1bc9a0SAchim Leubner *****************************************************************************/
168*4e1bc9a0SAchim Leubner osGLOBAL void
tdsaSetTimerRequest(tiRoot_t * tiRoot,tdsaTimerRequest_t * timerRequest,bit32 timeout,tdsaTimerCBFunc_t CBFunc,void * timerData1,void * timerData2,void * timerData3)169*4e1bc9a0SAchim Leubner tdsaSetTimerRequest(
170*4e1bc9a0SAchim Leubner tiRoot_t *tiRoot,
171*4e1bc9a0SAchim Leubner tdsaTimerRequest_t *timerRequest,
172*4e1bc9a0SAchim Leubner bit32 timeout,
173*4e1bc9a0SAchim Leubner tdsaTimerCBFunc_t CBFunc,
174*4e1bc9a0SAchim Leubner void *timerData1,
175*4e1bc9a0SAchim Leubner void *timerData2,
176*4e1bc9a0SAchim Leubner void *timerData3
177*4e1bc9a0SAchim Leubner )
178*4e1bc9a0SAchim Leubner {
179*4e1bc9a0SAchim Leubner timerRequest->timeout = timeout;
180*4e1bc9a0SAchim Leubner timerRequest->timerCBFunc = CBFunc;
181*4e1bc9a0SAchim Leubner timerRequest->timerData1 = timerData1;
182*4e1bc9a0SAchim Leubner timerRequest->timerData2 = timerData2;
183*4e1bc9a0SAchim Leubner timerRequest->timerData3 = timerData3;
184*4e1bc9a0SAchim Leubner }
185*4e1bc9a0SAchim Leubner
186*4e1bc9a0SAchim Leubner /*****************************************************************************
187*4e1bc9a0SAchim Leubner *! \brief tdsaAddTimer
188*4e1bc9a0SAchim Leubner *
189*4e1bc9a0SAchim Leubner * Purpose: This function adds timer request to timer list
190*4e1bc9a0SAchim Leubner *
191*4e1bc9a0SAchim Leubner * \param tiRoot: Pointer to initiator specific root data structure
192*4e1bc9a0SAchim Leubner * for this instance of the driver.
193*4e1bc9a0SAchim Leubner * \param timerListHdr Pointer to the timer list
194*4e1bc9a0SAchim Leubner * \param timerrequest Pointer to timer request
195*4e1bc9a0SAchim Leubner *
196*4e1bc9a0SAchim Leubner * \return: None
197*4e1bc9a0SAchim Leubner *
198*4e1bc9a0SAchim Leubner *
199*4e1bc9a0SAchim Leubner *****************************************************************************/
200*4e1bc9a0SAchim Leubner osGLOBAL void
tdsaAddTimer(tiRoot_t * tiRoot,tdList_t * timerListHdr,tdsaTimerRequest_t * timerRequest)201*4e1bc9a0SAchim Leubner tdsaAddTimer(
202*4e1bc9a0SAchim Leubner tiRoot_t *tiRoot,
203*4e1bc9a0SAchim Leubner tdList_t *timerListHdr,
204*4e1bc9a0SAchim Leubner tdsaTimerRequest_t *timerRequest
205*4e1bc9a0SAchim Leubner )
206*4e1bc9a0SAchim Leubner {
207*4e1bc9a0SAchim Leubner tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
208*4e1bc9a0SAchim Leubner TDLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr);
209*4e1bc9a0SAchim Leubner timerRequest->timerRunning = agTRUE;
210*4e1bc9a0SAchim Leubner tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
211*4e1bc9a0SAchim Leubner }
212*4e1bc9a0SAchim Leubner
213*4e1bc9a0SAchim Leubner /*****************************************************************************
214*4e1bc9a0SAchim Leubner *! \brief tdsaKillTimer
215*4e1bc9a0SAchim Leubner *
216*4e1bc9a0SAchim Leubner * Purpose: This function kills timer request.
217*4e1bc9a0SAchim Leubner *
218*4e1bc9a0SAchim Leubner * \param tiRoot: Pointer to initiator specific root data structure
219*4e1bc9a0SAchim Leubner * for this instance of the driver.
220*4e1bc9a0SAchim Leubner * \param timerrequest Pointer to timer request
221*4e1bc9a0SAchim Leubner *
222*4e1bc9a0SAchim Leubner * \return: None
223*4e1bc9a0SAchim Leubner *
224*4e1bc9a0SAchim Leubner *
225*4e1bc9a0SAchim Leubner *****************************************************************************/
226*4e1bc9a0SAchim Leubner osGLOBAL void
tdsaKillTimer(tiRoot_t * tiRoot,tdsaTimerRequest_t * timerRequest)227*4e1bc9a0SAchim Leubner tdsaKillTimer(
228*4e1bc9a0SAchim Leubner tiRoot_t *tiRoot,
229*4e1bc9a0SAchim Leubner tdsaTimerRequest_t *timerRequest
230*4e1bc9a0SAchim Leubner )
231*4e1bc9a0SAchim Leubner {
232*4e1bc9a0SAchim Leubner tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
233*4e1bc9a0SAchim Leubner timerRequest->timerRunning = agFALSE;
234*4e1bc9a0SAchim Leubner TDLIST_DEQUEUE_THIS(&(timerRequest->timerLink));
235*4e1bc9a0SAchim Leubner tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
236*4e1bc9a0SAchim Leubner }
237*4e1bc9a0SAchim Leubner
238*4e1bc9a0SAchim Leubner /*****************************************************************************
239*4e1bc9a0SAchim Leubner *! \brief tdsaProcessTimers
240*4e1bc9a0SAchim Leubner *
241*4e1bc9a0SAchim Leubner * Purpose: This function processes timer request.
242*4e1bc9a0SAchim Leubner *
243*4e1bc9a0SAchim Leubner * \param tiRoot: Pointer to initiator specific root data structure
244*4e1bc9a0SAchim Leubner * for this instance of the driver.
245*4e1bc9a0SAchim Leubner *
246*4e1bc9a0SAchim Leubner * \return: None
247*4e1bc9a0SAchim Leubner *
248*4e1bc9a0SAchim Leubner *
249*4e1bc9a0SAchim Leubner *****************************************************************************/
250*4e1bc9a0SAchim Leubner osGLOBAL void
tdsaProcessTimers(tiRoot_t * tiRoot)251*4e1bc9a0SAchim Leubner tdsaProcessTimers(
252*4e1bc9a0SAchim Leubner tiRoot_t *tiRoot
253*4e1bc9a0SAchim Leubner )
254*4e1bc9a0SAchim Leubner {
255*4e1bc9a0SAchim Leubner tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData);
256*4e1bc9a0SAchim Leubner tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
257*4e1bc9a0SAchim Leubner tdsaTimerRequest_t *timerRequest_to_process = agNULL;
258*4e1bc9a0SAchim Leubner tdList_t *timerlist_to_process, *nexttimerlist = agNULL;
259*4e1bc9a0SAchim Leubner
260*4e1bc9a0SAchim Leubner
261*4e1bc9a0SAchim Leubner timerlist_to_process = &tdsaAllShared->timerlist;
262*4e1bc9a0SAchim Leubner
263*4e1bc9a0SAchim Leubner timerlist_to_process = timerlist_to_process->flink;
264*4e1bc9a0SAchim Leubner
265*4e1bc9a0SAchim Leubner while ((timerlist_to_process != agNULL) && (timerlist_to_process != &tdsaAllShared->timerlist))
266*4e1bc9a0SAchim Leubner {
267*4e1bc9a0SAchim Leubner nexttimerlist = timerlist_to_process->flink;
268*4e1bc9a0SAchim Leubner
269*4e1bc9a0SAchim Leubner tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
270*4e1bc9a0SAchim Leubner timerRequest_to_process = TDLIST_OBJECT_BASE(tdsaTimerRequest_t, timerLink, timerlist_to_process);
271*4e1bc9a0SAchim Leubner tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
272*4e1bc9a0SAchim Leubner
273*4e1bc9a0SAchim Leubner if (timerRequest_to_process == agNULL)
274*4e1bc9a0SAchim Leubner {
275*4e1bc9a0SAchim Leubner TI_DBG1(("tdsaProcessTimers: timerRequest_to_process is NULL! Error!!!\n"));
276*4e1bc9a0SAchim Leubner return;
277*4e1bc9a0SAchim Leubner }
278*4e1bc9a0SAchim Leubner
279*4e1bc9a0SAchim Leubner timerRequest_to_process->timeout--;
280*4e1bc9a0SAchim Leubner
281*4e1bc9a0SAchim Leubner if (timerRequest_to_process->timeout == 0)
282*4e1bc9a0SAchim Leubner {
283*4e1bc9a0SAchim Leubner tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
284*4e1bc9a0SAchim Leubner if (timerRequest_to_process->timerRunning == agTRUE)
285*4e1bc9a0SAchim Leubner {
286*4e1bc9a0SAchim Leubner timerRequest_to_process->timerRunning = agFALSE;
287*4e1bc9a0SAchim Leubner TDLIST_DEQUEUE_THIS(timerlist_to_process);
288*4e1bc9a0SAchim Leubner }
289*4e1bc9a0SAchim Leubner tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
290*4e1bc9a0SAchim Leubner /* calling call back function */
291*4e1bc9a0SAchim Leubner (timerRequest_to_process->timerCBFunc)(tiRoot,
292*4e1bc9a0SAchim Leubner timerRequest_to_process->timerData1,
293*4e1bc9a0SAchim Leubner timerRequest_to_process->timerData2,
294*4e1bc9a0SAchim Leubner timerRequest_to_process->timerData3
295*4e1bc9a0SAchim Leubner );
296*4e1bc9a0SAchim Leubner }
297*4e1bc9a0SAchim Leubner timerlist_to_process = nexttimerlist;
298*4e1bc9a0SAchim Leubner }
299*4e1bc9a0SAchim Leubner return;
300*4e1bc9a0SAchim Leubner }
301*4e1bc9a0SAchim Leubner
302