Get the interface speed related information 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>
---
 clock.c     |  2 ++
 interface.c | 12 ++++++++++++
 interface.h | 14 ++++++++++++++
 port.c      |  5 +++++
 4 files changed, 33 insertions(+)

diff --git a/clock.c b/clock.c
index 5186010..7323636 100644
--- a/clock.c
+++ b/clock.c
@@ -1005,6 +1005,8 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
                memset(ts_label, 0, sizeof(ts_label));
                if (!rtnl_get_ts_device(interface_name(iface), ts_label))
                        interface_set_label(iface, ts_label);
+                /* Interface speed information */
+                interface_get_ifinfo(iface);
                interface_get_tsinfo(iface);
                if (interface_tsinfo_valid(iface) &&
                    !interface_tsmodes_supported(iface, required_modes)) {
diff --git a/interface.c b/interface.c
index 6c2630c..3157e8c 100644
--- a/interface.c
+++ b/interface.c
@@ -12,6 +12,7 @@ struct interface {
        char name[MAX_IFNAME_SIZE + 1];
        char ts_label[MAX_IFNAME_SIZE + 1];
        struct sk_ts_info ts_info;
+        struct sk_if_info if_info;
        int vclock;
 };
 
@@ -40,11 +41,22 @@ int interface_get_tsinfo(struct interface *iface)
        return sk_get_ts_info(iface->ts_label, &iface->ts_info);
 }
 
+int interface_get_ifinfo(struct interface *iface)
+{
+       return sk_get_if_info(iface->ts_label, &iface->if_info);
+}
+
 const char *interface_label(struct interface *iface)
 {
        return iface->ts_label;
 }
 
+bool interface_ifinfo_valid(struct interface *iface)
+{
+       return iface->if_info.valid ? true : false;
+}
+
+
 const char *interface_name(struct interface *iface)
 {
        return iface->name;
diff --git a/interface.h b/interface.h
index 5fc7836..f4b9545 100644
--- a/interface.h
+++ b/interface.h
@@ -40,6 +40,13 @@ void interface_destroy(struct interface *iface);
  */
 int interface_get_tsinfo(struct interface *iface);
 
+/**
+ * Populate the time stamping information of a given interface.
+ * @param iface  The interface of interest.
+ * @return       zero on success, negative on failure.
+ */
+int interface_get_ifinfo(struct interface *iface);
+
 /**
  * Obtain the time stamping label of a network interface.  This can be
  * different from the name of the interface when bonding is in effect.
@@ -77,6 +84,13 @@ void interface_set_label(struct interface *iface, const char 
*label);
  */
 bool interface_tsinfo_valid(struct interface *iface);
 
+/**
+ * Tests whether an interface's interface information is valid or not.
+ * @param iface  The interface of interest.
+ * @return       True if the interface information is valid, false otherwise.
+ */
+bool interface_ifinfo_valid(struct interface *iface);
+ 
 /**
  * Tests whether an interface supports a set of given time stamping modes.
  * @param iface  The interface of interest.
diff --git a/port.c b/port.c
index 1866a20..7fd50dd 100644
--- a/port.c
+++ b/port.c
@@ -2738,6 +2738,11 @@ void port_link_status(void *ctx, int linkup, int 
ts_index)
                p->link_status = link_state;
        } else {
                p->link_status = link_state | LINK_STATE_CHANGED;
+                /* Update Interface speed information on Link up*/
+                if (linkup) {
+                        interface_get_ifinfo(p->iface);
+                }
+
                pr_notice("%s: link %s", p->log_name, linkup ? "up" : "down");
        }
 
-- 
2.34.1



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

Reply via email to