Commit 7623fc53 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

Merge branch 'greg-t24p' into proposed_master

parents b3b066a2 22538c6b
......@@ -127,6 +127,12 @@ config PORT01_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT01_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 13600
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT01_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -292,6 +298,12 @@ config PORT02_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT02_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 10800
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT02_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -457,6 +469,12 @@ config PORT03_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT03_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 13650
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT03_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -622,6 +640,12 @@ config PORT04_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT04_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 12150
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT04_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -787,6 +811,12 @@ config PORT05_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT05_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 13550
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT05_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -952,6 +982,12 @@ config PORT06_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT06_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14500
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT06_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -1117,6 +1153,12 @@ config PORT07_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT07_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 13950
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT07_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -1282,6 +1324,12 @@ config PORT08_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT08_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14450
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT08_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -1447,6 +1495,12 @@ config PORT09_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT09_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14750
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT09_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -1612,6 +1666,12 @@ config PORT10_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT10_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 15100
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT10_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -1777,6 +1837,12 @@ config PORT11_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT11_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14500
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT11_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -1942,6 +2008,12 @@ config PORT12_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT12_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 9850
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT12_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -2107,6 +2179,12 @@ config PORT13_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT13_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14150
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT13_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -2272,6 +2350,12 @@ config PORT14_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT14_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 11950
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT14_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -2437,6 +2521,12 @@ config PORT15_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT15_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 12900
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT15_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -2602,6 +2692,12 @@ config PORT16_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT16_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 13800
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT16_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -2767,6 +2863,12 @@ config PORT17_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT17_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14200
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT17_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......@@ -2932,6 +3034,12 @@ config PORT18_INST01_INGRESS_LATENCY
help
Defines the reception constant delay (ps)
config PORT18_INST01_T24P_TRANS_POINT
int "timestampCorrectionPortDS.t24p_trans_point (ps)"
default 14350
help
Defines the phase transition point for reception timestamps t2/t4 (ps)
config PORT18_INST01_ANNOUNCE_INTERVAL
int "logAnnounceInterval"
default 1
......
......@@ -106,6 +106,7 @@ function print_instance_header() {
if [ $instIdx -eq 1 ] ; then prof=WR ; else prof=HA ; fi
local tx=${port_tx[$1]}
local rx=${port_rx[$1]}
local t24p=${port_t24p[$1]}
echo -e "\nmenu \"Instance ${instIdx}\"" >>$OUTPUT_FILE
echo -n " depends on " >>$OUTPUT_FILE
for inst in `seq $instIdx $instCount` ; do
......@@ -190,6 +191,12 @@ function print_instance_header() {
echo -e " default ${rx}" >>$OUTPUT_FILE
echo -e " help" >>$OUTPUT_FILE
echo -e " Defines the reception constant delay (ps)" >>$OUTPUT_FILE
echo -e "\nconfig PORT${portStr}_INST${instStr}_T24P_TRANS_POINT" >>$OUTPUT_FILE
echo -e " int \"timestampCorrectionPortDS.t24p_trans_point (ps)\"" >>$OUTPUT_FILE
echo -e " default ${t24p}" >>$OUTPUT_FILE
echo -e " help" >>$OUTPUT_FILE
echo -e " Defines the phase transition point for reception timestamps t2/t4 (ps)" >>$OUTPUT_FILE
echo -e "\nconfig PORT${portStr}_INST${instStr}_ANNOUNCE_INTERVAL" >>$OUTPUT_FILE
echo -e " int \"logAnnounceInterval\" " >>$OUTPUT_FILE
......@@ -339,6 +346,12 @@ declare -A port_rx=(
[13]=229225 [14]=229463 [15]=229850 [16]=229907 [17]=230106 [18]=230273
)
declare -A port_t24p=(
[1]=13600 [2]=10800 [3]=13650 [4]=12150 [5]=13550 [6]=14500
[7]=13950 [8]=14450 [9]=14750 [10]=15100 [11]=14500 [12]=9850
[13]=14150 [14]=11950 [15]=12900 [16]=13800 [17]=14200 [18]=14350
)
# Profile configuration
defaultProfile="WR"
profileList="PTP WR"
......
......@@ -2,7 +2,7 @@
# We are now Kconfig-based
-include ../../.config
TOOLS = rtu_stat wr_mon wr_phytool wrs_pps_control spll_dbg_proxy load-lm32 load-virtex com
TOOLS = wr_phytool wrs_pps_control spll_dbg_proxy load-lm32 load-virtex com
TOOLS += mapper wmapper
TOOLS += wrs_version wr_date lm32-vuart wrs_pstats wrs_leapsec
TOOLS += wrs_vlans wrs_dump_shmem
......
......@@ -316,10 +316,10 @@ void calc_trans(int ep, int argc, char *argv[])
struct wr_sockaddr to;
struct rts_pll_state pstate;
pcs_write(ep, MII_BMCR, BMCR_PDOWN);
/* pcs_write(ep, MII_BMCR, BMCR_PDOWN);
usleep(10000);
pcs_write(ep, MII_BMCR, 0); //BMCR_ANENABLE | BMCR_ANRESTART);
pcs_read(ep, MII_BMSR);
pcs_write(ep, MII_BMCR, 0);
pcs_read(ep, MII_BMSR);*/
while(! (pcs_read(ep, MII_BMSR) & BMSR_LSTATUS)) usleep(10000);
......@@ -1319,6 +1319,14 @@ void rt_command(int ep, int argc, char *argv[])
}
}
int measure_t24p(int endpoint, uint32_t *value);
void cmd_t24p_new(int ep, int argc, char *argv[])
{
uint32_t value;
measure_t24p( ep, &value );
}
struct {
char *cmd;
......@@ -1338,10 +1346,10 @@ struct {
try_autonegotiation},
{
"ttrans",
"t24p",
"",
"determine transition point",
calc_trans},
"determine transition point (new algo)",
cmd_t24p_new},
{
"dump",
......@@ -1382,6 +1390,259 @@ struct {
};
/* New calibrator for the transition phase value. A major pain in the ass for
the folks who frequently rebuild their gatewares. The idea is described
below:
- lock the PLL to the master
- scan the whole phase shifter range
- at each scanning step, generate a fake RX timestamp.
- check if the rising edge counter is ahead of the falling edge counter
(added a special bit for it in the TSU).
- determine phases at which positive/negative transitions occur
- transition phase value is in the middle between the rising and falling
edges.
This calibration procedure is fast enough to be run on slave nodes whenever
the link goes up. For master mode, the core must be run at least once as a
slave to calibrate itself and store the current transition phase value in
the EEPROM.
*/
/* how finely we scan the phase shift range to determine where we have the bit
* flip */
#define CAL_SCAN_STEP 100
/* deglitcher threshold (to remove 1->0->1 flip bit glitches that might occur
due to jitter) */
#define CAL_DEGLITCH_THRESHOLD 5
/* we scan at least one clock period to look for rising->falling edge transition
plus some headroom */
#define CAL_SCAN_RANGE (REF_CLOCK_PERIOD_PS + \
(3 * CAL_DEGLITCH_THRESHOLD * CAL_SCAN_STEP))
#define TD_WAIT_INACTIVE 0
#define TD_GOT_TRANSITION 1
#define TD_DONE 2
/* Number of retries for rxts_calibration_update
* value found experimentally */
#define CALIB_RETRIES 1000
/* state of transition detector */
struct trans_detect_state {
int prev_val;
int sample_count;
int state;
int trans_phase;
};
/* finds the transition in the value of flip_bit and returns phase associated
with it. If no transition phase has been found yet, returns 0. Non-zero
polarity means we are looking for positive transitions, 0 - negative
transitions */
static int lookup_transition(struct trans_detect_state *state, int flip_bit,
int phase, int polarity)
{
if (polarity)
polarity = 1;
switch (state->state) {
case TD_WAIT_INACTIVE:
/* first, wait until we have at least CAL_DEGLITCH_THRESHOLD of
inactive state samples */
if (flip_bit != polarity)
state->sample_count++;
else
state->sample_count = 0;
if (state->sample_count >= CAL_DEGLITCH_THRESHOLD) {
state->state = TD_GOT_TRANSITION;
state->sample_count = 0;
}
break;
case TD_GOT_TRANSITION:
if (flip_bit != polarity)
state->sample_count = 0;
else {
state->sample_count++;
if (state->sample_count >= CAL_DEGLITCH_THRESHOLD) {
state->state = TD_DONE;
state->trans_phase =
phase -
CAL_DEGLITCH_THRESHOLD * CAL_SCAN_STEP;
}
}
break;
case TD_DONE:
return 1;
break;
}
return 0;
}
static struct trans_detect_state det_rising, det_falling;
static int cal_cur_phase;
static int cal_endpoint;
static struct rts_pll_state cal_pstate;
static void rxts_calibration_init(int endpoint)
{
if( rts_connect(NULL) < 0)
{
printf("Can't connect to the RT subsys\n");
exit(1);
}
cal_endpoint = endpoint;
}
static void cal_spll_set_phase_shift(int endpoint, int shift )
{
printf("adjp ep %d shift %d\n", endpoint, shift );
rts_adjust_phase(endpoint, shift);
}
static int cal_spll_shifter_busy()
{
rts_get_state(&cal_pstate);
return ( cal_pstate.channels[cal_endpoint].flags & CHAN_SHIFTING ? 1 : 0);
}
/* Starts RX timestamper calibration process state machine. Invoked by
ptpnetif's check lock function when the PLL has already locked, to avoid
complicating the API of ptp-noposix/ppsi. */
void rxts_calibration_start(void)
{
cal_cur_phase = 0;
det_rising.prev_val = det_falling.prev_val = -1;
det_rising.state = det_falling.state = TD_WAIT_INACTIVE;
det_rising.sample_count = 0;
det_falling.sample_count = 0;
det_rising.trans_phase = 0;
det_falling.trans_phase = 0;
cal_spll_set_phase_shift(cal_endpoint, 0);
}
/* Updates RX timestamper state machine. Non-zero return value means that
calibration is done. */
int rxts_calibration_update(uint32_t *t24p_value)
{
int32_t ttrans = 0;
if (cal_spll_shifter_busy(cal_endpoint))
return 0;
/* generate a fake RX timestamp and check if falling edge counter is
ahead of rising edge counter */
int flip = cal_ep_timestamper_cal_pulse(cal_endpoint);
/* look for transitions (with deglitching) */
lookup_transition(&det_rising, flip, cal_cur_phase, 1);
lookup_transition(&det_falling, flip, cal_cur_phase, 0);
if (cal_cur_phase >= CAL_SCAN_RANGE) {
if (det_rising.state != TD_DONE || det_falling.state != TD_DONE)
{
printf("RXTS calibration error.\n");
return -1;
}
/* normalize */
while (det_falling.trans_phase >= REF_CLOCK_PERIOD_PS)
det_falling.trans_phase -= REF_CLOCK_PERIOD_PS;
while (det_rising.trans_phase >= REF_CLOCK_PERIOD_PS)
det_rising.trans_phase -= REF_CLOCK_PERIOD_PS;
/* Use falling edge as second sample of rising edge */
if (det_falling.trans_phase > det_rising.trans_phase)
ttrans = det_falling.trans_phase - REF_CLOCK_PERIOD_PS/2;
else if(det_falling.trans_phase < det_rising.trans_phase)
ttrans = det_falling.trans_phase + REF_CLOCK_PERIOD_PS/2;
ttrans += det_rising.trans_phase;
ttrans /= 2;
/*normalize ttrans*/
if(ttrans < 0) ttrans += REF_CLOCK_PERIOD_PS;
if(ttrans >= REF_CLOCK_PERIOD_PS) ttrans -= REF_CLOCK_PERIOD_PS;
printf("RXTS calibration: R@%dps, F@%dps, transition@%dps\n",
det_rising.trans_phase, det_falling.trans_phase,
ttrans);
*t24p_value = (uint32_t)ttrans;
return 1;
}
printf("Try phase %d flip %d\n", cal_cur_phase, flip );
cal_cur_phase += CAL_SCAN_STEP;
cal_spll_set_phase_shift(cal_endpoint, cal_cur_phase);
return 0;
}
int cal_ep_timestamper_cal_pulse()
{
uint32_t tscr = fpga_readl( IDX_TO_EP(cal_endpoint) + EP_REG(TSCR) );
tscr |= EP_TSCR_RX_CAL_START;
fpga_writel(tscr, IDX_TO_EP(cal_endpoint) + EP_REG(TSCR));
shw_udelay(1000);
tscr = fpga_readl( IDX_TO_EP(cal_endpoint) + EP_REG(TSCR) );
return tscr & EP_TSCR_RX_CAL_RESULT ? 1 : 0;
}
/* legacy function for 'calibration force' command */
int measure_t24p(int endpoint, uint32_t *value)
{
int rv;
printf("Measuring t24p for endpoint %d\n", endpoint );
rxts_calibration_init( endpoint );
printf("Waiting for link...\n");
while(! (pcs_read(cal_endpoint, MII_BMSR) & BMSR_LSTATUS))
{
shw_udelay(1000);
}
rts_set_mode( RTS_MODE_BC );
rts_lock_channel( endpoint, 0 );
printf("Locking PLL...\n");
while (1)
{
rts_get_state(&cal_pstate);
//printf("PState flags %x\n", cal_pstate.flags );
if (cal_pstate.flags & RTS_REF_LOCKED)
break;
shw_udelay(100000);
}
printf("\n");
printf("Calibrating RX timestamper...\n");
rxts_calibration_start();
while (!(rv = rxts_calibration_update(value))) ;
return rv;
}
int main(int argc, char **argv)
{
int i;
......
......@@ -19,6 +19,7 @@
#include <libwr/switch_hw.h>
#include <libwr/wrs-msg.h>
#include <libwr/generic_fsm.h>
#include <libwr/config.h>
#include "driver_stuff.h"
#include "hal_exports.h"
......@@ -448,10 +449,28 @@ static void reset_port(struct hal_port_state * ps)
/* Port initialization */
static void init_port(struct hal_port_state * ps)
{
char *retValue;
int t24p;
char key[128];
reset_port(ps);
ps->t2_phase_transition = DEFAULT_T2_PHASE_TRANS;
ps->t4_phase_transition = DEFAULT_T4_PHASE_TRANS;
ps->clock_period = REF_CLOCK_PERIOD_PS;
/* Rading t24p from the dot-config file could be done once in hal_ports, but
* I leave it here since we will implement automatic measurement procedure
* in the future release */
sprintf(key, "PORT%02i_INST01_T24P_TRANS_POINT", ps->hw_index+1);
if( (retValue=libwr_cfg_get(key))==NULL ) {
pr_error("port %i (%s): no key \"%s\" specified.\n",
ps->hw_index+1, ps->name, key);
t24p = DEFAULT_T2_PHASE_TRANS;
} else if (sscanf(retValue, "%i", &t24p) != 1) {
pr_error("port %i (%s): Invalid key \"%s\" value (%d).\n",
ps->hw_index+1, ps->name, key,*retValue);
}
ps->t2_phase_transition = t24p;
ps->t4_phase_transition = t24p;
}
......
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