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