Skip to content
Snippets Groups Projects
Commit 71d23818 authored by qzhou's avatar qzhou
Browse files

remove exec files

parent f446d4c7
No related branches found
No related tags found
2 merge requests!86links slc tool,!96links
/*-------------------------------------------------------------------------------*\
regconfig: Monitoring the status of PCIe40 board and belle2links
Qi-Dong Zhou, KEK
2020.04.28 0.01 first version based on staths.c
\*--------------------------------------------------------------------------------*/
#define VERSION 01
#define MOD_DATE 20200428
#include "pcie40_b2slc.h"
#include "pcie40_reg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <bitset>
extern "C" int ecs_open(int dev, int bar);
extern "C" void ecs_close(int dev, int bar);
//#define PCIE_DEV 0
#define MAX_NUM_CH 48
#define MAX_SLOT 3
#define SLC_BAR 2
#ifndef D
#define D(a,b,c) (((a)>>(c))&((1<<((b)+1-(c)))-1))
#define B(a,b) D(a,b,b)
#define Bs(a,b,s) (B(a,b)?(s):"")
#define Ds(a,b,c,s) (D(a,b,c)?(s):"")
#endif
// parse
int dev_slot = 0; // default device slot number, for use multiple PCIe40 on a server,--dev xx option
int ch = -1;
std::bitset<48> link_mask;
//Flag for switch slc access method
void argument(int argc, char **argv){
char *ARGV0 = argv[0];
std::bitset<48> en_link;
if(argc == 1){
link_mask.set();
std::cout<<std::hex<<link_mask<<std::endl;
}
for(int i=1;i<argc;i++){
std::string ss = argv[i];
if(ss=="--dev"){
dev_slot = atoi(argv[++i]);
if( dev_slot<0 || dev_slot >= MAX_SLOT){
fprintf(stderr, "Invalid device slot %d, Valid slot [0, %d]\n", dev_slot, MAX_SLOT);
}
}
if(ss=="--ch"){
for(int j = i+1; j<argc; j++){
ch = atoi(argv[j]);
if( ch<0 || ch >= MAX_NUM_CH){
fprintf(stderr, "Invalid channel ID %d, Valid ID [0, %d]\n", ch, MAX_NUM_CH);
}
en_link.reset();
en_link.set(ch, true);
link_mask = link_mask | en_link;
//std::cout <<i << " " << j <<" "<< ch <<" "<<std::hex<< en_link <<" "<<std::hex<<link_mask<< std::endl;
}
}
if(ss=="-h" || ss=="-help"){
fprintf(stderr, "%s version %d.%02d date %d\n"
, ARGV0, VERSION/100, VERSION%100, MOD_DATE);
fprintf(stderr, "usage: %s --ch 0 \n"
" --dev xx #device slot number which installed PCIe40\n"
" --ch xx xx ... #link channel number\n"
, ARGV0);
return;
}
}
}
/* ---------------------------------------------------------------------- *\
* statpcie40
\* ---------------------------------------------------------------------- */
int
statpice40(pcie40reg_t pcie40reg)
{
pcie40reg_t *pcie = &pcie40reg;
int pcie40_sta = pcie40_status(dev_slot);
int pcie40_fwver = 0;
printf("PCIE40 firmware version %d.%02d\n",pcie40_fwver / 100, pcie40_fwver % 100);
printf("memory: %s | ttd: %s | ttd clk: %s | run=: %d | trg: %d \n",
B(pcie40_sta, 8)?"FULL":"OK",
B(pcie40_sta, 12)?"UP":"DOWN",
B(pcie40_sta, 11)?"UP":"DOWN",
pcie40_run_number(dev_slot),
D(pcie40_sta, 28, 17));
printf("rxlink: %s | txlink: %s | txlink: %s | rxdisp: %s | rxdata: %s\n",
B(pcie40_sta, 0)?"READY":"NOT READY",
B(pcie40_sta, 1)?"READY":"NOT READY",
B(pcie40_sta, 2)?"SYNCED":"NOT SYNCED",
B(pcie40_sta, 3)?"ERROR":"OK",
B(pcie40_sta, 4)?"ERROR":"OK");
return 0;
}
/* ---------------------------------------------------------------------- *\
* statlink
\* ---------------------------------------------------------------------- */
int
statlink(std::bitset<48> link_mask, pcie40reg_t pcie40reg[])
{
int i;
int first = 1;
int quiet = 1;
for (i=0; i<48; i++) {
pcie40reg_t *pcie = &pcie40reg[i];
double total;
char prompt[128];
if (!link_mask[i]) continue;
quiet = 0;
if (! first) printf("\n");
first =0;
sprintf(prompt, "(%02d) ", i);
if ( !pcie40_b2l_status(dev_slot, i) ) {
printf("b2link is down\n");
//} else if (pcie->feeser & 0x8000) {
//printf("fee info is not available\n");
} else {
printf("%s serial %d version %d\n",
feename(pcie->feehw, pcie->feefw), pcie->feeser, pcie->feever);
}
// if (pcie->pcie40ver < 46) {
// printf("%s", prompt);
// printf("(old PCIE40 firmware < 0.46 gives incorrect stats)\n");
// }
printf("%s", prompt);
printf("b2l=%s (rx=%s tx=%s rxsta=%s txsta=%s mask=%s)\n",
pcie40_b2l_status(dev_slot, i)?"UP":"DOWN",
pcie40_b2l_rxstatus(dev_slot, i)?"UP":"DOWN",
pcie40_b2l_txstatus(dev_slot, i)?"UP":"DOWN",
pcie40_b2l_rxready(dev_slot, i)?"READY":"NOT READY",
pcie40_b2l_txready(dev_slot, i)?"READY":"NOT READY",
pcie40_b2l_mask(dev_slot, i)?"UNMASK":"MASK");
printf("%s", prompt);
printf("prtxff=%s (word=%x) prrxff=%s (word=%x)\n",
pcie40_writeFifoStatus(dev_slot, i)?"FULL":"NOT FULL",
//pcie40_writeFifoStatus(dev_slot, i),
pcie40_writeFifoWord(dev_slot, i),
pcie40_readFifoStatus(dev_slot, i)?"FULL":"NOT FULL",
pcie40_readFifoWord(dev_slot, i));
// printf("stat=%08x (ff=%x rx=%x pr=%x pt=%x tx=%x%s%s%s%s%s%s%s%s)\n",
// pcie->pcie40sta,
// D(pcie->pcie40sta,11,8),
// D(pcie->pcie40sta,15,12),
// D(pcie->pcie40sta,19,16),
// D(pcie->pcie40sta,23,20),
// D(pcie->pcie40sta,28,24),
// Bs(pcie->pcie40sta,0," linkdown"),
// B(pcie->pcie40sta,31)&&!B(pcie->pcie40sta,1)?" linklost":"",
// Bs(pcie->pcie40sta,5," ffstate"),
// Bs(pcie->pcie40sta,29," pll"),
// Bs(pcie->pcie40sta,7," pll2"),
// Bs(pcie->pcie40sta,1," masked"),
// Bs(pcie->pcie40sta,2," fful"),
// Bs(pcie->pcie40sta,4," nwff"));
printf("%s", prompt);
printf("rxdata=%04x rxlinkdown=%d rxcrcerr=%d feecrcerr=%d\n",
D(pcie->rxdata,15,0), D(pcie->rxdata,31,24), D(pcie->rxdata,23,16),
pcie->feecrce);
printf("%s", prompt);
total = (pcie->nkbyte * 256.0 + (pcie->nword & 0xff)) * 4.0;
printf("event=%d total=%1.0fkB", pcie->nevent, total / 1000);
if (pcie->nevent) {
double avg = total / pcie->nevent;
printf(" (avg=%1.0fB", avg);
if (D(pcie->eventsz,31,16) == 0xffff) {
printf(" last=oflow");
} else {
printf(" last=%dB", D(pcie->eventsz,31,16)*4);
}
if (D(pcie->eventsz,15,0) == 0xffff) {
printf(" max=oflow)");
} else {
printf(" max=%dB)", D(pcie->eventsz,15,0)*4);
}
}
printf("\n");
printf("%s", prompt);
if ((pcie->vetoset & 3) == 0) {
printf("no b2link error correction");
} else if (pcie->vetocnt == 0) {
printf("no b2link error");
} else {
printf("b2link error %d(%c) %d(%c) %c%02x %c%02x %c%02x %c%02x %c%02x %c%02x",
D(pcie->vetocnt,31,16),
B(pcie->vetoset,1) ? 'i' : '-',
D(pcie->vetocnt,15,0),
B(pcie->vetoset,0) ? 'd' : '-',
B(pcie->vetobuf[0],25)?'K':'D', D(pcie->vetobuf[0],15,8),
B(pcie->vetobuf[0],24)?'K':'D', D(pcie->vetobuf[0],7,0),
B(pcie->vetobuf[0],21)?'K':'D', D(pcie->vetobuf[1],31,24),
B(pcie->vetobuf[0],20)?'K':'D', D(pcie->vetobuf[1],23,16),
B(pcie->vetobuf[0],17)?'K':'D', D(pcie->vetobuf[1],15,8),
B(pcie->vetobuf[0],16)?'K':'D', D(pcie->vetobuf[1],7,0));
}
printf("\n");
}
if (quiet) {
printf("no PCIE40 was found.\n");
}
}
/* ---------------------------------------------------------------------- *\
* getfee
\* ---------------------------------------------------------------------- */
int
getfee( pcie40reg_t *pcie40p)
{
int i;
const char *feetype;
int ret;
int hwtype;
int serial;
int fwtype;
int fwver;
hwtype = pcie40_readfee8(dev_slot, ch, PCIE40REG_FEEHWTYPE);
serial = pcie40_readfee8(dev_slot, ch, PCIE40REG_FEESERIAL);
fwtype = pcie40_readfee8(dev_slot, ch, PCIE40REG_FEEFWTYPE);
fwver = pcie40_readfee8(dev_slot, ch, PCIE40REG_FEEFWVER);
pcie40p->feeser = (serial | (hwtype << 8)) & 0xfff;
pcie40p->feever = (fwver | (fwtype << 8)) & 0xfff;
pcie40p->feehw = (hwtype >> 4) & 0x0f;
pcie40p->feefw = (fwtype >> 4) & 0x0f;
pcie40p->feecrce = pcie40_readfee8(dev_slot, ch, PCIE40REG_CRCERR);
return 0;
}
/* ---------------------------------------------------------------------- *\
* readregs
\* ---------------------------------------------------------------------- */
int
readregs(std::bitset<48> link_mask, pcie40reg_t pcie40reg[])
{
int i;
int o_readonly = 1;
int notfound = 1;
for (i=0; i<48; i++) {
pcie40reg_t *pcie = &pcie40reg[i];
memset(pcie, 0, sizeof(*pcie));
if (!link_mask[i]) continue;
pcie->xbusy = pcie40_readfee32(dev_slot, ch, PCIE40REG_CCLK);
pcie->conf = pcie40_readfee32(dev_slot, ch, PCIE40REG_CONF);
pcie->pcie40ver = pcie40_readfee32(dev_slot, ch, PCIE40REGL_VER); /* 81 */
pcie->rxdata = pcie40_readfee32(dev_slot, ch, PCIE40REGL_RXDATA); /* 84 */
pcie->eventsz = pcie40_readfee32(dev_slot, ch, PCIE40REGL_EVENTSZ); /* 85 */
pcie->nevent = pcie40_readfee32(dev_slot, ch, PCIE40REGL_NEVENT); /* 86 */
pcie->nkbyte = pcie40_readfee32(dev_slot, ch, PCIE40REGL_NKBYTE); /* 87 */
pcie->nword = pcie40_readfee32(dev_slot, ch, PCIE40REGL_NWORD); /* 88 */
pcie->vetoset = pcie40_readfee32(dev_slot, ch, PCIE40REGL_VETOSET); /* 89 */
pcie->vetocnt = pcie40_readfee32(dev_slot, ch, PCIE40REGL_VETOCNT); /* 8a */
pcie->vetobuf[0] = pcie40_readfee32(dev_slot, ch, PCIE40REGL_VETOBUF0); /* 8b */
pcie->vetobuf[1] = pcie40_readfee32(dev_slot, ch, PCIE40REGL_VETOBUF1); /* 8c */
pcie->feeser = 0xffff;
pcie->feever = 0xffff;
if ( !pcie40_b2l_status(dev_slot, i) ) {
getfee(pcie);
}
}
return notfound;
}
int main(int argc, char** argv){
// parse arguments
argument(argc, argv);
pcie40reg_t pcie40;
pcie40reg_t pcie40reg[48];
// open pcie40 device driver for current process
ecs_open( dev_slot , SLC_BAR );
//printf("link status: %d\n", pcie40_b2l_status(dev_slot, ch));
//printf("FEE HWTYPE: %d\n", pcie40_status(dev_slot, ch));
//getfee(pcie40reg);
printf("statlink version %d (%d) / ", VERSION, MOD_DATE);
statpice40(pcie40);
readregs(link_mask, pcie40reg);
statlink(link_mask, pcie40reg);
// close pcie40 device driver for current process
ecs_close( dev_slot , SLC_BAR) ;
return 0 ;
}
qzhou@b3ropc02.8447:1591026256
\ No newline at end of file
File deleted
File deleted
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment