When master and slave instance interacting with each other operating
at different interface speed, delay assymetry needs to be compensated
as described in G.8271 appendix V.

In this patch we are adding changes to get the interface speed using
ethtool.

Signed-off-by: Greg Armstrong <greg.armstrong...@renesas.com>
Signed-off-by: Leon Goldin <leon.goldin...@renesas.com>
Signed-off-by: Devasish Dey <devasish....@syncmonk.net>
Signed-off-by: Vipin Sharma <vipin.sha...@syncmonk.net>
---
 sk.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sk.h | 18 ++++++++++++++++
 2 files changed, 87 insertions(+)

diff --git a/sk.c b/sk.c
index 80075be..d372fef 100644
--- a/sk.c
+++ b/sk.c
@@ -205,6 +205,75 @@ failed:
        return -1;
 }
 
+int sk_get_if_info(const char *name, struct sk_if_info *if_info)
+{
+#ifdef ETHTOOL_GLINKSETTINGS
+       struct ifreq ifr;
+       int fd, err;
+
+       struct {
+               struct ethtool_link_settings req;
+               /* link_mode_data consists of supported[], advertising[]
+                * and lp_advertising[] with size up to 127 each.
+                * The actual size is provided by the kernel.
+                */
+               __u32 link_mode_data[3 * 127];
+       } ecmd;
+
+       memset(&ifr, 0, sizeof(ifr));
+       memset(&ecmd, 0, sizeof(ecmd));
+
+       fd = socket(AF_INET, SOCK_DGRAM, 0);
+       if (fd < 0) {
+               goto failed;
+       }
+
+       ecmd.req.cmd = ETHTOOL_GLINKSETTINGS;
+
+       strncpy(ifr.ifr_name, name, IFNAMSIZ - 1);
+       ifr.ifr_data = (char *) &ecmd;
+
+       /* Handshake with kernel to determine number of words for link
+        * mode bitmaps. When requested number of bitmap words is not
+        * the one expected by kernel, the latter returns the integer
+        * opposite of what it is expecting. We request length 0 below
+        * (aka. invalid bitmap length) to get this info.
+        */
+       err = ioctl(fd, SIOCETHTOOL, &ifr);
+       if (err < 0) {
+               pr_err("ioctl SIOCETHTOOL failed: %m");
+               close(fd);
+               goto failed;
+       }
+
+       if (ecmd.req.link_mode_masks_nwords >= 0 ||
+                       ecmd.req.cmd != ETHTOOL_GLINKSETTINGS) {
+               return 1;
+       }
+       ecmd.req.link_mode_masks_nwords = -ecmd.req.link_mode_masks_nwords;
+
+       err = ioctl(fd, SIOCETHTOOL, &ifr);
+       if (err < 0) {
+               pr_err("ioctl SIOCETHTOOL failed: %m");
+               close(fd);
+               goto failed;
+       }
+
+       close(fd);
+
+       /* copy the necessary data to sk_info */
+       memset(if_info, 0, sizeof(struct sk_if_info));
+       if_info->valid = 1;
+       if_info->speed = ecmd.req.speed;
+
+       return 0;
+failed:
+#endif
+       /* clear data and ensure it is not marked valid */
+       memset(if_info, 0, sizeof(struct sk_if_info));
+       return -1;
+}
+
 static int sk_interface_guidaddr(const char *name, unsigned char *guid)
 {
        char file_name[64], buf[64], addr[8];
diff --git a/sk.h b/sk.h
index 486dbc4..853aadf 100644
--- a/sk.h
+++ b/sk.h
@@ -49,6 +49,16 @@ struct sk_ts_info {
        unsigned int rx_filters;
 };
 
+/**
+ * Contains interface information returned by theGLINKSETTINGS ioctl.
+ * @valid:            set to non-zero when the info struct contains valid data.
+ * @speed:            interface speed.
+ */
+struct sk_if_info {
+       int valid;
+       int speed;
+};
+
 /**
  * Obtains a socket suitable for use with sk_interface_index().
  * @return  An open socket on success, -1 otherwise.
@@ -78,6 +88,14 @@ int sk_general_init(int fd);
  */
 int sk_get_ts_info(const char *name, struct sk_ts_info *sk_info);
 
+/**
+ * Obtain supporte interface information
+ * @param name     The name of the interface
+ * @param info      Struct containing obtained interface information.
+ * @return          zero on success, negative on failure.
+ */
+int sk_get_if_info(const char *name, struct sk_if_info *sk_info);
+
 /**
  * Obtain the MAC address of a network interface.
  * @param name  The name of the interface
-- 
2.17.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to