1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
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
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.
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
21 ********************************************************************************/
22 /*******************************************************************************/
25 * This file contains timer functions in TD layer
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30 #include <dev/pms/config.h>
32 #include <dev/pms/freebsd/driver/common/osenv.h>
33 #include <dev/pms/freebsd/driver/common/ostypes.h>
34 #include <dev/pms/freebsd/driver/common/osdebug.h>
36 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
37 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
38 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
40 #include <dev/pms/RefTisa/tisa/api/titypes.h>
41 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
42 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
43 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
46 #include <dev/pms/RefTisa/sat/api/sm.h>
47 #include <dev/pms/RefTisa/sat/api/smapi.h>
48 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
52 #include <dev/pms/RefTisa/discovery/api/dm.h>
53 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
54 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
57 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
58 #include <dev/pms/freebsd/driver/common/osstring.h>
59 #include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
61 #ifdef INITIATOR_DRIVER
62 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
63 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
64 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
68 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
69 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
70 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
73 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
74 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
76 /*****************************************************************************
77 *! \brief tiCOMTimerTick
79 * Purpose: This function is called to every usecsPerTick interval
81 * \param tiRoot: Pointer to initiator specific root data structure for this
82 * instance of the driver.
87 *****************************************************************************/
93 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData);
94 agsaRoot_t *agRoot = &tdsaRoot->tdsaAllShared.agRootNonInt;
96 dmRoot_t *dmRoot = &tdsaRoot->tdsaAllShared.dmRoot;
100 smRoot_t *smRoot = &tdsaRoot->tdsaAllShared.smRoot;
102 /* checking the lower layer */
106 /* checking the DM */
110 #ifdef FDS_SM_NOT_YET
111 /* checking the SM */
117 checking tdsaRoot_t timers
120 tdsaProcessTimers(tiRoot);
124 /*****************************************************************************
125 *! \brief tdsaInitTimerRequest
127 * Purpose: This function initiallizes timer request
129 * \param tiRoot: Pointer to initiator specific root data structure
130 * for this instance of the driver.
131 * \param timerrequest Pointer to timer request
136 *****************************************************************************/
138 tdsaInitTimerRequest(
140 tdsaTimerRequest_t *timerRequest
143 timerRequest->timeout = 0;
144 timerRequest->timerCBFunc = agNULL;
145 timerRequest->timerData1 = agNULL;
146 timerRequest->timerData2 = agNULL;
147 timerRequest->timerData3 = agNULL;
148 TDLIST_INIT_ELEMENT((&timerRequest->timerLink));
151 /*****************************************************************************
152 *! \brief tdsaSetTimerRequest
154 * Purpose: This function sets timer request
156 * \param tiRoot: Pointer to initiator specific root data structure
157 * for this instance of the driver.
158 * \param timerrequest Pointer to timer request
159 * \param timeout timeout value
160 * \param CBFunc timer CB function
161 * \param timerData1 Data associated with the timer
162 * \param timerData2 Data associated with the timer
163 * \param timerData3 Data associated with the timer
168 *****************************************************************************/
172 tdsaTimerRequest_t *timerRequest,
174 tdsaTimerCBFunc_t CBFunc,
180 timerRequest->timeout = timeout;
181 timerRequest->timerCBFunc = CBFunc;
182 timerRequest->timerData1 = timerData1;
183 timerRequest->timerData2 = timerData2;
184 timerRequest->timerData3 = timerData3;
187 /*****************************************************************************
188 *! \brief tdsaAddTimer
190 * Purpose: This function adds timer request to timer list
192 * \param tiRoot: Pointer to initiator specific root data structure
193 * for this instance of the driver.
194 * \param timerListHdr Pointer to the timer list
195 * \param timerrequest Pointer to timer request
200 *****************************************************************************/
204 tdList_t *timerListHdr,
205 tdsaTimerRequest_t *timerRequest
208 tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
209 TDLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr);
210 timerRequest->timerRunning = agTRUE;
211 tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
214 /*****************************************************************************
215 *! \brief tdsaKillTimer
217 * Purpose: This function kills timer request.
219 * \param tiRoot: Pointer to initiator specific root data structure
220 * for this instance of the driver.
221 * \param timerrequest Pointer to timer request
226 *****************************************************************************/
230 tdsaTimerRequest_t *timerRequest
233 tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
234 timerRequest->timerRunning = agFALSE;
235 TDLIST_DEQUEUE_THIS(&(timerRequest->timerLink));
236 tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
239 /*****************************************************************************
240 *! \brief tdsaProcessTimers
242 * Purpose: This function processes timer request.
244 * \param tiRoot: Pointer to initiator specific root data structure
245 * for this instance of the driver.
250 *****************************************************************************/
256 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData);
257 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
258 tdsaTimerRequest_t *timerRequest_to_process = agNULL;
259 tdList_t *timerlist_to_process, *nexttimerlist = agNULL;
262 timerlist_to_process = &tdsaAllShared->timerlist;
264 timerlist_to_process = timerlist_to_process->flink;
266 while ((timerlist_to_process != agNULL) && (timerlist_to_process != &tdsaAllShared->timerlist))
268 nexttimerlist = timerlist_to_process->flink;
270 tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
271 timerRequest_to_process = TDLIST_OBJECT_BASE(tdsaTimerRequest_t, timerLink, timerlist_to_process);
272 tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
274 if (timerRequest_to_process == agNULL)
276 TI_DBG1(("tdsaProcessTimers: timerRequest_to_process is NULL! Error!!!\n"));
280 timerRequest_to_process->timeout--;
282 if (timerRequest_to_process->timeout == 0)
284 tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
285 if (timerRequest_to_process->timerRunning == agTRUE)
287 timerRequest_to_process->timerRunning = agFALSE;
288 TDLIST_DEQUEUE_THIS(timerlist_to_process);
290 tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
291 /* calling call back function */
292 (timerRequest_to_process->timerCBFunc)(tiRoot,
293 timerRequest_to_process->timerData1,
294 timerRequest_to_process->timerData2,
295 timerRequest_to_process->timerData3
298 timerlist_to_process = nexttimerlist;