Skip to content
Snippets Groups Projects
Commit df78c372 authored by Federico Vaga's avatar Federico Vaga
Browse files

lib|tools: get and show eeprom type


Signed-off-by: default avatarFederico Vaga <federico.vaga@cern.ch>
parent 66db6b97
No related merge requests found
......@@ -7,6 +7,7 @@
#ifndef _FMC_CORE_H
#define _FMC_CORE_H
#include <stddef.h>
#include <stdbool.h>
const char *fmc_version_get(void);
......@@ -26,6 +27,8 @@ void fmc_carrier_close(struct fmc_tkn *tkn);
bool fmc_slot_is_present(struct fmc_tkn *tkn, unsigned int slot_n);
bool fmc_slot_is_fru_valid(struct fmc_tkn *tkn, unsigned int slot_n);
int fmc_slot_geo_address(struct fmc_tkn *tkn, unsigned int slot_n,
unsigned int *ga);
unsigned int *ga);
int fmc_slot_eeprom_type_get(struct fmc_tkn *tkn, unsigned int slot_n,
char *str, size_t max_len);
#endif /* _FMC_CORE_H */
......@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
......@@ -29,6 +30,10 @@ const char *libfmc_version_full = "libfmc version:" GIT_VERSION;
#define BIT(_n) (1 << _n)
#endif
#ifndef MIN
#define MIN(_a,_b) (((_a) < (_b)) ? (_a) : (_b))
#endif
#define FMC_SLOT_PRESENT BIT(0)
#define FMC_SLOT_FRU_VALID BIT(1)
......@@ -155,6 +160,21 @@ static int __fmc_slot_ga_get(struct fmc_carrier *carr,
return err;
}
static int __fmc_slot_eeprom_type_get(struct fmc_carrier *carr,
unsigned int slot_n,
char *str, size_t max_len)
{
int ret;
ret = __fmc_sys_read_string(carr, slot_n, "eeprom_type", str, max_len);
if (ret < 0) {
strncpy(str, "unknown", MIN(strlen("unknown"), max_len));
return ret;
}
return 0;
}
static int fmc_carrier_slots_init(struct fmc_carrier *carr)
{
char pattern[MAX_PATH_LEN];
......@@ -182,6 +202,9 @@ static int fmc_carrier_slots_init(struct fmc_carrier *carr)
sscanf(basename(g.gl_pathv[i]), "fmc-slot-%*d.%d",
&carr->slot[i]->id);
__fmc_slot_ga_get(carr, carr->slot[i]->id, &carr->slot[i]->ga);
__fmc_slot_eeprom_type_get(carr, carr->slot[i]->id,
carr->slot[i]->eeprom_type,
MAX_SYS_LEN);
if (__fmc_slot_is_present(carr, carr->slot[i]->id))
carr->slot[i]->flags |= FMC_SLOT_PRESENT;
if (__fmc_slot_is_fru_valid(carr, carr->slot[i]->id))
......@@ -250,6 +273,19 @@ int fmc_slot_geo_address(struct fmc_tkn *tkn, unsigned int slot_n,
return 0;
}
int fmc_slot_eeprom_type_get(struct fmc_tkn *tkn, unsigned int slot_n,
char *buf, size_t count)
{
struct fmc_carrier *carrier = (struct fmc_carrier *)tkn;
struct fmc_slot *slot = __fmc_slot_get(carrier, slot_n);
if (!slot)
return -1;
strncpy(buf, slot->eeprom_type, MIN(count, MAX_SYS_LEN));
return 0;
}
/**
* Open an FMC carrier
*
......
......@@ -55,15 +55,30 @@ static void print_slot_geo_addr(struct fmc_tkn *tkn, unsigned int id)
fprintf(stdout, "\t\tgeo-addr: 0x%02x\n", ga);
}
#define BUF_LEN 16
static void print_slot_eeprom_type(struct fmc_tkn *tkn, unsigned int id)
{
char buf[BUF_LEN];
int err;
err = fmc_slot_eeprom_type_get(tkn, id, buf, BUF_LEN);
if (err)
fputs("\t\teeprom-type: unknown,\n", stdout);
else
fprintf(stdout, "\t\teeprom-type: %s\n", buf);
}
#undef BUFLEN
static void print_slot(struct fmc_tkn *tkn,
unsigned int carr_id, unsigned int id)
{
fprintf(stdout, "\t- fmc-slot-%d.%d:\n", carr_id, id);
if (verbose > 0)
print_slot_flags(tkn, id);
if (verbose > 1)
if (verbose > 1) {
print_slot_geo_addr(tkn, id);
fputc('\n', stdout);
print_slot_eeprom_type(tkn, id);
}
}
int main(int argc, char *argv[])
......
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