Skip to content

Commit 79cf254

Browse files
committed
[cru] Make sure the superpage size FIFO is parsed correctly
1 parent 8efaee6 commit 79cf254

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/Cru/CruBar.cxx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,19 @@ uint32_t CruBar::getSuperpageSize(uint32_t link)
133133
writeRegister(Cru::Registers::LINK_SUPERPAGE_SIZE.get(link).index, 0xbadcafe); // write a dummy value to update the FIFO
134134
uint32_t superpageSizeFifo = readRegister(Cru::Registers::LINK_SUPERPAGE_SIZE.get(link).index);
135135
uint32_t superpageSize = Utilities::getBits(superpageSizeFifo, 0, 23); // [0-23] -> superpage size (in bytes)
136-
//uint32_t superpageIndex = Utilities::getBits(superpageSizeFifo, 24, 31); // [24-31] -> superpage index (0-255) _for testing_
136+
if (superpageSize == 0) { // No reason to check for index -> superpageSize == 0 -> CRU FW < v3.4.0
137+
return 0;
138+
}
139+
uint32_t superpageSizeIndex = Utilities::getBits(superpageSizeFifo, 24, 31); // [24-31] -> superpage index (0-255)
140+
141+
while (superpageSizeIndex != mSuperpageSizeIndexCounter[link]) { // In case the PCIe bus wasn't fast enough
142+
//std::cout << "[SP INDEX] link " << link << " : " << superpageSizeIndex << " instead of " << mSuperpageSizeIndexCounter[link] << std::endl;
143+
superpageSizeFifo = readRegister(Cru::Registers::LINK_SUPERPAGE_SIZE.get(link).index);
144+
superpageSize = Utilities::getBits(superpageSizeFifo, 0, 23);
145+
superpageSizeIndex = Utilities::getBits(superpageSizeFifo, 24, 31);
146+
}
147+
148+
mSuperpageSizeIndexCounter[link] = (superpageSizeIndex + 1) % 256;
137149

138150
return superpageSize;
139151
}

src/Cru/CruBar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class CruBar final : public BarInterfaceBase
132132
uint32_t mOnuAddress;
133133
bool mDynamicOffset;
134134

135+
/// Per-link counter to verify superpage sizes received are valid
136+
uint32_t mSuperpageSizeIndexCounter[Cru::MAX_LINKS] = { 0 };
137+
135138
/// Checks if this is the correct BAR. Used to check for BAR 2 for special functions.
136139
void assertBarIndex(int index, std::string message) const
137140
{

src/Cru/CruDmaChannel.cxx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,13 @@ void CruDmaChannel::deviceStopDma()
173173
if (mReadyQueue.size() >= READY_QUEUE_CAPACITY) {
174174
break;
175175
}
176-
if (!link.queue.empty()) { // care for the extra filled superpage
177-
transferSuperpageFromLinkToReady(link, true);
176+
177+
if (!link.queue.empty()) { // care for the extra filled superpage
178+
if (i == amountAvailable) { // Propagate that it is the last popped to set the size only to the RDH (eox)
179+
transferSuperpageFromLinkToReady(link, true);
180+
} else {
181+
transferSuperpageFromLinkToReady(link);
182+
}
178183
moved++;
179184
}
180185
}
@@ -278,14 +283,18 @@ void CruDmaChannel::transferSuperpageFromLinkToReady(Link& link, bool isPopped)
278283
}
279284

280285
link.queue.front().setReady(true);
281-
uint32_t superpageSize = getBar()->getSuperpageSize(link.id);
282-
if (isPopped) { // Only RDH in case it is popped
283-
link.queue.front().setReceived(0x40);
284-
} else if (superpageSize == 0) { //backwards compatible in case the superpage size register is empty
285-
link.queue.front().setReceived(link.queue.front().getSize()); // force the full superpage size
286+
287+
if (isPopped) {
288+
link.queue.front().setReceived(0x40); // Only RDH in case it's popped
286289
} else {
287-
link.queue.front().setReceived(superpageSize);
290+
uint32_t superpageSize = getBar()->getSuperpageSize(link.id);
291+
if (superpageSize == 0) {
292+
link.queue.front().setReceived(link.queue.front().getSize()); // force the full superpage size for backwards compatibility
293+
} else {
294+
link.queue.front().setReceived(superpageSize);
295+
}
288296
}
297+
289298
mReadyQueue.push_back(link.queue.front());
290299
link.queue.pop_front();
291300
link.superpageCounter++;

0 commit comments

Comments
 (0)