Commit e3c75e5d authored by li hongming's avatar li hongming

Solve several bugs introduced by missing dualport configuration.

parent 456a64e2
......@@ -26,7 +26,7 @@
The bigger, the better precision, but slower rate */
#define DMTD_AVG_SAMPLES 256
static int autoneg_enabled;
static int autoneg_enabled[wr_num_ports];
volatile struct EP_WB *EP[wr_num_ports];
/* functions for accessing PCS (MDIO) registers */
......@@ -112,7 +112,7 @@ int ep_enable(int enabled, int autoneg, int port)
/* Enable TX/RX paths, reset RMON counters */
EP[port]->ECR = EP_ECR_TX_EN | EP_ECR_RX_EN | EP_ECR_RST_CNT;
autoneg_enabled = autoneg;
autoneg_enabled[port] = autoneg;
/* Reset the GTP Transceiver - it's important to do the GTP phase alignment every time
we start up the software, otherwise the calibration RX/TX deltas may not be correct */
......@@ -140,7 +140,7 @@ int ep_link_up(uint16_t * lpa,int port)
uint16_t flags = MDIO_MSR_LSTATUS;
volatile uint16_t msr;
if (autoneg_enabled)
if (autoneg_enabled[port])
flags |= MDIO_MSR_ANEGCOMPLETE;
msr = pcs_read(MDIO_REG_MSR,port);
......
......@@ -60,7 +60,7 @@ void pfilter_init_default(int port)
uint32_t m, *vini, *vend, *v, *v_vlan = NULL;
uint64_t cmd_word;
int i;
static int inited[2];
static int inited;
uint32_t latency_ethtype = CONFIG_LATENCY_ETHTYPE;
/* If vlan, use rule-set 1, else rule-set 0 */
......@@ -92,14 +92,14 @@ void pfilter_init_default(int port)
* First time: be extra-careful that the rule-set is ok. But if
* we change MAC address, this is re-called, and v[] is already changed
*/
if (!inited[port]) {
if (!inited) {
if ( (((v[2] >> 13) & 0xffff) != 0x1234)
|| (((v[4] >> 13) & 0xffff) != 0x5678)
|| (((v[6] >> 13) & 0xffff) != 0x9abc)) {
pp_printf("pfilter: wrong rule-set, can't apply\n");
return;
}
inited[port]++;
inited++;
}
/*
* Patch the local MAC address in place,
......
......@@ -40,7 +40,7 @@
fc = (raw >> 28) & 0xf;
struct wr_minic minic[wr_num_ports];
int ver_supported;
int ver_supported[wr_num_ports];
static inline void minic_writel(uint32_t reg, uint32_t data, int port)
{
......@@ -81,10 +81,10 @@ void minic_init(int port)
if (MINIC_MCR_VER_R(mcr) != MINIC_HDL_VERSION) {
pp_printf("Error: Minic HDL version %d not supported by sw\n",
MINIC_MCR_VER_R(mcr));
ver_supported = 0;
ver_supported[port] = 0;
return;
}
ver_supported = 1;
ver_supported[port] = 1;
/* disable interrupts, driver does polling */
minic_writel(MINIC_REG_EIC_IDR, MINIC_EIC_IDR_TX |
......@@ -103,7 +103,7 @@ int minic_poll_rx(port)
{
uint32_t mcr;
if (!ver_supported)
if (!ver_supported[port])
return 0;
mcr = minic_readl(MINIC_REG_MCR, port);
......@@ -127,7 +127,7 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
/* check if there is something in the Rx FIFO to be retrieved */
if ((minic_readl(MINIC_REG_MCR, port) & MINIC_MCR_RX_EMPTY) || !ver_supported)
if ((minic_readl(MINIC_REG_MCR, port) & MINIC_MCR_RX_EMPTY) || !ver_supported[port])
return 0;
hdr_size = 0;
......@@ -230,7 +230,7 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
int i, hsize;
uint16_t *ptr;
if (!ver_supported)
if (!ver_supported[port])
return 0;
if (hdr->ethtype == htons(0x8100))
......
......@@ -261,7 +261,7 @@ int calib_t24p(int mode, uint32_t *value, int port)
{
int ret;
if ((mode == WRC_MODE_SLAVE) && (port==0))
if (mode == WRC_MODE_SLAVE)
ret = calib_t24p_slave(value, port);
else
ret = calib_t24p_master(value, port);
......
......@@ -19,9 +19,9 @@
static uint8_t __arp_queue[2][128];
static struct wrpc_socket __static_arp_socket[2] = {
{.queue.buff = __arp_queue[0],
.queue.size = sizeof(__arp_queue),},
.queue.size = sizeof(__arp_queue[0]),},
{.queue.buff = __arp_queue[1],
.queue.size = sizeof(__arp_queue),},
.queue.size = sizeof(__arp_queue[1]),},
};
static struct wrpc_socket *arp_socket[2];
......@@ -108,7 +108,7 @@ static int arp_poll(void)
&addr, buf, sizeof(buf), 0, port)) > 0)
{
if ((len = process_arp(buf, len, 0)) > 0)
ptpd_netif_sendto(arp_socket, &addr, buf, len, 0, port);
ptpd_netif_sendto(arp_socket[port], &addr, buf, len, 0, port);
ret = 1;
}
}
......@@ -140,7 +140,7 @@ int send_arp(uint8_t * hisIP, int port)
getIP(buf + ARP_SPA, port);
memset(buf + ARP_THA, 0x00, 6); /* Broadcast */
memcpy(buf + ARP_TPA, hisIP, 4);
return (ptpd_netif_sendto(arp_socket, &addr, buf, ARP_END+10, 0, port));
return (ptpd_netif_sendto(arp_socket[port], &addr, buf, ARP_END+10, 0, port));
}
DEFINE_WRC_TASK(arp) = {
......
......@@ -43,7 +43,7 @@ int wrc_ui_refperiod = TICS_PER_SECOND; /* 1 sec */
int wrc_phase_tracking = 1;
char wrc_hw_name[HW_NAME_LENGTH];
uint32_t cal_phase_transition[wr_num_ports] = {2389,2389};
uint32_t cal_phase_transition[wr_num_ports];
int wrc_vlan_number = CONFIG_VLAN_NR;
......@@ -78,25 +78,23 @@ static void wrc_initialize(void)
if (get_persistent_mac(ONEWIRE_PORT, mac_addr[0]) == -1) {
pp_printf("Unable to determine MAC address\n");
mac_addr[0][0] = 0x22; /*
mac_addr[0][1] = 0x33; *
mac_addr[0][2] = 0x44; * fallback MAC if get_persistent_mac fails
mac_addr[0][3] = 0x55; *
mac_addr[0][4] = 0x66; *
mac_addr[0][5] = 0x77; */
mac_addr[1][0] = 0x23; /*
mac_addr[1][1] = 0x33; *
mac_addr[1][2] = 0x44; * fallback MAC if get_persistent_mac fails
mac_addr[1][3] = 0x55; *
mac_addr[1][4] = 0x66; *
mac_addr[1][5] = 0x77; */
for (port=0; port<wr_num_ports;port++) {
mac_addr[0][0] = 0x22+port; //fallback MAC if get_persistent_mac fails
mac_addr[0][1] = 0x33;
mac_addr[0][2] = 0x44;
mac_addr[0][3] = 0x55;
mac_addr[0][4] = 0x66;
mac_addr[0][5] = 0x77;
}
} else {
mac_addr[1][0]=mac_addr[0][0]+1;
mac_addr[1][1]=mac_addr[0][1];
mac_addr[1][2]=mac_addr[0][2];
mac_addr[1][3]=mac_addr[0][3];
mac_addr[1][4]=mac_addr[0][4];
mac_addr[1][5]=mac_addr[0][5];
for (port=0; port<wr_num_ports;port++) {
mac_addr[port][0]=mac_addr[0][0]+port;
mac_addr[port][1]=mac_addr[0][1];
mac_addr[port][2]=mac_addr[0][2];
mac_addr[port][3]=mac_addr[0][3];
mac_addr[port][4]=mac_addr[0][4];
mac_addr[port][5]=mac_addr[0][5];
}
}
net_rst();
......@@ -119,8 +117,10 @@ static void wrc_initialize(void)
shw_pps_gen_init();
wrc_ptp_init();
/* try reading t24 phase transition from EEPROM */
for (port=0; port<wr_num_ports;port++)
for (port=0; port<wr_num_ports;port++){
cal_phase_transition[port] = 2389; // default
calib_t24p(WRC_MODE_MASTER, &cal_phase_transition[port],port);
}
spll_very_init();
usleep_init();
......@@ -129,8 +129,11 @@ static void wrc_initialize(void)
wrc_ui_mode = UI_SHELL_MODE;
_endram = ENDRAM_MAGIC;
wrc_ptp_set_mode(WRC_MODE_MASTER, 1);
for (port=1; port<wr_num_ports;port++)
wrc_ptp_set_mode(WRC_MODE_MASTER, port);
wrc_ptp_set_mode(WRC_MODE_SLAVE, 0);
for (port=0; port<wr_num_ports;port++) {
wrc_ptp_start(port);
}
......@@ -148,42 +151,55 @@ uint8_t link_status[wr_num_ports];
static int wrc_check_link(void)
{
static int prev_state[] = {-1,-1};
static int prev_state[wr_num_ports];
static uint8_t first_run=0;
int state[wr_num_ports];
int rv = 0;
int port;
for(port=0; port<wr_num_ports; port++) {
state[port] = ep_link_up(NULL, port);
if (!prev_state[port] && state[port]) {
wrc_verbose("Port 0 Link up.\n");
if (port==0)
gpio_out(GPIO_LED_LINK, 1);
else
gpio_out(GPIO_DP_LED_LINK, 1);
sfp_match(port);
wrc_ptp_start(port);
link_status[port] = LINK_WENT_UP;
rv = 1;
} else if (prev_state[port] && !state[port]) {
wrc_verbose("Port %d Link down.\n",port);
if (port==0)
gpio_out(GPIO_LED_LINK, 0);
else
gpio_out(GPIO_DP_LED_LINK, 0);
link_status[port] = LINK_WENT_DOWN;
wrc_ptp_stop(port);
rv = 1;
/* special case */
if (port==0) {
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
shw_pps_gen_enable_output(0);
if (first_run==0)
{
for(port=0; port<wr_num_ports; port++) {
prev_state[port] = 0;
}
first_run++;
} else {
for(port=0; port<wr_num_ports; port++) {
state[port] = ep_link_up(NULL, port);
if (!prev_state[port] && state[port]) {
wrc_verbose("Port 0 Link up.\n");
if (port==0) gpio_out(GPIO_LED_LINK, 1);
else gpio_out(GPIO_DP_LED_LINK, 1);
sfp_match(port);
wrc_ptp_start(port);
link_status[port] = LINK_WENT_UP;
/* special case */
if (port==0)
{
spll_init(SPLL_MODE_SLAVE, 0, 1);
shw_pps_gen_unmask_output(0);
}
rv = 1;
} else if (prev_state[port] && !state[port]) {
wrc_verbose("Port %d Link down.\n",port);
if (port==0) gpio_out(GPIO_LED_LINK, 0);
else gpio_out(GPIO_DP_LED_LINK, 0);
link_status[port] = LINK_WENT_DOWN;
wrc_ptp_stop(port);
rv = 1;
/* special case */
if (port==0) {
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
shw_pps_gen_enable_output(0);
}
} else {
link_status[port] = (state[port] ? LINK_UP : LINK_DOWN);
}
} else
link_status[port] = (state[port] ? LINK_UP : LINK_DOWN);
prev_state[port] = state[port];
}
prev_state[port] = state[port];
}
}
return rv;
}
DEFINE_WRC_TASK(link) = {
......
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