Commit d6a1db54 authored by li hongming's avatar li hongming

Add dualport support for command "ip", "sfp", "delays"

    ip/ip get: print ip address of port 0&1
    ip set xx.xx.xx.xx [port]: set ip address of port, default port is 0

    sfp show: print sfp database of port 0&1
    sfp add sfp_pn dtx drx alpha [port]: set sfp database of port,
  default port is 0.
parent d3d11dd8
......@@ -427,7 +427,7 @@ static int sfp_valid(struct s_sfpinfo *sfp)
static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos, int port)
{
static uint8_t sfpcount = 0;
static uint8_t sfpcount[wr_num_ports];
struct s_sfpinfo tempsfp;
int ret = -1;
uint8_t i, chksum = 0;
......@@ -448,31 +448,31 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos, int port)
/* Read how many SFPs are in the database, but only in the first
* call */
if (!pos) {
sfpcount = 0;
sdb_offset = sizeof(sfpcount);
sfpcount[port] = 0;
sdb_offset = sizeof(sfpcount[port]);
while (sdbfs_fread(&wrc_sdb, sdb_offset, &tempsfp,
sizeof(tempsfp)) == sizeof(tempsfp)) {
if (!sfp_valid(&tempsfp))
break;
sfpcount++;
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(tempsfp);
sfpcount[port]++;
sdb_offset = sizeof(sfpcount[port]) + sfpcount[port] * sizeof(tempsfp);
}
}
if ((oper == SFP_ADD) && (sfpcount == SFPS_MAX)) {
if ((oper == SFP_ADD) && (sfpcount[port] == SFPS_MAX)) {
/* no more space to add new SFPs */
ret = EE_RET_DBFULL;
goto out;
}
if (!pos && (oper == SFP_GET) && sfpcount == 0) {
if (!pos && (oper == SFP_GET) && sfpcount[port] == 0) {
/* no SFPs in the database */
ret = 0;
goto out;
}
if (oper == SFP_GET) {
sdb_offset = sizeof(sfpcount) + pos * sizeof(*sfp);
sdb_offset = sizeof(sfpcount[port]) + pos * sizeof(*sfp);
if (sdbfs_fread(&wrc_sdb, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp))
goto out;
......@@ -494,14 +494,15 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos, int port)
chksum = chksum + *(ptr++);
sfp->chksum = chksum;
/* add SFP at the end of DB */
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(*sfp);
sdb_offset = sizeof(sfpcount[port]) + sfpcount[port] * sizeof(*sfp);
if (sdbfs_fwrite(&wrc_sdb, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp)) {
goto out;
}
sfpcount++;
sfpcount[port]++;
}
ret = sfpcount;
ret = sfpcount[port];
out:
sdbfs_close(&wrc_sdb);
return ret;
......
......@@ -15,6 +15,29 @@
#include "softpll_ng.h"
#include "shell.h"
void print_ip(void)
{
unsigned char ip[wr_num_ports][4];
char buf[20];
int port;
for (port = 0; port < wr_num_ports; port++) {
getIP(ip[port], port);
format_ip(buf, ip[port]);
switch (ip_status[port]) {
case IP_TRAINING:
pp_printf("IP-address: in training\n");
break;
case IP_OK_BOOTP:
pp_printf("IP-address: %s (from bootp)\n", buf);
break;
case IP_OK_STATIC:
pp_printf("IP-address: %s (static assignment)\n", buf);
break;
}
}
}
void decode_ip(const char *str, unsigned char *ip)
{
int i, x;
......@@ -38,33 +61,23 @@ char *format_ip(char *s, const unsigned char *ip)
static int cmd_ip(const char *args[])
{
unsigned char ip[4];
char buf[20];
int port;
if (!args[0] || !strcasecmp(args[0], "get")) {
getIP(ip, 0);
getIP(ip, 1);
print_ip();
} else if (!strcasecmp(args[0], "set") && args[1]) {
ip_status[0] = IP_OK_STATIC;
if (args[2])
port = atoi(args[2]);
else
port = 0;
if (port > 1) return -EINVAL;
ip_status[port] = IP_OK_STATIC;
decode_ip(args[1], ip);
setIP(ip, 0);
ip[3]=ip[3]+1;
setIP(ip, 1);
setIP(ip, port);
print_ip();
} else {
return -EINVAL;
}
format_ip(buf, ip);
switch (ip_status[0]) {
case IP_TRAINING:
pp_printf("IP-address: in training\n");
break;
case IP_OK_BOOTP:
pp_printf("IP-address: %s (from bootp)\n", buf);
break;
case IP_OK_STATIC:
pp_printf("IP-address: %s (static assignment)\n", buf);
break;
}
return 0;
}
......
......@@ -41,23 +41,35 @@ extern struct pp_instance ppi_static[wr_num_ports];
static int cmd_delays(const char *args[])
{
int tx, rx;
struct wr_data *wrp = (void *)(ppi_static[0].ext_data);
struct wr_servo_state *s = &wrp->servo_state;
int port;
struct wr_data *wrp;
struct wr_servo_state *s;
if (args[0] && !args[1]) {
pp_printf("delays: use: \"delays [<txdelay> <rxdelay>]\"\n");
pp_printf("delays: use: \"delays [<txdelay> <rxdelay>] [port]\"\n");
return 0;
}
if (args[1]) {
fromdec(args[0], &tx);
fromdec(args[1], &rx);
sfp_deltaTx[0] = tx;
sfp_deltaRx[0] = rx;
if (args[2])
port = atoi(args[2]);
else
port = 0;
if (port > 1) return -1;
sfp_deltaTx[port] = tx;
sfp_deltaRx[port] = rx;
wrp = (void *)(ppi_static[port].ext_data);
s = &wrp->servo_state;
/* Change the active value too (add bislide here) */
s->delta_tx_m = tx;
s->delta_rx_m = rx + ep_get_bitslide(0);
s->delta_rx_m = rx + ep_get_bitslide(port);
} else {
pp_printf("tx: %i rx: %i\n", sfp_deltaTx, sfp_deltaRx);
for (port = 0; port < wr_num_ports; ++port)
{
pp_printf("port %d: tx: %i rx: %i\n", port, sfp_deltaTx[port], sfp_deltaRx[port]);
}
}
return 0;
}
......
......@@ -35,7 +35,7 @@
static int cmd_sfp(const char *args[])
{
int8_t sfpcount[2] = {1,1};
int8_t i, temp, ret[2]={0,0};
int8_t i, temp, ret=0;
int port;
struct s_sfpinfo sfp;
......@@ -54,9 +54,9 @@ static int cmd_sfp(const char *args[])
if (storage_sfpdb_erase(port) == EE_RET_I2CERR) {
pp_printf("Port %d Could not erase DB\n", port);
ret[port] = -EIO;
ret = -EIO;
}
return (ret[0]||ret[1]);
return ret;
} else if (args[4] && !strcasecmp(args[0], "add")) {
temp = strnlen(args[1], SFP_PN_LEN);
......@@ -74,7 +74,6 @@ static int cmd_sfp(const char *args[])
sfp.port = 0;
if (sfp.port > 1) return -EINVAL;
temp = storage_get_sfp(&sfp, SFP_ADD, 0, sfp.port);
if (temp == EE_RET_DBFULL) {
pp_printf("SFP DB is full\n");
......@@ -90,15 +89,15 @@ static int cmd_sfp(const char *args[])
return 0;
} else if (!strcasecmp(args[0], "show")) {
for (port = 0; port < 2; ++port) {
sfpcount[port] = storage_get_sfp(&sfp, SFP_GET, i, port);
if (sfpcount[port] == 0) {
pp_printf("Port %d SFP database empty\n", port);
} else if (sfpcount[port] < 0) {
pp_printf("Port %d SFP database error (%d)\n", port,
sfpcount[0]);
ret[port] = -EFAULT;
} else {
for (i = 0; i< sfpcount[0]; ++i) {
for (i = 0; i< sfpcount[port]; ++i) {
sfpcount[port] = storage_get_sfp(&sfp, SFP_GET, i, port);
if (sfpcount[port] == 0) {
pp_printf("Port %d SFP database empty\n", port);
} else if (sfpcount[port] < 0) {
pp_printf("Port %d SFP database error (%d)\n", port,
sfpcount[port]);
ret = -EFAULT;
} else {
pp_printf("Port %d, SFP %d: PN:", port, i + 1);
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp.pn[temp]);
......@@ -107,13 +106,13 @@ static int cmd_sfp(const char *args[])
}
}
}
return (ret[0] || ret[1]);
return ret;
} else if (!strcasecmp(args[0], "match")) {
for (port = 0; port < 2; ++port) {
ret[port] = sfp_match(port);
if (ret[0] == -ENODEV)
ret = sfp_match(port);
if (ret == -ENODEV)
pp_printf("Port %d No SFP.\n", port);
else if (ret[0] == -EIO)
else if (ret == -EIO)
pp_printf("Port %d SFP read error\n", port);
else if (ret == -ENXIO)
pp_printf("Port %d Could not match to DB\n", port);
......@@ -123,7 +122,7 @@ static int cmd_sfp(const char *args[])
port, sfp_deltaTx[0], sfp_deltaRx[0], sfp_alpha[0]);
}
}
return (ret[0] || ret[1]);
return ret;
} else if (args[1] && !strcasecmp(args[0], "ena")) {
if (args[2])
......
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