--- a/kernel/eka/drivers/usbc/usbdma.cpp Thu Aug 19 11:14:22 2010 +0300
+++ b/kernel/eka/drivers/usbc/usbdma.cpp Tue Aug 31 16:34:26 2010 +0300
@@ -23,6 +23,11 @@
*/
#include <drivers/usbc.h>
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "usbdmaTraces.h"
+#endif
+
#if defined(_DEBUG)
@@ -102,20 +107,25 @@
// At most 2 packets (clump of max packet size packets) + possible zlp
TUsbcPacketArray* bufPtr = iPacketInfoStorage;
// this divides up the packet indexing & packet size array over the number of buffers
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Construct() array base=0x%08x", bufPtr));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_CONSTRUCT,
+ "TDmaBuf::Construct() array base=0x%08x", bufPtr );
for (TInt i = 0; i < iNumberofBuffers; i++)
{
iPacketIndex[i] = bufPtr;
bufPtr += KUsbcDmaBufMaxPkts;
iPacketSize[i] = bufPtr;
bufPtr += KUsbcDmaBufMaxPkts;
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Construct() packetIndex[%d]=0x%08x packetSize[%d]=0x%08x",
- i, iPacketIndex[i], i, iPacketSize[i]));
+ OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_CONSTRUCT_DUP1,
+ "TDmaBuf::Construct() packetIndex[%d]=0x%08x packetSize[%d]=0x%08x",
+ i, reinterpret_cast<TUint>(iPacketIndex[i]), i,
+ reinterpret_cast<TUint>(iPacketSize[i]) );
+
}
}
else
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Construct() IN endpoint"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_CONSTRUCT_DUP2,
+ "TDmaBuf::Construct() IN endpoint" );
}
Flush();
return KErrNone;
@@ -124,7 +134,7 @@
TDmaBuf::~TDmaBuf()
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::~TDmaBuf()"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TDMABUF_TDMABUF_DES, "TDmaBuf::~TDmaBuf()" );
}
TInt TDmaBuf::BufferTotalSize() const
@@ -144,7 +154,9 @@
iDrainable[aBufInd] = iCanBeFreed[aBufInd] = EFalse;
iBuffers[aBufInd] = aBufAddr;
iBufferPhys[aBufInd] = Epoc::LinearToPhysical((TLinAddr)aBufAddr);
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::SetBufferAddr() iBuffers[%d]=0x%08x", aBufInd, iBuffers[aBufInd]));
+ OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_SETBUFFERADDR,
+ "TDmaBuf::SetBufferAddr() iBuffers[%d]=0x%08x", aBufInd,
+ reinterpret_cast<TUint>(iBuffers[aBufInd]) );
return KErrNone;
}
@@ -161,7 +173,8 @@
void TDmaBuf::Flush()
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Flush %x", this));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_FLUSH,
+ "TDmaBuf::Flush %x", this );
iRxActive = EFalse;
iTxActive = EFalse;
iExtractOffset = 0;
@@ -196,14 +209,16 @@
void TDmaBuf::RxSetActive()
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxSetActive %x", this));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXSETACTIVE,
+ "TDmaBuf::RxSetActive %x", this );
iRxActive = ETrue;
}
void TDmaBuf::RxSetInActive()
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxSetInActive %x", this));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXSETINACTIVE,
+ "TDmaBuf::RxSetInActive %x", this );
iRxActive = EFalse;
}
@@ -314,8 +329,8 @@
// used to decide whether a client read can complete straight away
TBool TDmaBuf::IsReaderEmpty()
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::IsReaderEmpty iTotalRxPacketsAvail=%d",
- iTotalRxPacketsAvail));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_ISREADEREMPTY,
+ "TDmaBuf::IsReaderEmpty iTotalRxPacketsAvail=%d", iTotalRxPacketsAvail);
return (iTotalRxPacketsAvail == 0);
}
@@ -340,8 +355,8 @@
iNumberofPacketsRxRemain[iCurrentFillingBufferIndex] = aNoPacketsRecv;
#endif
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::ReadXferComplete 2 # of bytes=%d # of packets=%d",
- iTotalRxBytesAvail, iTotalRxPacketsAvail));
+ OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_READXFERCOMPLETE,
+ "TDmaBuf::ReadXferComplete 2 # of bytes=%d # of packets=%d", iTotalRxBytesAvail, iTotalRxPacketsAvail );
iDrainable[iCurrentFillingBufferIndex] = ETrue;
iError[iCurrentFillingBufferIndex] = aErrorCode;
AddToDrainQueue(iCurrentFillingBufferIndex);
@@ -355,15 +370,17 @@
TInt TDmaBuf::RxGetNextXfer(TUint8*& aBufferAddr, TUsbcPacketArray*& aIndexArray,
TUsbcPacketArray*& aSizeArray, TInt& aLength, TPhysAddr& aBufferPhys)
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxGetNextXfer 1"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER,
+ "TDmaBuf::RxGetNextXfer 1" );
if (RxIsActive())
{
- __KTRACE_OPT(KUSB, Kern::Printf(" ---> RxIsActive, returning"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER_DUP1,
+ " ---> RxIsActive, returning" );
return KErrInUse;
}
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxGetNextXfer Current buffer=%d",
- iCurrentFillingBufferIndex));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER_DUP2,
+ "TDmaBuf::RxGetNextXfer Current buffer=%d", iCurrentFillingBufferIndex );
if (iDrainable[iCurrentFillingBufferIndex])
{
// If the controller refused the last read request, then the current buffer will still be marked
@@ -375,8 +392,8 @@
}
}
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxGetNextXfer New buffer=%d",
- iCurrentFillingBufferIndex));
+ OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER_DUP3,
+ "TDmaBuf::RxGetNextXfer New buffer=%d", iCurrentFillingBufferIndex );
aBufferAddr = iBuffers[iCurrentFillingBufferIndex];
aBufferPhys = iBufferPhys[iCurrentFillingBufferIndex];
aIndexArray = iPacketIndex[iCurrentFillingBufferIndex];
@@ -393,7 +410,8 @@
TInt TDmaBuf::RxCopyPacketToClient(DThread* aThread, TClientBuffer *aTcb, TInt aLength)
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyPacketToClient 1"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT,
+ "TDmaBuf::RxCopyPacketToClient 1" );
#if defined(USBC_LDD_BUFFER_TRACE)
const TInt numPkts = NoRxPackets();
@@ -403,25 +421,26 @@
if (numPkts != numPktsAlt)
{
- Kern::Printf(
- "TDmaBuf::RxCopyPacketToClient: Error: #pkts mismatch global=%d actual=%d",
- numPkts, numPktsAlt);
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP1,
+ "TDmaBuf::RxCopyPacketToClient: Error: #pkts mismatch global=%d actual=%d",
+ numPkts, numPktsAlt);
}
if (numBytes != numBytesAlt)
{
- Kern::Printf(
- "TDmaBuf::RxCopyPacketToClient: Error: #bytes mismatch global=%d actual=%d",
- numBytes, numBytesAlt);
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP2,
+ "TDmaBuf::RxCopyPacketToClient: Error: #bytes mismatch global=%d actual=%d",
+ numBytes, numBytesAlt);
+
}
if ((numPkts == 0) && (numBytes !=0))
{
- Kern::Printf(
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP3,
"TDmaBuf::RxCopyPacketToClient: Error: global bytes & pkts mismatch pkts=%d bytes=%d",
numPkts, numBytes);
}
if ((numPktsAlt == 0) && (numBytesAlt !=0))
{
- Kern::Printf(
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP4,
"TDmaBuf::RxCopyPacketToClient: Error: actual bytes & pkts mismatch pkts=%d bytes=%d",
numPktsAlt, numBytesAlt);
}
@@ -430,7 +449,8 @@
if (!NoRxPackets())
return KErrNotFound;
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyPacketToClient 2"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP5,
+ "TDmaBuf::RxCopyPacketToClient 2" );
// the next condition should be true because we have some packets available
// coverity[var_tested_neg]
if (iCurrentDrainingBufferIndex == KUsbcInvalidBufferIndex)
@@ -504,7 +524,9 @@
{
r = errorCode;
}
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyPacketToClient 3"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP6,
+ "TDmaBuf::RxCopyPacketToClient 3" );
+
FreeDrainedBuffers();
@@ -516,7 +538,8 @@
TInt TDmaBuf::RxCopyDataToClient(DThread* aThread, TClientBuffer *aTcb, TInt aLength, TUint32& aDestOffset,
TBool aRUS, TBool& aCompleteNow)
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyDataToClient 1"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT,
+ "TDmaBuf::RxCopyDataToClient 1" );
aCompleteNow = ETrue;
#if defined(USBC_LDD_BUFFER_TRACE)
@@ -527,25 +550,25 @@
if (numPkts != numPktsAlt)
{
- Kern::Printf(
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP1,
"TDmaBuf::RxCopyDataToClient: Error: #pkts mismatch global=%d actual=%d",
numPkts, numPktsAlt);
}
if (numBytes != numBytesAlt)
{
- Kern::Printf(
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP2,
"TDmaBuf::RxCopyDataToClient: Error: #bytes mismatch global=%d actual=%d",
numBytes, numBytesAlt);
}
if ((numPkts == 0) && (numBytes != 0))
{
- Kern::Printf(
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP3,
"TDmaBuf::RxCopyDataToClient: Error: global bytes & pkts mismatch pkts=%d bytes=%d",
numPkts, numBytes);
}
if ((numPktsAlt == 0) && (numBytesAlt != 0))
{
- Kern::Printf(
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP4,
"TDmaBuf::RxCopyDataToClient: Error: actual bytes & pkts mismatch pkts=%d bytes=%d",
numPktsAlt, numBytesAlt);
}
@@ -566,8 +589,9 @@
if (!NextDrainableBuffer())
{
#if defined(USBC_LDD_BUFFER_TRACE)
- Kern::Printf("TDmaBuf::RxCopyDataToClient: Error: No buffer draining=%d, packets=%d",
- iCurrentDrainingBufferIndex, iTotalRxPacketsAvail);
+ OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP5,
+ "TDmaBuf::RxCopyDataToClient: Error: No buffer draining=%d, packets=%d",
+ iCurrentDrainingBufferIndex, iTotalRxPacketsAvail);
#endif
return KErrNotFound;
}
@@ -579,11 +603,13 @@
if (iDrainingOrder != iFillingOrderArray[iCurrentDrainingBufferIndex])
{
- Kern::Printf("!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 10 draining=%d",
- iCurrentDrainingBufferIndex);
+ OstTrace1( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP6,
+ "!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 10 draining=%d",
+ iCurrentDrainingBufferIndex);
}
#endif
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyDataToClient 2"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP7,
+ "TDmaBuf::RxCopyDataToClient 2" );
TUint8* blockStartAddr = iCurrentDrainingBuffer + iCurrentPacketIndexArray[iCurrentPacket] + iExtractOffset;
TUint8* lastEndAddr = blockStartAddr; // going to track the contiguity of the memory
@@ -603,8 +629,9 @@
bufnum = iCurrentDrainingBufferIndex;
if (iDrainingOrder != iFillingOrderArray[iCurrentDrainingBufferIndex])
{
- Kern::Printf("!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 20 draining=%d",
- iCurrentDrainingBufferIndex);
+ OstTrace1( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP8,
+ "!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 20 draining=%d",
+ iCurrentDrainingBufferIndex);
}
}
#endif
@@ -619,7 +646,14 @@
{
if (iEndpointType == KUsbEpTypeBulk)
{
- isShortPacket = (size < iMaxPacketSize) || (size & maxPacketSizeMask);
+ if(iExtractOffset & maxPacketSizeMask)
+ {
+ isShortPacket = ((size+iExtractOffset) < iMaxPacketSize) || ((size+iExtractOffset) & maxPacketSizeMask);
+ }
+ else
+ {
+ isShortPacket = (size < iMaxPacketSize) || (size & maxPacketSizeMask);
+ }
}
else
{
@@ -728,9 +762,9 @@
TUint& pktsRemain = iNumberofPacketsRxRemain[iCurrentDrainingBufferIndex];
if ((bytesRemain != 0) || (pktsRemain != 0))
{
- Kern::Printf(
- "TDmaBuf::NextDrainableBuffer: Error: data discarded buffer=%d pkts=%d bytes=%d",
- iCurrentDrainingBufferIndex, pktsRemain, bytesRemain);
+ OstTraceExt3( TRACE_NORMAL, TDMABUF_NEXTDRAINABLEBUFFER,
+ "TDmaBuf::NextDrainableBuffer: Error: data discarded buffer=%d pkts=%d bytes=%d",
+ iCurrentDrainingBufferIndex, pktsRemain, bytesRemain);
bytesRemain = 0;
pktsRemain = 0;
}
@@ -812,7 +846,8 @@
TBool TDmaBuf::ShortPacketExists()
{
// Actually, a short packet or residue data
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::ShortPacketExists 1"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_SHORTPACKETEXISTS,
+ "TDmaBuf::ShortPacketExists 1" );
TInt index = iCurrentDrainingBufferIndex;
TUsbcPacketArray* pktSizeArray = iCurrentPacketSizeArray;
@@ -830,17 +865,7 @@
if (iEndpointType == KUsbEpTypeBulk)
{
const TInt mask = iMaxPacketSize - 1;
- if (iTotalRxBytesAvail & mask)
- return ETrue;
- // residue==0; this can be because
- // zlps exist, or short packets combine to n * max_packet_size
- // This means spadework
- const TInt s = iCurrentPacketSizeArray[iCurrentPacket] - iExtractOffset;
- if ((s == 0) || (s & mask))
- {
- return ETrue;
- }
for (TInt i = 0; i < iNumberofBuffers; i++)
{
@@ -901,7 +926,7 @@
if (iDrainQueue[iDrainQueueIndex + 1] != KUsbcInvalidBufferIndex)
{
#if defined(USBC_LDD_BUFFER_TRACE)
- Kern::Printf("TDmaBuf::AddToDrainQueue: Error: invalid iDrainQueue[x]");
+ OstTrace0( TRACE_NORMAL, TDMABUF_ADDTODRAINQUEUE, "TDmaBuf::AddToDrainQueue: Error: invalid iDrainQueue[x]" );
#endif
}
iDrainQueue[++iDrainQueueIndex] = aBufferIndex;
@@ -941,12 +966,13 @@
// We only store 1 transaction, no other buffering is done
TInt TDmaBuf::TxStoreData(DThread* aThread, TClientBuffer *aTcb, TInt aTxLength, TUint32 aBufferOffset)
{
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::TxStoreData 1"));
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_TXSTOREDATA,
+ "TDmaBuf::TxStoreData 1" );
if (!IsReaderEmpty())
return KErrInUse;
- __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::TxStoreData 2"));
-
+ OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_TXSTOREDATA_DUP1,
+ "TDmaBuf::TxStoreData 2" );
TInt remainTxLength = aTxLength;
TUint32 bufferOffset = aBufferOffset;
// Store each buffer separately