105 // IN endpoints don't need a packet array |
100 // IN endpoints don't need a packet array |
106 |
101 |
107 // At most 2 packets (clump of max packet size packets) + possible zlp |
102 // At most 2 packets (clump of max packet size packets) + possible zlp |
108 TUsbcPacketArray* bufPtr = iPacketInfoStorage; |
103 TUsbcPacketArray* bufPtr = iPacketInfoStorage; |
109 // this divides up the packet indexing & packet size array over the number of buffers |
104 // this divides up the packet indexing & packet size array over the number of buffers |
110 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_CONSTRUCT, |
105 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Construct() array base=0x%08x", bufPtr)); |
111 "TDmaBuf::Construct() array base=0x%08x", bufPtr ); |
|
112 for (TInt i = 0; i < iNumberofBuffers; i++) |
106 for (TInt i = 0; i < iNumberofBuffers; i++) |
113 { |
107 { |
114 iPacketIndex[i] = bufPtr; |
108 iPacketIndex[i] = bufPtr; |
115 bufPtr += KUsbcDmaBufMaxPkts; |
109 bufPtr += KUsbcDmaBufMaxPkts; |
116 iPacketSize[i] = bufPtr; |
110 iPacketSize[i] = bufPtr; |
117 bufPtr += KUsbcDmaBufMaxPkts; |
111 bufPtr += KUsbcDmaBufMaxPkts; |
118 OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_CONSTRUCT_DUP1, |
112 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Construct() packetIndex[%d]=0x%08x packetSize[%d]=0x%08x", |
119 "TDmaBuf::Construct() packetIndex[%d]=0x%08x packetSize[%d]=0x%08x", |
113 i, iPacketIndex[i], i, iPacketSize[i])); |
120 i, reinterpret_cast<TUint>(iPacketIndex[i]), i, |
|
121 reinterpret_cast<TUint>(iPacketSize[i]) ); |
|
122 |
|
123 } |
114 } |
124 } |
115 } |
125 else |
116 else |
126 { |
117 { |
127 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_CONSTRUCT_DUP2, |
118 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::Construct() IN endpoint")); |
128 "TDmaBuf::Construct() IN endpoint" ); |
|
129 } |
119 } |
130 Flush(); |
120 Flush(); |
131 return KErrNone; |
121 return KErrNone; |
132 } |
122 } |
133 |
123 |
134 |
124 |
135 TDmaBuf::~TDmaBuf() |
125 TDmaBuf::~TDmaBuf() |
136 { |
126 { |
137 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TDMABUF_TDMABUF_DES, "TDmaBuf::~TDmaBuf()" ); |
127 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::~TDmaBuf()")); |
138 } |
128 } |
139 |
129 |
140 TInt TDmaBuf::BufferTotalSize() const |
130 TInt TDmaBuf::BufferTotalSize() const |
141 { |
131 { |
142 return iBufSz * iNumberofBuffers; |
132 return iBufSz * iNumberofBuffers; |
152 __ASSERT_DEBUG((aBufInd < iNumberofBuffers), |
142 __ASSERT_DEBUG((aBufInd < iNumberofBuffers), |
153 Kern::Fault(KUsbPanicLdd, __LINE__)); |
143 Kern::Fault(KUsbPanicLdd, __LINE__)); |
154 iDrainable[aBufInd] = iCanBeFreed[aBufInd] = EFalse; |
144 iDrainable[aBufInd] = iCanBeFreed[aBufInd] = EFalse; |
155 iBuffers[aBufInd] = aBufAddr; |
145 iBuffers[aBufInd] = aBufAddr; |
156 iBufferPhys[aBufInd] = Epoc::LinearToPhysical((TLinAddr)aBufAddr); |
146 iBufferPhys[aBufInd] = Epoc::LinearToPhysical((TLinAddr)aBufAddr); |
157 OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_SETBUFFERADDR, |
147 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::SetBufferAddr() iBuffers[%d]=0x%08x", aBufInd, iBuffers[aBufInd])); |
158 "TDmaBuf::SetBufferAddr() iBuffers[%d]=0x%08x", aBufInd, |
|
159 reinterpret_cast<TUint>(iBuffers[aBufInd]) ); |
|
160 return KErrNone; |
148 return KErrNone; |
161 } |
149 } |
162 |
150 |
163 TInt TDmaBuf::BufferNumber() const |
151 TInt TDmaBuf::BufferNumber() const |
164 { |
152 { |
207 } |
194 } |
208 |
195 |
209 |
196 |
210 void TDmaBuf::RxSetActive() |
197 void TDmaBuf::RxSetActive() |
211 { |
198 { |
212 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXSETACTIVE, |
199 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxSetActive %x", this)); |
213 "TDmaBuf::RxSetActive %x", this ); |
|
214 iRxActive = ETrue; |
200 iRxActive = ETrue; |
215 } |
201 } |
216 |
202 |
217 |
203 |
218 void TDmaBuf::RxSetInActive() |
204 void TDmaBuf::RxSetInActive() |
219 { |
205 { |
220 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXSETINACTIVE, |
206 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxSetInActive %x", this)); |
221 "TDmaBuf::RxSetInActive %x", this ); |
|
222 iRxActive = EFalse; |
207 iRxActive = EFalse; |
223 } |
208 } |
224 |
209 |
225 |
210 |
226 TBool TDmaBuf::RxIsActive() |
211 TBool TDmaBuf::RxIsActive() |
327 |
312 |
328 |
313 |
329 // used to decide whether a client read can complete straight away |
314 // used to decide whether a client read can complete straight away |
330 TBool TDmaBuf::IsReaderEmpty() |
315 TBool TDmaBuf::IsReaderEmpty() |
331 { |
316 { |
332 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_ISREADEREMPTY, |
317 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::IsReaderEmpty iTotalRxPacketsAvail=%d", |
333 "TDmaBuf::IsReaderEmpty iTotalRxPacketsAvail=%d", iTotalRxPacketsAvail); |
318 iTotalRxPacketsAvail)); |
334 return (iTotalRxPacketsAvail == 0); |
319 return (iTotalRxPacketsAvail == 0); |
335 } |
320 } |
336 |
321 |
337 |
322 |
338 void TDmaBuf::ReadXferComplete(TInt aNoBytesRecv, TInt aNoPacketsRecv, TInt aErrorCode) |
323 void TDmaBuf::ReadXferComplete(TInt aNoBytesRecv, TInt aNoPacketsRecv, TInt aErrorCode) |
353 #if defined(USBC_LDD_BUFFER_TRACE) |
338 #if defined(USBC_LDD_BUFFER_TRACE) |
354 iNumberofBytesRxRemain[iCurrentFillingBufferIndex] = aNoBytesRecv; |
339 iNumberofBytesRxRemain[iCurrentFillingBufferIndex] = aNoBytesRecv; |
355 iNumberofPacketsRxRemain[iCurrentFillingBufferIndex] = aNoPacketsRecv; |
340 iNumberofPacketsRxRemain[iCurrentFillingBufferIndex] = aNoPacketsRecv; |
356 #endif |
341 #endif |
357 |
342 |
358 OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_READXFERCOMPLETE, |
343 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::ReadXferComplete 2 # of bytes=%d # of packets=%d", |
359 "TDmaBuf::ReadXferComplete 2 # of bytes=%d # of packets=%d", iTotalRxBytesAvail, iTotalRxPacketsAvail ); |
344 iTotalRxBytesAvail, iTotalRxPacketsAvail)); |
360 iDrainable[iCurrentFillingBufferIndex] = ETrue; |
345 iDrainable[iCurrentFillingBufferIndex] = ETrue; |
361 iError[iCurrentFillingBufferIndex] = aErrorCode; |
346 iError[iCurrentFillingBufferIndex] = aErrorCode; |
362 AddToDrainQueue(iCurrentFillingBufferIndex); |
347 AddToDrainQueue(iCurrentFillingBufferIndex); |
363 if (iCurrentDrainingBufferIndex == KUsbcInvalidBufferIndex) |
348 if (iCurrentDrainingBufferIndex == KUsbcInvalidBufferIndex) |
364 { |
349 { |
368 |
353 |
369 |
354 |
370 TInt TDmaBuf::RxGetNextXfer(TUint8*& aBufferAddr, TUsbcPacketArray*& aIndexArray, |
355 TInt TDmaBuf::RxGetNextXfer(TUint8*& aBufferAddr, TUsbcPacketArray*& aIndexArray, |
371 TUsbcPacketArray*& aSizeArray, TInt& aLength, TPhysAddr& aBufferPhys) |
356 TUsbcPacketArray*& aSizeArray, TInt& aLength, TPhysAddr& aBufferPhys) |
372 { |
357 { |
373 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER, |
358 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxGetNextXfer 1")); |
374 "TDmaBuf::RxGetNextXfer 1" ); |
|
375 if (RxIsActive()) |
359 if (RxIsActive()) |
376 { |
360 { |
377 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER_DUP1, |
361 __KTRACE_OPT(KUSB, Kern::Printf(" ---> RxIsActive, returning")); |
378 " ---> RxIsActive, returning" ); |
|
379 return KErrInUse; |
362 return KErrInUse; |
380 } |
363 } |
381 |
364 |
382 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER_DUP2, |
365 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxGetNextXfer Current buffer=%d", |
383 "TDmaBuf::RxGetNextXfer Current buffer=%d", iCurrentFillingBufferIndex ); |
366 iCurrentFillingBufferIndex)); |
384 if (iDrainable[iCurrentFillingBufferIndex]) |
367 if (iDrainable[iCurrentFillingBufferIndex]) |
385 { |
368 { |
386 // If the controller refused the last read request, then the current buffer will still be marked |
369 // If the controller refused the last read request, then the current buffer will still be marked |
387 // as !Drainable, because the controller never completed the read to the ldd. and therefore the buffer |
370 // as !Drainable, because the controller never completed the read to the ldd. and therefore the buffer |
388 // can be reused. |
371 // can be reused. |
390 { |
373 { |
391 return KErrNoMemory; |
374 return KErrNoMemory; |
392 } |
375 } |
393 } |
376 } |
394 |
377 |
395 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXGETNEXTXFER_DUP3, |
378 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxGetNextXfer New buffer=%d", |
396 "TDmaBuf::RxGetNextXfer New buffer=%d", iCurrentFillingBufferIndex ); |
379 iCurrentFillingBufferIndex)); |
397 aBufferAddr = iBuffers[iCurrentFillingBufferIndex]; |
380 aBufferAddr = iBuffers[iCurrentFillingBufferIndex]; |
398 aBufferPhys = iBufferPhys[iCurrentFillingBufferIndex]; |
381 aBufferPhys = iBufferPhys[iCurrentFillingBufferIndex]; |
399 aIndexArray = iPacketIndex[iCurrentFillingBufferIndex]; |
382 aIndexArray = iPacketIndex[iCurrentFillingBufferIndex]; |
400 aSizeArray = iPacketSize[iCurrentFillingBufferIndex]; |
383 aSizeArray = iPacketSize[iCurrentFillingBufferIndex]; |
401 aLength = iBufSz; |
384 aLength = iBufSz; |
408 } |
391 } |
409 |
392 |
410 |
393 |
411 TInt TDmaBuf::RxCopyPacketToClient(DThread* aThread, TClientBuffer *aTcb, TInt aLength) |
394 TInt TDmaBuf::RxCopyPacketToClient(DThread* aThread, TClientBuffer *aTcb, TInt aLength) |
412 { |
395 { |
413 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT, |
396 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyPacketToClient 1")); |
414 "TDmaBuf::RxCopyPacketToClient 1" ); |
|
415 |
397 |
416 #if defined(USBC_LDD_BUFFER_TRACE) |
398 #if defined(USBC_LDD_BUFFER_TRACE) |
417 const TInt numPkts = NoRxPackets(); |
399 const TInt numPkts = NoRxPackets(); |
418 const TInt numPktsAlt = NoRxPacketsAlt(); |
400 const TInt numPktsAlt = NoRxPacketsAlt(); |
419 const TInt numBytes = RxBytesAvailable(); |
401 const TInt numBytes = RxBytesAvailable(); |
420 const TInt numBytesAlt = NoRxBytesAlt(); |
402 const TInt numBytesAlt = NoRxBytesAlt(); |
421 |
403 |
422 if (numPkts != numPktsAlt) |
404 if (numPkts != numPktsAlt) |
423 { |
405 { |
424 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP1, |
406 Kern::Printf( |
425 "TDmaBuf::RxCopyPacketToClient: Error: #pkts mismatch global=%d actual=%d", |
407 "TDmaBuf::RxCopyPacketToClient: Error: #pkts mismatch global=%d actual=%d", |
426 numPkts, numPktsAlt); |
408 numPkts, numPktsAlt); |
427 } |
409 } |
428 if (numBytes != numBytesAlt) |
410 if (numBytes != numBytesAlt) |
429 { |
411 { |
430 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP2, |
412 Kern::Printf( |
431 "TDmaBuf::RxCopyPacketToClient: Error: #bytes mismatch global=%d actual=%d", |
413 "TDmaBuf::RxCopyPacketToClient: Error: #bytes mismatch global=%d actual=%d", |
432 numBytes, numBytesAlt); |
414 numBytes, numBytesAlt); |
433 |
|
434 } |
415 } |
435 if ((numPkts == 0) && (numBytes !=0)) |
416 if ((numPkts == 0) && (numBytes !=0)) |
436 { |
417 { |
437 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP3, |
418 Kern::Printf( |
438 "TDmaBuf::RxCopyPacketToClient: Error: global bytes & pkts mismatch pkts=%d bytes=%d", |
419 "TDmaBuf::RxCopyPacketToClient: Error: global bytes & pkts mismatch pkts=%d bytes=%d", |
439 numPkts, numBytes); |
420 numPkts, numBytes); |
440 } |
421 } |
441 if ((numPktsAlt == 0) && (numBytesAlt !=0)) |
422 if ((numPktsAlt == 0) && (numBytesAlt !=0)) |
442 { |
423 { |
443 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP4, |
424 Kern::Printf( |
444 "TDmaBuf::RxCopyPacketToClient: Error: actual bytes & pkts mismatch pkts=%d bytes=%d", |
425 "TDmaBuf::RxCopyPacketToClient: Error: actual bytes & pkts mismatch pkts=%d bytes=%d", |
445 numPktsAlt, numBytesAlt); |
426 numPktsAlt, numBytesAlt); |
446 } |
427 } |
447 #endif |
428 #endif |
448 |
429 |
449 if (!NoRxPackets()) |
430 if (!NoRxPackets()) |
450 return KErrNotFound; |
431 return KErrNotFound; |
451 |
432 |
452 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP5, |
433 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyPacketToClient 2")); |
453 "TDmaBuf::RxCopyPacketToClient 2" ); |
|
454 // the next condition should be true because we have some packets available |
434 // the next condition should be true because we have some packets available |
455 // coverity[var_tested_neg] |
435 // coverity[var_tested_neg] |
456 if (iCurrentDrainingBufferIndex == KUsbcInvalidBufferIndex) |
436 if (iCurrentDrainingBufferIndex == KUsbcInvalidBufferIndex) |
457 { |
437 { |
458 // Marked as Coverity "Intentional" as the member variable |
438 // Marked as Coverity "Intentional" as the member variable |
522 TInt r=Kern::ThreadBufWrite(aThread, aTcb, des, 0, 0, aThread); |
502 TInt r=Kern::ThreadBufWrite(aThread, aTcb, des, 0, 0, aThread); |
523 if (r == KErrNone) |
503 if (r == KErrNone) |
524 { |
504 { |
525 r = errorCode; |
505 r = errorCode; |
526 } |
506 } |
527 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYPACKETTOCLIENT_DUP6, |
507 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyPacketToClient 3")); |
528 "TDmaBuf::RxCopyPacketToClient 3" ); |
|
529 |
|
530 |
508 |
531 FreeDrainedBuffers(); |
509 FreeDrainedBuffers(); |
532 |
510 |
533 // Use this error code to complete client read request: |
511 // Use this error code to complete client read request: |
534 return r; |
512 return r; |
536 |
514 |
537 |
515 |
538 TInt TDmaBuf::RxCopyDataToClient(DThread* aThread, TClientBuffer *aTcb, TInt aLength, TUint32& aDestOffset, |
516 TInt TDmaBuf::RxCopyDataToClient(DThread* aThread, TClientBuffer *aTcb, TInt aLength, TUint32& aDestOffset, |
539 TBool aRUS, TBool& aCompleteNow) |
517 TBool aRUS, TBool& aCompleteNow) |
540 { |
518 { |
541 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT, |
519 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyDataToClient 1")); |
542 "TDmaBuf::RxCopyDataToClient 1" ); |
|
543 aCompleteNow = ETrue; |
520 aCompleteNow = ETrue; |
544 |
521 |
545 #if defined(USBC_LDD_BUFFER_TRACE) |
522 #if defined(USBC_LDD_BUFFER_TRACE) |
546 const TInt numPkts = NoRxPackets(); |
523 const TInt numPkts = NoRxPackets(); |
547 const TInt numPktsAlt = NoRxPacketsAlt(); |
524 const TInt numPktsAlt = NoRxPacketsAlt(); |
548 const TInt numBytes = RxBytesAvailable(); |
525 const TInt numBytes = RxBytesAvailable(); |
549 const TInt numBytesAlt = NoRxBytesAlt(); |
526 const TInt numBytesAlt = NoRxBytesAlt(); |
550 |
527 |
551 if (numPkts != numPktsAlt) |
528 if (numPkts != numPktsAlt) |
552 { |
529 { |
553 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP1, |
530 Kern::Printf( |
554 "TDmaBuf::RxCopyDataToClient: Error: #pkts mismatch global=%d actual=%d", |
531 "TDmaBuf::RxCopyDataToClient: Error: #pkts mismatch global=%d actual=%d", |
555 numPkts, numPktsAlt); |
532 numPkts, numPktsAlt); |
556 } |
533 } |
557 if (numBytes != numBytesAlt) |
534 if (numBytes != numBytesAlt) |
558 { |
535 { |
559 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP2, |
536 Kern::Printf( |
560 "TDmaBuf::RxCopyDataToClient: Error: #bytes mismatch global=%d actual=%d", |
537 "TDmaBuf::RxCopyDataToClient: Error: #bytes mismatch global=%d actual=%d", |
561 numBytes, numBytesAlt); |
538 numBytes, numBytesAlt); |
562 } |
539 } |
563 if ((numPkts == 0) && (numBytes != 0)) |
540 if ((numPkts == 0) && (numBytes != 0)) |
564 { |
541 { |
565 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP3, |
542 Kern::Printf( |
566 "TDmaBuf::RxCopyDataToClient: Error: global bytes & pkts mismatch pkts=%d bytes=%d", |
543 "TDmaBuf::RxCopyDataToClient: Error: global bytes & pkts mismatch pkts=%d bytes=%d", |
567 numPkts, numBytes); |
544 numPkts, numBytes); |
568 } |
545 } |
569 if ((numPktsAlt == 0) && (numBytesAlt != 0)) |
546 if ((numPktsAlt == 0) && (numBytesAlt != 0)) |
570 { |
547 { |
571 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP4, |
548 Kern::Printf( |
572 "TDmaBuf::RxCopyDataToClient: Error: actual bytes & pkts mismatch pkts=%d bytes=%d", |
549 "TDmaBuf::RxCopyDataToClient: Error: actual bytes & pkts mismatch pkts=%d bytes=%d", |
573 numPktsAlt, numBytesAlt); |
550 numPktsAlt, numBytesAlt); |
574 } |
551 } |
575 #endif |
552 #endif |
576 |
553 |
587 // initialization to KUsbcInvalidBufferIndex (which equals -1). |
564 // initialization to KUsbcInvalidBufferIndex (which equals -1). |
588 |
565 |
589 if (!NextDrainableBuffer()) |
566 if (!NextDrainableBuffer()) |
590 { |
567 { |
591 #if defined(USBC_LDD_BUFFER_TRACE) |
568 #if defined(USBC_LDD_BUFFER_TRACE) |
592 OstTraceExt2( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP5, |
569 Kern::Printf("TDmaBuf::RxCopyDataToClient: Error: No buffer draining=%d, packets=%d", |
593 "TDmaBuf::RxCopyDataToClient: Error: No buffer draining=%d, packets=%d", |
570 iCurrentDrainingBufferIndex, iTotalRxPacketsAvail); |
594 iCurrentDrainingBufferIndex, iTotalRxPacketsAvail); |
|
595 #endif |
571 #endif |
596 return KErrNotFound; |
572 return KErrNotFound; |
597 } |
573 } |
598 } |
574 } |
599 #if defined(USBC_LDD_BUFFER_TRACE) |
575 #if defined(USBC_LDD_BUFFER_TRACE) |
601 __ASSERT_DEBUG((iCurrentDrainingBufferIndex >= 0 ), |
577 __ASSERT_DEBUG((iCurrentDrainingBufferIndex >= 0 ), |
602 Kern::Fault(KUsbPanicLdd, __LINE__)); |
578 Kern::Fault(KUsbPanicLdd, __LINE__)); |
603 |
579 |
604 if (iDrainingOrder != iFillingOrderArray[iCurrentDrainingBufferIndex]) |
580 if (iDrainingOrder != iFillingOrderArray[iCurrentDrainingBufferIndex]) |
605 { |
581 { |
606 OstTrace1( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP6, |
582 Kern::Printf("!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 10 draining=%d", |
607 "!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 10 draining=%d", |
583 iCurrentDrainingBufferIndex); |
608 iCurrentDrainingBufferIndex); |
584 } |
609 } |
585 #endif |
610 #endif |
586 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::RxCopyDataToClient 2")); |
611 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP7, |
|
612 "TDmaBuf::RxCopyDataToClient 2" ); |
|
613 |
587 |
614 TUint8* blockStartAddr = iCurrentDrainingBuffer + iCurrentPacketIndexArray[iCurrentPacket] + iExtractOffset; |
588 TUint8* blockStartAddr = iCurrentDrainingBuffer + iCurrentPacketIndexArray[iCurrentPacket] + iExtractOffset; |
615 TUint8* lastEndAddr = blockStartAddr; // going to track the contiguity of the memory |
589 TUint8* lastEndAddr = blockStartAddr; // going to track the contiguity of the memory |
616 TUint8* thisStartAddr = blockStartAddr; |
590 TUint8* thisStartAddr = blockStartAddr; |
617 TInt toDo = Min(aLength - (TInt)aDestOffset, iTotalRxBytesAvail); |
591 TInt toDo = Min(aLength - (TInt)aDestOffset, iTotalRxBytesAvail); |
627 if (bufnum != iCurrentDrainingBufferIndex) |
601 if (bufnum != iCurrentDrainingBufferIndex) |
628 { |
602 { |
629 bufnum = iCurrentDrainingBufferIndex; |
603 bufnum = iCurrentDrainingBufferIndex; |
630 if (iDrainingOrder != iFillingOrderArray[iCurrentDrainingBufferIndex]) |
604 if (iDrainingOrder != iFillingOrderArray[iCurrentDrainingBufferIndex]) |
631 { |
605 { |
632 OstTrace1( TRACE_NORMAL, TDMABUF_RXCOPYDATATOCLIENT_DUP8, |
606 Kern::Printf("!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 20 draining=%d", |
633 "!!! Out of Order Draining TDmaBuf::RxCopyDataToClient 20 draining=%d", |
607 iCurrentDrainingBufferIndex); |
634 iCurrentDrainingBufferIndex); |
|
635 } |
608 } |
636 } |
609 } |
637 #endif |
610 #endif |
638 if (errorCode == KErrNone) |
611 if (errorCode == KErrNone) |
639 { |
612 { |
760 #if defined(USBC_LDD_BUFFER_TRACE) |
726 #if defined(USBC_LDD_BUFFER_TRACE) |
761 TUint& bytesRemain = iNumberofBytesRxRemain[iCurrentDrainingBufferIndex]; |
727 TUint& bytesRemain = iNumberofBytesRxRemain[iCurrentDrainingBufferIndex]; |
762 TUint& pktsRemain = iNumberofPacketsRxRemain[iCurrentDrainingBufferIndex]; |
728 TUint& pktsRemain = iNumberofPacketsRxRemain[iCurrentDrainingBufferIndex]; |
763 if ((bytesRemain != 0) || (pktsRemain != 0)) |
729 if ((bytesRemain != 0) || (pktsRemain != 0)) |
764 { |
730 { |
765 OstTraceExt3( TRACE_NORMAL, TDMABUF_NEXTDRAINABLEBUFFER, |
731 Kern::Printf( |
766 "TDmaBuf::NextDrainableBuffer: Error: data discarded buffer=%d pkts=%d bytes=%d", |
732 "TDmaBuf::NextDrainableBuffer: Error: data discarded buffer=%d pkts=%d bytes=%d", |
767 iCurrentDrainingBufferIndex, pktsRemain, bytesRemain); |
733 iCurrentDrainingBufferIndex, pktsRemain, bytesRemain); |
768 bytesRemain = 0; |
734 bytesRemain = 0; |
769 pktsRemain = 0; |
735 pktsRemain = 0; |
770 } |
736 } |
771 #endif |
737 #endif |
772 |
738 |
844 |
810 |
845 |
811 |
846 TBool TDmaBuf::ShortPacketExists() |
812 TBool TDmaBuf::ShortPacketExists() |
847 { |
813 { |
848 // Actually, a short packet or residue data |
814 // Actually, a short packet or residue data |
849 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_SHORTPACKETEXISTS, |
815 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::ShortPacketExists 1")); |
850 "TDmaBuf::ShortPacketExists 1" ); |
|
851 TInt index = iCurrentDrainingBufferIndex; |
816 TInt index = iCurrentDrainingBufferIndex; |
852 TUsbcPacketArray* pktSizeArray = iCurrentPacketSizeArray; |
817 TUsbcPacketArray* pktSizeArray = iCurrentPacketSizeArray; |
853 |
818 |
854 if (iMaxPacketSize > 0) |
819 if (iMaxPacketSize > 0) |
855 { |
820 { |
863 return ETrue; |
828 return ETrue; |
864 |
829 |
865 if (iEndpointType == KUsbEpTypeBulk) |
830 if (iEndpointType == KUsbEpTypeBulk) |
866 { |
831 { |
867 const TInt mask = iMaxPacketSize - 1; |
832 const TInt mask = iMaxPacketSize - 1; |
868 |
833 if (iTotalRxBytesAvail & mask) |
|
834 return ETrue; |
|
835 |
|
836 // residue==0; this can be because |
|
837 // zlps exist, or short packets combine to n * max_packet_size |
|
838 // This means spadework |
|
839 const TInt s = iCurrentPacketSizeArray[iCurrentPacket] - iExtractOffset; |
|
840 if ((s == 0) || (s & mask)) |
|
841 { |
|
842 return ETrue; |
|
843 } |
869 |
844 |
870 for (TInt i = 0; i < iNumberofBuffers; i++) |
845 for (TInt i = 0; i < iNumberofBuffers; i++) |
871 { |
846 { |
872 if (index == KUsbcInvalidBufferIndex) |
847 if (index == KUsbcInvalidBufferIndex) |
873 break; |
848 break; |
964 |
939 |
965 |
940 |
966 // We only store 1 transaction, no other buffering is done |
941 // We only store 1 transaction, no other buffering is done |
967 TInt TDmaBuf::TxStoreData(DThread* aThread, TClientBuffer *aTcb, TInt aTxLength, TUint32 aBufferOffset) |
942 TInt TDmaBuf::TxStoreData(DThread* aThread, TClientBuffer *aTcb, TInt aTxLength, TUint32 aBufferOffset) |
968 { |
943 { |
969 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_TXSTOREDATA, |
944 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::TxStoreData 1")); |
970 "TDmaBuf::TxStoreData 1" ); |
|
971 if (!IsReaderEmpty()) |
945 if (!IsReaderEmpty()) |
972 return KErrInUse; |
946 return KErrInUse; |
973 |
947 |
974 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TDMABUF_TXSTOREDATA_DUP1, |
948 __KTRACE_OPT(KUSB, Kern::Printf("TDmaBuf::TxStoreData 2")); |
975 "TDmaBuf::TxStoreData 2" ); |
949 |
976 TInt remainTxLength = aTxLength; |
950 TInt remainTxLength = aTxLength; |
977 TUint32 bufferOffset = aBufferOffset; |
951 TUint32 bufferOffset = aBufferOffset; |
978 // Store each buffer separately |
952 // Store each buffer separately |
979 for( TInt i=0;(i<iNumberofBuffers)&&(remainTxLength>0);i++) |
953 for( TInt i=0;(i<iNumberofBuffers)&&(remainTxLength>0);i++) |
980 { |
954 { |