Commit 456a64e2 authored by li hongming's avatar li hongming

split the ptp mode for dualports.

    command "ptp [mode] [port,df=0]" or "mode [mode] [port,df=0]"
  will set the ptp mode of port.
    Currently, if one port act as slave, its mode should be set
  after other ports.
parent 76260ebe
...@@ -579,7 +579,9 @@ int storage_match_sfp(struct s_sfpinfo *sfp, int port) ...@@ -579,7 +579,9 @@ int storage_match_sfp(struct s_sfpinfo *sfp, int port)
sfpcount = sfp_entry(&dbsfp, SFP_GET, i, port); sfpcount = sfp_entry(&dbsfp, SFP_GET, i, port);
if (sfpcount <= 0) if (sfpcount <= 0)
return sfpcount; return sfpcount;
if (!strncmp(dbsfp.pn, sfp->pn, 16)) { if (!strncmp(dbsfp.pn, sfp->pn, 16)) {
sfp->port = dbsfp.port;
sfp->dTx = dbsfp.dTx; sfp->dTx = dbsfp.dTx;
sfp->dRx = dbsfp.dRx; sfp->dRx = dbsfp.dRx;
sfp->alpha = dbsfp.alpha; sfp->alpha = dbsfp.alpha;
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
#include "storage.h" #include "storage.h"
/* Calibration data (from EEPROM if available) */ /* Calibration data (from EEPROM if available) */
int32_t sfp_alpha[2] = {64398396,-64398396}; /* default values if could not read EEPROM */ int32_t sfp_alpha[] = {64398396,-64398396}; /* default values if could not read EEPROM */
int32_t sfp_deltaTx[2] = {0,0}; int32_t sfp_deltaTx[] = {0,0};
int32_t sfp_deltaRx[2] = {0,0}; int32_t sfp_deltaRx[] = {0,0};
int32_t sfp_in_db[2] = {0,0}; int32_t sfp_in_db[] = {0,0};
char sfp_pn[2][SFP_PN_LEN]; char sfp_pn[wr_num_ports][SFP_PN_LEN];
int sfp_present(int port) int sfp_present(int port)
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* File : wrc_syscon_regs.h * File : wrc_syscon_regs.h
* Author : auto-generated by wbgen2 from wrc_syscon_wb.wb * Author : auto-generated by wbgen2 from wrc_syscon_wb.wb
* Created : Wed Sep 26 16:28:55 2018 * Created : Tue Oct 2 10:46:20 2018
* Standard : ANSI C * Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE wrc_syscon_wb.wb THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE wrc_syscon_wb.wb
...@@ -119,12 +119,6 @@ ...@@ -119,12 +119,6 @@
/* definitions for field: FMC I2C bitbanged SDA in reg: GPIO Clear Register */ /* definitions for field: FMC I2C bitbanged SDA in reg: GPIO Clear Register */
#define SYSC_GPCR_FMC_SDA WBGEN2_GEN_MASK(3, 1) #define SYSC_GPCR_FMC_SDA WBGEN2_GEN_MASK(3, 1)
/* definitions for field: DP Status LED in reg: GPIO Clear Register */
#define SYSC_GPCR_DP_LED_STAT WBGEN2_GEN_MASK(4, 1)
/* definitions for field: DP Link LED in reg: GPIO Clear Register */
#define SYSC_GPCR_DP_LED_LINK WBGEN2_GEN_MASK(5, 1)
/* definitions for field: SFP I2C bitbanged SCL in reg: GPIO Clear Register */ /* definitions for field: SFP I2C bitbanged SCL in reg: GPIO Clear Register */
#define SYSC_GPCR_SFP_SCL WBGEN2_GEN_MASK(8, 1) #define SYSC_GPCR_SFP_SCL WBGEN2_GEN_MASK(8, 1)
...@@ -140,11 +134,17 @@ ...@@ -140,11 +134,17 @@
/* definitions for field: SPI bitbanged MOSI in reg: GPIO Clear Register */ /* definitions for field: SPI bitbanged MOSI in reg: GPIO Clear Register */
#define SYSC_GPCR_SPI_MOSI WBGEN2_GEN_MASK(12, 1) #define SYSC_GPCR_SPI_MOSI WBGEN2_GEN_MASK(12, 1)
/* definitions for field: DP Status LED in reg: GPIO Clear Register */
#define SYSC_GPCR_DP_LED_STAT WBGEN2_GEN_MASK(14, 1)
/* definitions for field: DP Link LED in reg: GPIO Clear Register */
#define SYSC_GPCR_DP_LED_LINK WBGEN2_GEN_MASK(15, 1)
/* definitions for field: DP SFP I2C bitbanged SCL in reg: GPIO Clear Register */ /* definitions for field: DP SFP I2C bitbanged SCL in reg: GPIO Clear Register */
#define SYSC_GPCR_DP_SFP_SCL WBGEN2_GEN_MASK(13, 1) #define SYSC_GPCR_DP_SFP_SCL WBGEN2_GEN_MASK(17, 1)
/* definitions for field: DP SFP I2C bitbanged SDA in reg: GPIO Clear Register */ /* definitions for field: DP SFP I2C bitbanged SDA in reg: GPIO Clear Register */
#define SYSC_GPCR_DP_SFP_SDA WBGEN2_GEN_MASK(14, 1) #define SYSC_GPCR_DP_SFP_SDA WBGEN2_GEN_MASK(18, 1)
/* definitions for register: Hardware Feature Register */ /* definitions for register: Hardware Feature Register */
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define SFP_GET 0 #define SFP_GET 0
#define SFP_ADD 1 #define SFP_ADD 1
extern char sfp_pn[2][SFP_PN_LEN]; extern char sfp_pn[wr_num_ports][SFP_PN_LEN];
extern int32_t sfp_in_db[2]; extern int32_t sfp_in_db[2];
extern int32_t sfp_alpha[2]; extern int32_t sfp_alpha[2];
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
#define WRC_MODE_SLAVE 3 #define WRC_MODE_SLAVE 3
#define WRC_MODE_ABSCAL 4 #define WRC_MODE_ABSCAL 4
extern int ptp_mode; extern int ptp_mode[wr_num_ports];
int wrc_ptp_init(void); int wrc_ptp_init(void);
int wrc_ptp_set_mode(int mode); int wrc_ptp_set_mode(int mode, int port);
int wrc_ptp_get_mode(void); int wrc_ptp_get_mode(int port);
int wrc_ptp_start(int port); int wrc_ptp_start(int port);
int wrc_ptp_stop(int port); int wrc_ptp_stop(int port);
int wrc_ptp_update(void); int wrc_ptp_update(void);
......
...@@ -198,6 +198,7 @@ static int rmupdate_poll(void) ...@@ -198,6 +198,7 @@ static int rmupdate_poll(void)
uint32_t data_addr; uint32_t data_addr;
uint8_t* reg_addr; uint8_t* reg_addr;
int data_size; int data_size;
int port;
len = ptpd_netif_recvfrom(rmupdate_socket, &addr, len = ptpd_netif_recvfrom(rmupdate_socket, &addr,
buf, sizeof(buf), NULL, 0); buf, sizeof(buf), NULL, 0);
...@@ -228,7 +229,8 @@ static int rmupdate_poll(void) ...@@ -228,7 +229,8 @@ static int rmupdate_poll(void)
switch(type) switch(type)
{ {
case FLASH_ERASE: case FLASH_ERASE:
wrc_ptp_run(0); for (port = 0; port < wr_num_ports; ++port)
wrc_ptp_run(0,port);
data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11]; data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11];
data_size = (buf[UDP_END+12]<<24)+(buf[UDP_END+13]<<16)+(buf[UDP_END+14]<<8)+buf[UDP_END+15]; data_size = (buf[UDP_END+12]<<24)+(buf[UDP_END+13]<<16)+(buf[UDP_END+14]<<8)+buf[UDP_END+15];
flash_erase(data_addr,data_size); flash_erase(data_addr,data_size);
......
...@@ -41,7 +41,7 @@ extern int32_t sfp_alpha[2]; ...@@ -41,7 +41,7 @@ extern int32_t sfp_alpha[2];
int wrpc_get_port_state(struct hal_port_state *state, const char *port_name) int wrpc_get_port_state(struct hal_port_state *state, const char *port_name)
{ {
int port = atoi(&port_name[2]); int port = atoi(&port_name[2]);
int wrc_mode = wrc_ptp_get_mode(); int wrc_mode = wrc_ptp_get_mode(port);
if(port == 0) if(port == 0)
if(wrc_mode == WRC_MODE_SLAVE) if(wrc_mode == WRC_MODE_SLAVE)
......
...@@ -181,7 +181,7 @@ int wrc_mon_gui(void) ...@@ -181,7 +181,7 @@ int wrc_mon_gui(void)
if (port==0) if (port==0)
{ {
switch (ptp_mode) { switch (ptp_mode[port]) {
case WRC_MODE_GM: case WRC_MODE_GM:
case WRC_MODE_MASTER: case WRC_MODE_MASTER:
cprintf(C_WHITE, "WR Master "); cprintf(C_WHITE, "WR Master ");
...@@ -343,11 +343,11 @@ static int wrc_log_stats(void) ...@@ -343,11 +343,11 @@ static int wrc_log_stats(void)
if (!last_jiffies) if (!last_jiffies)
last_jiffies = timer_get_tics() - 1 - wrc_ui_refperiod; last_jiffies = timer_get_tics() - 1 - wrc_ui_refperiod;
/* stats update condition for Slave mode */ /* stats update condition for Slave mode */
if (wrc_stats_last == s[port]->update_count && ptp_mode==WRC_MODE_SLAVE) if (wrc_stats_last == s[port]->update_count && ptp_mode[port]==WRC_MODE_SLAVE)
return 0; return 0;
/* stats update condition for Master mode */ /* stats update condition for Master mode */
if (time_before(timer_get_tics(), last_jiffies + wrc_ui_refperiod) && if (time_before(timer_get_tics(), last_jiffies + wrc_ui_refperiod) &&
ptp_mode != WRC_MODE_SLAVE) ptp_mode[port] != WRC_MODE_SLAVE)
return 0; return 0;
last_jiffies = timer_get_tics(); last_jiffies = timer_get_tics();
wrc_stats_last = s[port]->update_count; wrc_stats_last = s[port]->update_count;
...@@ -358,7 +358,7 @@ static int wrc_log_stats(void) ...@@ -358,7 +358,7 @@ static int wrc_log_stats(void)
pp_printf("lnk:%d rx:%d tx:%d ", state.state, rx, tx); pp_printf("lnk:%d rx:%d tx:%d ", state.state, rx, tx);
pp_printf("lock:%d ", state.locked ? 1 : 0); pp_printf("lock:%d ", state.locked ? 1 : 0);
pp_printf("ptp:%s ", wrc_ptp_state(ppi[port], port)); pp_printf("ptp:%s ", wrc_ptp_state(ppi[port], port));
if(ptp_mode == WRC_MODE_SLAVE) { if(ptp_mode[port] == WRC_MODE_SLAVE) {
pp_printf("sv:%d ", (s[port]->flags & WR_FLAG_VALID) ? 1 : 0); pp_printf("sv:%d ", (s[port]->flags & WR_FLAG_VALID) ? 1 : 0);
pp_printf("ss:'%s' ", s[port]->servo_state_name); pp_printf("ss:'%s' ", s[port]->servo_state_name);
} }
...@@ -494,7 +494,7 @@ int wrc_wr_diags(void) ...@@ -494,7 +494,7 @@ int wrc_wr_diags(void)
wdiags_write_ptp_state((uint8_t )ppi[port]->state); wdiags_write_ptp_state((uint8_t )ppi[port]->state);
/* servo state (if slave)s */ /* servo state (if slave)s */
if(ptp_mode == WRC_MODE_SLAVE){ if(ptp_mode[port] == WRC_MODE_SLAVE){
struct wr_servo_state *ss[wr_num_ports]; struct wr_servo_state *ss[wr_num_ports];
int32_t asym[wr_num_ports]; int32_t asym[wr_num_ports];
int wr_mode[wr_num_ports]; int wr_mode[wr_num_ports];
......
This diff is collapsed.
ppsi @ 4ec34a29
Subproject commit f13b2ae9628ca46cd20efc8bbf42657baeee511a Subproject commit 4ec34a29dab48cc7a7f1b161717673750564452c
...@@ -12,15 +12,11 @@ ...@@ -12,15 +12,11 @@
struct subcmd { struct subcmd {
char *name; char *name;
int (*fun)(int); int (*fun)(int, int);
int arg; int arg;
} subcmd[] = { } subcmd[] = {
{"start", wrc_ptp_run, 1}, {"start", wrc_ptp_run, 1},
{"stop", wrc_ptp_run, 0}, {"stop", wrc_ptp_run, 0},
#ifdef CONFIG_DUALPORT
{"start1", wrc_ptp_run, 3},
{"stop1", wrc_ptp_run, 2},
#endif
{"e2e", wrc_ptp_sync_mech, PP_E2E_MECH}, {"e2e", wrc_ptp_sync_mech, PP_E2E_MECH},
{"delay", wrc_ptp_sync_mech, PP_E2E_MECH}, {"delay", wrc_ptp_sync_mech, PP_E2E_MECH},
#ifdef CONFIG_P2P #ifdef CONFIG_P2P
...@@ -35,13 +31,7 @@ struct subcmd { ...@@ -35,13 +31,7 @@ struct subcmd {
#endif #endif
}; };
#ifdef CONFIG_DUALPORT
static char *is_run[] = {"Port 0&1 stopped", "Port 0 running, Port 1 stopped",
"Port 0 stopped, Port 1 running","Port 0&1 running"};
#else
static char *is_run[] = {"stopped", "running"}; static char *is_run[] = {"stopped", "running"};
#endif
static char *is_mech[] = {[PP_E2E_MECH] = "e2e", [PP_P2P_MECH] = "p2p"}; static char *is_mech[] = {[PP_E2E_MECH] = "e2e", [PP_P2P_MECH] = "p2p"};
static char *is_mode[] = {[WRC_MODE_GM] = "gm", [WRC_MODE_MASTER] = "master", static char *is_mode[] = {[WRC_MODE_GM] = "gm", [WRC_MODE_MASTER] = "master",
[WRC_MODE_SLAVE] = "slave" [WRC_MODE_SLAVE] = "slave"
...@@ -54,20 +44,29 @@ static int cmd_ptp(const char *args[]) ...@@ -54,20 +44,29 @@ static int cmd_ptp(const char *args[])
{ {
int i, j, ret; int i, j, ret;
struct subcmd *c; struct subcmd *c;
int port;
if (!args[0]) { if (!args[0]) {
pp_printf("%s; %s %s\n", for (port = 0; port < wr_num_ports; ++port)
is_run[wrc_ptp_run(-1)], {
is_mech[wrc_ptp_sync_mech(-1)], pp_printf("port %d %s; %s %s\n", port,
is_mode[wrc_ptp_get_mode()]); is_run[wrc_ptp_run(-1, port)],
is_mech[wrc_ptp_sync_mech(-1, port)],
is_mode[wrc_ptp_get_mode(port)]);
}
return 0; return 0;
} }
for (j = 0; args[j]; j++) { for (j = 0; args[j]; j++) {
for (i = 0, c = subcmd; i < ARRAY_SIZE(subcmd); i++, c++) { for (i = 0, c = subcmd; i < ARRAY_SIZE(subcmd); i++, c++) {
if (!strcasecmp(args[j], c->name)) { if (!strcasecmp(args[j], c->name)) {
ret = c->fun(c->arg); if (args[j+1]){
port = atoi(args[j+1]);
j++;
}
else
port = 0;
ret = c->fun(c->arg, port);
if (ret < 0) if (ret < 0)
return ret; return ret;
break; break;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
static int cmd_sfp(const char *args[]) static int cmd_sfp(const char *args[])
{ {
int8_t sfpcount[2] = {1,1}; int8_t sfpcount[] = {1,1};
int8_t i, temp, ret=0; int8_t i, temp, ret=0;
int port; int port;
...@@ -88,7 +88,7 @@ static int cmd_sfp(const char *args[]) ...@@ -88,7 +88,7 @@ static int cmd_sfp(const char *args[])
pp_printf("Port %d has %d SFPs in DB\n", sfp.port, temp); pp_printf("Port %d has %d SFPs in DB\n", sfp.port, temp);
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 < wr_num_ports; ++port) {
for (i = 0; i< sfpcount[port]; ++i) { for (i = 0; i< sfpcount[port]; ++i) {
sfpcount[port] = storage_get_sfp(&sfp, SFP_GET, i, port); sfpcount[port] = storage_get_sfp(&sfp, SFP_GET, i, port);
if (sfpcount[port] == 0) { if (sfpcount[port] == 0) {
...@@ -108,20 +108,32 @@ static int cmd_sfp(const char *args[]) ...@@ -108,20 +108,32 @@ static int cmd_sfp(const char *args[])
} }
return ret; return ret;
} else if (!strcasecmp(args[0], "match")) { } else if (!strcasecmp(args[0], "match")) {
for (port = 0; port < 2; ++port) { for (port = 0; port < wr_num_ports; ++port) {
ret = sfp_match(port); ret = sfp_match(port);
if (ret == -ENODEV) if (ret == -ENODEV) {
pp_printf("Port %d No SFP.\n", port); pp_printf("Port %d No SFP.\n", port);
else if (ret == -EIO) continue;
} 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) continue;
}
/* SFP read correctly */
for (temp = 0; temp < SFP_PN_LEN; ++temp)
pp_printf("%c", sfp_pn[port][temp]);
pp_printf("\n");
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);
else { continue;
/* match successful */
pp_printf("\nPort %d SFP matched, dTx=%d dRx=%d alpha=%d\n",
port, sfp_deltaTx[0], sfp_deltaRx[0], sfp_alpha[0]);
} }
/* match successful */
pp_printf("Port %d SFP matched, dTx=%d dRx=%d alpha=%d\n",
port, sfp_deltaTx[0], sfp_deltaRx[0], sfp_alpha[0]);
} }
return ret; return ret;
} else if (args[1] && !strcasecmp(args[0], "ena")) { } else if (args[1] && !strcasecmp(args[0], "ena")) {
......
...@@ -32,19 +32,19 @@ static int cmd_time(const char *args[]) ...@@ -32,19 +32,19 @@ static int cmd_time(const char *args[])
shw_pps_gen_get_time(&sec, &nsec); shw_pps_gen_get_time(&sec, &nsec);
if (args[2] && !strcasecmp(args[0], "set")) { if (args[2] && !strcasecmp(args[0], "set")) {
if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) { if (wrc_ptp_get_mode(0) != WRC_MODE_SLAVE) {
shw_pps_gen_set_time((uint64_t) atoi(args[1]), shw_pps_gen_set_time((uint64_t) atoi(args[1]),
atoi(args[2]), PPSG_SET_ALL); atoi(args[2]), PPSG_SET_ALL);
return 0; return 0;
} else } else
return -EBUSY; return -EBUSY;
} else if (args[0] && !strcasecmp(args[0], "setsec")) { } else if (args[0] && !strcasecmp(args[0], "setsec")) {
if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) { if (wrc_ptp_get_mode(0) != WRC_MODE_SLAVE) {
shw_pps_gen_set_time((int64_t) atoi(args[1]), 0, PPSG_SET_SEC); shw_pps_gen_set_time((int64_t) atoi(args[1]), 0, PPSG_SET_SEC);
return 0; return 0;
} }
} else if (args[0] && !strcasecmp(args[0], "setnsec")) { } else if (args[0] && !strcasecmp(args[0], "setnsec")) {
if (wrc_ptp_get_mode() != WRC_MODE_SLAVE) { if (wrc_ptp_get_mode(0) != WRC_MODE_SLAVE) {
shw_pps_gen_set_time(0, atoi(args[1]), PPSG_SET_NSEC); shw_pps_gen_set_time(0, atoi(args[1]), PPSG_SET_NSEC);
return 0; return 0;
} }
......
...@@ -129,7 +129,8 @@ static void wrc_initialize(void) ...@@ -129,7 +129,8 @@ static void wrc_initialize(void)
wrc_ui_mode = UI_SHELL_MODE; wrc_ui_mode = UI_SHELL_MODE;
_endram = ENDRAM_MAGIC; _endram = ENDRAM_MAGIC;
wrc_ptp_set_mode(WRC_MODE_SLAVE); wrc_ptp_set_mode(WRC_MODE_MASTER, 1);
wrc_ptp_set_mode(WRC_MODE_SLAVE, 0);
for (port=0; port<wr_num_ports;port++) { for (port=0; port<wr_num_ports;port++) {
wrc_ptp_start(port); wrc_ptp_start(port);
} }
......
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