Jacob Keller
2012-09-28 03:42:37 UTC
This patch adds support for sk_interface_phc to lookup the /dev/ptpX device
using ethtool's get_ts_info ioctl
-v2-
* set ethdev to null initially
* rebased on top of phc2sys changes
-v3-
* fixed typo regarding slash
Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 2 +-
phc2sys.c | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/makefile b/makefile
index fd032f5..0ddc6fb 100644
--- a/makefile
+++ b/makefile
@@ -43,7 +43,7 @@ ptp4l: $(OBJ)
pmc: pmc.o msg.o print.o raw.o sk.o tlv.o transport.o udp.o udp6.o uds.o util.o
-phc2sys: phc2sys.o
+phc2sys: phc2sys.o sk.o print.o
hwstamp_ctl: hwstamp_ctl.o
diff --git a/phc2sys.c b/phc2sys.c
index 1e406ba..26a0c2b 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -33,6 +33,7 @@
#include <linux/ptp_clock.h>
#include "missing.h"
+#include "sk.h"
#define KP 0.7
#define KI 0.3
@@ -226,6 +227,7 @@ static void usage(char *progname)
" -d [device] master device, source of PPS events\n"
" -h prints this message and exits\n"
" -s [device] set the time from this PHC device\n"
+ " -i [device] set the time from PHC connected to this eth device\n"
" -P [val] set proportional constant to 'val'\n"
" -I [val] set integration constant to 'val'\n"
" -R [val] set PHC update rate to 'val' Hz\n"
@@ -237,7 +239,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
double kp = KP, ki = KI;
- char *device = NULL, *progname;
+ char *device = NULL, *progname, *ethdev = NULL;
clockid_t src = CLOCK_INVALID, dst = CLOCK_REALTIME;
uint64_t phc_ts;
int64_t phc_offset;
@@ -246,7 +248,7 @@ int main(int argc, char *argv[])
/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
- while (EOF != (c = getopt(argc, argv, "c:d:hs:P:I:R:N:"))) {
+ while (EOF != (c = getopt(argc, argv, "c:d:hs:P:I:R:N:i:"))) {
switch (c) {
case 'c':
dst = clock_open(optarg);
@@ -269,6 +271,9 @@ int main(int argc, char *argv[])
case 'N':
phc_readings = atoi(optarg);
break;
+ case 'i':
+ ethdev = optarg;
+ break;
case 'h':
usage(progname);
return 0;
@@ -278,6 +283,16 @@ int main(int argc, char *argv[])
}
}
+ if (src == CLOCK_INVALID && ethdev) {
+ int phc_index = -1;
+ char phc_device[16];
+ if (sk_interface_phc(ethdev, &phc_index) || phc_index < 0) {
+ fprintf(stderr, "can't autodiscover PHC device\n");
+ return -1;
+ }
+ sprintf(phc_device, "/dev/ptp%d", phc_index);
+ src = clock_open(phc_device);
+ }
if (!(device || src != CLOCK_INVALID) || dst == CLOCK_INVALID) {
usage(progname);
return -1;
using ethtool's get_ts_info ioctl
-v2-
* set ethdev to null initially
* rebased on top of phc2sys changes
-v3-
* fixed typo regarding slash
Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 2 +-
phc2sys.c | 19 +++++++++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/makefile b/makefile
index fd032f5..0ddc6fb 100644
--- a/makefile
+++ b/makefile
@@ -43,7 +43,7 @@ ptp4l: $(OBJ)
pmc: pmc.o msg.o print.o raw.o sk.o tlv.o transport.o udp.o udp6.o uds.o util.o
-phc2sys: phc2sys.o
+phc2sys: phc2sys.o sk.o print.o
hwstamp_ctl: hwstamp_ctl.o
diff --git a/phc2sys.c b/phc2sys.c
index 1e406ba..26a0c2b 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -33,6 +33,7 @@
#include <linux/ptp_clock.h>
#include "missing.h"
+#include "sk.h"
#define KP 0.7
#define KI 0.3
@@ -226,6 +227,7 @@ static void usage(char *progname)
" -d [device] master device, source of PPS events\n"
" -h prints this message and exits\n"
" -s [device] set the time from this PHC device\n"
+ " -i [device] set the time from PHC connected to this eth device\n"
" -P [val] set proportional constant to 'val'\n"
" -I [val] set integration constant to 'val'\n"
" -R [val] set PHC update rate to 'val' Hz\n"
@@ -237,7 +239,7 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
double kp = KP, ki = KI;
- char *device = NULL, *progname;
+ char *device = NULL, *progname, *ethdev = NULL;
clockid_t src = CLOCK_INVALID, dst = CLOCK_REALTIME;
uint64_t phc_ts;
int64_t phc_offset;
@@ -246,7 +248,7 @@ int main(int argc, char *argv[])
/* Process the command line arguments. */
progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0];
- while (EOF != (c = getopt(argc, argv, "c:d:hs:P:I:R:N:"))) {
+ while (EOF != (c = getopt(argc, argv, "c:d:hs:P:I:R:N:i:"))) {
switch (c) {
case 'c':
dst = clock_open(optarg);
@@ -269,6 +271,9 @@ int main(int argc, char *argv[])
case 'N':
phc_readings = atoi(optarg);
break;
+ case 'i':
+ ethdev = optarg;
+ break;
case 'h':
usage(progname);
return 0;
@@ -278,6 +283,16 @@ int main(int argc, char *argv[])
}
}
+ if (src == CLOCK_INVALID && ethdev) {
+ int phc_index = -1;
+ char phc_device[16];
+ if (sk_interface_phc(ethdev, &phc_index) || phc_index < 0) {
+ fprintf(stderr, "can't autodiscover PHC device\n");
+ return -1;
+ }
+ sprintf(phc_device, "/dev/ptp%d", phc_index);
+ src = clock_open(phc_device);
+ }
if (!(device || src != CLOCK_INVALID) || dst == CLOCK_INVALID) {
usage(progname);
return -1;