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 ********************************************************************************/
23 /*******************************************************************************/
25 * \brief The file is a MPI Libraries to implement the MPI debug and trace functions
27 * The file implements the MPI functions.
30 /*******************************************************************************/
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 #include <dev/pms/config.h>
35 #include <dev/pms/RefTisa/sallsdk/spc/saglobal.h>
36 #ifdef MPI_DEBUG_TRACE_ENABLE /* enable with CCBUILD_MPI_TRACE*/
38 /*******************************************************************************/
40 #ifdef OSLAYER_USE_HI_RES_TIMER
42 GetHiResTimeStamp(void);
43 #endif /* OSLAYER_USE_HI_RES_TIMER */
44 /*******************************************************************************/
45 /*******************************************************************************/
47 /*******************************************************************************/
48 mpiDebugObTrace_t obTraceData;
49 mpiDebugIbTrace_t ibTraceData;
51 void mpiTraceInit(void)
54 SA_DBG1(("mpiTraceInit:obTraceData @ %p\n",&obTraceData ));
55 SA_DBG1(("mpiTraceInit:ibTraceData @ %p\n",&ibTraceData ));
56 SA_DBG1(("mpiTraceInit: num enties %d Ib Iomb size %d Ob Iomb size %d\n",
57 MPI_DEBUG_TRACE_BUFFER_MAX,
58 MPI_DEBUG_TRACE_IB_IOMB_SIZE,
59 MPI_DEBUG_TRACE_OB_IOMB_SIZE ));
61 si_memset(&obTraceData, 0, sizeof(obTraceData));
62 si_memset(&ibTraceData, 0, sizeof(ibTraceData));
65 void mpiTraceAdd( bit32 q,bit32 pici,bit32 ib, void *iomb, bit32 numBytes)
68 mpiDebugIbTraceEntry_t *curIbTrace;
69 mpiDebugObTraceEntry_t *curObTrace;
71 mpiDebugIbTrace_t * ibTrace = &ibTraceData;
72 mpiDebugObTrace_t * obTrace = &obTraceData;
76 if(ibTrace->Idx >= MPI_DEBUG_TRACE_BUFFER_MAX)
80 curIdx = ibTrace->Idx;
82 curIbTrace = &ibTrace->Data[curIdx];
83 curIbTrace->pEntry = iomb;
85 curIbTrace->pici = pici;
86 #ifdef OSLAYER_USE_HI_RES_TIMER
87 #ifdef SA_64BIT_TIMESTAMP
88 curIbTrace->Time = ossaTimeStamp64(agNULL);
89 #else /* SA_64BIT_TIMESTAMP */
90 curIbTrace->Time = ossaTimeStamp(agNULL);
91 #endif /* SA_64BIT_TIMESTAMP */
92 #else /* OSLAYER_USE_HI_RES_TIMER */
95 si_memcpy(curIbTrace->Iomb, iomb, MIN(numBytes, MPI_DEBUG_TRACE_IB_IOMB_SIZE));
100 if(obTrace->Idx >= MPI_DEBUG_TRACE_BUFFER_MAX )
104 curIdx = obTrace->Idx;
105 curObTrace = &obTrace->Data[curIdx];
106 curObTrace->pEntry = iomb;
107 curObTrace->QNum = q;
108 curObTrace->pici = pici;
109 #ifdef OSLAYER_USE_HI_RES_TIMER
110 #ifdef SA_64BIT_TIMESTAMP
111 curObTrace->Time = ossaTimeStamp64(agNULL);
112 #else /* SA_64BIT_TIMESTAMP */
113 curObTrace->Time = ossaTimeStamp(agNULL);
114 #endif /* SA_64BIT_TIMESTAMP */
115 #else /* OSLAYER_USE_HI_RES_TIMER */
116 curObTrace->Time = 0;
118 si_memcpy(curObTrace->Iomb, iomb, MIN(numBytes, MPI_DEBUG_TRACE_OB_IOMB_SIZE));
126 #endif /* MPI_DEBUG_TRACE_ENABLE */
130 #ifdef SA_ENABLE_TRACE_FUNCTIONS
135 * This fucntion is called to initialize tracing of FC layer.
138 void siEnableTracing (agsaRoot_t *agRoot)
141 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
142 agsaSwConfig_t *swC = &saRoot->swConfig;
145 OS_ASSERT(saRoot != NULL, "");
147 if( saRoot->TraceBlockReInit != 0)
153 /* Initialize tracing first */
155 for (count = 0; count < 10; count++)
157 saRoot->traceBuffLookup[count] = (bit8)('0' + count);
159 for (count = 0; count < 6; count++)
161 saRoot->traceBuffLookup[(bitptr)count + 10] = (bit8)('a' + count);
165 saRoot->TraceDestination = swC->TraceDestination;
166 saRoot->TraceMask = swC->TraceMask;
167 saRoot->CurrentTraceIndexWrapCount = 0;
168 saRoot->CurrentTraceIndex = 0;
169 saRoot->TraceBlockReInit = 1;
172 SA_DBG1(("siEnableTracing: \n" ));
174 SA_DBG1 ((" length = %08x\n", saRoot->TraceBufferLength ));
175 SA_DBG1 ((" virt = %p\n", saRoot->TraceBuffer ));
176 SA_DBG1 ((" traceMask = %08x @ %p\n", saRoot->TraceMask, &saRoot->TraceMask));
177 SA_DBG1 ((" last trace entry @ %p\n", &saRoot->CurrentTraceIndex));
178 SA_DBG1 ((" TraceWrapAround = %x\n", saRoot->TraceMask & hpDBG_TraceBufferWrapAround ? 1 : 0));
179 SA_DBG1 ((" da %p l %x\n",saRoot->TraceBuffer ,saRoot->TraceBufferLength));
181 #ifdef SA_PRINTOUT_IN_WINDBG
183 DbgPrint("siTraceEnable: \n" );
185 DbgPrint(" length = %08x\n", saRoot->TraceBufferLength );
186 DbgPrint(" virt = %p\n", saRoot->TraceBuffer );
187 DbgPrint(" last trace entry @ %p\n", &saRoot->CurrentTraceIndex);
188 DbgPrint(" traceMask = %08x @ %p\n", saRoot->TraceMask, &saRoot->TraceMask);
189 DbgPrint(" da %p l %x\n",saRoot->TraceBuffer ,saRoot->TraceBufferLength);
191 #endif /* SA_PRINTOUT_IN_WINDBG */
193 ** Init trace buffer with all spaces
195 for (count = 0; count < saRoot->TraceBufferLength; count++)
197 saRoot->TraceBuffer[count] = (bit8)' ';
207 * PURPOSE: convenience macro for the "to output or not to output" logic
213 * SIDE EFFECTS & CAVEATS:
219 * MODIFICATION HISTORY ***********************
221 * ENGINEER NAME DATE DESCRIPTION
222 * ------------- -------- -----------
225 #define IF_DO_TRACE \
226 if ( (saRoot != NULL) && \
227 (saRoot->TraceDestination & siTraceDestMask) && \
228 (mask & saRoot->TraceMask) ) \
231 /* #define TRACE_ENTER_LOCK ossaSingleThreadedEnter(agRoot, LL_TRACE_LOCK); */
232 /* #define TRACE_LEAVE_LOCK ossaSingleThreadedLeave(agRoot, LL_TRACE_LOCK); */
233 #define TRACE_ENTER_LOCK
234 #define TRACE_LEAVE_LOCK
238 * PURPOSE: Checks if the tracing buffer tracing index is too high. If it is,
239 * the buffer index gets reset to 0 or tracing stops..
241 #define BUFFER_WRAP_CHECK \
242 if( (saRoot->CurrentTraceIndex + TMP_TRACE_BUFF_SIZE) \
243 >= saRoot->TraceBufferLength ) \
245 /* Trace wrap-Around is enabled. */ \
246 if( saRoot->TraceMask & hpDBG_TraceBufferWrapAround ) \
248 /* Fill the end of the buffer with spaces */ \
249 for( i = saRoot->CurrentTraceIndex; \
250 i < saRoot->TraceBufferLength; i++ ) \
252 saRoot->TraceBuffer[i] = (bit8)' '; \
254 /* Wrap the current trace index back to 0.. */ \
255 saRoot->CurrentTraceIndex = 0; \
256 saRoot->CurrentTraceIndexWrapCount++; \
260 /* Don't do anything -- trace buffer is filled up */ \
266 * LOCAL_OS_LOG_DEBUG_STRING
268 * PURPOSE: protects against a change in the api for this function
274 * SIDE EFFECTS & CAVEATS:
280 * MODIFICATION HISTORY ***********************
282 * ENGINEER NAME DATE DESCRIPTION
283 * ------------- -------- -----------
284 * Laurent Chavey 03/09/00 - changed cast of 3rd parameter to (char *)
286 #define LOCAL_OS_LOG_DEBUG_STRING(H,S) \
287 osLogDebugString(H,hpDBG_ALWAYS,(char *)(S))
289 /******************************************************************************
290 *******************************************************************************
294 ** PURPOSE: Copies a hex version of a bit32 into a bit8 buffer
296 *******************************************************************************
297 ******************************************************************************/
298 #define copyHex(bit32Val, bitSize) \
300 bit32 nibbleLen = bitSize / 4; \
302 for( i = 0; i < nibbleLen; i++ ) \
305 saRoot->traceBuffLookup[0xf & (bit32Val >> ((bitSize - 4) - (i << 2)))]; \
308 saRoot->traceBuffLookup[0xf & (bit32Val >> ((bitSize - 4) - (i << 2)))]; \
309 /* Skip leading 0-s to save memory buffer space */ \
311 && (bPtr[pos-2] == '0') \
312 && (bPtr[pos-1] == '0') ) \
324 /* The value is 0 and nothing got put in the buffer. Do */ \
325 /* print at least two zeros. */ \
335 * PURPOSE: Check if any other destinations are enabled. If yes, use them
338 #define TRACE_OTHER_DEST \
340 bit32 bitptrscratch; \
341 if( saRoot->TraceDestination & smTraceDestDebugger ) \
343 bPtr[pos++] = (bit8)'\n'; \
344 bPtr[pos++] = (bit8)0; \
345 LOCAL_OS_LOG_DEBUG_STRING(hpRoot, (char *)bPtr); \
347 if( saRoot->TraceDestination & smTraceDestRegister ) \
349 while( (pos & 0x3) != 0x3 ) \
351 bPtr[pos++] = (bit8)' '; \
354 for( i = 0; i < pos; i = i + 4 ) \
356 bitptrscratch = bPtr[i+0]; \
357 bitptrscratch <<= 8; \
358 bitptrscratch |= bPtr[i+1]; \
359 bitptrscratch <<= 8; \
360 bitptrscratch |= bPtr[i+2]; \
361 bitptrscratch <<= 8; \
362 bitptrscratch |= bPtr[i+3]; \
363 osChipRegWrite(hpRoot, \
364 FC_rFMReceivedALPA, (bit32)bitptrscratch ); \
372 * siGetCurrentTraceIndex()
374 * PURPOSE: Returns the current tracing index ( if tracing buffer is
381 * SIDE EFFECTS & CAVEATS:
386 * MODIFICATION HISTORY ***********************
388 * ENGINEER NAME DATE DESCRIPTION
389 * ------------- -------- -----------
390 * Tom Nalepa 02/27/03
396 GLOBAL bit32 siGetCurrentTraceIndex(agsaRoot_t *agRoot)
398 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
399 return(saRoot->CurrentTraceIndex);
408 * PURPOSE: Sets saRoot->CurrentTraceIndex to 0.
414 GLOBAL void siResetTraceBuffer(agsaRoot_t *agRoot)
417 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
418 saRoot->CurrentTraceIndex = 0;
420 for ( count = 0; count < saRoot->TraceBufferLength; count++ )
422 saRoot->TraceBuffer[count] = (bit8)' ';
430 * PURPOSE: Format a function entry trace and post it to the appropriate
437 * SIDE EFFECTS & CAVEATS:
441 * siTraceFuncEnter : _[Xxxxx_
442 * fileid---^ ^------funcid
445 * MODIFICATION HISTORY ***********************
447 * ENGINEER NAME DATE DESCRIPTION
448 * ------------- -------- -----------
458 #define TMP_TRACE_BUFF_SIZE 32
461 GLOBAL void siTraceFuncEnter( agsaRoot_t *agRoot,
466 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
468 bit8 tmpB[TMP_TRACE_BUFF_SIZE];
475 if ( saRoot->TraceDestination & smTraceDestBuffer )
478 bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
484 bPtr[pos++] = (bit8)'[';
486 #ifndef FC_DO_NOT_INCLUDE_FILE_NAME_TAGS_IN_ENTER_EXIT_TRACE
487 bPtr[pos++] = (bit8)fileid;
490 for ( i=0; i<4; i++ )
492 if ( funcid[i] == 0 )
496 bPtr[pos++] = (bit8)funcid[i];
499 if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
503 saRoot->traceLineFeedCnt = 0;
505 saRoot->CurrentTraceIndex += pos;
517 * PURPOSE: Format a function exit trace and post it to the appropriate
524 * SIDE EFFECTS & CAVEATS:
528 * siTraceFuncExit _Xxxxx]_
529 * fileid---^ ^------funcid
532 * MODIFICATION HISTORY ***********************
534 * ENGINEER NAME DATE DESCRIPTION
535 * ------------- -------- -----------
545 GLOBAL void siTraceFuncExit( agsaRoot_t *agRoot, bit32 mask, char fileid, char * funcid, char exitId )
548 bit8 tmpB[TMP_TRACE_BUFF_SIZE];
552 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
557 if ( saRoot->TraceDestination & smTraceDestBuffer )
560 bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
567 #ifndef FC_DO_NOT_INCLUDE_FILE_NAME_TAGS_IN_ENTER_EXIT_TRACE
568 bPtr[pos++] = (bit8)fileid;
571 for ( i=0; i<4; i++ )
573 if ( funcid[i] == 0 )
577 bPtr[pos++] = (bit8)funcid[i];
579 bPtr[pos++] = (bit8)exitId;
580 bPtr[pos++] = (bit8)']';
581 bPtr[pos++] = (bit8)' ';
582 if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
586 saRoot->traceLineFeedCnt = 0;
588 saRoot->CurrentTraceIndex += pos;
598 * PURPOSE: Adds a trace tag for an exchange that is removed from a list
604 * SIDE EFFECTS & CAVEATS:
609 * MODIFICATION HISTORY ***********************
611 * ENGINEER NAME DATE DESCRIPTION
612 * ------------- -------- -----------
613 * Tom Nalepa 12/16/02 Initial Developmet
622 GLOBAL void siTraceListRemove(agsaRoot_t *agRoot,
627 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
629 bit8 tmpB[TMP_TRACE_BUFF_SIZE];
636 if ( saRoot->TraceDestination & smTraceDestBuffer )
639 bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
645 bPtr[pos++] = (bit8)'<';
646 bPtr[pos++] = (bit8)listId;
647 copyHex(exchangeId, 32);
648 bPtr[pos++] = (bit8)' ';
649 if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
653 saRoot->traceLineFeedCnt = 0;
655 saRoot->CurrentTraceIndex += pos;
665 * PURPOSE: Adds a trace tag for an exchange that is added to a list
671 * SIDE EFFECTS & CAVEATS:
676 * MODIFICATION HISTORY ***********************
678 * ENGINEER NAME DATE DESCRIPTION
679 * ------------- -------- -----------
680 * Tom Nalepa 12/16/02 Initial Developmet
689 GLOBAL void siTraceListAdd(agsaRoot_t *agRoot,
695 agsaLLRoot_t *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
698 bit8 tmpB[TMP_TRACE_BUFF_SIZE];
704 if ( saRoot->TraceDestination & smTraceDestBuffer )
707 bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
713 bPtr[pos++] = (bit8)'>';
714 bPtr[pos++] = (bit8)listId;
715 copyHex(exchangeId, 32);
716 bPtr[pos++] = (bit8)' ';
717 if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
721 saRoot->traceLineFeedCnt = 0;
723 saRoot->CurrentTraceIndex += pos;
732 * PURPOSE: Format a function parameter trace and post it to the appropriate
739 * SIDE EFFECTS & CAVEATS:
743 * siTrace : index is 0 for return value, 1 for first parm after "("
744 * produces: _nn" XXXXXXXXXX
745 * index-----^ value--^
748 * MODIFICATION HISTORY ***********************
750 * ENGINEER NAME DATE DESCRIPTION
751 * ------------- -------- -----------
760 GLOBAL void siTrace64(agsaRoot_t *agRoot,
764 bit32 dataSizeInBits)
767 agsaLLRoot_t *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
769 bit8 tmpB[TMP_TRACE_BUFF_SIZE];
775 if ( saRoot->TraceDestination & smTraceDestBuffer )
778 bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
784 bPtr[pos++] = (bit8)'"';
785 bPtr[pos++] = (bit8)uId[0];
786 bPtr[pos++] = (bit8)uId[1];
787 bPtr[pos++] = (bit8)':';
788 copyHex(value, dataSizeInBits);
789 bPtr[pos++] = (bit8)' ';
790 if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
794 saRoot->traceLineFeedCnt = 0;
796 saRoot->CurrentTraceIndex += pos;
807 * PURPOSE: Format a function parameter trace and post it to the appropriate
814 * SIDE EFFECTS & CAVEATS:
818 * fiTrace : index is 0 for return value, 1 for first parm after "("
819 * produces: _nn" XXXXXXXXXX
820 * index-----^ value--^
823 * MODIFICATION HISTORY ***********************
825 * ENGINEER NAME DATE DESCRIPTION
826 * ------------- -------- -----------
835 GLOBAL void siTrace( agsaRoot_t *agRoot,
839 bit32 dataSizeInBits)
842 agsaLLRoot_t *saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
845 bit8 tmpB[TMP_TRACE_BUFF_SIZE];
851 if ( saRoot->TraceDestination & smTraceDestBuffer )
854 bPtr = &saRoot->TraceBuffer[saRoot->CurrentTraceIndex];
860 bPtr[pos++] = (bit8)'"';
861 bPtr[pos++] = (bit8)uId[0];
862 bPtr[pos++] = (bit8)uId[1];
863 bPtr[pos++] = (bit8)':';
864 copyHex(value, dataSizeInBits);
865 bPtr[pos++] = (bit8)' ';
866 if ( saRoot->traceLineFeedCnt > FC_TRACE_LINE_SIZE )
870 saRoot->traceLineFeedCnt = 0;
872 saRoot->CurrentTraceIndex += pos;
879 /*Set Wrap 0 for Wrapping non zero stops when full */
882 GLOBAL void siTraceGetInfo(agsaRoot_t *agRoot, hpTraceBufferParms_t * pBParms)
884 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)agRoot->sdkData;
886 pBParms->TraceCompiled = TRUE;
888 pBParms->TraceWrap = saRoot->TraceMask & 0x80000000;
889 pBParms->CurrentTraceIndexWrapCount = saRoot->CurrentTraceIndexWrapCount;
890 pBParms->BufferSize = saRoot->TraceBufferLength;
891 pBParms->CurrentIndex = saRoot->CurrentTraceIndex;
892 pBParms->pTrace = saRoot->TraceBuffer;
893 pBParms->pTraceIndexWrapCount = &saRoot->CurrentTraceIndexWrapCount;
894 pBParms->pTraceMask = &saRoot->TraceMask;
895 pBParms->pCurrentTraceIndex = &saRoot->CurrentTraceIndex;
899 GLOBAL void siTraceSetMask(agsaRoot_t *agRoot, bit32 TraceMask )
901 agsaLLRoot_t *saRoot = (agsaLLRoot_t *)agRoot->sdkData;
902 saRoot->TraceMask = TraceMask;