Commit 69f53c93 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

Merge branch 'snmp-support' into proposed_master

parents 699fb5da da0dcab6
......@@ -136,6 +136,23 @@ config SYSLOG
The user (or init script) must use "syslog <ipaddr> <macaddr>"
to enable it. The special "off" ipaddr disables syslog.
config SNMP
depends on IP
default y
boolean "Mini SNMP responder"
config SNMP_SET
depends on SNMP
default y
boolean "Add SET support to the Mini SNMP responder"
help
This option enables support for SET requests for Mini SNMP responder
config SNMP_HW_TYPE
depends on SNMP
default "spec"
string "Hardware type reported by SNMP"
config BUILD_INIT
depends on WR_NODE
default n
......@@ -360,6 +377,12 @@ config WRC_VERBOSE
help
This enables some more diagnostic messages. Normally off.
config SNMP_VERBOSE
depends on DEVELOPER && SNMP
boolean "More verbose messages in SNMP"
help
This enables some more diagnostic messages. Normally off.
config FAKE_TEMPERATURES
depends on DEVELOPER
boolean "Offer an array of 3 fake temperatures, for testing"
......
......@@ -110,6 +110,12 @@ OUTPUT-$(CONFIG_WR_SWITCH) = rt_cpu
OUTPUT := $(OUTPUT-y)
GIT_VER = $(shell git describe --always --dirty | sed 's;^wr-switch-sw-;;')
GIT_USR = $(shell git config --get-all user.name)
# if user.name is not available from git use user@hostname
ifeq ($(GIT_USR),)
GIT_USR = $(shell whoami)@$(shell hostname)
endif
all: tools $(OUTPUT).elf $(arch-files-y)
......@@ -140,7 +146,7 @@ sdb-lib/libsdbfs.a:
$(MAKE) -C sdb-lib
$(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules $(OUTPUT).o config.o
$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -c revision.c
$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\"" -c revision.c
${CC} -o $@ revision.o config.o $(OUTPUT).o $(LDFLAGS)
${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
$(SIZE) $@
......
#
# Automatically generated make config: don't edit
#
# CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y
CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=0
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
# CONFIG_SYSLOG is not set
CONFIG_SNMP=y
# CONFIG_SNMP_SET is not set
CONFIG_SNMP_HW_TYPE="spec"
# CONFIG_BUILD_INIT is not set
CONFIG_INIT_COMMAND=""
CONFIG_HAS_BUILD_INIT=0
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
#
# wrpc-sw is tainted if you change the following options
#
# CONFIG_DEVELOPER is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
CONFIG_VLAN_ARRAY_SIZE=1
#
# Automatically generated make config: don't edit
#
# CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y
CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
# CONFIG_PLL_VERBOSE is not set
# CONFIG_PFILTER_VERBOSE is not set
# CONFIG_WRC_VERBOSE is not set
# CONFIG_VLAN is not set
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048
CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y
CONFIG_LATENCY_ETHTYPE=0
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set
# CONFIG_SYSLOG is not set
CONFIG_SNMP=y
CONFIG_SNMP_SET=y
CONFIG_SNMP_HW_TYPE="spec"
# CONFIG_BUILD_INIT is not set
CONFIG_INIT_COMMAND=""
CONFIG_HAS_BUILD_INIT=0
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
#
# wrpc-sw is tainted if you change the following options
#
CONFIG_DEVELOPER=y
# CONFIG_CMD_LL is not set
# CONFIG_CHECK_RESET is not set
# CONFIG_SPLL_FIFO_LOG is not set
# CONFIG_PRINTF_FULL is not set
# CONFIG_PRINTF_MINI is not set
# CONFIG_PRINTF_NONE is not set
# CONFIG_DETERMINISTIC_BINARY is not set
# CONFIG_UART_SW is not set
# CONFIG_NET_VERBOSE is not set
CONFIG_SNMP_VERBOSE=y
CONFIG_FAKE_TEMPERATURES=y
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_LATENCY_PROBE is not set
CONFIG_VLAN_ARRAY_SIZE=1
......@@ -57,6 +57,10 @@
* ------------------------------------------------
*/
#define SFP_DB_EMPTY 0xff
static uint8_t sfpcount = SFP_DB_EMPTY;
uint8_t has_eeprom = 0;
static int i2cif, i2c_addr; /* globals, using the names we always used */
......@@ -137,7 +141,7 @@ static int eeprom_write(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset,
int32_t storage_sfpdb_erase(void)
{
uint8_t sfpcount = 0;
sfpcount = 0;
//just a dummy function that writes '0' to sfp count field of the SFP DB
if (eeprom_write(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
......@@ -147,28 +151,44 @@ int32_t storage_sfpdb_erase(void)
return sfpcount;
}
int storage_get_sfp(struct s_sfpinfo * sfp,
uint8_t add, uint8_t pos)
static uint8_t sfp_chksum(uint8_t *ptr)
{
int i;
uint8_t chksum = 0;
/* '-1' because we do not include chksum in computation */
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i)
chksum = (uint8_t) ((uint16_t) chksum + *(ptr++)) & 0xff;
return chksum;
}
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{
static uint8_t sfpcount = 0;
uint8_t i, chksum = 0;
uint8_t *ptr;
uint8_t i;
struct s_sfpinfo dbsfp;
if (pos >= SFPS_MAX)
return EE_RET_POSERR; //position in database outside the range
if (pos >= SFPS_MAX) {
/* position in database outside the range */
return EE_RET_POSERR;
}
//read how many SFPs are in the database, but only in the first call (pos==0)
if (!pos
/* Read how many SFPs are in the database, but only in the first call
*/
if (sfpcount == SFP_DB_EMPTY
&& eeprom_read(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
sizeof(sfpcount)) != sizeof(sfpcount))
return EE_RET_I2CERR;
if (add && sfpcount == SFPS_MAX) //no more space in the database to add new SFPs
return EE_RET_DBFULL;
else if (!pos && !add && sfpcount == 0) //there are no SFPs in the database to read
return sfpcount;
/* for not written flash set sfpcount to 0 */
if (sfpcount == SFP_DB_EMPTY)
sfpcount = 0;
if (oper == SFP_GET) {
if (sfpcount == 0) {
/* There are no SFPs in the database to read */
return 0;
}
if (!add) {
if (eeprom_read(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount)
+ pos * sizeof(struct s_sfpinfo),
......@@ -176,27 +196,42 @@ int storage_get_sfp(struct s_sfpinfo * sfp,
!= sizeof(struct s_sfpinfo) )
return EE_RET_I2CERR;
ptr = (uint8_t *) sfp;
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i) //'-1' because we do not include chksum in computation
chksum =
(uint8_t) ((uint16_t) chksum + *(ptr++)) & 0xff;
if (chksum != sfp->chksum)
if (sfp_chksum((uint8_t *)sfp) != sfp->chksum)
return EE_RET_CORRPT;
} else {
/*count checksum */
ptr = (uint8_t *) sfp;
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i) //'-1' because we do not include chksum in computation
chksum =
(uint8_t) ((uint16_t) chksum + *(ptr++)) & 0xff;
sfp->chksum = chksum;
/*add SFP at the end of DB */
}
if (oper == SFP_ADD) {
for (i = 0; i < sfpcount; i++) {
if (eeprom_read(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount)
+ i * sizeof(struct s_sfpinfo),
(uint8_t *)&dbsfp, sizeof(struct s_sfpinfo))
!= sizeof(struct s_sfpinfo))
return EE_RET_I2CERR;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) { /* sfp matched */
pp_printf("Update existing SFP entry\n");
break;
}
}
if (i >= SFPS_MAX) { /* database is full */
return EE_RET_DBFULL;
}
/* Count checksum */
sfp->chksum = sfp_chksum((uint8_t *)sfp);
/* Add an entry at the given pos in the DB */
eeprom_write(i2cif, i2c_addr,
EE_BASE_SFP + sizeof(sfpcount)
+ sfpcount * sizeof(struct s_sfpinfo),
+ i * sizeof(struct s_sfpinfo),
(uint8_t *) sfp, sizeof(struct s_sfpinfo));
sfpcount++;
eeprom_write(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
sizeof(sfpcount));
if (i >= sfpcount) {
pp_printf("Adding new SFP entry\n");
/* We're adding a new entry, update sfpcount */
sfpcount++;
eeprom_write(i2cif, i2c_addr, EE_BASE_SFP, &sfpcount,
sizeof(sfpcount));
}
}
return sfpcount;
......@@ -204,19 +239,15 @@ int storage_get_sfp(struct s_sfpinfo * sfp,
int storage_match_sfp(struct s_sfpinfo * sfp)
{
uint8_t sfpcount = 1;
int8_t i, temp;
int8_t i;
int sfp_cnt = 1;
struct s_sfpinfo dbsfp;
for (i = 0; i < sfpcount; ++i) {
temp = storage_get_sfp(&dbsfp, 0, i);
if (!i) {
sfpcount = temp; //only in first round valid sfpcount is returned from eeprom_get_sfp
if (sfpcount == 0 || sfpcount == 0xFF)
return 0;
else if (sfpcount < 0)
return sfpcount;
}
for (i = 0; i < sfp_cnt; ++i) {
sfp_cnt = storage_get_sfp(&dbsfp, SFP_GET, i);
if (sfp_cnt <= 0)
return sfp_cnt;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) {
sfp->dTx = dbsfp.dTx;
sfp->dRx = dbsfp.dRx;
......
......@@ -80,6 +80,11 @@ int flash_write(uint32_t addr, uint8_t *buf, int count)
}
bbspi_transfer(1,0);
/* make sure the write is complete */
while (flash_rsr() & 0x01) {
/* do nothing */
}
return count;
}
......
......@@ -52,16 +52,7 @@
static volatile uint32_t dma_tx_buf[MINIC_DMA_TX_BUF_SIZE / 4];
static volatile uint32_t dma_rx_buf[MINIC_DMA_RX_BUF_SIZE / 4];
struct wr_minic {
volatile uint32_t *rx_head, *rx_base;
uint32_t rx_avail, rx_size;
volatile uint32_t *tx_head, *tx_base;
uint32_t tx_avail, tx_size;
int tx_count, rx_count;
};
static struct wr_minic minic;
struct wr_minic minic;
static inline void minic_writel(uint32_t reg, uint32_t data)
{
......
......@@ -7,7 +7,6 @@
*
* Released according to the GNU GPL, version 2 or any later version.
*/
//#include <string.h>
#include <wrc.h>
#include <w1.h>
#include <storage.h>
......@@ -166,7 +165,7 @@ static void storage_sdb_list(struct sdbfs *fs)
{
struct sdb_device *d;
int new = 1;
while ( (d = sdbfs_scan(fs, new)) != NULL) {
while ((d = sdbfs_scan(fs, new)) != NULL) {
d->sdb_component.product.record_type = '\0';
pp_printf("file 0x%08x @ %4i, name %s\n",
(int)(d->sdb_component.product.device_id),
......@@ -196,12 +195,12 @@ void storage_init(int chosen_i2cif, int chosen_i2c_addr)
uint32_t magic = 0;
static unsigned entry_points_eeprom[] = {0, 64, 128, 256, 512, 1024};
static unsigned entry_points_flash[] = {
0x000000, // flash base
0x100, // second page in flash
0x200, // IPMI with MultiRecord
0x300, // IPMI with larger MultiRecord
0x170000, // after first FPGA bitstream
0x2e0000}; // after MultiBoot bitstream
0x000000, /* flash base */
0x100, /* second page in flash */
0x200, /* IPMI with MultiRecord */
0x300, /* IPMI with larger MultiRecord */
0x170000, /* after first FPGA bitstream */
0x2e0000}; /* after MultiBoot bitstream */
int i, ret;
/*
......@@ -209,7 +208,7 @@ void storage_init(int chosen_i2cif, int chosen_i2c_addr)
*/
for (i = 0; i < ARRAY_SIZE(entry_points_flash); i++) {
flash_read(entry_points_flash[i], (void *)&magic, sizeof(magic));
if(magic == SDB_MAGIC)
if (magic == SDB_MAGIC)
break;
}
if (magic == SDB_MAGIC) {
......@@ -292,7 +291,7 @@ found_exit:
* setting if no sdbfs is there, but CONFIG_SDB_STORAGE depends on
* CONFIG_W1 anyways.
*/
int get_persistent_mac(uint8_t portnum, uint8_t * mac)
int get_persistent_mac(uint8_t portnum, uint8_t *mac)
{
int ret;
int i, class;
......@@ -310,7 +309,7 @@ int get_persistent_mac(uint8_t portnum, uint8_t * mac)
ret = sdbfs_fread(&wrc_sdb, 0, mac, 6);
sdbfs_close(&wrc_sdb);
if(ret < 0)
if (ret < 0)
pp_printf("%s: SDB error\n", __func__);
if (mac[0] == 0xff ||
(mac[0] | mac[1] | mac[2] | mac[3] | mac[4] | mac[5]) == 0) {
......@@ -340,7 +339,7 @@ int get_persistent_mac(uint8_t portnum, uint8_t * mac)
return 0;
}
int set_persistent_mac(uint8_t portnum, uint8_t * mac)
int set_persistent_mac(uint8_t portnum, uint8_t *mac)
{
int ret;
......@@ -383,7 +382,7 @@ int32_t storage_sfpdb_erase(void)
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_SFP) < 0)
return -1;
ret = sdbfs_ferase(&wrc_sdb, 0, wrc_sdb.f_len);
if(ret == wrc_sdb.f_len)
if (ret == wrc_sdb.f_len)
ret = 1;
sdbfs_close(&wrc_sdb);
return ret == 1 ? 0 : -1;
......@@ -394,51 +393,59 @@ int32_t storage_sfpdb_erase(void)
static int sfp_valid(struct s_sfpinfo *sfp)
{
int i;
for(i=0; i<SFP_PN_LEN; ++i) {
if(sfp->pn[i] == 0xff)
for (i = 0; i < SFP_PN_LEN; ++i) {
if (sfp->pn[i] == 0xff)
return 0;
}
return 1;
}
int storage_get_sfp(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;
struct s_sfpinfo tempsfp;
int ret = -1;
uint8_t i, chksum = 0;
uint8_t *ptr;
int sdb_offset;
if (pos >= SFPS_MAX)
return EE_RET_POSERR; //position outside the range
return EE_RET_POSERR; /* position outside the range */
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_SFP) < 0)
return -1;
//read how many SFPs are in the database, but only in the first call
if(!pos) {
/* Read how many SFPs are in the database, but only in the first
* call */
if (!pos) {
sfpcount = 0;
while (sdbfs_fread(&wrc_sdb, sizeof(sfpcount) +
sfpcount*sizeof(tempsfp), &tempsfp,
sdb_offset = sizeof(sfpcount);
while (sdbfs_fread(&wrc_sdb, sdb_offset, &tempsfp,
sizeof(tempsfp)) == sizeof(tempsfp)) {
if(!sfp_valid(&tempsfp))
if (!sfp_valid(&tempsfp))
break;
sfpcount++;
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(tempsfp);
}
}
if (add && sfpcount == SFPS_MAX) //no more space to add new SFPs
return EE_RET_DBFULL;
if (!pos && !add && sfpcount == 0) // no SFPs in the database
return 0;
if ((oper == SFP_ADD) && (sfpcount == SFPS_MAX)) {
/* no more space to add new SFPs */
ret = EE_RET_DBFULL;
goto out;
}
if (!add) {
if (sdbfs_fread(&wrc_sdb, sizeof(sfpcount) + pos * sizeof(*sfp),
sfp, sizeof(*sfp))
!= sizeof(*sfp))
if (!pos && (oper == SFP_GET) && sfpcount == 0) {
/* no SFPs in the database */
ret = 0;
goto out;
}
if (oper == SFP_GET) {
sdb_offset = sizeof(sfpcount) + pos * sizeof(*sfp);
if (sdbfs_fread(&wrc_sdb, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp))
goto out;
ptr = (uint8_t *)sfp;
......@@ -449,46 +456,99 @@ int storage_get_sfp(struct s_sfpinfo * sfp,
pp_printf("sfp: corrupted checksum\n");
goto out;
}
} else {
/*count checksum */
}
if (oper == SFP_ADD) {
/* count checksum */
ptr = (uint8_t *)sfp;
/* use sizeof() - 1 because we don't include checksum */
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i)
chksum = chksum + *(ptr++);
sfp->chksum = chksum;
/* add SFP at the end of DB */
if (sdbfs_fwrite(&wrc_sdb, sizeof(sfpcount)
+ sfpcount * sizeof(*sfp), sfp, sizeof(*sfp))
!= sizeof(*sfp))
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(*sfp);
if (sdbfs_fwrite(&wrc_sdb, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp)) {
goto out;
}
sfpcount++;
if (sdbfs_fwrite(&wrc_sdb, 0, &sfpcount, sizeof(sfpcount))
!= sizeof(sfpcount))
goto out;
}
ret = sfpcount;
out:
sdbfs_close(&wrc_sdb);
return ret;
return 0;
}
int storage_match_sfp(struct s_sfpinfo * sfp)
static int storage_update_sfp(struct s_sfpinfo *sfp)
{
int sfpcount = 1;
int temp;
int8_t i;
struct s_sfpinfo sfp_db[SFPS_MAX];
struct s_sfpinfo *dbsfp;
/* copy entries from flash to the memory, update entry if matched */
for (i = 0; i < sfpcount; ++i) {
dbsfp = &sfp_db[i];
sfpcount = sfp_entry(dbsfp, SFP_GET, i);
if (sfpcount <= 0)
return sfpcount;
if (!strncmp(dbsfp->pn, sfp->pn, 16)) {
/* update matched entry */
dbsfp->dTx = sfp->dTx;
dbsfp->dRx = sfp->dRx;
dbsfp->alpha = sfp->alpha;
}
}
/* erase entire database */
if (storage_sfpdb_erase() == EE_RET_I2CERR) {
pp_printf("Could not erase DB\n");
return -1;
}
/* add all SFPs */
for (i = 0; i < sfpcount; ++i) {
dbsfp = &sfp_db[i];
temp = sfp_entry(dbsfp, SFP_ADD, 0);
if (temp < 0) {
/* if error, return it */
return temp;
}
}
return i;
}
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{
struct s_sfpinfo tmp_sfp;
if (oper == SFP_GET) {
/* Get SFP entry */
return sfp_entry(sfp, SFP_GET, pos);
}
/* storage_match_sfp replaces content of parameter, so do the copy
* first */
tmp_sfp = *sfp;
if (!storage_match_sfp(&tmp_sfp)) { /* add a new sfp entry */
pp_printf("Adding new SFP entry\n");
return sfp_entry(sfp, SFP_ADD, 0);
}
pp_printf("Update existing SFP entry\n");
return storage_update_sfp(sfp);
}
int storage_match_sfp(struct s_sfpinfo *sfp)
{
uint8_t sfpcount = 1;
int8_t i, temp;
int8_t i;
struct s_sfpinfo dbsfp;
for (i = 0; i < sfpcount; ++i) {
temp = storage_get_sfp(&dbsfp, 0, i);
if (!i) {
// first round: valid sfpcount is returned
sfpcount = temp;
if (sfpcount == 0 || sfpcount == 0xFF)
return 0;
else if (sfpcount < 0)
return sfpcount;
}
sfpcount = sfp_entry(&dbsfp, SFP_GET, i);
if (sfpcount <= 0)
return sfpcount;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) {
sfp->dTx = dbsfp.dTx;
sfp->dRx = dbsfp.dRx;
......@@ -504,8 +564,7 @@ int storage_match_sfp(struct s_sfpinfo * sfp)
* Phase transition ("calibration" file)
*/
#define VALIDITY_BIT 0x80000000
int storage_phtrans(uint32_t * valp,
uint8_t write)
int storage_phtrans(uint32_t *valp, uint8_t write)
{
int ret = -1;
uint32_t value;
......@@ -551,7 +610,7 @@ int storage_init_erase(void)
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_INIT) < 0)
return -1;
ret = sdbfs_ferase(&wrc_sdb, 0, wrc_sdb.f_len);
if(ret == wrc_sdb.f_len)
if (ret == wrc_sdb.f_len)
ret = 1;
sdbfs_close(&wrc_sdb);
return ret == 1 ? 0 : -1;
......@@ -576,7 +635,7 @@ int storage_init_add(const char *args[])
while (sdbfs_fread(&wrc_sdb, sizeof(used)+used, &byte, 1) == 1) {
if (byte == 0xff)
break;
used ++;
used++;
}
if (used > 256 /* 0xffff or wrong */)
......@@ -589,7 +648,7 @@ int storage_init_add(const char *args[])
(void *)args[i], len) != len)
goto out;
used += len;
if(args[i+1] != NULL) /* next one is another word of the same command */
if (args[i+1] != NULL) /* next one is another word of the same command */
separator = ' ';
else /* no more words, end command with '\n' */
separator = '\n';
......@@ -622,18 +681,18 @@ int storage_init_show(void)
if (sdbfs_open_id(&wrc_sdb, SDB_VENDOR, SDB_DEV_INIT) < 0)
return -1;
used = 0;
do {
if (sdbfs_fread(&wrc_sdb, sizeof(used) + used, &byte, 1) != 1)
goto out;
if(byte != 0xff) {
if (byte != 0xff) {
pp_printf("%c", byte);
used++;
}
} while(byte != 0xff);
} while (byte != 0xff);
if(used == 0)
if (used == 0)
pp_printf("Empty init script...\n");
ret = 0;
out:
......
......@@ -10,10 +10,21 @@
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <errno.h>
#include "syscon.h"
#include "i2c.h"
#include "sfp.h"
#include "storage.h"
/* Calibration data (from EEPROM if available) */
int32_t sfp_alpha = 73622176; /* default values if could not read EEPROM */
int32_t sfp_deltaTx = 0;
int32_t sfp_deltaRx = 0;
int32_t sfp_in_db = 0;
char sfp_pn[SFP_PN_LEN];
int sfp_present(void)
{
......@@ -52,3 +63,27 @@ int sfp_read_part_id(char *part_id)
return -1;
}
int sfp_match(void)
{
struct s_sfpinfo sfp;
sfp_pn[0] = '\0';
if (!sfp_present()) {
return -ENODEV;
}
if (sfp_read_part_id(sfp_pn)) {