Skip to content

Commit 79f3836

Browse files
committed
Improve roc-status with RX/TX frequencies, status bits and optical power
1 parent 8fdd34e commit 79f3836

File tree

16 files changed

+217
-20
lines changed

16 files changed

+217
-20
lines changed

include/ReadoutCard/BarInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BarInterface: public virtual RegisterReadWriteInterface
5858

5959
virtual boost::optional<std::string> getCardId() = 0;
6060

61-
virtual int32_t getDroppedPackets() = 0;
61+
virtual int32_t getDroppedPackets(int endpoint) = 0;
6262

6363
virtual uint32_t getCTPClock() = 0;
6464

src/BarInterfaceBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class BarInterfaceBase: public BarInterface
7676
}
7777

7878
/// Default implementation for optional function
79-
virtual int32_t getDroppedPackets() override
79+
virtual int32_t getDroppedPackets(int /*endpoint*/) override
8080
{
8181
return 0;
8282
}

src/CommandLineUtilities/ProgramMetrics.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ class ProgramMetrics: public Program
7878

7979
int i = 0;
8080
for (const auto& card : cardsFound) {
81-
Parameters params = Parameters::makeParameters(card.pciAddress, 2);
82-
auto bar2 = ChannelFactory().getBar(params);
81+
Parameters params0 = Parameters::makeParameters(card.pciAddress, 0);
82+
auto bar0 = ChannelFactory().getBar(params0);
83+
Parameters params2 = Parameters::makeParameters(card.pciAddress, 2);
84+
auto bar2 = ChannelFactory().getBar(params2);
8385

8486
float temperature = bar2->getTemperature().value_or(0);
85-
int32_t dropped = bar2->getDroppedPackets();
87+
int32_t dropped = bar2->getDroppedPackets(bar0->getEndpointNumber());
8688
float ctp_clock = bar2->getCTPClock()/1e6;
8789
float local_clock = bar2->getLocalClock()/1e6;
8890
int32_t links = bar2->getLinks();

src/CommandLineUtilities/ProgramStatus.cxx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class ProgramStatus: public Program
6666

6767
std::ostringstream table;
6868

69-
auto formatHeader = " %-9s %-16s %-10s %-14s %-15s %-10s\n";
70-
auto formatRow = " %-9s %-16s %-10s %-14s %-15s %-10s\n";
69+
auto formatHeader = " %-9s %-16s %-10s %-14s %-15s %-10s %-14s %-14s %-8s %-15s\n";
70+
auto formatRow = " %-9s %-16s %-10s %-14s %-15s %-10s %-14.2f %-14.2f %-8s %-15.1f\n";
7171
auto header = (boost::format(formatHeader)
72-
% "Link ID" % "GBT Mode Tx/Rx" % "Loopback" % "GBT MUX" % "Datapath Mode" % "Datapath").str();
72+
% "Link ID" % "GBT Mode Tx/Rx" % "Loopback" % "GBT MUX" % "Datapath Mode" % "Datapath" % "RX freq(MHz)" % "TX freq(MHz)" % "Status" % "Optical power").str();
7373
auto lineFat = std::string(header.length(), '=') + '\n';
7474
auto lineThin = std::string(header.length(), '-') + '\n';
7575

@@ -115,7 +115,13 @@ class ProgramStatus: public Program
115115

116116
std::string enabled = (link.enabled) ? "Enabled" : "Disabled" ;
117117

118-
auto format = boost::format(formatRow) % globalId % gbtTxRxMode % loopback % gbtMux % datapathMode % enabled;
118+
float rxFreq = link.rxFreq;
119+
float txFreq = link.txFreq;
120+
121+
std::string linkStatus = link.stickyBit ? "UP" : "DOWN" ;
122+
float opticalPower = link.opticalPower;
123+
124+
auto format = boost::format(formatRow) % globalId % gbtTxRxMode % loopback % gbtMux % datapathMode % enabled % rxFreq % txFreq % linkStatus % opticalPower;
119125

120126
table << format;
121127
}

