Commit 9f7ff591 authored by Michel Arruat's avatar Michel Arruat Committed by Adam Wujek

tools:wr-streamers Fix endianness issue + use latest HW register layout.

Signed-off-by: Michel Arruat's avatarMichel Arruat <michel.arruat@cern.ch>
parent 9e117cd4
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
#include <getopt.h> #include <getopt.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <arpa/inet.h>
#include <libdevmap.h> #include <libdevmap.h>
#include <extest.h> #include <extest.h>
#include <hw/wr-streamer.h> #include <hw/wr_streamers.h>
static struct mapping_desc *wrstm = NULL; static struct mapping_desc *wrstm = NULL;
...@@ -32,7 +33,7 @@ int read_stats(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -32,7 +33,7 @@ int read_stats(struct cmd_desc *cmdd, struct atom *atoms)
(volatile struct WR_STREAMERS_WB *)wrstm->base; (volatile struct WR_STREAMERS_WB *)wrstm->base;
int val, overflow; int val, overflow;
double max_lat, min_lat, avg_lat; double max_lat, min_lat, avg_lat;
uint64_t acc_lat; uint64_t acc_lat, cnt_lat;
if (atoms == (struct atom *)VERBOSE_HELP) { if (atoms == (struct atom *)VERBOSE_HELP) {
printf("%s - options\n" printf("%s - options\n"
...@@ -51,53 +52,83 @@ int read_stats(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -51,53 +52,83 @@ int read_stats(struct cmd_desc *cmdd, struct atom *atoms)
if (atoms->type == Numeric) if (atoms->type == Numeric)
val = atoms->val; // specific stats val = atoms->val; // specific stats
//snapshot stats //snapshot stats
ptr->SSCR1 = WR_STREAMERS_SSCR1_SNAPSHOT_STATS; ptr->SSCR1 = iomemw32(wrstm->is_be, WR_STREAMERS_SSCR1_SNAPSHOT_STATS);
switch(val) { switch(val) {
case -1: case -1: //all stats
max_lat = WR_STREAMERS_RX_STAT3_RX_LATENCY_MAX_R(ptr->RX_STAT3); max_lat = WR_STREAMERS_RX_STAT0_RX_LATENCY_MAX_R(
iomemr32(wrstm->is_be, ptr->RX_STAT0));
max_lat = (max_lat * 8) / 1000.0; max_lat = (max_lat * 8) / 1000.0;
min_lat = WR_STREAMERS_RX_STAT3_RX_LATENCY_MAX_R(ptr->RX_STAT4); min_lat = WR_STREAMERS_RX_STAT1_RX_LATENCY_MIN_R(
iomemr32(wrstm->is_be, ptr->RX_STAT1));
min_lat = (min_lat * 8) / 1000.0; min_lat = (min_lat * 8) / 1000.0;
val = WR_STREAMERS_SSCR1_RX_LATENCY_ACC_OVERFLOW & overflow = WR_STREAMERS_SSCR1_RX_LATENCY_ACC_OVERFLOW &
ptr->RX_STAT7; iomemr32(wrstm->is_be, ptr->SSCR1);
overflow = val != 0;
//put it all together //put it all together
acc_lat = (((uint64_t)ptr->RX_STAT6) << 32) | ptr->RX_STAT5; acc_lat = ((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT11)
avg_lat = (((double)acc_lat) * 8 / 1000) / (double)ptr->RX_STAT7; << 32) |iomemr32(wrstm->is_be, ptr->RX_STAT10);
cnt_lat = ((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT13)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT12);
avg_lat = (((double)acc_lat) * 8 / 1000) / (double)cnt_lat;
fprintf(stderr, "Latency [us] : min=%10g max=%10g avg =%10g " fprintf(stderr, "Latency [us] : min=%10g max=%10g avg =%10g "
"(0x%x, 0x%x, %lld=%u << 32 | %u)*8/1000 us, cnt=%u)\n", "(0x%x, 0x%x, %lu=%u << 32 | %u)*8/1000 us, "
min_lat, max_lat, avg_lat, ptr->RX_STAT4, "cnt =%lu overflow =%d)\n",
ptr->RX_STAT3, (long long)acc_lat, ptr->RX_STAT6, min_lat, max_lat, avg_lat,
ptr->RX_STAT5, ptr->RX_STAT7); iomemr32(wrstm->is_be, ptr->RX_STAT1),
fprintf(stderr, "Frames [number]: tx =%10u rx =%10u lost=%10u " iomemr32(wrstm->is_be, ptr->RX_STAT0),
"(lost blocks%5u)\n", acc_lat, iomemr32(wrstm->is_be, ptr->RX_STAT11),
ptr->TX_STAT, ptr->RX_STAT1, ptr->RX_STAT2, iomemr32(wrstm->is_be, ptr->RX_STAT10),
ptr->RX_STAT8); cnt_lat, overflow);
fprintf(stderr, "Frames [number]: tx =%lu rx =%lu lost=%lu "
"(lost blocks =%lu)\n",
((uint64_t)iomemr32(wrstm->is_be, ptr->TX_STAT3)
<< 32) | iomemr32(wrstm->is_be, ptr->TX_STAT2),
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT5)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT4),
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT7)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT6),
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT9)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT8));
break; break;
case 0: case 0:
fprintf(stderr, "%s:%10u\n", stats_mesg[0][1], ptr->RX_STAT1); fprintf(stderr, "%s:%lu\n", stats_mesg[0][1],
((uint64_t)iomemr32(wrstm->is_be, ptr->TX_STAT3)
<< 32) | iomemr32(wrstm->is_be, ptr->TX_STAT2));
break; break;
case 1: case 1:
fprintf(stderr, "%s:%10u\n", stats_mesg[1][1], ptr->RX_STAT2); fprintf(stderr, "%s:%lu\n", stats_mesg[1][1],
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT5)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT4));
break; break;
case 2: case 2:
fprintf(stderr, "%s: 0x%x\n", stats_mesg[2][1], ptr->RX_STAT3); fprintf(stderr, "%s:%lu\n", stats_mesg[2][1],
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT7)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT6));
break; break;
case 3: case 3:
fprintf(stderr, "%s: 0x%x\n", stats_mesg[3][1], ptr->RX_STAT4); fprintf(stderr, "%s: 0x%x\n", stats_mesg[3][1],
WR_STREAMERS_RX_STAT0_RX_LATENCY_MAX_R(
iomemr32(wrstm->is_be, ptr->RX_STAT0)));
break; break;
case 4: case 4:
fprintf(stderr, "%s:%10u\n", stats_mesg[4][1], ptr->RX_STAT5); fprintf(stderr, "%s:%10u\n", stats_mesg[4][1],
WR_STREAMERS_RX_STAT1_RX_LATENCY_MIN_R(
iomemr32(wrstm->is_be, ptr->RX_STAT1)));
break; break;
case 5: case 5:
fprintf(stderr, "%s:%10u\n", stats_mesg[5][1], ptr->RX_STAT6); fprintf(stderr, "%s:%lu\n", stats_mesg[5][1],
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT11)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT10));
break; break;
case 6: case 6:
fprintf(stderr, "%s:%10u\n", stats_mesg[6][1], ptr->RX_STAT7); fprintf(stderr, "%s:%lu\n", stats_mesg[6][1],
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT13)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT12));
break; break;
case 7: case 7:
fprintf(stderr, "%s: 0x%x\n", stats_mesg[7][1], ptr->RX_STAT8); fprintf(stderr, "%s:%lu\n", stats_mesg[7][1],
((uint64_t)iomemr32(wrstm->is_be, ptr->RX_STAT9)
<< 32) | iomemr32(wrstm->is_be, ptr->RX_STAT8));
break; break;
} }
...@@ -110,7 +141,7 @@ int read_stats(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -110,7 +141,7 @@ int read_stats(struct cmd_desc *cmdd, struct atom *atoms)
#define LEAP_SECONDS 37 #define LEAP_SECONDS 37
int read_reset_time(struct cmd_desc *cmdd, struct atom *atoms) int read_reset_time(struct cmd_desc *cmdd, struct atom *atoms)
{ {
uint32_t val=0; uint32_t val;
int days=0, hours=0, minutes=0, seconds; int days=0, hours=0, minutes=0, seconds;
double reset_time_elapsed=0; double reset_time_elapsed=0;
time_t cur_time; time_t cur_time;
...@@ -123,9 +154,9 @@ int read_reset_time(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -123,9 +154,9 @@ int read_reset_time(struct cmd_desc *cmdd, struct atom *atoms)
return 1; return 1;
} }
val = ptr->SSCR2; val = iomemr32(wrstm->is_be, ptr->SSCR2);
res_time_sec = (time_t)(WR_STREAMERS_SSCR2_RST_TS_TAI_LSB_R(val) + res_time_sec = (time_t)(WR_STREAMERS_SSCR2_RST_TS_TAI_LSB_R(val) +
LEAP_SECONDS);//to UTC LEAP_SECONDS);//to UTC
cur_time = time(NULL); cur_time = time(NULL);
reset_time_elapsed = difftime(cur_time,res_time_sec); reset_time_elapsed = difftime(cur_time,res_time_sec);
...@@ -133,8 +164,10 @@ int read_reset_time(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -133,8 +164,10 @@ int read_reset_time(struct cmd_desc *cmdd, struct atom *atoms)
hours = (reset_time_elapsed-days*60*60*24)/(60*60); hours = (reset_time_elapsed-days*60*60*24)/(60*60);
minutes = (reset_time_elapsed-days*60*60*24-hours*60*60)/(60); minutes = (reset_time_elapsed-days*60*60*24-hours*60*60)/(60);
seconds = (reset_time_elapsed-days*60*60*24-hours*60*60-minutes*60); seconds = (reset_time_elapsed-days*60*60*24-hours*60*60-minutes*60);
fprintf(stderr, "Time elapsed from reset: %d days, %d h, %d m, %d s; Reseted on %s\n", fprintf(stderr, "Time elapsed from reset: %d days, %d h, %d m, %d s; "
days, hours, minutes, seconds, asctime(localtime(&res_time_sec))); "Reseted on %s\n",
days, hours, minutes, seconds,
asctime(localtime(&res_time_sec)));
return 1; return 1;
} }
...@@ -148,7 +181,7 @@ int reset_counters(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -148,7 +181,7 @@ int reset_counters(struct cmd_desc *cmdd, struct atom *atoms)
return 1; return 1;
} }
ptr->SSCR1 = WR_STREAMERS_SSCR1_RST_STATS; ptr->SSCR1 = iomemw32(wrstm->is_be, WR_STREAMERS_SSCR1_RST_STATS);
fprintf(stderr, "Reseted statistics counters\n"); fprintf(stderr, "Reseted statistics counters\n");
return 1; return 1;
} }
...@@ -163,7 +196,7 @@ int reset_seqid(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -163,7 +196,7 @@ int reset_seqid(struct cmd_desc *cmdd, struct atom *atoms)
return 1; return 1;
} }
ptr->SSCR1 = WR_STREAMERS_SSCR1_RST_SEQ_ID; ptr->SSCR1 = iomemw32(wrstm->is_be, WR_STREAMERS_SSCR1_RST_SEQ_ID);
return 1; return 1;
} }
...@@ -219,26 +252,29 @@ int get_set_latency(struct cmd_desc *cmdd, struct atom *atoms) ...@@ -219,26 +252,29 @@ int get_set_latency(struct cmd_desc *cmdd, struct atom *atoms)
if (atoms->type == Terminator) { if (atoms->type == Terminator) {
// Get Latency // Get Latency
fprintf(stderr, "Fixed latency configured: %d [us]\n", fprintf(stderr, "Fixed latency configured: %d [us]\n",
ptr->RX_CFG5); (iomemr32(wrstm->is_be, ptr->RX_CFG5) * 8) / 1000);
} }
else { else {
if (atoms->type != Numeric) if (atoms->type != Numeric)
return -TST_ERR_WRONG_ARG; return -TST_ERR_WRONG_ARG;
lat = atoms->val; lat = atoms->val;
if (lat < 0) { if (lat < 0) {
val = ~WR_STREAMERS_CFG_OR_RX_FIX_LAT & ptr->CFG; val = ~WR_STREAMERS_CFG_OR_RX_FIX_LAT &
ptr->CFG = val; iomemr32(wrstm->is_be, ptr->CFG);
ptr->CFG = iomemw32(wrstm->is_be, val);
fprintf(stderr, "Disabled overriding of default fixed " fprintf(stderr, "Disabled overriding of default fixed "
"latency value (it is now the default/set " "latency value (it is now the default/set "
"by application)\n"); "by application)\n");
} }
else { else {
val = (lat * 1000) / 8; val = (lat * 1000) / 8;
ptr->RX_CFG5 = WR_STREAMERS_RX_CFG5_FIXED_LATENCY_W(val); ptr->RX_CFG5 = iomemw32(wrstm->is_be,
val = ptr->CFG; WR_STREAMERS_RX_CFG5_FIXED_LATENCY_W(val));
val = iomemr32(wrstm->is_be, ptr->CFG);
val |= WR_STREAMERS_CFG_OR_RX_FIX_LAT; val |= WR_STREAMERS_CFG_OR_RX_FIX_LAT;
ptr->CFG = val; ptr->CFG = iomemw32(wrstm->is_be, val);
val = WR_STREAMERS_RX_CFG5_FIXED_LATENCY_R(ptr->RX_CFG5); val = WR_STREAMERS_RX_CFG5_FIXED_LATENCY_R(
iomemr32(wrstm->is_be, ptr->RX_CFG5));
fprintf(stderr, "Fixed latency set: %d [us] " fprintf(stderr, "Fixed latency set: %d [us] "
"(set %d | read : %d [cycles])\n", "(set %d | read : %d [cycles])\n",
lat, ((lat * 1000) / 8), val); lat, ((lat * 1000) / 8), val);
...@@ -342,7 +378,7 @@ int main(int argc, char *argv[]) ...@@ -342,7 +378,7 @@ int main(int argc, char *argv[])
} }
/* execute command loop */ /* execute command loop */
ret = extest_run("wrtsm", sig_hndl); ret = extest_run("wrstm", sig_hndl);
dev_unmap(wrstm); dev_unmap(wrstm);
return (ret) ? -1 : 0; return (ret) ? -1 : 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment