Commit 8b0d60e5 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

shell: sfp add/erase/show commands for handling SFP DB in eeprom

parent 4300100f
This diff is collapsed.
......@@ -97,3 +97,18 @@ void mi2c_init(uint8_t i2cif)
M_SCL_OUT(i2cif, 1);
M_SDA_OUT(i2cif, 1);
}
//void mi2c_scan(uint8_t i2cif)
//{
// int i;
//
// //for(i=0;i<0x80;i++)
// for(i=0x50;i<0x51;i++)
// {
// mi2c_start(i2cif);
// if(!mi2c_put_byte(i2cif, i<<1)) mprintf("found : %x\n", i);
// mi2c_stop(i2cif);
//
// }
// mprintf("Nothing more found...\n");
//}
......@@ -2,20 +2,29 @@
#define __EEPROM_H
#define SFP_SECTION_PATTERN 0xdeadbeef
#define SFPINFO_MAX 4
#define SFPS_MAX 4
#define EE_BASE_SFP 4*1024
#define EE_BASE_INIT 4*1024+SFPS_MAX*29
__attribute__ ((packed)) struct s_sfpinfo
#define EE_RET_I2CERR -1
#define EE_RET_DBFULL -2
#define EE_RET_CHKSUM -3
#define EE_RET_POSERR -4
struct s_sfpinfo
{
char pn[16];
int32_t alpha;
int32_t deltaTx;
int32_t deltaRx;
};
int32_t dTx;
int32_t dRx;
uint8_t chksum;
} __attribute__((__packed__));
int eeprom_read(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, uint8_t *buf, size_t size);
int eeprom_write(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, uint8_t *buf, size_t size);
int32_t eeprom_sfpdb_erase(uint8_t i2cif, uint8_t i2c_addr);
int32_t eeprom_sfp_section(uint8_t i2cif, uint8_t i2c_addr, size_t size, uint16_t *section_sz);
int8_t eeprom_get_sfpinfo(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, struct s_sfpinfo *sfpinfo, uint16_t section_sz);
int8_t access_eeprom(char *sfp_pn, int32_t *alpha, int32_t *deltaTx, int32_t *deltaRx);
......
......@@ -6,15 +6,21 @@
Subcommands:
add vendor_type delta_tx delta_rx alpha - adds an SFP to the database, with given alpha/delta_rx/delta_rx values
show - shows the SFP database
erase - cleans the SFP database
detect - detects the transceiver type
*/
#include "shell.h"
#include "eeprom.h"
#include "syscon.h"
#include "sfp.h"
int cmd_sfp(const char *args[])
{
int8_t sfpcount=1, i, temp;
struct s_sfpinfo sfp;
if(args[0] && !strcasecmp(args[0], "detect"))
{
char pn[17];
......@@ -25,11 +31,60 @@ int cmd_sfp(const char *args[])
pn[16]=0;
mprintf("%s\n",pn);
return 0;
} else if (args[3] && !strcasecmp(args[0], "add"))
}
// else if (!strcasecmp(args[0], "i2cscan"))
// {
// mi2c_scan(WRPC_FMC_I2C);
// return 0;
// }
else if (!strcasecmp(args[0], "erase"))
{
if( eeprom_sfpdb_erase(WRPC_FMC_I2C, FMC_EEPROM_ADR) == EE_RET_I2CERR)
mprintf("Could not erase DB\n");
}
else if (args[4] && !strcasecmp(args[0], "add"))
{
if(strlen( args[1] )>16) temp=16;
else temp=strlen( args[1] );
for(i=0; i<temp; ++i)
sfp.pn[i]=args[1][i];
while(i<16) sfp.pn[i++]=' '; //padding
sfp.dTx = atoi(args[2]);
sfp.dRx = atoi(args[3]);
sfp.alpha = atoi(args[4]);
temp = eeprom_get_sfp(WRPC_FMC_I2C, FMC_EEPROM_ADR, &sfp, 1, 0);
if(temp == EE_RET_DBFULL)
mprintf("SFP DB is full\n");
else if(temp == EE_RET_I2CERR)
mprintf("I2C error\n");
else
mprintf("%d SFPs in DB\n", temp);
}
else if (args[0] && !strcasecmp(args[0], "show"))
{
for(i=0; i<sfpcount; ++i)
{
temp = eeprom_get_sfp(WRPC_FMC_I2C, FMC_EEPROM_ADR, &sfp, 0, i);
if(!i)
{
sfpcount=temp; //only in first round valid sfpcount is returned from eeprom_get_sfp
if(sfpcount == 0 || sfpcount == 0xFF)
{
mprintf("SFP database empty...\n");
return 0;
}
else if(sfpcount == -1)
{
mprintf("SFP database corrupted...\n");
return 0;
}
}
mprintf("%d: PN:", i+1);
for(temp=0; temp<16; ++temp)
mprintf("%c", sfp.pn[temp]);
mprintf(" dTx: %d, dRx: %d, alpha: %d\n", sfp.dTx, sfp.dRx, sfp.alpha);
}
}
return 0;
}
\ No newline at end of file
}
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