src/Cru/Common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ struct Link {
3939
bool loopback = false;
4040
DatapathMode::type datapathMode = DatapathMode::type::Packet;
4141
bool enabled = false;
42+
bool stickyBit = false;
43+
float opticalPower = 0.0;
44+
float txFreq = 0x0; //In MHz
45+
float rxFreq = 0x0; //In MHz
4246

4347
bool operator== (const Link &dlink) const {
4448
if (enabled == dlink.enabled && enabled == false) {

src/Cru/Constants.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ static constexpr Register FPGA_CHIP_HIGH(0x00010014);
149149
/// Must be accessed on BAR 2
150150
static constexpr Register FPGA_CHIP_LOW(0x00010018);
151151

152-
/// Register containing the number of dropped packets
152+
/// Registers containing the number of dropped packets
153153
/// Must be accessed on BAR 2
154-
// not yet in cru_tables.py
155-
static constexpr Register NUM_DROPPED_PACKETS(0x0060001C);
154+
/// Endpoint resolution must be done *manually*
155+
/// HARDCODED
156+
static constexpr Register NUM_DROPPED_PACKETS_ENDPOINT0(0x0060001C);
157+
158+
static constexpr Register NUM_DROPPED_PACKETS_ENDPOINT1(0x0070001C);
156159

157160
/// Registers for controlling the DDG
158161
static constexpr Register DDG_CTRL0(0x00d00000);
@@ -161,6 +164,9 @@ static constexpr Register DDG_CTRL2(0x00d00004);
161164
/// Register to control BSP
162165
static constexpr Register BSP_USER_CONTROL(0x00000018);
163166

167+
/// Register to access I2C minipod information
168+
static constexpr Register BSP_I2C_MINIPODS(0x00030600);
169+
164170
//** TTC **//
165171
/// Register for setting the Clock
166172
static constexpr Register CLOCK_CONTROL(0x00240010);
@@ -204,9 +210,19 @@ static constexpr Register GBT_WRAPPER_BANK_OFFSET(0x00020000);
204210
static constexpr Register GBT_BANK_LINK_OFFSET(0x00002000);
205211
static constexpr Register GBT_LINK_REGS_OFFSET(0x00000000);
206212

213+
// Register for getting the GBT link status (i.e. sticky bit)
214+
static constexpr Register GBT_LINK_STATUS(0x00000000);
215+
207216
/// Register for selecting the GBT link source (i.e. Internal Data Generator)
208217
static constexpr Register GBT_LINK_SOURCE_SELECT(0x00000030);
209218

219+
/// Register for clearing the GBT link error counters
220+
static constexpr Register GBT_LINK_CLEAR_ERRORS(0x00000038);
221+
222+
/// Registers for getting the RX and TX link frequencies
223+
static constexpr Register GBT_LINK_RX_CLOCK(0x00000008);
224+
static constexpr Register GBT_LINK_TX_CLOCK(0x00000004);
225+
210226
/// Register for selecting the the GBT Multiplexer
211227
static constexpr Register GBT_MUX_SELECT(0x0000001c);
212228
/*static constexpr uint32_t GBT_MUX_TTC(0x0);

src/Cru/CruBar.cxx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,16 @@ FirmwareFeatures CruBar::getFirmwareFeatures()
172172
return mFeatures;
173173
}
174174

175-
/// Get number of dropped packets
176-
int32_t CruBar::getDroppedPackets()
175+
/// Get number of dropped packets on endpoint 2
176+
int32_t CruBar::getDroppedPackets(int endpoint)
177177
{
178-
return readRegister(Cru::Registers::NUM_DROPPED_PACKETS.index);
178+
if (endpoint == 0) {
179+
return readRegister(Cru::Registers::NUM_DROPPED_PACKETS_ENDPOINT0.index);
180+
} else if (endpoint == 1) {
181+
return readRegister(Cru::Registers::NUM_DROPPED_PACKETS_ENDPOINT1.index);
182+
} else {
183+
return -1;
184+
}
179185
}
180186

181187
// Get CTP clock (Hz)
@@ -444,8 +450,15 @@ Cru::ReportInfo CruBar::report()
444450
auto& link = el.second;
445451
link.datapathMode = datapathWrapper.getDatapathMode(link);
446452
link.enabled = datapathWrapper.getLinkEnabled(link);
453+
link.stickyBit = gbt.getStickyBit(link);
454+
link.rxFreq = gbt.getRxClockFrequency(link) / 1e6; // Hz -> Mhz
455+
link.txFreq = gbt.getTxClockFrequency(link) / 1e6; // Hz -> Mhz
447456
}
448457

458+
// Update the link map with optical power information through I2C
459+
I2c i2c = I2c(Cru::Registers::BSP_I2C_MINIPODS.address, 0x0, mPdaBar);
460+
i2c.getOpticalPower(linkMap);
461+
449462
Ttc ttc = Ttc(mPdaBar);
450463
// Mismatch between values returned by getPllClock and value required to set the clock
451464
// getPllClock: 0 for Local clock, 1 for TTC clock
@@ -604,7 +617,7 @@ std::map<int, Link> CruBar::initializeLinkMap()
604617

605618
// Calculate "new" positions to accommodate CRU FW v3.0.0 link mapping
606619
std::map<int, Link> newLinkMap;
607-
for(int i=0; i<links.size(); i++) {
620+
for(size_t i=0; i < links.size(); i++) {
608621
Link link = links.at(i);
609622
int newPos = (i-link.bank*6) * 2 + 12*(int)(link.bank/2) + (link.bank %2);
610623
link.dwrapperId = newPos % 12;
@@ -713,5 +726,6 @@ uint16_t CruBar::getCruId()
713726
{
714727
return (readRegister(Cru::Registers::BSP_USER_CONTROL.index) >> 16) & 0x0fff;
715728
}
729+
716730
} // namespace roc
717731
} // namespace AliceO2

src/Cru/CruBar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CruBar final : public BarInterfaceBase
5454
virtual boost::optional<float> getTemperature() override;
5555
virtual boost::optional<std::string> getFirmwareInfo() override;
5656
virtual boost::optional<std::string> getCardId() override;
57-
virtual int32_t getDroppedPackets() override;
57+
virtual int32_t getDroppedPackets(int endpoint) override;
5858
virtual uint32_t getCTPClock() override;
5959
virtual uint32_t getLocalClock() override;
6060
virtual int32_t getLinks() override;

src/Cru/CruDmaChannel.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ bool CruDmaChannel::isReadyQueueFull()
369369

370370
int32_t CruDmaChannel::getDroppedPackets()
371371
{
372-
return getBar2()->getDroppedPackets();
372+
int endpoint = getBar()->getEndpointNumber();
373+
return getBar2()->getDroppedPackets(endpoint);
373374
}
374375

375376
bool CruDmaChannel::injectError()

src/Cru/Gbt.cxx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ void Gbt::txcal()
164164
}
165165
}
166166

167+
uint32_t Gbt::getStatusAddress(Link link)
168+
{
169+
uint32_t address = Cru::getWrapperBaseAddress(link.wrapper) +
170+
Cru::Registers::GBT_WRAPPER_BANK_OFFSET.address * (link.bank + 1) +
171+
Cru::Registers::GBT_BANK_LINK_OFFSET.address * (link.id + 1) +
172+
Cru::Registers::GBT_LINK_REGS_OFFSET.address +
173+
Cru::Registers::GBT_LINK_STATUS.address;
174+
175+
return address;
176+
}
177+
178+
uint32_t Gbt::getClearErrorAddress(Link link)
179+
{
180+
uint32_t address = Cru::getWrapperBaseAddress(link.wrapper) +
181+
Cru::Registers::GBT_WRAPPER_BANK_OFFSET.address * (link.bank + 1) +
182+
Cru::Registers::GBT_BANK_LINK_OFFSET.address * (link.id + 1) +
183+
Cru::Registers::GBT_LINK_REGS_OFFSET.address +
184+
Cru::Registers::GBT_LINK_CLEAR_ERRORS.address;
185+
186+
return address;
187+
}
188+
167189
uint32_t Gbt::getSourceSelectAddress(Link link)
168190
{
169191
uint32_t address = Cru::getWrapperBaseAddress(link.wrapper) +
@@ -203,5 +225,44 @@ uint32_t Gbt::getAtxPllRegisterAddress(int wrapper, uint32_t reg)
203225
Cru::Registers::GBT_WRAPPER_ATX_PLL.address + 4 * reg;
204226
}
205227

228+
bool Gbt::getStickyBit(Link link)
229+
{
230+
uint32_t addr = getStatusAddress(link);
231+
uint32_t data = mPdaBar->readRegister(addr/4);
232+
uint32_t lockedData = Utilities::getBit(~data, 14); //phy up 1 = locked, 0 = down
233+
uint32_t ready = Utilities::getBit(~data, 15); //data layer up 1 = locked, 0 = down
234+
if ((lockedData == 0x0) || (ready == 0x0)) {
235+
resetStickyBit(link);
236+
}
237+
238+
return (lockedData == 0x1 && ready == 0x1) ? true : false;
239+
}
240+
241+
void Gbt::resetStickyBit(Link link) {
242+
uint32_t addr = getClearErrorAddress(link);
243+
244+
mPdaBar->writeRegister(addr/4, 0x0);
245+
}
246+
247+
uint32_t Gbt::getRxClockFrequency(Link link) { //In Hz
248+
uint32_t address = Cru::getWrapperBaseAddress(link.wrapper) +
249+
Cru::Registers::GBT_WRAPPER_BANK_OFFSET.address * (link.bank + 1) +
250+
Cru::Registers::GBT_BANK_LINK_OFFSET.address * (link.id + 1) +
251+
Cru::Registers::GBT_LINK_REGS_OFFSET.address +
252+
Cru::Registers::GBT_LINK_RX_CLOCK.address;
253+
254+
return mPdaBar->readRegister(address/4);
255+
}
256+
257+
uint32_t Gbt::getTxClockFrequency(Link link) { //In Hz
258+
uint32_t address = Cru::getWrapperBaseAddress(link.wrapper) +
259+
Cru::Registers::GBT_WRAPPER_BANK_OFFSET.address * (link.bank + 1) +
260+
Cru::Registers::GBT_BANK_LINK_OFFSET.address * (link.id + 1) +
261+
Cru::Registers::GBT_LINK_REGS_OFFSET.address +
262+
Cru::Registers::GBT_LINK_TX_CLOCK.address;
263+
264+
return mPdaBar->readRegister(address/4);
265+
}
266+
206267
} // namespace roc
207268
} // namespace AliceO2

0 commit comments

Comments
 (0)