Skip to content

Commit 822956c

Browse files
authored
[crorc + bench-dma] Support latest superpage-aware CRORC firmware
* [crorc] Updates to push whole superpages * [crorc]s/READYFIFO_ENTRIES/MAX_SUPERPAGE_DESCRIPTORS * [bench-dma] Error-checking according to RDH-reported event size * [crorc] Get superpage size from FreeFifo * [bench-dma] Common Data Format between CRORC and CRU * [bench-dma + cru] Remove duplicate dwrapper datagen control register" * [bench-dma] Strongly-typed loopback mode * [bench-dma] Properly propagate exception information * [clang] Format & remove stale TODOs * [bench-dma] Update error-checking for new CRU internal loopback data format
1 parent d11170e commit 822956c

File tree

11 files changed

+170
-233
lines changed

11 files changed

+170
-233
lines changed

src/CommandLineUtilities/ProgramDmaBench.cxx

Lines changed: 123 additions & 169 deletions
Large diffs are not rendered by default.

src/Crorc/Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace AliceO2
2121
namespace roc
2222
{
2323

24+
static constexpr int MAX_SUPERPAGE_DESCRIPTORS = 128;
25+
2426
namespace Rorc
2527
{
2628
constexpr int RCSR = 0; ///< RORC Control and Status register

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void CrorcDmaChannel::deviceStartDma()
138138

139139
log("DMA start deferred until enough superpages available");
140140

141+
mFreeFifoFront = 0;
141142
mFreeFifoBack = 0;
142143
mFreeFifoSize = 0;
143144
mReadyQueue.clear();
@@ -292,7 +293,7 @@ void CrorcDmaChannel::armDdl(ResetLevel::type resetLevel)
292293
void CrorcDmaChannel::startDataGenerator()
293294
{
294295
getCrorc().armDataGenerator(mGeneratorInitialValue, mGeneratorInitialWord, mGeneratorPattern, mGeneratorDataSize,
295-
mGeneratorSeed);
296+
mGeneratorSeed); //TODO: To be simplified
296297

297298
if (LoopbackMode::Internal == mLoopbackMode) {
298299
getCrorc().setLoopbackOn();
@@ -343,26 +344,20 @@ void CrorcDmaChannel::pushSuperpage(Superpage superpage)
343344
{
344345
checkSuperpage(superpage);
345346

346-
if (superpage.getSize() != SUPERPAGE_SIZE) {
347-
BOOST_THROW_EXCEPTION(CrorcException()
348-
<< ErrorInfo::Message("Could not enqueue superpage, the C-RORC backend only supports superpage sizes of 1 MiB"));
349-
}
350-
351347
if (mTransferQueue.size() >= TRANSFER_QUEUE_CAPACITY) {
352348
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("Could not push superpage, transfer queue was full"));
353349
}
354350

355-
if (mFreeFifoSize >= READYFIFO_ENTRIES) {
351+
if (mFreeFifoSize >= MAX_SUPERPAGE_DESCRIPTORS) {
356352
BOOST_THROW_EXCEPTION(Exception()
357353
<< ErrorInfo::Message("Could not push superpage, firmware queue was full (this should never happen)"));
358354
}
359355

360-
for (int i = 0; i < READYFIFO_ENTRIES; i++) { // *always* push 128 FIFO entries
361-
auto busAddress = getBusOffsetAddress(superpage.getOffset() + i * mPageSize);
362-
pushFreeFifoPage(i, busAddress);
363-
}
364-
mFreeFifoSize = READYFIFO_ENTRIES;
365-
;
356+
auto busAddress = getBusOffsetAddress(superpage.getOffset());
357+
pushFreeFifoPage(mFreeFifoFront, busAddress, superpage.getSize());
358+
mFreeFifoSize++;
359+
mFreeFifoFront = (mFreeFifoFront + 1) % MAX_SUPERPAGE_DESCRIPTORS;
360+
366361
mTransferQueue.push_back(superpage);
367362
}
368363

@@ -388,39 +383,26 @@ void CrorcDmaChannel::fillSuperpages()
388383
}
389384

390385
// Check for arrivals & handle them
391-
if (!mTransferQueue.empty()) {
386+
if (!mTransferQueue.empty()) { // i.e. If something is pushed to the CRORC
392387
auto isArrived = [&](int descriptorIndex) { return dataArrived(descriptorIndex) == DataArrivalStatus::WholeArrived; };
393388
auto resetDescriptor = [&](int descriptorIndex) { getReadyFifoUser()->entries[descriptorIndex].reset(); };
389+
auto getLength = [&](int descriptorIndex) { return getReadyFifoUser()->entries[descriptorIndex].length * 4; }; // length in 4B words
394390

395391
while (mFreeFifoSize > 0) {
396392
if (isArrived(mFreeFifoBack)) {
397-
uint32_t length = getReadyFifoUser()->entries[mFreeFifoBack].getSize();
398-
399-
// Write length of the DMA page in the RDH
400-
auto writeRdhLength = [](uintptr_t dmaPageAddress, uint32_t length) {
401-
auto writeTo = reinterpret_cast<volatile uint32_t*>(dmaPageAddress + sizeof(uint32_t) * 2); //writeTo the 3rd word
402-
uint32_t shiftedLength = (length << 16) & 0xffff0000;
403-
*writeTo |= shiftedLength; //Only the 16 MSBs
404-
};
405-
406-
// Write the length of the DMA page in its RDH
407-
if ((mLoopbackMode == LoopbackMode::None) && mRDYRX) { //Don't write the header for STBRD
408-
auto superpage = mTransferQueue.front();
409-
auto dmaPageAddress = mDmaBufferUserspace + superpage.getOffset() + mFreeFifoBack * mPageSize;
410-
writeRdhLength(dmaPageAddress, length);
411-
}
393+
//size_t superpageFilled = SUPERPAGE_SIZE; // Get the length before updating our descriptor index
394+
size_t superpageFilled = getLength(mFreeFifoBack); // Get the length before updating our descriptor index
412395
resetDescriptor(mFreeFifoBack);
413396

414397
mFreeFifoSize--;
415-
mFreeFifoBack = (mFreeFifoBack + 1) % READYFIFO_ENTRIES;
416-
417-
if (mFreeFifoBack == 0) { // Push the superpage after all of the 128 fifo entries are pushed
418-
auto superpage = mTransferQueue.front();
419-
superpage.setReceived(mPageSize * READYFIFO_ENTRIES); // Always full Superpages
420-
superpage.setReady(true);
421-
mReadyQueue.push_back(superpage);
422-
mTransferQueue.pop_front();
423-
}
398+
mFreeFifoBack = (mFreeFifoBack + 1) % MAX_SUPERPAGE_DESCRIPTORS;
399+
400+
// Push Superpage
401+
auto superpage = mTransferQueue.front();
402+
superpage.setReceived(superpageFilled);
403+
superpage.setReady(true);
404+
mReadyQueue.push_back(superpage);
405+
mTransferQueue.pop_front();
424406
} else {
425407
// If the back one hasn't arrived yet, the next ones will certainly not have arrived either...
426408
break;
@@ -449,9 +431,9 @@ int32_t CrorcDmaChannel::getDroppedPackets()
449431
return -1;
450432
}
451433

452-
void CrorcDmaChannel::pushFreeFifoPage(int readyFifoIndex, uintptr_t pageBusAddress)
434+
void CrorcDmaChannel::pushFreeFifoPage(int readyFifoIndex, uintptr_t pageBusAddress, int pageSize)
453435
{
454-
size_t pageWords = mPageSize / 4; // Size in 32-bit words
436+
size_t pageWords = pageSize / 4; // Size in 32-bit words
455437
getCrorc().pushRxFreeFifo(pageBusAddress, pageWords, readyFifoIndex);
456438
}
457439

src/Crorc/CrorcDmaChannel.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
7676
static constexpr size_t DMA_PAGE_SIZE = 8 * 1024;
7777

7878
/// Max amount of superpages in the transfer queue (i.e. pending transfer).
79-
static constexpr size_t TRANSFER_QUEUE_CAPACITY = SUPERPAGE_SIZE / (READYFIFO_ENTRIES * DMA_PAGE_SIZE);
79+
static constexpr size_t TRANSFER_QUEUE_CAPACITY = MAX_SUPERPAGE_DESCRIPTORS;
8080

8181
/// Max amount of superpages in the ready queue (i.e. finished transfer).
8282
/// This is an arbitrary size, can easily be increased if more headroom is needed.
@@ -117,7 +117,7 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
117117
/// Pushes a page to the CRORC's Free FIFO
118118
/// \param readyFifoIndex Index of the Ready FIFO to write the page's transfer status to
119119
/// \param pageBusAddress Address on the bus to push the page to
120-
void pushFreeFifoPage(int readyFifoIndex, uintptr_t pageBusAddress);
120+
void pushFreeFifoPage(int readyFifoIndex, uintptr_t pageBusAddress, int pageSize);
121121

122122
/// Check if data has arrived
123123
DataArrivalStatus::type dataArrived(int index);
@@ -154,7 +154,10 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
154154
/// Bus address of FIFO in DMA buffer
155155
uintptr_t mReadyFifoAddressBus;
156156

157-
/// Back index of the firmware FIFO
157+
/// Front index of the firmware FIFO (WRITE)
158+
int mFreeFifoFront = 0;
159+
160+
/// Back index of the firmware FIFO (READ)
158161
int mFreeFifoBack = 0;
159162

160163
/// Amount of elements in the firmware FIFO

src/Crorc/ReadyFifo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace AliceO2
2424
namespace roc
2525
{
2626

27-
constexpr int READYFIFO_ENTRIES = 128;
27+
constexpr int READYFIFO_ENTRIES = MAX_SUPERPAGE_DESCRIPTORS;
2828

2929
/// Class representing CRORC readyFifo
3030
/// This class is meant to be used as an aliased type, reinterpret_casted from a raw memory pointer

src/Cru/Constants.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ static constexpr Register DWRAPPER_GREGS(0x00000000);
259259
/// Datapath Wrapper offset for "Enabled(?) Registers"
260260
static constexpr Register DWRAPPER_ENREG(0x00000000);
261261

262-
/// Register to control the Datapath Wrapper multiplexer
263-
static constexpr Register DWRAPPER_MUX_CONTROL(0x00000004);
264-
265262
/// Datapath Wrapper configuration registers
266263
static constexpr Register DATAPATHLINK_OFFSET(0x00040000);
267264
static constexpr Register DATALINK_OFFSET(0x00002000);

src/Cru/CruDmaChannel.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void CruDmaChannel::transferSuperpageFromLinkToReady(Link& link)
303303
}
304304

305305
link.queue.front().setReady(true);
306-
link.queue.front().setReceived(link.queue.front().getSize());
306+
link.queue.front().setReceived(link.queue.front().getSize()); //TODO: Update this with the effective superpage size when available
307307
mReadyQueue.push_back(link.queue.front());
308308
link.queue.pop_front();
309309
link.superpageCounter++;

src/Cru/DatapathWrapper.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void DatapathWrapper::setPacketArbitration(int wrapperCount, int arbitrationMode
9696
for (int i = 0; i < wrapperCount; i++) {
9797
uint32_t address = getDatapathWrapperBaseAddress(i) +
9898
Cru::Registers::DWRAPPER_GREGS.address +
99-
Cru::Registers::DWRAPPER_MUX_CONTROL.address;
99+
Cru::Registers::DWRAPPER_DATAGEN_CONTROL.address;
100100

101101
mPdaBar->writeRegister(address / 4, value);
102102
}

src/Cru/cru_constants_populate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
#'add_refgen2_offset':'I2C_COMMAND',
6666
'add_flowctrl_offset':'FLOW_CONTROL_OFFSET',
6767
'add_flowctrl_ctrlreg':'FLOW_CONTROL_REGISTER',
68-
'add_dwrapper_muxctrl':'DWRAPPER_MUX_CONTROL',
6968
'add_gbt_wrapper_atx_pll':'GBT_WRAPPER_ATX_PLL',
7069
'add_gbt_bank_fpll':'GBT_BANK_FPLL',
7170
'add_bsp_i2c_minipods':"BSP_I2C_MINIPODS",
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
///
1414
/// \author Pascal Boeschoten ([email protected])
1515

16-
#ifndef ALICEO2_READOUTCARD_CRU_DATAFORMAT_H_
17-
#define ALICEO2_READOUTCARD_CRU_DATAFORMAT_H_
16+
#ifndef ALICEO2_READOUTCARD_DATAFORMAT_H_
17+
#define ALICEO2_READOUTCARD_DATAFORMAT_H_
1818

1919
#include <cstddef>
2020
#include <cstdint>
@@ -25,8 +25,6 @@ namespace AliceO2
2525
{
2626
namespace roc
2727
{
28-
namespace Cru
29-
{
3028
namespace DataFormat
3129
{
3230
namespace
@@ -44,7 +42,7 @@ uint32_t getLinkId(const char* data)
4442
return Utilities::getBits(getWord(data, 3), 0, 7); //bits #[96-103] from RDH
4543
}
4644

47-
uint32_t getEventSize(const char* data)
45+
uint32_t getMemsize(const char* data)
4846
{
4947
return Utilities::getBits(getWord(data, 2), 16, 31); //bits #[80-95] from RDH
5048
}
@@ -54,7 +52,10 @@ uint32_t getPacketCounter(const char* data)
5452
return Utilities::getBits(getWord(data, 3), 8, 15); //bits #[104-111] from RDH
5553
}
5654

57-
////TODO: Add getOffset (pointer to the beginning of the next dma page)
55+
uint32_t getOffset(const char* data)
56+
{
57+
return Utilities::getBits(getWord(data, 2), 0, 15); //bits #[64-79] from RDH
58+
}
5859

5960
/// Get header size in bytes
6061
constexpr size_t getHeaderSize()
@@ -70,8 +71,7 @@ constexpr size_t getHeaderSizeWords()
7071
}
7172

7273
} // namespace DataFormat
73-
} // namespace Cru
7474
} // namespace roc
7575
} // namespace AliceO2
7676

77-
#endif // ALICEO2_READOUTCARD_CRU_DATAFORMAT_H_
77+
#endif // ALICEO2_READOUTCARD_DATAFORMAT_H_

0 commit comments

Comments
 (0)