Commit 202451db authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: replace spaces with zeros in header read from SFP

Remove spaces from read SFP header
-vendor_name
-vendor_pn
-vendor_serial

Don't read SFP header twice at hal_port_insert_sfp in hal_port. Before header
was read first in function shw_sfp_read_verify_header, then indirectly by
shw_sfp_get_cal_data
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 646783f1
......@@ -520,7 +520,7 @@ int shw_sfp_read_header(int num, struct shw_sfp_header *head)
ret = shw_sfp_module_scan();
if (!(ret & (1 << num)))
return -1;
return -2;
ret =
shw_sfp_read(num, I2C_SFP_ADDRESS, 0x0,
......@@ -605,32 +605,35 @@ int shw_sfp_read_db(void)
return 0;
}
struct shw_sfp_caldata *shw_sfp_get_cal_data(int num)
struct shw_sfp_caldata *shw_sfp_get_cal_data(int num,
struct shw_sfp_header *head)
{
uint32_t ret;
struct shw_sfp_header head;
struct shw_sfp_caldata *t;
struct shw_sfp_caldata *other = NULL;
char *vn = (char *)head->vendor_name;
char *pn = (char *)head->vendor_pn;
char *vs = (char *)head->vendor_serial;
int i;
ret = shw_sfp_module_scan();
if (!(ret & (1 << num))) {
printf("sfp not inserted into slot: %d\n", num);
return NULL;
/* Replace spaces at the end of strings with 0 needed for
* string comparison inside shw_sfp_get_cal_data.
* String may contain spaces, standard says only about space padding */
for (i = 15; i >= 0 ; i--) {
if (vn[i] != 0x20)
break;
vn[i] = 0;
}
if (shw_sfp_read_header(num, &head) < 0) {
printf("failed to read sfp header for slot %d\n", num);
return NULL;
for (i = 15; i >= 0 ; i--) {
if (pn[i] != 0x20)
break;
pn[i] = 0;
}
char *pn = (char *)head.vendor_pn;
char *vs = (char *)head.vendor_serial;
int i;
for (i = 0; i < 16; i++) {
if (pn[i] == 0x20)
pn[i] = 0;
if (vs[i] == 0x20)
vs[i] = 0;
for (i = 15; i >= 0 ; i--) {
if (vs[i] != 0x20)
break;
vs[i] = 0;
}
t = shw_sfp_cal_list;
/* In the first pass, look for serial number */
while (t) {
......
......@@ -103,7 +103,8 @@ int shw_sfp_read_db(void);
int shw_sfp_read_verify_header(int num, struct shw_sfp_header *head);
/* return NULL if no data found */
struct shw_sfp_caldata *shw_sfp_get_cal_data(int num);
struct shw_sfp_caldata *shw_sfp_get_cal_data(int num,
struct shw_sfp_header *head);
/* Read and verify the header all at once. returns -1 on failure */
int shw_sfp_read_verify_header(int num, struct shw_sfp_header *head);
......
......@@ -442,14 +442,19 @@ static void hal_port_insert_sfp(struct hal_port_state * p)
char subname[48];
int err;
if (shw_sfp_read_verify_header(p->hw_index, &shdr) < 0) {
err = shw_sfp_read_verify_header(p->hw_index, &shdr);
if (err == -2) {
pr_error("SFP module not inserted. Failed to read SFP "
"configuration header\n");
return;
} else if (err < 0) {
pr_error("Failed to read SFP configuration header\n");
return;
}
pr_info("SFP Info: Manufacturer: %.16s P/N: %.16s, S/N: %.16s\n",
shdr.vendor_name, shdr.vendor_pn, shdr.vendor_serial);
cdata = shw_sfp_get_cal_data(p->hw_index);
cdata = shw_sfp_get_cal_data(p->hw_index, &shdr);
if (cdata) {
pr_info("SFP Info: (%s) deltaTx %d "
"delta Rx %d alpha %.3f (* 1e6)\n",
......
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