Commit ee70aadd authored by Adam Wujek's avatar Adam Wujek 💬

shell: merge "sfp detect" and "sfp match" commands

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent a574856e
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
* *
* Released according to the GNU GPL, version 2 or any later version. * Released according to the GNU GPL, version 2 or any later version.
*/ */
/* Command: sfp /* Command: sfp
Arguments: subcommand [subcommand-specific args] * Arguments: subcommand [subcommand-specific args]
*
Description: SFP detection/database manipulation. * Description: SFP detection/database manipulation.
* Subcommands:
Subcommands: * add <product_number> <delta_tx> <delta_rx> <alpha> - adds an SFP to
add vendor_type delta_tx delta_rx alpha - adds an SFP to the database, with given alpha/delta_rx/delta_rx values * the database, with given alpha/delta_rx/delta_rx values
show - shows the SFP database * show - shows the SFP database
match - tries to get calibration parameters from DB for a detected SFP * match - detects the transceiver type and tries to get calibration parameters
erase - cleans the SFP database * from DB for a detected SFP
detect - detects the transceiver type * erase - cleans the SFP database
*/ */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -40,38 +40,14 @@ static int cmd_sfp(const char *args[]) ...@@ -40,38 +40,14 @@ static int cmd_sfp(const char *args[])
pp_printf("Wrong parameter\n"); pp_printf("Wrong parameter\n");
return -EINVAL; return -EINVAL;
} }
if (!strcasecmp(args[0], "detect")) { if (!strcasecmp(args[0], "erase")) {
/* clear sfp_pn */
sfp_pn[0] = '\0';
if (!sfp_present()) {
pp_printf("No SFP.\n");
return -ENODEV;
}
if (sfp_read_part_id(sfp_pn)) {
pp_printf("SFP read error\n");
return -EIO;
}
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp.pn[temp]);
pp_printf("\n");
return 0;
}
// else if (!strcasecmp(args[0], "i2cscan"))
// {
// mi2c_scan(WRPC_FMC_I2C);
// return 0;
// }
else if (!strcasecmp(args[0], "erase")) {
if (storage_sfpdb_erase() == EE_RET_I2CERR) { if (storage_sfpdb_erase() == EE_RET_I2CERR) {
pp_printf("Could not erase DB\n"); pp_printf("Could not erase DB\n");
return -EIO; return -EIO;
} }
return 0; return 0;
} else if (args[4] && !strcasecmp(args[0], "add")) { } else if (args[4] && !strcasecmp(args[0], "add")) {
if (strlen(args[1]) > SFP_PN_LEN) temp = strnlen(args[1], SFP_PN_LEN);
temp = SFP_PN_LEN;
else
temp = strlen(args[1]);
for (i = 0; i < temp; ++i) for (i = 0; i < temp; ++i)
sfp.pn[i] = args[1][i]; sfp.pn[i] = args[1][i];
while (i < SFP_PN_LEN) while (i < SFP_PN_LEN)
...@@ -105,22 +81,31 @@ static int cmd_sfp(const char *args[]) ...@@ -105,22 +81,31 @@ static int cmd_sfp(const char *args[])
pp_printf("%d: PN:", i + 1); pp_printf("%d: PN:", i + 1);
for (temp = 0; temp < SFP_PN_LEN; ++temp) for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp.pn[temp]); pp_printf("%c", sfp.pn[temp]);
pp_printf(" dTx: %d dRx: %d alpha: %d\n", sfp.dTx, pp_printf(" dTx: %8d dRx: %8d alpha: %8d\n", sfp.dTx,
sfp.dRx, sfp.alpha); sfp.dRx, sfp.alpha);
} }
return 0; return 0;
} else if (!strcasecmp(args[0], "match")) { } else if (!strcasecmp(args[0], "match")) {
if (sfp_pn[0] == '\0') { sfp_pn[0] = '\0';
pp_printf("Run sfp detect first\n"); if (!sfp_present()) {
return -EFAULT; pp_printf("No SFP.\n");
return -ENODEV;
} }
if (sfp_read_part_id(sfp_pn)) {
pp_printf("SFP read error\n");
return -EIO;
}
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp_pn[temp]);
pp_printf("\n");
strncpy(sfp.pn, sfp_pn, SFP_PN_LEN); strncpy(sfp.pn, sfp_pn, SFP_PN_LEN);
if (storage_match_sfp(&sfp) == 0) { if (storage_match_sfp(&sfp) == 0) {
pp_printf("Could not match to DB\n"); pp_printf("Could not match to DB\n");
sfp_in_db = SFP_NOT_MATCHED; sfp_in_db = SFP_NOT_MATCHED;
return -ENXIO; return -ENXIO;
} }
pp_printf("SFP matched, dTx=%d, dRx=%d, alpha=%d\n", pp_printf("SFP matched, dTx=%d dRx=%d alpha=%d\n",
sfp.dTx, sfp.dRx, sfp.alpha); sfp.dTx, sfp.dRx, sfp.alpha);
sfp_deltaTx = sfp.dTx; sfp_deltaTx = sfp.dTx;
sfp_deltaRx = sfp.dRx; sfp_deltaRx = sfp.dRx;
......
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