Commit e9c831a4 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

hal: fixed RX alignment detection (and some other suspicious code in the FSMs too - see comments)

parent 923912fe
......@@ -130,8 +130,6 @@ static halPortFsmGen_t _portFsm = {
static int _hal_port_state_init(void *vpfg, int eventMsk, int isNewState) {
struct hal_port_state * ps=((halPortFsmGen_t *)vpfg)->ps;
// printf("HalPortStateIni ps %p hwi %d\n", ps, ps->hw_index );
//
if ( isNewState ) {
_init_port(ps);
/* Init the tx state machine */
......@@ -182,8 +180,6 @@ static int _hal_port_state_link_down(void *vpfg, int eventMsk, int isNewState) {
return 0;
}
// printf("port %d link down state\n", ps->hw_index);
//
if ( isNewState ) {
_reset_port(ps);// clears ps->tx_cal_pending & ps->calib*, except ps->calib.bitslide_ps
/* Init the rx state machine */
......@@ -332,16 +328,12 @@ void hal_port_state_fsm( struct hal_port_state * ps ) {
hal_port_poll_rts_state(); // Update rts state on all ports
// printf("hal_port_state_fsm ENTRY\n");
/* Call state machine for all ports */
for (portIndex = 0; portIndex < HAL_MAX_PORTS; portIndex++) {
if ( ps->in_use) {
_portFsm.ps=ps;
_portFsm.st=&ps->portStates;
// printf("port %d %p in_use %d\n", ps->hw_index, ps, ps->in_use);
/* Update evt_linkUp */
if ( _get_port_link_state(ps,&ps->evt_linkUp)==-1 ) {
// IOTCL error : We put -1 in the link state. It will be considered as invalid
......
......@@ -123,16 +123,14 @@ static __inline__ void updatePllState(struct hal_port_state * ps) {
* nothing to do, go to DONE and wait for link up
* fi
*/
static int _hal_port_rx_setup_state_start(void *vpfg, int eventMsk, int isNewState) {
struct hal_port_state * ps=((halPortFsmGen_t *)vpfg)->ps;
// prevent RX FSM from starting up when the TX path calibration of the port is
// not completed.
if( ps->lpdc.txSetupStates.state != HAL_PORT_TX_SETUP_STATE_DONE)
{
// printf("***** too early to fire rx fsm\n");
return 0;
}
if ( ps->lpdc.isSupported ) {
// LPDC support
......@@ -140,8 +138,6 @@ static int _hal_port_rx_setup_state_start(void *vpfg, int eventMsk, int isNewSta
MDIO_LPC_CTRL_DMTD_SOURCE_RXRECCLK,
MDIO_LPC_CTRL);
// printf("p %d early: %d\n", ps->hw_index, _isHalRxSetupEventEarlyLinkUp(eventMsk) ? 1: 0);
if( _isHalRxSetupEventEarlyLinkUp(eventMsk)) {
halPortLpdcRx_t *rxSetup=ps->lpdc.rxSetup;
......@@ -168,6 +164,10 @@ static int _hal_port_rx_setup_state_reset_pcs(void *vpfg, int eventMsk, int isNe
halPortLpdcRx_t *rxSetup=ps->lpdc.rxSetup;
libwr_tmo_init(&rxSetup->link_timeout, 100, 1);
// establish a 1ms wait for the LINK_ALIGNED flag -
// alignment detection takes a little bit more time than early
// link detect. Without the wait (depending on execution timing of the HAL code)
// the wait_lock state might detect the early link but never see it's aligned.
libwr_tmo_init(&rxSetup->align_timeout, 1, 1);
pcs_writel(ps, MDIO_LPC_CTRL_RESET_RX |
......@@ -193,39 +193,16 @@ static int _hal_port_rx_setup_state_wait_lock(void *vpfg, int eventMsk, int isNe
struct hal_port_state * ps=((halPortFsmGen_t *)vpfg)->ps;
halPortLpdcRx_t *rxSetup=ps->lpdc.rxSetup;
// printf("**** port %p lup %d alined %d\n", ps->hw_index, _isHalRxSetupEventEarlyLinkUp(eventMsk)?1:0, _isHalRxSetupEventRxAligned(eventMsk)?1:0);
if ( _isHalRxSetupEventEarlyLinkUp(eventMsk)) {
// 1ms rx align detection window, described in previous state.
if(! libwr_tmo_expired(&rxSetup->align_timeout) )
{
return 0; // call me again 1ms later...
}
if ( _isHalRxSetupEventRxAligned(eventMsk)) {
// int i;
rts_enable_ptracker(ps->hw_index, 0);
rts_enable_ptracker(ps->hw_index, 1);
_pll_state.channels[ps->hw_index].flags = 0;
/* uint32_t val;
pcs_readl( ps, MDIO_LPC_STAT, &val );
printf("*** PRE lpc_stat %x\n", val );
printf("****************** %d go to f****ing validate state [%d %d]\n", ps->hw_index, _isHalRxSetupEventEarlyLinkUp(eventMsk), _isHalRxSetupEventRxAligned(eventMsk) );
for(i = 0; i < 1; i++)
{
uint32_t val;
pcs_readl( ps, MDIO_LPC_STAT, &val );
printf("*** lpc_stat %x\n", val );
usleep(100000);
}
dupa = ps->hw_index;*/
_fireState(vpfg,HAL_PORT_RX_SETUP_STATE_VALIDATE);
} else {
_fireState(vpfg,HAL_PORT_RX_SETUP_STATE_RESET_PCS);
......@@ -252,20 +229,13 @@ static int _hal_port_rx_setup_state_validate(void *vpfg, int eventMsk, int isNew
halPortLpdcRx_t *rxSetup=ps->lpdc.rxSetup;
uint32_t value;
// printf("******************validate state callied [%d %d]\n", _isHalRxSetupEventEarlyLinkUp(eventMsk), _isHalRxSetupEventRxAligned(eventMsk) );
//
pcs_writel(ps, MDIO_LPC_CTRL_RX_ENABLE |
MDIO_LPC_CTRL_TX_ENABLE |
MDIO_LPC_CTRL_DMTD_SOURCE_RXRECCLK,
MDIO_LPC_CTRL);
//*(volatile int *)(0xdeadeef) = 0;
// exit(-1);
pcs_writel(ps, BMCR_ANENABLE | BMCR_ANRESTART, MII_BMCR);
//TODO-ML: change to port name
printf("wri%d: RX calibration complete at phase %d "
pr_info("wri%d: RX calibration complete at phase %d "
"ps (after %d attempts).\n", ps->hw_index + 1,
phase, rxSetup->attempts);
rts_enable_ptracker(ps->hw_index, 0);
......@@ -289,8 +259,6 @@ static int _hal_port_rx_setup_state_done(void *vpfg, int eventMsk, int isNewStat
/* earlyLinkUp detection only if LPDC support */
if ( ps->lpdc.isSupported ) {
// printf("******************done state callied [%d %d]\n", _isHalRxSetupEventEarlyLinkUp(eventMsk), _isHalRxSetupEventRxAligned(eventMsk) );
//
if ( !_isHalRxSetupEventEarlyLinkUp(eventMsk)) {
// Port went done
pr_info("rxcal: early link flag lost on port wri%d\n",
......@@ -320,20 +288,6 @@ static int _buildEvents(void *vpfg) {
uint32_t mioLpcStat;
if ( pcs_readl(ps, MDIO_LPC_STAT,&mioLpcStat) >= 0 ) {
/* if( (ps->hw_index == 9) && (mioLpcStat & MDIO_LPC_STAT_LINK_ALIGNED ) && (ps->lpdc.rxSetupStates.state != HAL_PORT_RX_SETUP_STATE_START) )
{
printf("*************MioLpcStat 1ST %x\n", mioLpcStat & MDIO_LPC_STAT_LINK_ALIGNED);
int i;
for(i=0;i<2;i++)
{
pcs_readl(ps, MDIO_LPC_STAT,&mioLpcStat);
printf("*************MioLpcStat %x\n", mioLpcStat & MDIO_LPC_STAT_LINK_ALIGNED);
usleep(100000);
}
}
printf("********************** vpfg %p port %d lpcstat %x\n", vpfg, ps->hw_index, mioLpcStat ); */
if (mioLpcStat & MDIO_LPC_STAT_LINK_UP)
portEventMask |= HAL_PORT_RX_SETUP_EVENT_EARLY_LINK_UP;
if (mioLpcStat & MDIO_LPC_STAT_LINK_ALIGNED)
......@@ -348,7 +302,6 @@ static int _buildEvents(void *vpfg) {
* Init RX SETUP FSM
*/
void hal_port_rx_setup_init_fsm(struct hal_port_state * ps ) {
// printf("initRxFsm: ps %p (idx %d)\n", ps, ps->hw_index);
_portFsm.ps=ps;
_portFsm.st=&ps->lpdc.rxSetupStates;
ps->lpdc.rxSetupStates.state=-1;
......
......@@ -129,7 +129,6 @@ static int _hal_port_tx_setup_state_start(void *vpfg, int eventMsk, int isNewSta
} else {
// LPDC support
halPortLpdcTx_t *txSetup=ps->lpdc.txSetup;
struct halGlobalLPDC * gl = ps->lpdc.globalLpdc;
txSetup->attempts=0;
txSetup->expected_phase = 0;
......@@ -243,15 +242,13 @@ static int _hal_port_tx_setup_state_measure_phase(void *vpfg, int eventMsk, int
int phase_max = txSetup->expected_phase + txSetup->tollerance;
//TODO-ML: change to name of interface, remove two phases
//pr_info("TX Calibration: upd port %d phase %d %d after %d "
// "attempts target %d tollerance %d (temp = %.3f degC)\n",
// ps->hw_index, txSetup->measured_phase, txSetup->measured_phase,
// txSetup->attempts, txSetup->expected_phase, txSetup->tollerance,
// hal_get_fpga_temperature() / 256.0);
pr_info("TX Calibration: upd port %d phase %d %d after %d "
"attempts target %d tollerance %d (temp = %.3f degC)\n",
ps->hw_index, txSetup->measured_phase, txSetup->measured_phase,
txSetup->attempts, txSetup->expected_phase, txSetup->tollerance,
hal_get_fpga_temperature() / 256.0);
if(_within_range(phase, phase_min, phase_max, 16000)) {
int i;
pr_info("FIX port %d phase %d after %d attempts "
"(temp = %.3f degC)\n", ps->hw_index, txSetup->measured_phase,
txSetup->attempts, hal_get_fpga_temperature() / 256.0);
......
......@@ -18,15 +18,12 @@ int hal_port_generic_fsm( halPortFsmGen_t *pfg) {
if ( pfg->ps->in_use ) {
int portEventMask,isNewState;
char *evtStr=_generic_build_events(pfg, &portEventMask);
/* Check if state has changed */
if ( (isNewState=_isPendingState(pfg))==1 ) {
_consumeState(pfg);
}
// printf("ps i %d newstate %d pmask %x state_idx %d gs %d\n", pfg->ps->hw_index, isNewState, portEventMask, pfg->pt->state, _getState(pfg));
/* Call state entry */
if (portEventMask || isNewState) {
halPortStateTable_t *pt=pfg->pt;
......@@ -54,8 +51,6 @@ static char * _generic_build_events( halPortFsmGen_t *pfg, int *portEventMask) {
*portEventMask=0;
// printf("************call genbuildedvents\n");
if ( pfg->fctBuilEvents )
*portEventMask=(*pfg->fctBuilEvents)(pfg);
if ( FSM_GEN_DEBUG ) {
......
......@@ -282,7 +282,7 @@ int pcs_writel(struct hal_port_state *ps, uint16_t value, int reg)
uint32_t rv;
strncpy(ifr.ifr_name, ps->name, sizeof(ifr.ifr_name));
// printf("***** pcs_wrtel %d %d %x\n", ps->hw_index, reg, value );
rv = NIC_WRITE_PHY_CMD(reg, value);
ifr.ifr_data = (void *)&rv;
if (ioctl(halPorts.hal_port_fd, PRIV_IOCPHYREG, &ifr) < 0)
......
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