Dong Zhu
2012-11-13 11:14:51 UTC
Signed-off-by: Dong Zhu <***@gmail.com>
---
ptp4l.c | 8 ++++++++
sk.c | 39 +++++++++++++++++++++++++++++++++++++++
sk.h | 7 +++++++
3 files changed, 54 insertions(+)
diff --git a/ptp4l.c b/ptp4l.c
index 5838d53..377ada9 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -253,6 +253,14 @@ int main(int argc, char *argv[])
return -1;
}
+ if (*timestamping == TS_SOFTWARE) {
+ if (software_timestamp_support(iface[0].name)) {
+ fprintf(stderr, "network driver do not "
+ "support Software Time Stamp\n");
+ return -1;
+ }
+ }
+
/* determine PHC Clock index */
if (ds->free_running) {
phc_index = -1;
diff --git a/sk.c b/sk.c
index b6ba8a5..7257386 100644
--- a/sk.c
+++ b/sk.c
@@ -123,6 +123,45 @@ int sk_interface_phc(char *name, int *index)
#endif
}
+int software_timestamp_support(char *name)
+{
+#ifdef ETHTOOL_GET_TS_INFO
+ struct ethtool_ts_info info;
+ struct ifreq ifr;
+ int fd, err;
+
+ memset(&ifr, 0, sizeof(ifr));
+ memset(&info, 0, sizeof(info));
+ info.cmd = ETHTOOL_GET_TS_INFO;
+ strcpy(ifr.ifr_name, name);
+ ifr.ifr_data = (char *) &info;
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (fd < 0) {
+ pr_err("socket failed: %m");
+ return -1;
+ }
+
+ err = ioctl(fd, SIOCETHTOOL, &ifr);
+ if (err < 0) {
+ pr_err("ioctl SIOCETHTOOL failed: %m");
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ if (info.so_timestamping & (SOF_TIMESTAMPING_TX_SOFTWARE |
+ SOF_TIMESTAMPING_RX_SOFTWARE |
+ SOF_TIMESTAMPING_SOFTWARE))
+ return 0;
+ else
+ return -1;
+#else
+ return -1;
+#endif
+}
+
int sk_interface_macaddr(char *name, unsigned char *mac, int len)
{
struct ifreq ifreq;
diff --git a/sk.h b/sk.h
index 671e839..6a4aa38 100644
--- a/sk.h
+++ b/sk.h
@@ -48,6 +48,13 @@ int sk_interface_phc(char *name, int *index);
int sk_interface_macaddr(char *name, unsigned char *mac, int len);
/**
+ * Check whether the network driver support software time stamp
+ * @param name The name of the interface
+ * @return Zero on success, non-zero otherwise.
+ */
+int software_timestamp_support(char *name);
+
+/**
* Read a message from a socket.
* @param fd An open socket.
* @param buf Buffer to receive the message.
---
ptp4l.c | 8 ++++++++
sk.c | 39 +++++++++++++++++++++++++++++++++++++++
sk.h | 7 +++++++
3 files changed, 54 insertions(+)
diff --git a/ptp4l.c b/ptp4l.c
index 5838d53..377ada9 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -253,6 +253,14 @@ int main(int argc, char *argv[])
return -1;
}
+ if (*timestamping == TS_SOFTWARE) {
+ if (software_timestamp_support(iface[0].name)) {
+ fprintf(stderr, "network driver do not "
+ "support Software Time Stamp\n");
+ return -1;
+ }
+ }
+
/* determine PHC Clock index */
if (ds->free_running) {
phc_index = -1;
diff --git a/sk.c b/sk.c
index b6ba8a5..7257386 100644
--- a/sk.c
+++ b/sk.c
@@ -123,6 +123,45 @@ int sk_interface_phc(char *name, int *index)
#endif
}
+int software_timestamp_support(char *name)
+{
+#ifdef ETHTOOL_GET_TS_INFO
+ struct ethtool_ts_info info;
+ struct ifreq ifr;
+ int fd, err;
+
+ memset(&ifr, 0, sizeof(ifr));
+ memset(&info, 0, sizeof(info));
+ info.cmd = ETHTOOL_GET_TS_INFO;
+ strcpy(ifr.ifr_name, name);
+ ifr.ifr_data = (char *) &info;
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (fd < 0) {
+ pr_err("socket failed: %m");
+ return -1;
+ }
+
+ err = ioctl(fd, SIOCETHTOOL, &ifr);
+ if (err < 0) {
+ pr_err("ioctl SIOCETHTOOL failed: %m");
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ if (info.so_timestamping & (SOF_TIMESTAMPING_TX_SOFTWARE |
+ SOF_TIMESTAMPING_RX_SOFTWARE |
+ SOF_TIMESTAMPING_SOFTWARE))
+ return 0;
+ else
+ return -1;
+#else
+ return -1;
+#endif
+}
+
int sk_interface_macaddr(char *name, unsigned char *mac, int len)
{
struct ifreq ifreq;
diff --git a/sk.h b/sk.h
index 671e839..6a4aa38 100644
--- a/sk.h
+++ b/sk.h
@@ -48,6 +48,13 @@ int sk_interface_phc(char *name, int *index);
int sk_interface_macaddr(char *name, unsigned char *mac, int len);
/**
+ * Check whether the network driver support software time stamp
+ * @param name The name of the interface
+ * @return Zero on success, non-zero otherwise.
+ */
+int software_timestamp_support(char *name);
+
+/**
* Read a message from a socket.
* @param fd An open socket.
* @param buf Buffer to receive the message.
--
1.7.11.7
--
Best Regards,
Dong Zhu
1.7.11.7
--
Best Regards,
Dong Zhu