/******************************************************************************* *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved. * *Redistribution and use in source and binary forms, with or without modification, are permitted provided *that the following conditions are met: *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the *following disclaimer. *2. Redistributions in binary form must reproduce the above copyright notice, *this list of conditions and the following disclaimer in the documentation and/or other materials provided *with the distribution. * *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE ********************************************************************************/ /*******************************************************************************/ /** \file * * This file contains timer functions in TD layer * */ #include #include #include #include #include #include #include #include #include #include #include #include #ifdef FDS_SM #include #include #include #endif #ifdef FDS_DM #include #include #include #endif #include #include #include #ifdef INITIATOR_DRIVER #include #include #include #endif #ifdef TARGET_DRIVER #include #include #include #endif #include #include /***************************************************************************** *! \brief tiCOMTimerTick * * Purpose: This function is called to every usecsPerTick interval * * \param tiRoot: Pointer to initiator specific root data structure for this * instance of the driver. * * \return: None * * *****************************************************************************/ osGLOBAL void tiCOMTimerTick ( tiRoot_t * tiRoot ) { tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData); agsaRoot_t *agRoot = &tdsaRoot->tdsaAllShared.agRootNonInt; #ifdef FDS_DM dmRoot_t *dmRoot = &tdsaRoot->tdsaAllShared.dmRoot; #endif #ifdef FDS_SM_NOT_YET smRoot_t *smRoot = &tdsaRoot->tdsaAllShared.smRoot; #endif /* checking the lower layer */ saTimerTick(agRoot); #ifdef FDS_DM /* checking the DM */ dmTimerTick(dmRoot); #endif #ifdef FDS_SM_NOT_YET /* checking the SM */ smTimerTick(smRoot); #endif /* timers for discovery checking tdsaRoot_t timers */ tdsaProcessTimers(tiRoot); } /***************************************************************************** *! \brief tdsaInitTimerRequest * * Purpose: This function initiallizes timer request * * \param tiRoot: Pointer to initiator specific root data structure * for this instance of the driver. * \param timerrequest Pointer to timer request * * \return: None * * *****************************************************************************/ osGLOBAL void tdsaInitTimerRequest( tiRoot_t *tiRoot, tdsaTimerRequest_t *timerRequest ) { timerRequest->timeout = 0; timerRequest->timerCBFunc = agNULL; timerRequest->timerData1 = agNULL; timerRequest->timerData2 = agNULL; timerRequest->timerData3 = agNULL; TDLIST_INIT_ELEMENT((&timerRequest->timerLink)); } /***************************************************************************** *! \brief tdsaSetTimerRequest * * Purpose: This function sets timer request * * \param tiRoot: Pointer to initiator specific root data structure * for this instance of the driver. * \param timerrequest Pointer to timer request * \param timeout timeout value * \param CBFunc timer CB function * \param timerData1 Data associated with the timer * \param timerData2 Data associated with the timer * \param timerData3 Data associated with the timer * * \return: None * * *****************************************************************************/ osGLOBAL void tdsaSetTimerRequest( tiRoot_t *tiRoot, tdsaTimerRequest_t *timerRequest, bit32 timeout, tdsaTimerCBFunc_t CBFunc, void *timerData1, void *timerData2, void *timerData3 ) { timerRequest->timeout = timeout; timerRequest->timerCBFunc = CBFunc; timerRequest->timerData1 = timerData1; timerRequest->timerData2 = timerData2; timerRequest->timerData3 = timerData3; } /***************************************************************************** *! \brief tdsaAddTimer * * Purpose: This function adds timer request to timer list * * \param tiRoot: Pointer to initiator specific root data structure * for this instance of the driver. * \param timerListHdr Pointer to the timer list * \param timerrequest Pointer to timer request * * \return: None * * *****************************************************************************/ osGLOBAL void tdsaAddTimer( tiRoot_t *tiRoot, tdList_t *timerListHdr, tdsaTimerRequest_t *timerRequest ) { tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK); TDLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr); timerRequest->timerRunning = agTRUE; tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK); } /***************************************************************************** *! \brief tdsaKillTimer * * Purpose: This function kills timer request. * * \param tiRoot: Pointer to initiator specific root data structure * for this instance of the driver. * \param timerrequest Pointer to timer request * * \return: None * * *****************************************************************************/ osGLOBAL void tdsaKillTimer( tiRoot_t *tiRoot, tdsaTimerRequest_t *timerRequest ) { tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK); timerRequest->timerRunning = agFALSE; TDLIST_DEQUEUE_THIS(&(timerRequest->timerLink)); tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK); } /***************************************************************************** *! \brief tdsaProcessTimers * * Purpose: This function processes timer request. * * \param tiRoot: Pointer to initiator specific root data structure * for this instance of the driver. * * \return: None * * *****************************************************************************/ osGLOBAL void tdsaProcessTimers( tiRoot_t *tiRoot ) { tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData); tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared; tdsaTimerRequest_t *timerRequest_to_process = agNULL; tdList_t *timerlist_to_process, *nexttimerlist = agNULL; timerlist_to_process = &tdsaAllShared->timerlist; timerlist_to_process = timerlist_to_process->flink; while ((timerlist_to_process != agNULL) && (timerlist_to_process != &tdsaAllShared->timerlist)) { nexttimerlist = timerlist_to_process->flink; tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK); timerRequest_to_process = TDLIST_OBJECT_BASE(tdsaTimerRequest_t, timerLink, timerlist_to_process); tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK); if (timerRequest_to_process == agNULL) { TI_DBG1(("tdsaProcessTimers: timerRequest_to_process is NULL! Error!!!\n")); return; } timerRequest_to_process->timeout--; if (timerRequest_to_process->timeout == 0) { tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK); if (timerRequest_to_process->timerRunning == agTRUE) { timerRequest_to_process->timerRunning = agFALSE; TDLIST_DEQUEUE_THIS(timerlist_to_process); } tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK); /* calling call back function */ (timerRequest_to_process->timerCBFunc)(tiRoot, timerRequest_to_process->timerData1, timerRequest_to_process->timerData2, timerRequest_to_process->timerData3 ); } timerlist_to_process = nexttimerlist; } return; }