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