Skip to content

Commit

Permalink
config: Add port-specific phc_index option.
Browse files Browse the repository at this point in the history
Allow the PHC index to be configured for each port. The default value is
-1, which enables the original behavior using the PHC specified by -p or
the index from ETHTOOL_GET_TS_INFO.

Signed-off-by: Miroslav Lichvar <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Mar 8, 2022
1 parent 18dee45 commit e56964c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
char ts_label[IF_NAMESIZE], phc[32], *tmp;
enum timestamp_type timestamping;
int fadj = 0, max_adj = 0, sw_ts;
int phc_index, required_modes = 0;
int phc_index, conf_phc_index, required_modes = 0;
struct clock *c = &the_clock;
const char *uds_ifname;
struct port *p;
Expand Down Expand Up @@ -1016,6 +1016,8 @@ struct clock *clock_create(enum clock_type type, struct config *config,

iface = STAILQ_FIRST(&config->interfaces);

conf_phc_index = config_get_int(config, interface_name(iface), "phc_index");

/* determine PHC Clock index */
if (config_get_int(config, NULL, "free_running")) {
phc_index = -1;
Expand All @@ -1025,6 +1027,8 @@ struct clock *clock_create(enum clock_type type, struct config *config,
if (1 != sscanf(phc_device, "/dev/ptp%d", &phc_index)) {
phc_index = -1;
}
} else if (conf_phc_index >= 0) {
phc_index = conf_phc_index;
} else if (interface_tsinfo_valid(iface)) {
phc_index = interface_phc_index(iface);
} else {
Expand Down
1 change: 1 addition & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("operLogPdelayReqInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("operLogSyncInterval", 0, INT8_MIN, INT8_MAX),
PORT_ITEM_INT("path_trace_enabled", 0, 0, 1),
PORT_ITEM_INT("phc_index", -1, -1, INT_MAX),
GLOB_ITEM_DBL("pi_integral_const", 0.0, 0.0, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_exponent", 0.4, -DBL_MAX, DBL_MAX),
GLOB_ITEM_DBL("pi_integral_norm_max", 0.3, DBL_MIN, 2.0),
Expand Down
1 change: 1 addition & 0 deletions configs/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ delay_filter_length 10
egressLatency 0
ingressLatency 0
boundary_clock_jbod 0
phc_index -1
#
# Clock description
#
Expand Down
8 changes: 5 additions & 3 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -3173,7 +3173,9 @@ struct port *port_open(const char *phc_device,
goto err_log_name;
}

p->phc_index = phc_index;
p->phc_index = config_get_int(cfg, interface_name(interface), "phc_index");
if (p->phc_index < 0)
p->phc_index = phc_index;
p->jbod = config_get_int(cfg, interface_name(interface), "boundary_clock_jbod");
p->master_only = config_get_int(cfg, interface_name(interface), "serverOnly");
p->bmca = config_get_int(cfg, interface_name(interface), "BMCA");
Expand All @@ -3200,8 +3202,8 @@ struct port *port_open(const char *phc_device,
; /* UDS cannot have a PHC. */
} else if (!interface_tsinfo_valid(interface)) {
pr_warning("%s: get_ts_info not supported", p->log_name);
} else if (phc_index >= 0 &&
phc_index != interface_phc_index(interface)) {
} else if (p->phc_index >= 0 &&
p->phc_index != interface_phc_index(interface)) {
if (p->jbod) {
pr_warning("%s: just a bunch of devices", p->log_name);
p->phc_index = interface_phc_index(interface);
Expand Down
5 changes: 5 additions & 0 deletions ptp4l.8
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ collection of clocks must be synchronized by an external program, for
example phc2sys(8) in "automatic" mode.
The default is 0 (disabled).
.TP
.B phc_index
Specifies the index of the PHC to be used for synchronization with hardware
timestamping. The default is -1, which means the index will be set to the PHC
associated with the interface, or the device specified by the \fB-p\fP option.
.TP
.B udp_ttl
Specifies the Time to live (TTL) value for IPv4 multicast messages and the hop
limit for IPv6 multicast messages. This option is only relevant with the IPv4
Expand Down

0 comments on commit e56964c

Please sign in to comment.