Commit ad02993e authored by Maciej Lipinski's avatar Maciej Lipinski

[WIP] first versio with detection of LPC and non-LPC ports

parent fcbe242b
......@@ -143,9 +143,13 @@ struct hal_port_state {
int synchronized; // <>0 if port is synchronized
int portInfoUpdated; // Set to 1 when updated
/* Indicate support for Low Phase Drift Calibration (read from GW)*/
int lpc_supported;
/* needed for the Low Phase Drift Calibration */
struct hal_port_tx_setup_state *tx_setup_fsm;
struct hal_port_rx_setup_state *rx_setup_fsm;
};
struct hal_temp_sensors {
......@@ -156,7 +160,8 @@ struct hal_temp_sensors {
};
/* This is the overall structure stored in shared memory */
#define HAL_SHMEM_VERSION 13 /* Version 13, added Low Phase Drift Calib */
#define HAL_SHMEM_VERSION 14 /* Version 14, added flag for
Low Phase Drift Calib */
struct hal_shmem_header {
int nports;
......
Subproject commit e72b21c976f6d25d9e1cc1ba592bb737ac3b4eed
Subproject commit 12e21844c12ef377ad0b953e62fce0867aa5b333
......@@ -33,4 +33,9 @@
#define MDIO_LPC_CTRL_DMTD_SOURCE_TXOUTCLK (1 << 14)
#define MDIO_LPC_CTRL_DMTD_SOURCE_RXRECCLK (0 << 14)
/*
* Address and mask to discover support for Low Phase Drift
* Calibration, taken from endpoint-regs.h
*/
#define EP_ECR_FEAT_LPC (1 << 28)
#define EP_ECR_ADDR 0x0
......@@ -162,6 +162,43 @@ static int hal_port_check_presence(const char *if_name, unsigned char *mac)
memcpy(mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
return 1;
}
static uint32_t ep_read(struct hal_port_state * p, int reg_addr)
{
struct ifreq ifr;
uint32_t rv;
strncpy(ifr.ifr_name, p->name, sizeof(ifr.ifr_name));
rv = reg_addr;
ifr.ifr_data = (void *)&rv;
pr_info("raw fd %d name %s\n", hal_port_fd, ifr.ifr_name);
if (ioctl(hal_port_fd, PRIV_IOCREADREG, &ifr) < 0) {
pr_error("ioctl failed\n");
};
pr_info("ep_read: reg %d data %x\n", reg_addr, rv);
return rv;
}
/* checks if the port supports Low Phase Drift Calibration*/
static int hal_port_check_lpc_support(struct hal_port_state * p)
{
uint32_t rv = ep_read(p, EP_ECR_ADDR);
if (rv & EP_ECR_FEAT_LPC)
{
pr_info("Supports for Low Phase Drift Calibration detected"
"at port %s\n", p->name);
return 1;
}
else
{
pr_info("NO supports for Low Phase Drift Calibration detected"
"at port %s\n", p->name);
return 0;
}
}
/* Port initialization, from dot-config values */
static int hal_port_init(int index)
......@@ -190,6 +227,7 @@ static int hal_port_init(int index)
p->state = HAL_PORT_STATE_INIT;
p->in_use = 1;
p->lpc_supported = hal_port_check_lpc_support(p);
p->tx_setup_fsm = malloc(sizeof(struct hal_port_tx_setup_state));
p->rx_setup_fsm = malloc(sizeof(struct hal_port_rx_setup_state));
......@@ -484,11 +522,15 @@ static void hal_port_fsm(struct hal_port_state * p)
hal_port_link_down(p, link_up);
//TODO-ML: this needs to be moved... it is done for each port
if( tx_fsm_done_for_all_ports() )
update_tx_calibration_file();
tx_init_complete = tx_fsm_update(p);
rx_fsm_update(p);
if(p->lpc_supported)
{
tx_init_complete = tx_fsm_update(p);
rx_fsm_update(p);
}
//TODO-ML: add here link_down check removed by Tom with additional check
// if (hal_port_link_down(p, link_up))
......@@ -947,7 +989,7 @@ static void update_link_leds(void) {
for (i = 0; i < HAL_MAX_PORTS; i++) {
//TODO-ML: modify to use pointers
if (port->in_use &&
if (port->in_use && port->lpc_supported &&
((ports[i].rx_setup_fsm->state != RX_SETUP_DONE &&
ports[i].rx_setup_fsm->state != RX_SETUP_STATE_INIT) ||
ports[i].tx_setup_fsm->state != TX_SETUP_DONE))
......@@ -1124,7 +1166,8 @@ static void update_tx_calibration_file(void)
int i;
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use && ports[i].tx_setup_fsm->cal_file_updated )
if (ports[i].in_use && ports[i].lpc_supported &&
ports[i].tx_setup_fsm->cal_file_updated )
return;
if (file_exists(calibration_file_name))
......@@ -1136,7 +1179,7 @@ static void update_tx_calibration_file(void)
struct config_file *cfg = cfg_load(calibration_file_name, 1);
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use)
if (ports[i].in_use && ports[i].lpc_supported)
{
char key_name[80];
snprintf(key_name, sizeof(key_name), "TX_PHASE_PORT%d", ports[i].hw_index);
......@@ -1148,7 +1191,7 @@ static void update_tx_calibration_file(void)
cfg_close(cfg);
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use)
if (ports[i].in_use && ports[i].lpc_supported)
ports[i].tx_setup_fsm->cal_file_updated = 1;
}
......@@ -1166,7 +1209,7 @@ static void load_tx_calibration_file(void)
}
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use)
if (ports[i].in_use && ports[i].lpc_supported)
{
char key_name[80];
int value;
......@@ -1188,7 +1231,8 @@ static int tx_fsm_done_for_all_ports(void)
{
int i;
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use && ports[i].tx_setup_fsm->state != TX_SETUP_DONE)
if (ports[i].in_use && ports[i].lpc_supported &&
ports[i].tx_setup_fsm->state != TX_SETUP_DONE)
return 0;
return 1;
......
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