1285809Sscottl/*******************************************************************************
2285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285809Sscottl*
4285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285809Sscottl*that the following conditions are met:
6285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285809Sscottl*following disclaimer.
8285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice,
9285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285809Sscottl*with the distribution.
11285809Sscottl*
12285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285809Sscottl
21285809Sscottl********************************************************************************/
22285809Sscottl
23285809Sscottl/*******************************************************************************/
24285809Sscottl/*! \file mpidebug.c
25285809Sscottl *  \brief The file is a MPI Libraries to implement the MPI debug and trace functions
26285809Sscottl *
27285809Sscottl * The file implements the MPI functions.
28285809Sscottl *
29285809Sscottl */
30285809Sscottl/*******************************************************************************/
31285809Sscottl#include <sys/cdefs.h>
32285809Sscottl__FBSDID("$FreeBSD$");
33285809Sscottl#include <dev/pms/config.h>
34285809Sscottl
35285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/saglobal.h>
36285809Sscottl#ifdef MPI_DEBUG_TRACE_ENABLE /* enable with CCBUILD_MPI_TRACE*/
37285809Sscottl
38285809Sscottl/*******************************************************************************/
39285809Sscottl
40285809Sscottl#ifdef OSLAYER_USE_HI_RES_TIMER
41285809Sscottlunsigned __int64
42285809SscottlGetHiResTimeStamp(void);
43285809Sscottl#endif /* OSLAYER_USE_HI_RES_TIMER */
44285809Sscottl/*******************************************************************************/
45285809Sscottl/*******************************************************************************/
46285809Sscottl/* FUNCTIONS                                                                   */
47285809Sscottl/*******************************************************************************/
48285809SscottlmpiDebugObTrace_t obTraceData;
49285809SscottlmpiDebugIbTrace_t ibTraceData;
50285809Sscottl
51285809Sscottlvoid mpiTraceInit(void)
52285809Sscottl{
53285809Sscottl
54285809Sscottl  SA_DBG1(("mpiTraceInit:obTraceData @ %p\n",&obTraceData ));
55285809Sscottl  SA_DBG1(("mpiTraceInit:ibTraceData @ %p\n",&ibTraceData ));
56285809Sscottl  SA_DBG1(("mpiTraceInit: num enties %d Ib Iomb size %d Ob Iomb size %d\n",
57285809Sscottl               MPI_DEBUG_TRACE_BUFFER_MAX,
58285809Sscottl               MPI_DEBUG_TRACE_IB_IOMB_SIZE,
59285809Sscottl               MPI_DEBUG_TRACE_OB_IOMB_SIZE ));
60285809Sscottl
61285809Sscottl  si_memset(&obTraceData, 0, sizeof(obTraceData));
62285809Sscottl  si_memset(&ibTraceData, 0, sizeof(ibTraceData));
63285809Sscottl}
64285809Sscottl
65285809Sscottlvoid mpiTraceAdd( bit32 q,bit32 pici,bit32 ib, void *iomb, bit32 numBytes)
66285809Sscottl{
67285809Sscottl  bit32                  curIdx;
68285809Sscottl  mpiDebugIbTraceEntry_t *curIbTrace;
69285809Sscottl  mpiDebugObTraceEntry_t *curObTrace;
70285809Sscottl
71285809Sscottl  mpiDebugIbTrace_t * ibTrace = &ibTraceData;
72285809Sscottl  mpiDebugObTrace_t * obTrace = &obTraceData;
73285809Sscottl
74285809Sscottl  if (ib)
75285809Sscottl  {
76285809Sscottl    if(ibTrace->Idx >= MPI_DEBUG_TRACE_BUFFER_MAX)
77285809Sscottl    {
78285809Sscottl      ibTrace->Idx = 0;
79285809Sscottl    }
80285809Sscottl    curIdx = ibTrace->Idx;
81285809Sscottl
82285809Sscottl    curIbTrace = &ibTrace->Data[curIdx];
83285809Sscottl    curIbTrace->pEntry =  iomb;
84285809Sscottl    curIbTrace->QNum = q;
85285809Sscottl    curIbTrace->pici = pici;
86285809Sscottl#ifdef OSLAYER_USE_HI_RES_TIMER
87285809Sscottl#ifdef SA_64BIT_TIMESTAMP
88285809Sscottl  curIbTrace->Time = ossaTimeStamp64(agNULL);
89285809Sscottl#else /* SA_64BIT_TIMESTAMP */
90285809Sscottl  curIbTrace->Time = ossaTimeStamp(agNULL);
91285809Sscottl#endif /* SA_64BIT_TIMESTAMP */
92285809Sscottl#else /* OSLAYER_USE_HI_RES_TIMER */
93285809Sscottl  curIbTrace->Time = 0;
94285809Sscottl#endif
95285809Sscottl    si_memcpy(curIbTrace->Iomb, iomb, MIN(numBytes, MPI_DEBUG_TRACE_IB_IOMB_SIZE));
96285809Sscottl    ibTrace->Idx++;
97285809Sscottl  }
98285809Sscottl  else
99285809Sscottl  {
100285809Sscottl    if(obTrace->Idx >= MPI_DEBUG_TRACE_BUFFER_MAX )
101285809Sscottl    {
102285809Sscottl      obTrace->Idx = 0;
103285809Sscottl    }
104285809Sscottl    curIdx = obTrace->Idx;
105285809Sscottl    curObTrace = &obTrace->Data[curIdx];
106285809Sscottl    curObTrace->pEntry =  iomb;
107285809Sscottl    curObTrace->QNum = q;
108285809Sscottl    curObTrace->pici = pici;
109285809Sscottl#ifdef OSLAYER_USE_HI_RES_TIMER
110285809Sscottl#ifdef SA_64BIT_TIMESTAMP
111285809Sscottl    curObTrace->Time = ossaTimeStamp64(agNULL);
112285809Sscottl#else /* SA_64BIT_TIMESTAMP */
113285809Sscottl    curObTrace->Time = ossaTimeStamp(agNULL);
114285809Sscottl#endif /* SA_64BIT_TIMESTAMP */
115285809Sscottl#else /* OSLAYER_USE_HI_RES_TIMER */
116285809Sscottl    curObTrace->Time = 0;
117285809Sscottl#endif
118285809Sscottl    si_memcpy(curObTrace->Iomb, iomb, MIN(numBytes, MPI_DEBUG_TRACE_OB_IOMB_SIZE));
119285809Sscottl    obTrace->Idx++;
120285809Sscottl  }
121285809Sscottl
122285809Sscottl
123285809Sscottl  return;
124285809Sscottl}
125285809Sscottl
126285809Sscottl#endif /* MPI_DEBUG_TRACE_ENABLE */
127285809Sscottl
128285809Sscottl
129285809Sscottl
130285809Sscottl#ifdef SA_ENABLE_TRACE_FUNCTIONS
131285809Sscottl
132285809Sscottl/**
133285809Sscottl * fiEnableTracing
134285809Sscottl *
135285809Sscottl *    This fucntion is called to initialize tracing of FC layer.
136285809Sscottl *
137285809Sscottl */
138285809Sscottlvoid siEnableTracing (agsaRoot_t  *agRoot)
139285809Sscottl{
140285809Sscottl
141285809Sscottl  agsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
142285809Sscottl  agsaSwConfig_t    *swC  = &saRoot->swConfig;
143285809Sscottl  bit32 count;
144285809Sscottl
145285809Sscottl  OS_ASSERT(saRoot != NULL, "");
146285809Sscottl
147285809Sscottl  if( saRoot->TraceBlockReInit != 0)
148285809Sscottl  {
149285809Sscottl    return;
150285809Sscottl  }
151285809Sscottl
152285809Sscottl
153285809Sscottl  /* Initialize tracing first */
154285809Sscottl
155285809Sscottl  for (count = 0; count < 10; count++)
156285809Sscottl  {
157285809Sscottl      saRoot->traceBuffLookup[count] = (bit8)('0' + count);
158285809Sscottl  }
159285809Sscottl  for (count = 0; count < 6; count++)
160285809Sscottl  {
161285809Sscottl      saRoot->traceBuffLookup[(bitptr)count + 10] = (bit8)('a' + count);
162285809Sscottl  }
163285809Sscottl
164285809Sscottl
165285809Sscottl  saRoot->TraceDestination = swC->TraceDestination;
166285809Sscottl  saRoot->TraceMask = swC->TraceMask;
167285809Sscottl  saRoot->CurrentTraceIndexWrapCount = 0;
168285809Sscottl  saRoot->CurrentTraceIndex = 0;
169285809Sscottl  saRoot->TraceBlockReInit = 1;
170285809Sscottl
171285809Sscottl
172285809Sscottl  SA_DBG1(("siEnableTracing: \n" ));
173285809Sscottl
174285809Sscottl  SA_DBG1 (("      length       = %08x\n", saRoot->TraceBufferLength ));
175285809Sscottl  SA_DBG1 (("      virt         = %p\n",   saRoot->TraceBuffer ));
176285809Sscottl  SA_DBG1 (("    traceMask        = %08x @ %p\n", saRoot->TraceMask, &saRoot->TraceMask));
177285809Sscottl  SA_DBG1 (("    last trace entry @ %p\n", &saRoot->CurrentTraceIndex));
178285809Sscottl  SA_DBG1 (("    TraceWrapAround  = %x\n", saRoot->TraceMask & hpDBG_TraceBufferWrapAround ? 1 : 0));
179285809Sscottl  SA_DBG1 (("    da %p l %x\n",saRoot->TraceBuffer ,saRoot->TraceBufferLength));
180285809Sscottl
181285809Sscottl#ifdef SA_PRINTOUT_IN_WINDBG
182285809Sscottl#ifndef DBG
183285809Sscottl  DbgPrint("siTraceEnable: \n" );
184285809Sscottl
185285809Sscottl  DbgPrint("      length       = %08x\n", saRoot->TraceBufferLength );
186285809Sscottl  DbgPrint("      virt         = %p\n",   saRoot->TraceBuffer );
187285809Sscottl  DbgPrint("    last trace entry @ %p\n", &saRoot->CurrentTraceIndex);
188285809Sscottl  DbgPrint("    traceMask      = %08x @ %p\n", saRoot->TraceMask, &saRoot->TraceMask);
189285809Sscottl  DbgPrint("    da %p l %x\n",saRoot->TraceBuffer ,saRoot->TraceBufferLength);
190285809Sscottl#endif /* DBG  */
191285809Sscottl#endif /* SA_PRINTOUT_IN_WINDBG  */
192285809Sscottl  /*
193285809Sscottl  ** Init trace buffer with all spaces
194285809Sscottl  */
195285809Sscottl  for (count = 0; count < saRoot->TraceBufferLength; count++)
196285809Sscottl  {
197285809Sscottl      saRoot->TraceBuffer[count] = (bit8)' ';
198285809Sscottl  }
199285809Sscottl
200285809Sscottl}
201285809Sscottl
202285809Sscottl
203285809Sscottl
204285809Sscottl/**
205285809Sscottl * IF_DO_TRACE
206285809Sscottl *
207285809Sscottl * PURPOSE:     convenience macro for the "to output or not to output" logic
208285809Sscottl *
209285809Sscottl * PARAMETERS:
210285809Sscottl *
211285809Sscottl * CALLS:
212285809Sscottl *
213285809Sscottl * SIDE EFFECTS & CAVEATS:
214285809Sscottl *
215285809Sscottl * ALGORITHM:
216285809Sscottl *
217285809Sscottl *
218285809Sscottl *
219285809Sscottl *     MODIFICATION HISTORY     ***********************
220285809Sscottl *
221285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
222285809Sscottl * -------------    --------   -----------
223285809Sscottl */
224285809Sscottl
225285809Sscottl#define IF_DO_TRACE                                     \
226285809Sscottl  if ( (saRoot != NULL) &&                              \
227285809Sscottl       (saRoot->TraceDestination & siTraceDestMask) &&  \
228285809Sscottl       (mask & saRoot->TraceMask) )                     \
229285809Sscottl
230285809Sscottl
231285809Sscottl/* #define TRACE_ENTER_LOCK  ossaSingleThreadedEnter(agRoot, LL_TRACE_LOCK); */
232285809Sscottl/* #define TRACE_LEAVE_LOCK  ossaSingleThreadedLeave(agRoot, LL_TRACE_LOCK); */
233285809Sscottl#define TRACE_ENTER_LOCK
234285809Sscottl#define TRACE_LEAVE_LOCK
235285809Sscottl/**
236285809Sscottl * BUFFER_WRAP_CHECK
237285809Sscottl *
238285809Sscottl * PURPOSE: Checks if the tracing buffer tracing index is too high.  If it is,
239285809Sscottl *          the buffer index gets reset to 0 or tracing stops..
240285809Sscottl */
241285809Sscottl#define BUFFER_WRAP_CHECK                                           \
242285809Sscottl    if( (saRoot->CurrentTraceIndex + TMP_TRACE_BUFF_SIZE)               \
243285809Sscottl                           >= saRoot->TraceBufferLength )               \
244285809Sscottl    {                                                                   \
245285809Sscottl        /* Trace wrap-Around is enabled.  */                            \
246285809Sscottl        if( saRoot->TraceMask & hpDBG_TraceBufferWrapAround )           \
247285809Sscottl        {                                                               \
248285809Sscottl            /* Fill the end of the buffer with spaces */                \
249285809Sscottl            for( i = saRoot->CurrentTraceIndex;                         \
250285809Sscottl                     i < saRoot->TraceBufferLength; i++ )               \
251285809Sscottl            {                                                           \
252285809Sscottl                saRoot->TraceBuffer[i] = (bit8)' ';                     \
253285809Sscottl            }                                                           \
254285809Sscottl            /* Wrap the current trace index back to 0.. */              \
255285809Sscottl            saRoot->CurrentTraceIndex = 0;                              \
256285809Sscottl            saRoot->CurrentTraceIndexWrapCount++;                       \
257285809Sscottl        }                                                               \
258285809Sscottl        else                                                            \
259285809Sscottl        {                                                               \
260285809Sscottl            /* Don't do anything -- trace buffer is filled up */        \
261285809Sscottl            return;                                                     \
262285809Sscottl        }                                                               \
263285809Sscottl    }
264285809Sscottl
265285809Sscottl/**
266285809Sscottl * LOCAL_OS_LOG_DEBUG_STRING
267285809Sscottl *
268285809Sscottl * PURPOSE:     protects against a change in the api for this function
269285809Sscottl *
270285809Sscottl * PARAMETERS:
271285809Sscottl *
272285809Sscottl * CALLS:
273285809Sscottl *
274285809Sscottl * SIDE EFFECTS & CAVEATS:
275285809Sscottl *
276285809Sscottl * ALGORITHM:
277285809Sscottl *
278285809Sscottl *
279285809Sscottl *
280285809Sscottl *     MODIFICATION HISTORY     ***********************
281285809Sscottl *
282285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
283285809Sscottl * -------------    --------   -----------
284285809Sscottl * Laurent Chavey   03/09/00   - changed cast of 3rd parameter to (char *)
285285809Sscottl */
286285809Sscottl    #define LOCAL_OS_LOG_DEBUG_STRING(H,S)  \
287285809Sscottl            osLogDebugString(H,hpDBG_ALWAYS,(char *)(S))
288285809Sscottl
289285809Sscottl/******************************************************************************
290285809Sscottl*******************************************************************************
291285809Sscottl**
292285809Sscottl** copyHex
293285809Sscottl**
294285809Sscottl** PURPOSE:  Copies a hex version of a bit32 into a bit8 buffer
295285809Sscottl**
296285809Sscottl*******************************************************************************
297285809Sscottl******************************************************************************/
298285809Sscottl#define copyHex(bit32Val, bitSize)                                     \
299285809Sscottl{                                                                      \
300285809Sscottl  bit32 nibbleLen = bitSize / 4;                                       \
301285809Sscottl  bit32 scratch = 0;                                                   \
302285809Sscottl  for( i = 0; i < nibbleLen; i++ )                                     \
303285809Sscottl  {                                                                    \
304285809Sscottl    bPtr[pos++] =                                                      \
305285809Sscottl        saRoot->traceBuffLookup[0xf & (bit32Val >> ((bitSize - 4) - (i << 2)))];  \
306285809Sscottl    i++;                                                               \
307285809Sscottl    bPtr[pos++] =                                                      \
308285809Sscottl    saRoot->traceBuffLookup[0xf & (bit32Val >> ((bitSize - 4) - (i << 2)))]; \
309285809Sscottl    /* Skip leading 0-s to save memory buffer space */                 \
310285809Sscottl    if( !scratch                                                       \
311285809Sscottl          && (bPtr[pos-2] == '0')                                      \
312285809Sscottl          && (bPtr[pos-1] == '0') )                                    \
313285809Sscottl    {                                                                  \
314285809Sscottl      pos -= 2;                                                        \
315285809Sscottl      continue;                                                        \
316285809Sscottl    }                                                                  \
317285809Sscottl    else                                                               \
318285809Sscottl    {                                                                  \
319285809Sscottl      scratch = 1;                                                     \
320285809Sscottl    }                                                                  \
321285809Sscottl  }                                                                    \
322285809Sscottl  if( scratch == 0 )                                                   \
323285809Sscottl  {                                                                    \
324285809Sscottl    /* The value is 0 and nothing got put in the buffer.  Do       */  \
325285809Sscottl    /* print at least two zeros.                                   */  \
326285809Sscottl    bPtr[pos++] = '0';                                                 \
327285809Sscottl    bPtr[pos++] = '0';                                                 \
328285809Sscottl  }                                                                    \
329285809Sscottl}
330285809Sscottl
331285809Sscottl
332285809Sscottl/**
333285809Sscottl * TRACE_OTHER_DEST
334285809Sscottl *
335285809Sscottl * PURPOSE:  Check if any other destinations are enabled.  If yes, use them
336285809Sscottl *           for debug log.
337285809Sscottl */
338285809Sscottl#define TRACE_OTHER_DEST                                                \
339285809Sscottl    {                                                                   \
340285809Sscottl    bit32 bitptrscratch;                                                \
341285809Sscottl    if( saRoot->TraceDestination & smTraceDestDebugger )                \
342285809Sscottl    {                                                                   \
343285809Sscottl        bPtr[pos++] = (bit8)'\n';                                       \
344285809Sscottl        bPtr[pos++] = (bit8)0;                                          \
345285809Sscottl        LOCAL_OS_LOG_DEBUG_STRING(hpRoot, (char *)bPtr);                \
346285809Sscottl    }                                                                   \
347285809Sscottl    if( saRoot->TraceDestination & smTraceDestRegister )                \
348285809Sscottl    {                                                                   \
349285809Sscottl        while( (pos & 0x3) != 0x3 )                                     \
350285809Sscottl        {                                                               \
351285809Sscottl            bPtr[pos++] = (bit8)' ';                                    \
352285809Sscottl        }                                                               \
353285809Sscottl        bPtr[pos] = ' ';                                                \
354285809Sscottl        for( i = 0; i < pos; i = i + 4 )                                \
355285809Sscottl        {                                                               \
356285809Sscottl            bitptrscratch =  bPtr[i+0];                                 \
357285809Sscottl            bitptrscratch <<= 8;                                        \
358285809Sscottl            bitptrscratch |= bPtr[i+1];                                 \
359285809Sscottl            bitptrscratch <<= 8;                                        \
360285809Sscottl            bitptrscratch |= bPtr[i+2];                                 \
361285809Sscottl            bitptrscratch <<= 8;                                        \
362285809Sscottl            bitptrscratch |= bPtr[i+3];                                 \
363285809Sscottl            osChipRegWrite(hpRoot,                                      \
364285809Sscottl                 FC_rFMReceivedALPA, (bit32)bitptrscratch );            \
365285809Sscottl        }                                                               \
366285809Sscottl    }                                                                   \
367285809Sscottl    }
368285809Sscottl
369285809Sscottl
370285809Sscottl
371285809Sscottl/**
372285809Sscottl * siGetCurrentTraceIndex()
373285809Sscottl *
374285809Sscottl * PURPOSE:     Returns the current tracing index ( if tracing buffer is
375285809Sscottl *              used ).
376285809Sscottl *
377285809Sscottl * PARAMETERS:
378285809Sscottl *
379285809Sscottl * CALLS:
380285809Sscottl *
381285809Sscottl * SIDE EFFECTS & CAVEATS:
382285809Sscottl *
383285809Sscottl * ALGORITHM:
384285809Sscottl *
385285809Sscottl *
386285809Sscottl *     MODIFICATION HISTORY     ***********************
387285809Sscottl *
388285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
389285809Sscottl * -------------    --------   -----------
390285809Sscottl * Tom Nalepa       02/27/03
391285809Sscottl *
392285809Sscottl * @param hpRoot
393285809Sscottl *
394285809Sscottl * @return
395285809Sscottl */
396285809SscottlGLOBAL bit32 siGetCurrentTraceIndex(agsaRoot_t  *agRoot)
397285809Sscottl{
398285809Sscottl    agsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
399285809Sscottl    return(saRoot->CurrentTraceIndex);
400285809Sscottl}
401285809Sscottl
402285809Sscottl
403285809Sscottl
404285809Sscottl
405285809Sscottl/**
406285809Sscottl * siResetTraceBuffer
407285809Sscottl *
408285809Sscottl * PURPOSE:     Sets saRoot->CurrentTraceIndex to 0.
409285809Sscottl *
410285809Sscottl * @param hpRoot
411285809Sscottl *
412285809Sscottl * @return
413285809Sscottl */
414285809SscottlGLOBAL void siResetTraceBuffer(agsaRoot_t  *agRoot)
415285809Sscottl{
416285809Sscottl    bit32 count;
417285809Sscottl    agsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
418285809Sscottl    saRoot->CurrentTraceIndex = 0;
419285809Sscottl
420285809Sscottl    for ( count = 0; count < saRoot->TraceBufferLength; count++ )
421285809Sscottl    {
422285809Sscottl        saRoot->TraceBuffer[count] = (bit8)' ';
423285809Sscottl    }
424285809Sscottl}
425285809Sscottl
426285809Sscottl
427285809Sscottl/**
428285809Sscottl * siTraceFuncEnter
429285809Sscottl *
430285809Sscottl * PURPOSE:     Format a function entry trace and post it to the appropriate
431285809Sscottl *              destination.
432285809Sscottl *
433285809Sscottl * PARAMETERS:
434285809Sscottl *
435285809Sscottl * CALLS:
436285809Sscottl *
437285809Sscottl * SIDE EFFECTS & CAVEATS:
438285809Sscottl *
439285809Sscottl * ALGORITHM:
440285809Sscottl *
441285809Sscottl * siTraceFuncEnter  :    _[Xxxxx_
442285809Sscottl *                 fileid---^  ^------funcid
443285809Sscottl *
444285809Sscottl *
445285809Sscottl *     MODIFICATION HISTORY     ***********************
446285809Sscottl *
447285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
448285809Sscottl * -------------    --------   -----------
449285809Sscottl *
450285809Sscottl * @param hpRoot
451285809Sscottl * @param mask
452285809Sscottl * @param fileid
453285809Sscottl * @param funcid
454285809Sscottl *
455285809Sscottl * @return
456285809Sscottl */
457285809Sscottl
458285809Sscottl#define TMP_TRACE_BUFF_SIZE 32
459285809Sscottl
460285809Sscottl
461285809SscottlGLOBAL void siTraceFuncEnter( agsaRoot_t  *agRoot,
462285809Sscottl                             bit32        mask,
463285809Sscottl                             bit32        fileid,
464285809Sscottl                             char       * funcid)
465285809Sscottl{
466285809SscottlagsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
467285809Sscottl    bitptr         i;
468285809Sscottl    bit8           tmpB[TMP_TRACE_BUFF_SIZE];
469285809Sscottl    bit8          *bPtr;
470285809Sscottl    bit8           pos = 0;
471285809Sscottl
472285809Sscottl    IF_DO_TRACE
473285809Sscottl    {
474285809Sscottl      TRACE_ENTER_LOCK
475285809Sscottl      if ( saRoot->TraceDestination & smTraceDestBuffer )
476285809Sscottl      {
477285809Sscottl        BUFFER_WRAP_CHECK
478285809Sscottl        bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
479285809Sscottl      }
480285809Sscottl      else
481285809Sscottl      {
482285809Sscottl        bPtr = tmpB;
483285809Sscottl      }
484285809Sscottl      bPtr[pos++] = (bit8)'[';
485285809Sscottl
486285809Sscottl#ifndef FC_DO_NOT_INCLUDE_FILE_NAME_TAGS_IN_ENTER_EXIT_TRACE
487285809Sscottl        bPtr[pos++] = (bit8)fileid;
488285809Sscottl#endif
489285809Sscottl
490285809Sscottl        for ( i=0; i<4; i++ )
491285809Sscottl        {
492285809Sscottl            if ( funcid[i] == 0 )
493285809Sscottl            {
494285809Sscottl                break;
495285809Sscottl            }
496285809Sscottl            bPtr[pos++] = (bit8)funcid[i];
497285809Sscottl        }
498285809Sscottl        bPtr[pos++] = ' ';
499285809Sscottl        if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
500285809Sscottl        {
501285809Sscottl            bPtr[pos++] = '\r';
502285809Sscottl            bPtr[pos++] = '\n';
503285809Sscottl            saRoot->traceLineFeedCnt = 0;
504285809Sscottl        }
505285809Sscottl        saRoot->CurrentTraceIndex += pos;
506285809Sscottl//        TRACE_OTHER_DEST
507285809Sscottl    TRACE_LEAVE_LOCK
508285809Sscottl
509285809Sscottl    }
510285809Sscottl    return;
511285809Sscottl}
512285809Sscottl
513285809Sscottl
514285809Sscottl/**
515285809Sscottl * siTraceFuncExit
516285809Sscottl *
517285809Sscottl * PURPOSE:     Format a function exit trace and post it to the appropriate
518285809Sscottl *              destination.
519285809Sscottl *
520285809Sscottl * PARAMETERS:
521285809Sscottl *
522285809Sscottl * CALLS:
523285809Sscottl *
524285809Sscottl * SIDE EFFECTS & CAVEATS:
525285809Sscottl *
526285809Sscottl * ALGORITHM:
527285809Sscottl *
528285809Sscottl * siTraceFuncExit         _Xxxxx]_
529285809Sscottl *                 fileid---^  ^------funcid
530285809Sscottl *
531285809Sscottl *
532285809Sscottl *     MODIFICATION HISTORY     ***********************
533285809Sscottl *
534285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
535285809Sscottl * -------------    --------   -----------
536285809Sscottl *
537285809Sscottl * @param hpRoot
538285809Sscottl * @param mask
539285809Sscottl * @param fileid
540285809Sscottl * @param funcid
541285809Sscottl * @param exitId
542285809Sscottl *
543285809Sscottl * @return
544285809Sscottl */
545285809SscottlGLOBAL void siTraceFuncExit(   agsaRoot_t  *agRoot,  bit32   mask, char  fileid, char  * funcid, char  exitId )
546285809Sscottl{
547285809Sscottl    bitptr         i;
548285809Sscottl    bit8           tmpB[TMP_TRACE_BUFF_SIZE];
549285809Sscottl    bit8          *bPtr;
550285809Sscottl    bit8           pos = 0;
551285809Sscottl
552285809Sscottl    agsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
553285809Sscottl
554285809Sscottl    IF_DO_TRACE
555285809Sscottl    {
556285809Sscottl      TRACE_ENTER_LOCK
557285809Sscottl      if ( saRoot->TraceDestination & smTraceDestBuffer )
558285809Sscottl      {
559285809Sscottl        BUFFER_WRAP_CHECK
560285809Sscottl        bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
561285809Sscottl      }
562285809Sscottl      else
563285809Sscottl      {
564285809Sscottl        bPtr = tmpB;
565285809Sscottl      }
566285809Sscottl
567285809Sscottl#ifndef FC_DO_NOT_INCLUDE_FILE_NAME_TAGS_IN_ENTER_EXIT_TRACE
568285809Sscottl        bPtr[pos++] = (bit8)fileid;
569285809Sscottl#endif
570285809Sscottl
571285809Sscottl        for ( i=0; i<4; i++ )
572285809Sscottl        {
573285809Sscottl            if ( funcid[i] == 0 )
574285809Sscottl            {
575285809Sscottl                break;
576285809Sscottl            }
577285809Sscottl            bPtr[pos++] = (bit8)funcid[i];
578285809Sscottl        }
579285809Sscottl        bPtr[pos++] = (bit8)exitId;
580285809Sscottl        bPtr[pos++] = (bit8)']';
581285809Sscottl        bPtr[pos++] = (bit8)' ';
582285809Sscottl        if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
583285809Sscottl        {
584285809Sscottl            bPtr[pos++] = '\r';
585285809Sscottl            bPtr[pos++] = '\n';
586285809Sscottl            saRoot->traceLineFeedCnt = 0;
587285809Sscottl        }
588285809Sscottl        saRoot->CurrentTraceIndex += pos;
589285809Sscottl//        TRACE_OTHER_DEST
590285809Sscottl    TRACE_LEAVE_LOCK
591285809Sscottl    }
592285809Sscottl    return;
593285809Sscottl}
594285809Sscottl
595285809Sscottl/**
596285809Sscottl * siTraceListRemove
597285809Sscottl *
598285809Sscottl * PURPOSE:     Adds a trace tag for an exchange that is removed from a list
599285809Sscottl *
600285809Sscottl * PARAMETERS:
601285809Sscottl *
602285809Sscottl * CALLS:
603285809Sscottl *
604285809Sscottl * SIDE EFFECTS & CAVEATS:
605285809Sscottl *
606285809Sscottl * ALGORITHM:
607285809Sscottl *
608285809Sscottl *
609285809Sscottl *     MODIFICATION HISTORY     ***********************
610285809Sscottl *
611285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
612285809Sscottl * -------------    --------   -----------
613285809Sscottl * Tom Nalepa       12/16/02   Initial Developmet
614285809Sscottl *
615285809Sscottl * @param hpRoot
616285809Sscottl * @param mask
617285809Sscottl * @param listId
618285809Sscottl * @param exchangeId
619285809Sscottl *
620285809Sscottl * @return
621285809Sscottl */
622285809SscottlGLOBAL void siTraceListRemove(agsaRoot_t  *agRoot,
623285809Sscottl                              bit32        mask,
624285809Sscottl                              char         listId,
625285809Sscottl                              bitptr       exchangeId)
626285809Sscottl{
627285809Sscottl    agsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
628285809Sscottl    bitptr         i;
629285809Sscottl    bit8           tmpB[TMP_TRACE_BUFF_SIZE];
630285809Sscottl    bit8          *bPtr;
631285809Sscottl    bit8           pos = 0;
632285809Sscottl
633285809Sscottl    IF_DO_TRACE
634285809Sscottl    {
635285809Sscottl     TRACE_ENTER_LOCK
636285809Sscottl        if ( saRoot->TraceDestination & smTraceDestBuffer )
637285809Sscottl        {
638285809Sscottl            BUFFER_WRAP_CHECK
639285809Sscottl            bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
640285809Sscottl        }
641285809Sscottl        else
642285809Sscottl        {
643285809Sscottl            bPtr = tmpB;
644285809Sscottl        }
645285809Sscottl        bPtr[pos++] = (bit8)'<';
646285809Sscottl        bPtr[pos++] = (bit8)listId;
647285809Sscottl        copyHex(exchangeId, 32);
648285809Sscottl        bPtr[pos++] = (bit8)' ';
649285809Sscottl        if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
650285809Sscottl        {
651285809Sscottl            bPtr[pos++] = '\r';
652285809Sscottl            bPtr[pos++] = '\n';
653285809Sscottl            saRoot->traceLineFeedCnt = 0;
654285809Sscottl        }
655285809Sscottl        saRoot->CurrentTraceIndex += pos;
656285809Sscottl//        TRACE_OTHER_DEST
657285809Sscottl    TRACE_LEAVE_LOCK
658285809Sscottl    }
659285809Sscottl    return;
660285809Sscottl}
661285809Sscottl
662285809Sscottl/**
663285809Sscottl * siTraceListAdd
664285809Sscottl *
665285809Sscottl * PURPOSE:     Adds a trace tag for an exchange that is added to a list
666285809Sscottl *
667285809Sscottl * PARAMETERS:
668285809Sscottl *
669285809Sscottl * CALLS:
670285809Sscottl *
671285809Sscottl * SIDE EFFECTS & CAVEATS:
672285809Sscottl *
673285809Sscottl * ALGORITHM:
674285809Sscottl *
675285809Sscottl *
676285809Sscottl *     MODIFICATION HISTORY     ***********************
677285809Sscottl *
678285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
679285809Sscottl * -------------    --------   -----------
680285809Sscottl * Tom Nalepa       12/16/02   Initial Developmet
681285809Sscottl *
682285809Sscottl * @param hpRoot
683285809Sscottl * @param mask
684285809Sscottl * @param listId
685285809Sscottl * @param exchangeId
686285809Sscottl *
687285809Sscottl * @return
688285809Sscottl */
689285809SscottlGLOBAL void siTraceListAdd(agsaRoot_t      *agRoot,
690285809Sscottl                           bit32        mask,
691285809Sscottl                           char         listId,
692285809Sscottl                           bitptr       exchangeId)
693285809Sscottl{
694285809Sscottl
695285809Sscottl  agsaLLRoot_t          *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
696285809Sscottl
697285809Sscottl    bitptr         i;
698285809Sscottl    bit8           tmpB[TMP_TRACE_BUFF_SIZE];
699285809Sscottl    bit8          *bPtr;
700285809Sscottl    bit8           pos = 0;
701285809Sscottl
702285809Sscottl    IF_DO_TRACE
703285809Sscottl    {
704285809Sscottl        if ( saRoot->TraceDestination & smTraceDestBuffer )
705285809Sscottl        {
706285809Sscottl            BUFFER_WRAP_CHECK
707285809Sscottl            bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
708285809Sscottl        }
709285809Sscottl        else
710285809Sscottl        {
711285809Sscottl            bPtr = tmpB;
712285809Sscottl        }
713285809Sscottl        bPtr[pos++] = (bit8)'>';
714285809Sscottl        bPtr[pos++] = (bit8)listId;
715285809Sscottl        copyHex(exchangeId, 32);
716285809Sscottl        bPtr[pos++] = (bit8)' ';
717285809Sscottl        if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
718285809Sscottl        {
719285809Sscottl            bPtr[pos++] = '\r';
720285809Sscottl            bPtr[pos++] = '\n';
721285809Sscottl            saRoot->traceLineFeedCnt = 0;
722285809Sscottl        }
723285809Sscottl        saRoot->CurrentTraceIndex += pos;
724285809Sscottl//        TRACE_OTHER_DEST
725285809Sscottl    }
726285809Sscottl    return;
727285809Sscottl}
728285809Sscottl
729285809Sscottl/**
730285809Sscottl * siTrace64
731285809Sscottl *
732285809Sscottl * PURPOSE:     Format a function parameter trace and post it to the appropriate
733285809Sscottl *              destination.
734285809Sscottl *
735285809Sscottl * PARAMETERS:
736285809Sscottl *
737285809Sscottl * CALLS:
738285809Sscottl *
739285809Sscottl * SIDE EFFECTS & CAVEATS:
740285809Sscottl *
741285809Sscottl * ALGORITHM:
742285809Sscottl *
743285809Sscottl * siTrace : index is 0 for return value, 1 for first parm after "("
744285809Sscottl *           produces:   _nn" XXXXXXXXXX
745285809Sscottl *           index-----^    value--^
746285809Sscottl *
747285809Sscottl *
748285809Sscottl *     MODIFICATION HISTORY     ***********************
749285809Sscottl *
750285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
751285809Sscottl * -------------    --------   -----------
752285809Sscottl *
753285809Sscottl * @param hpRoot
754285809Sscottl * @param mask
755285809Sscottl * @param uId
756285809Sscottl * @param value
757285809Sscottl *
758285809Sscottl * @return
759285809Sscottl */
760285809SscottlGLOBAL void siTrace64(agsaRoot_t      *agRoot,
761285809Sscottl                      bit32        mask,
762285809Sscottl                      char       * uId,
763285809Sscottl                      bit64        value,
764285809Sscottl                      bit32        dataSizeInBits)
765285809Sscottl{
766285809Sscottl
767285809Sscottl    agsaLLRoot_t  *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
768285809Sscottl    bitptr         i;
769285809Sscottl    bit8           tmpB[TMP_TRACE_BUFF_SIZE];
770285809Sscottl    bit8          *bPtr;
771285809Sscottl    bit8           pos = 0;
772285809Sscottl
773285809Sscottl    IF_DO_TRACE
774285809Sscottl    {
775285809Sscottl        if ( saRoot->TraceDestination & smTraceDestBuffer )
776285809Sscottl        {
777285809Sscottl            BUFFER_WRAP_CHECK
778285809Sscottl            bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
779285809Sscottl        }
780285809Sscottl        else
781285809Sscottl        {
782285809Sscottl            bPtr = tmpB;
783285809Sscottl        }
784285809Sscottl        bPtr[pos++] = (bit8)'"';
785285809Sscottl        bPtr[pos++] = (bit8)uId[0];
786285809Sscottl        bPtr[pos++] = (bit8)uId[1];
787285809Sscottl        bPtr[pos++] = (bit8)':';
788285809Sscottl        copyHex(value, dataSizeInBits);
789285809Sscottl        bPtr[pos++] = (bit8)' ';
790285809Sscottl        if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
791285809Sscottl        {
792285809Sscottl            bPtr[pos++] = '\r';
793285809Sscottl            bPtr[pos++] = '\n';
794285809Sscottl            saRoot->traceLineFeedCnt = 0;
795285809Sscottl        }
796285809Sscottl        saRoot->CurrentTraceIndex += pos;
797285809Sscottl//        TRACE_OTHER_DEST
798285809Sscottl    }
799285809Sscottl    return;
800285809Sscottl}
801285809Sscottl
802285809Sscottl
803285809Sscottl
804285809Sscottl/**
805285809Sscottl * siTrace
806285809Sscottl *
807285809Sscottl * PURPOSE:     Format a function parameter trace and post it to the appropriate
808285809Sscottl *              destination.
809285809Sscottl *
810285809Sscottl * PARAMETERS:
811285809Sscottl *
812285809Sscottl * CALLS:
813285809Sscottl *
814285809Sscottl * SIDE EFFECTS & CAVEATS:
815285809Sscottl *
816285809Sscottl * ALGORITHM:
817285809Sscottl *
818285809Sscottl * fiTrace : index is 0 for return value, 1 for first parm after "("
819285809Sscottl *           produces:   _nn" XXXXXXXXXX
820285809Sscottl *           index-----^    value--^
821285809Sscottl *
822285809Sscottl *
823285809Sscottl *     MODIFICATION HISTORY     ***********************
824285809Sscottl *
825285809Sscottl * ENGINEER NAME      DATE     DESCRIPTION
826285809Sscottl * -------------    --------   -----------
827285809Sscottl *
828285809Sscottl * @param hpRoot
829285809Sscottl * @param mask
830285809Sscottl * @param uId
831285809Sscottl * @param value
832285809Sscottl *
833285809Sscottl * @return
834285809Sscottl */
835285809SscottlGLOBAL void siTrace( agsaRoot_t      *agRoot,
836285809Sscottl                    bit32        mask,
837285809Sscottl                    char       * uId,
838285809Sscottl                    bit32        value,
839285809Sscottl                    bit32        dataSizeInBits)
840285809Sscottl{
841285809Sscottl
842285809Sscottl   agsaLLRoot_t   *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
843285809Sscottl
844285809Sscottl    bitptr         i;
845285809Sscottl    bit8           tmpB[TMP_TRACE_BUFF_SIZE];
846285809Sscottl    bit8          *bPtr;
847285809Sscottl    bit8           pos = 0;
848285809Sscottl
849285809Sscottl    IF_DO_TRACE
850285809Sscottl    {
851285809Sscottl        if ( saRoot->TraceDestination & smTraceDestBuffer )
852285809Sscottl        {
853285809Sscottl            BUFFER_WRAP_CHECK
854285809Sscottl            bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
855285809Sscottl        }
856285809Sscottl        else
857285809Sscottl        {
858285809Sscottl            bPtr = tmpB;
859285809Sscottl        }
860285809Sscottl        bPtr[pos++] = (bit8)'"';
861285809Sscottl        bPtr[pos++] = (bit8)uId[0];
862285809Sscottl        bPtr[pos++] = (bit8)uId[1];
863285809Sscottl        bPtr[pos++] = (bit8)':';
864285809Sscottl        copyHex(value, dataSizeInBits);
865285809Sscottl        bPtr[pos++] = (bit8)' ';
866285809Sscottl        if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
867285809Sscottl        {
868285809Sscottl            bPtr[pos++] = '\r';
869285809Sscottl            bPtr[pos++] = '\n';
870285809Sscottl            saRoot->traceLineFeedCnt = 0;
871285809Sscottl        }
872285809Sscottl        saRoot->CurrentTraceIndex += pos;
873285809Sscottl//        TRACE_OTHER_DEST
874285809Sscottl    }
875285809Sscottl    return;
876285809Sscottl}
877285809Sscottl
878285809Sscottl
879285809Sscottl/*Set Wrap 0 for Wrapping non zero stops when full  */
880285809Sscottl
881285809Sscottl
882285809SscottlGLOBAL void siTraceGetInfo(agsaRoot_t  *agRoot, hpTraceBufferParms_t * pBParms)
883285809Sscottl{
884285809Sscottl    agsaLLRoot_t  *saRoot = (agsaLLRoot_t *)agRoot->sdkData;
885285809Sscottl
886285809Sscottl    pBParms->TraceCompiled  =  TRUE;
887285809Sscottl
888285809Sscottl    pBParms->TraceWrap                  = saRoot->TraceMask & 0x80000000;
889285809Sscottl    pBParms->CurrentTraceIndexWrapCount = saRoot->CurrentTraceIndexWrapCount;
890285809Sscottl    pBParms->BufferSize                 = saRoot->TraceBufferLength;
891285809Sscottl    pBParms->CurrentIndex               = saRoot->CurrentTraceIndex;
892285809Sscottl    pBParms->pTrace                     = saRoot->TraceBuffer;
893285809Sscottl    pBParms->pTraceIndexWrapCount       = &saRoot->CurrentTraceIndexWrapCount;
894285809Sscottl    pBParms->pTraceMask                 = &saRoot->TraceMask;
895285809Sscottl    pBParms->pCurrentTraceIndex         = &saRoot->CurrentTraceIndex;
896285809Sscottl}
897285809Sscottl/**/
898285809Sscottl
899285809SscottlGLOBAL void siTraceSetMask(agsaRoot_t  *agRoot, bit32 TraceMask  )
900285809Sscottl{
901285809Sscottl    agsaLLRoot_t  *saRoot = (agsaLLRoot_t *)agRoot->sdkData;
902285809Sscottl    saRoot->TraceMask = TraceMask;
903285809Sscottl}
904285809Sscottl
905285809Sscottl
906285809Sscottl
907285809Sscottl#endif
908285809Sscottl
909285809Sscottl
910