Currently the PHC index is retrieved only through an ethtool ioctl if the PHC is specified as an Ethernet interface. If it's a char device such as /dev/ptp5, the phc_index will remain unpopulated. Try to infer it from the char device's path.
This is useful when trying to determine whether multiple clocks are in fact the same (such as /dev/ptp3 and sw1p3), just compare their PHC index. Signed-off-by: Vladimir Oltean <olte...@gmail.com> --- util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util.c b/util.c index 296dd59a08c1..027d694ea854 100644 --- a/util.c +++ b/util.c @@ -211,6 +211,16 @@ clockid_t posix_clock_open(const char *device, int *phc_index) /* check if device is valid phc device */ clkid = phc_open(device); if (clkid != CLOCK_INVALID) { + if (!strncmp(device, "/dev/ptp", strlen("/dev/ptp"))) { + int r = get_ranged_int(device + strlen("/dev/ptp"), + phc_index, 0, 65535); + if (r) { + fprintf(stderr, + "failed to parse PHC index from %s\n", + device); + return -1; + } + } return clkid; } /* check if device is a valid ethernet device */ -- 2.25.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel