Commit 7eae5a89 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/tools: add new tool wrs_sfp_dump

New tool is to dump SFP's internal memory.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 6b2888d9
......@@ -21,4 +21,5 @@ nbtee
wrs_auxclk
wrs_checkcfg
mkpasswd
wrs_status_led
\ No newline at end of file
wrs_status_led
wrs_sfp_dump
......@@ -8,6 +8,7 @@ TOOLS += wrs_auxclk
TOOLS += wrs_checkcfg
TOOLS += wrs_status_led
TOOLS += mkpasswd
TOOLS += wrs_sfp_dump
PPSI_CONFIG = ../ppsi/include/generated/autoconf.h
WR_INSTALL_ROOT ?= /usr/lib/white-rabbit
......
#include <stdlib.h>
#include <unistd.h>
#include <libwr/switch_hw.h>
#include <libwr/wrs-msg.h>
#include <libwr/shw_io.h>
/* for shw_sfp_buses_init and shw_sfp_print_header*/
#include "../libwr/i2c_sfp.h"
void print_info(char *prgname)
{
printf("usage: %s [parameters]\n", prgname);
printf(""
" Dump sfp header info for all ports\n"
" -p <num> Dump sfp header for specific port (1-18)\n"
" -h Show this message\n"
" -q Decrease verbosity\n"
" -v Increase verbosity\n"
"\n"
"NOTE: Be carefull! All reads (i2c transfers) are in race with hal!\n"
);
}
int main(int argc, char **argv)
{
int c;
struct shw_sfp_header shdr;
int err;
int nports;
int dump_port;
int i;
wrs_msg_init(argc, argv);
nports = 18;
dump_port = 1;
while ((c = getopt(argc, argv, "ahqvp:")) != -1) {
switch (c) {
case 'p':
dump_port = atoi(optarg);
if (dump_port) {
nports = dump_port;
} else {
printf("Wrong port number!\n");
print_info(argv[0]);
exit(1);
}
break;
case 'q': break; /* done in wrs_msg_init() */
case 'v': break; /* done in wrs_msg_init() */
case 'h':
default:
print_info(argv[0]);
exit(1);
}
}
/* init i2c, be carefull all i2c transfers are in race with hal! */
assert_init(shw_io_init());
assert_init(shw_fpga_mmap_init());
assert_init(shw_sfp_buses_init());
for (i = dump_port; i <= nports; i++) {
printf("========= port %d =========\n", i);
err = shw_sfp_read_verify_header(i - 1, &shdr);
if (err == -2) {
pr_error("SFP module not inserted in port %d. Failed "
"to read SFP configuration header\n", i);
} else if (err < 0) {
pr_error("Failed to read SFP configuration header on "
"port %d\n", i);
} else {
shw_sfp_print_header(&shdr);
}
}
return 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