Commit 469248b5 authored by Adam Wujek's avatar Adam Wujek 💬

include/sfp: use SFP_GET/SFP_ADD as a storage_get_sfp parameter

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent fd5aa7b7
...@@ -183,7 +183,7 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos) ...@@ -183,7 +183,7 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
if (sfpcount == SFP_DB_EMPTY) if (sfpcount == SFP_DB_EMPTY)
sfpcount = 0; sfpcount = 0;
if (!oper) { if (oper == SFP_GET) {
if (sfpcount == 0) { if (sfpcount == 0) {
/* There are no SFPs in the database to read */ /* There are no SFPs in the database to read */
return 0; return 0;
...@@ -199,7 +199,7 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos) ...@@ -199,7 +199,7 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
if (sfp_chksum((uint8_t *)sfp) != sfp->chksum) if (sfp_chksum((uint8_t *)sfp) != sfp->chksum)
return EE_RET_CORRPT; return EE_RET_CORRPT;
} }
if (oper) { if (oper == SFP_ADD) {
for (i = 0; i < sfpcount; i++) { for (i = 0; i < sfpcount; i++) {
if (eeprom_read(i2cif, i2c_addr, if (eeprom_read(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount) EE_BASE_SFP + sizeof(sfpcount)
...@@ -244,7 +244,7 @@ int storage_match_sfp(struct s_sfpinfo * sfp) ...@@ -244,7 +244,7 @@ int storage_match_sfp(struct s_sfpinfo * sfp)
struct s_sfpinfo dbsfp; struct s_sfpinfo dbsfp;
for (i = 0; i < sfp_cnt; ++i) { for (i = 0; i < sfp_cnt; ++i) {
sfp_cnt = storage_get_sfp(&dbsfp, 0, i); sfp_cnt = storage_get_sfp(&dbsfp, SFP_GET, i);
if (sfp_cnt <= 0) if (sfp_cnt <= 0)
return sfp_cnt; return sfp_cnt;
......
...@@ -402,7 +402,7 @@ static int sfp_valid(struct s_sfpinfo *sfp) ...@@ -402,7 +402,7 @@ static int sfp_valid(struct s_sfpinfo *sfp)
return 1; return 1;
} }
static int sfp_entry(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos) static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{ {
static uint8_t sfpcount = 0; static uint8_t sfpcount = 0;
struct s_sfpinfo tempsfp; struct s_sfpinfo tempsfp;
...@@ -430,17 +430,19 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos) ...@@ -430,17 +430,19 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos)
} }
} }
if (add && sfpcount == SFPS_MAX) { /* no more space to add new SFPs */ if ((oper == SFP_ADD) && (sfpcount == SFPS_MAX)) {
/* no more space to add new SFPs */
ret = EE_RET_DBFULL; ret = EE_RET_DBFULL;
goto out; goto out;
} }
if (!pos && !add && sfpcount == 0) { /* no SFPs in the database */ if (!pos && (oper == SFP_GET) && sfpcount == 0) {
/* no SFPs in the database */
ret = 0; ret = 0;
goto out; goto out;
} }
if (!add) { if (oper == SFP_GET) {
if (sdbfs_fread(&wrc_sdb, sizeof(sfpcount) + pos * sizeof(*sfp), if (sdbfs_fread(&wrc_sdb, sizeof(sfpcount) + pos * sizeof(*sfp),
sfp, sizeof(*sfp)) sfp, sizeof(*sfp))
!= sizeof(*sfp)) != sizeof(*sfp))
...@@ -454,7 +456,8 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos) ...@@ -454,7 +456,8 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos)
pp_printf("sfp: corrupted checksum\n"); pp_printf("sfp: corrupted checksum\n");
goto out; goto out;
} }
} else { }
if (oper == SFP_ADD) {
/* count checksum */ /* count checksum */
ptr = (uint8_t *)sfp; ptr = (uint8_t *)sfp;
/* use sizeof() - 1 because we don't include checksum */ /* use sizeof() - 1 because we don't include checksum */
...@@ -488,7 +491,7 @@ static int storage_update_sfp(struct s_sfpinfo *sfp) ...@@ -488,7 +491,7 @@ static int storage_update_sfp(struct s_sfpinfo *sfp)
/* copy entries from flash to the memory, update entry if matched */ /* copy entries from flash to the memory, update entry if matched */
for (i = 0; i < sfpcount; ++i) { for (i = 0; i < sfpcount; ++i) {
dbsfp = &sfp_db[i]; dbsfp = &sfp_db[i];
sfpcount = sfp_entry(dbsfp, 0, i); sfpcount = sfp_entry(dbsfp, SFP_GET, i);
if (sfpcount <= 0) if (sfpcount <= 0)
return sfpcount; return sfpcount;
if (!strncmp(dbsfp->pn, sfp->pn, 16)) { if (!strncmp(dbsfp->pn, sfp->pn, 16)) {
...@@ -508,7 +511,7 @@ static int storage_update_sfp(struct s_sfpinfo *sfp) ...@@ -508,7 +511,7 @@ static int storage_update_sfp(struct s_sfpinfo *sfp)
/* add all SFPs */ /* add all SFPs */
for (i = 0; i < sfpcount; ++i) { for (i = 0; i < sfpcount; ++i) {
dbsfp = &sfp_db[i]; dbsfp = &sfp_db[i];
temp = sfp_entry(dbsfp, 1, 0); temp = sfp_entry(dbsfp, SFP_ADD, 0);
if (temp < 0) { if (temp < 0) {
/* if error, return it */ /* if error, return it */
return temp; return temp;
...@@ -517,13 +520,13 @@ static int storage_update_sfp(struct s_sfpinfo *sfp) ...@@ -517,13 +520,13 @@ static int storage_update_sfp(struct s_sfpinfo *sfp)
return i; return i;
} }
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos) int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{ {
struct s_sfpinfo tmp_sfp; struct s_sfpinfo tmp_sfp;
if (!add) { if (oper == SFP_GET) {
/* Get SFP entry */ /* Get SFP entry */
return sfp_entry(sfp, add, pos); return sfp_entry(sfp, SFP_GET, pos);
} }
/* storage_match_sfp replaces content of parameter, so do the copy /* storage_match_sfp replaces content of parameter, so do the copy
...@@ -531,7 +534,7 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos) ...@@ -531,7 +534,7 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos)
tmp_sfp = *sfp; tmp_sfp = *sfp;
if (!storage_match_sfp(&tmp_sfp)) { /* add a new sfp entry */ if (!storage_match_sfp(&tmp_sfp)) { /* add a new sfp entry */
pp_printf("Adding new SFP entry\n"); pp_printf("Adding new SFP entry\n");
return sfp_entry(sfp, 1, 0); return sfp_entry(sfp, SFP_ADD, 0);
} }
pp_printf("Update existing SFP entry\n"); pp_printf("Update existing SFP entry\n");
...@@ -545,7 +548,7 @@ int storage_match_sfp(struct s_sfpinfo * sfp) ...@@ -545,7 +548,7 @@ int storage_match_sfp(struct s_sfpinfo * sfp)
struct s_sfpinfo dbsfp; struct s_sfpinfo dbsfp;
for (i = 0; i < sfpcount; ++i) { for (i = 0; i < sfpcount; ++i) {
sfpcount = sfp_entry(&dbsfp, 0, i); sfpcount = sfp_entry(&dbsfp, SFP_GET, i);
if (sfpcount <= 0) if (sfpcount <= 0)
return sfpcount; return sfpcount;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) { if (!strncmp(dbsfp.pn, sfp->pn, 16)) {
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#define SFP_NOT_MATCHED 1 #define SFP_NOT_MATCHED 1
#define SFP_MATCHED 2 #define SFP_MATCHED 2
#define SFP_GET 0
#define SFP_ADD 1
extern char sfp_pn[SFP_PN_LEN]; extern char sfp_pn[SFP_PN_LEN];
extern int32_t sfp_in_db; extern int32_t sfp_in_db;
......
...@@ -55,7 +55,7 @@ static int cmd_sfp(const char *args[]) ...@@ -55,7 +55,7 @@ static int cmd_sfp(const char *args[])
sfp.dTx = atoi(args[2]); sfp.dTx = atoi(args[2]);
sfp.dRx = atoi(args[3]); sfp.dRx = atoi(args[3]);
sfp.alpha = atoi(args[4]); sfp.alpha = atoi(args[4]);
temp = storage_get_sfp(&sfp, 1, 0); temp = storage_get_sfp(&sfp, SFP_ADD, 0);
if (temp == EE_RET_DBFULL) { if (temp == EE_RET_DBFULL) {
pp_printf("SFP DB is full\n"); pp_printf("SFP DB is full\n");
return -ENOSPC; return -ENOSPC;
...@@ -70,7 +70,7 @@ static int cmd_sfp(const char *args[]) ...@@ -70,7 +70,7 @@ static int cmd_sfp(const char *args[])
return 0; return 0;
} else if (!strcasecmp(args[0], "show")) { } else if (!strcasecmp(args[0], "show")) {
for (i = 0; i < sfpcount; ++i) { for (i = 0; i < sfpcount; ++i) {
sfpcount = storage_get_sfp(&sfp, 0, i); sfpcount = storage_get_sfp(&sfp, SFP_GET, i);
if (sfpcount == 0) { if (sfpcount == 0) {
pp_printf("SFP database empty\n"); pp_printf("SFP database empty\n");
return 0; 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