Re: [Linuxptp-devel] [PATCHv3 08/10] ptp4l: use ts label to get ts info
PTP IEEE 1588 stack for Linux
Brought to you by:
rcochran
From: Hangbin L. <liu...@gm...> - 2017-09-10 14:32:26
|
Hi Richard, On Wed, Aug 16, 2017 at 09:32:09PM +0800, Hangbin Liu wrote: > @@ -2240,6 +2243,35 @@ static void port_link_status(void *ctx, int linkup, int ts_index) > pr_notice("port %hu: link %s", portnum(p), linkup ? "up" : "down"); > } > > + /* ts_label changed */ > + if (if_indextoname(ts_index, ts_label) && strcmp(p->iface->ts_label, ts_label)) { > + strncpy(p->iface->ts_label, ts_label, MAX_IFNAME_SIZE); > + sk_get_ts_info(p->iface->ts_label, &p->iface->ts_info); > + > + p->link_status |= TS_LABEL_CHANGED; > + pr_notice("port %hu: ts label changed to %s", portnum(p), ts_label); > + } > + > + /* We set the link status to down by force if its timestamp not > + * support required mode. But the link's status is actually up. > + * > + * So the next time we receive this link's rtnl message, we need > + * to check the required_modes again. If still not support > + * required_modes, then keep the link status down. > + */ > + if (p->iface->ts_info.valid) { > + required_modes = clock_required_modes(p->clock); > + if ((p->iface->ts_info.so_timestamping & required_modes) != required_modes) { > + pr_err("interface '%s' does not support requested " > + "timestamping mode, set link status down by force.", > + p->iface->ts_label); > + p->link_status = LINK_DOWN | LINK_STATE_CHANGED; > + } else if (p->link_status & TS_LABEL_CHANGED) { > + p->phc_index = p->iface->ts_info.phc_index; > + clock_switch_phc(p->clock, p->phc_index); > + } > + } > + FYI, I will changed this part with new version like: + /* ts_label changed */ + if (if_indextoname(ts_index, ts_label) && strcmp(p->iface->ts_label, ts_label)) { + strncpy(p->iface->ts_label, ts_label, MAX_IFNAME_SIZE); + p->link_status |= TS_LABEL_CHANGED; + pr_notice("port %hu: ts label changed to %s", portnum(p), ts_label); + } + + /* Both link down/up and change ts_label may change phc index. */ + if (p->link_status & LINK_UP && + (p->link_status & LINK_STATE_CHANGED || p->link_status & TS_LABEL_CHANGED)) { + sk_get_ts_info(p->iface->ts_label, &p->iface->ts_info); + + if (p->iface->ts_info.valid) { + required_modes = clock_required_modes(p->clock); + if ((p->iface->ts_info.so_timestamping & required_modes) != required_modes) { + pr_err("interface '%s' does not support requested " + "timestamping mode, set link status down by force.", + p->iface->ts_label); + p->link_status = LINK_DOWN | LINK_STATE_CHANGED; + } else if (p->phc_index != p->iface->ts_info.phc_index) { + p->phc_index = p->iface->ts_info.phc_index; + + if (clock_switch_phc(p->clock, p->phc_index)) { + p->last_fault_type = FT_SWITCH_PHC; + port_dispatch(p, EV_FAULT_DETECTED, 0); + return; + } + clock_sync_interval(p->clock, p->log_sync_interval); + } + } + } + Thanks Hangbin |