1285809Sscottl/******************************************************************************* 2285809Sscottl** 3285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved. 4285809Sscottl* 5285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided 6285809Sscottl*that the following conditions are met: 7285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the 8285809Sscottl*following disclaimer. 9285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice, 10285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided 11285809Sscottl*with the distribution. 12285809Sscottl* 13285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED 14285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 15285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 17285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 18285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 19285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 20285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 21285809Sscottl 22285809Sscottl** 23285809Sscottl********************************************************************************/ 24285809Sscottl#include <sys/cdefs.h> 25285809Sscottl__FBSDID("$FreeBSD$"); 26285809Sscottl#include <dev/pms/config.h> 27285809Sscottl 28285809Sscottl#include <dev/pms/freebsd/driver/common/osenv.h> 29285809Sscottl#include <dev/pms/freebsd/driver/common/ostypes.h> 30285809Sscottl#include <dev/pms/freebsd/driver/common/osdebug.h> 31285809Sscottl 32285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/sa.h> 33285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/saapi.h> 34285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/saosapi.h> 35285809Sscottl 36285809Sscottl#ifdef FDS_DM 37285809Sscottl#include <dev/pms/RefTisa/discovery/api/dm.h> 38285809Sscottl#include <dev/pms/RefTisa/discovery/api/dmapi.h> 39285809Sscottl#include <dev/pms/RefTisa/discovery/api/tddmapi.h> 40285809Sscottl 41285809Sscottl#include <dev/pms/RefTisa/discovery/dm/dmdefs.h> 42285809Sscottl#include <dev/pms/RefTisa/discovery/dm/dmtypes.h> 43285809Sscottl#include <dev/pms/RefTisa/discovery/dm/dmproto.h> 44285809Sscottl 45285809SscottlosGLOBAL void 46285809SscottldmTimerTick(dmRoot_t *dmRoot ) 47285809Sscottl{ 48285809Sscottl DM_DBG6(("dmTimerTick: start\n")); 49285809Sscottl 50285809Sscottl dmProcessTimers(dmRoot); 51285809Sscottl 52285809Sscottl return; 53285809Sscottl} 54285809Sscottl 55285809SscottlosGLOBAL void 56285809SscottldmInitTimerRequest( 57285809Sscottl dmRoot_t *dmRoot, 58285809Sscottl dmTimerRequest_t *timerRequest 59285809Sscottl ) 60285809Sscottl{ 61285809Sscottl timerRequest->timeout = 0; 62285809Sscottl timerRequest->timerCBFunc = agNULL; 63285809Sscottl timerRequest->timerData1 = agNULL; 64285809Sscottl timerRequest->timerData2 = agNULL; 65285809Sscottl timerRequest->timerData3 = agNULL; 66285809Sscottl DMLIST_INIT_ELEMENT((&timerRequest->timerLink)); 67285809Sscottl} 68285809Sscottl 69285809SscottlosGLOBAL void 70285809SscottldmSetTimerRequest( 71285809Sscottl dmRoot_t *dmRoot, 72285809Sscottl dmTimerRequest_t *timerRequest, 73285809Sscottl bit32 timeout, 74285809Sscottl dmTimerCBFunc_t CBFunc, 75285809Sscottl void *timerData1, 76285809Sscottl void *timerData2, 77285809Sscottl void *timerData3 78285809Sscottl ) 79285809Sscottl{ 80285809Sscottl timerRequest->timeout = timeout; 81285809Sscottl timerRequest->timerCBFunc = CBFunc; 82285809Sscottl timerRequest->timerData1 = timerData1; 83285809Sscottl timerRequest->timerData2 = timerData2; 84285809Sscottl timerRequest->timerData3 = timerData3; 85285809Sscottl} 86285809Sscottl 87285809SscottlosGLOBAL void 88285809SscottldmAddTimer( 89285809Sscottl dmRoot_t *dmRoot, 90285809Sscottl dmList_t *timerListHdr, 91285809Sscottl dmTimerRequest_t *timerRequest 92285809Sscottl ) 93285809Sscottl{ 94285809Sscottl tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK); 95285809Sscottl DMLIST_ENQUEUE_AT_TAIL(&(timerRequest->timerLink), timerListHdr); 96285809Sscottl timerRequest->timerRunning = agTRUE; 97285809Sscottl tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK); 98285809Sscottl} 99285809Sscottl 100285809SscottlosGLOBAL void 101285809SscottldmKillTimer( 102285809Sscottl dmRoot_t *dmRoot, 103285809Sscottl dmTimerRequest_t *timerRequest 104285809Sscottl ) 105285809Sscottl{ 106285809Sscottl tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK); 107285809Sscottl timerRequest->timerRunning = agFALSE; 108285809Sscottl DMLIST_DEQUEUE_THIS(&(timerRequest->timerLink)); 109285809Sscottl tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK); 110285809Sscottl} 111285809Sscottl 112285809Sscottl 113285809SscottlosGLOBAL void 114285809SscottldmProcessTimers( 115285809Sscottl dmRoot_t *dmRoot 116285809Sscottl ) 117285809Sscottl{ 118285809Sscottl dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData; 119285809Sscottl dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared; 120285809Sscottl dmTimerRequest_t *timerRequest_to_process = agNULL; 121285809Sscottl dmList_t *timerlist_to_process, *nexttimerlist = agNULL; 122285809Sscottl 123285809Sscottl 124285809Sscottl timerlist_to_process = &dmAllShared->timerlist; 125285809Sscottl 126285809Sscottl timerlist_to_process = timerlist_to_process->flink; 127285809Sscottl 128285809Sscottl while ((timerlist_to_process != agNULL) && (timerlist_to_process != &dmAllShared->timerlist)) 129285809Sscottl { 130285809Sscottl nexttimerlist = timerlist_to_process->flink; 131285809Sscottl 132285809Sscottl tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK); 133285809Sscottl timerRequest_to_process = DMLIST_OBJECT_BASE(dmTimerRequest_t, timerLink, timerlist_to_process); 134285809Sscottl tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK); 135285809Sscottl 136285809Sscottl if (timerRequest_to_process == agNULL) 137285809Sscottl { 138285809Sscottl DM_DBG1(("dmProcessTimers: timerRequest_to_process is NULL! Error!!!\n")); 139285809Sscottl return; 140285809Sscottl } 141285809Sscottl 142285809Sscottl timerRequest_to_process->timeout--; 143285809Sscottl 144285809Sscottl if (timerRequest_to_process->timeout == 0) 145285809Sscottl { 146285809Sscottl tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK); 147285809Sscottl timerRequest_to_process->timerRunning = agFALSE; 148285809Sscottl DMLIST_DEQUEUE_THIS(timerlist_to_process); 149285809Sscottl tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK); 150285809Sscottl /* calling call back function */ 151285809Sscottl (timerRequest_to_process->timerCBFunc)(dmRoot, 152285809Sscottl timerRequest_to_process->timerData1, 153285809Sscottl timerRequest_to_process->timerData2, 154285809Sscottl timerRequest_to_process->timerData3 155285809Sscottl ); 156285809Sscottl } 157285809Sscottl timerlist_to_process = nexttimerlist; 158285809Sscottl } 159285809Sscottl 160285809Sscottl return; 161285809Sscottl} 162285809Sscottl#endif /* FDS_ DM */ 163285809Sscottl 164