[Linuxptp-devel] SYNCHRONIZATION_FAULT on I219-LM

2022-12-07 Thread Jonas Licht
Hi,

I'm unable to sync my intel PHC to a ptp master with ptp4l.
Can anybody give me a hint, to solve the problem?
Best regards,
Jonas

ptp4l says:
ptp4l[597.134]: selected /dev/ptp0 as PTP clock
ptp4l[597.135]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[597.135]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[598.093]: port 1: new foreign master
ptp4l[600.093]: selected best master clock
ptp4l[600.093]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE
ptp4l[600.323]: port 1: minimum delay request interval 2^0
ptp4l[600.626]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[600.751]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[600.751]: port 1: SLAVE to UNCALIBRATED on SYNCHRONIZATION_FAULT
ptp4l[600.876]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.001]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.126]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.252]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.252]: rms 7038422606 max 14104201307 freq +2399 +/-   0 delay
-16659872 +/- 3486084
ptp4l[601.377]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.502]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.627]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.752]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[601.877]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.002]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.127]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.252]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.252]: rms 753138307 max 981531165 freq +2399 +/-   0 delay
-18532559 +/-   0
ptp4l[602.377]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.502]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.627]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.752]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[602.877]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[603.002]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[603.127]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[603.252]: clockcheck: clock jumped forward or running faster than
expected!
ptp4l[603.252]: rms 1307987135 max 1544258031 freq +2399 +/-   0 delay
-19391313 +/- 52056

kernel version is 5.19.17

ethtool -T eth0
Time stamping parameters for eth0:
Capabilities:
hardware-transmit (SOF_TIMESTAMPING_TX_HARDWARE)
software-transmit (SOF_TIMESTAMPING_TX_SOFTWARE)
hardware-receive  (SOF_TIMESTAMPING_RX_HARDWARE)
software-receive  (SOF_TIMESTAMPING_RX_SOFTWARE)
software-system-clock (SOF_TIMESTAMPING_SOFTWARE)
hardware-raw-clock(SOF_TIMESTAMPING_RAW_HARDWARE)
PTP Hardware Clock: 0
Hardware Transmit Timestamp Modes:
off   (HWTSTAMP_TX_OFF)
on(HWTSTAMP_TX_ON)
Hardware Receive Filter Modes:
none  (HWTSTAMP_FILTER_NONE)
all   (HWTSTAMP_FILTER_ALL)
ptpv1-l4-sync (HWTSTAMP_FILTER_PTP_V1_L4_SYNC)
ptpv1-l4-delay-req(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ)
ptpv2-l4-sync (HWTSTAMP_FILTER_PTP_V2_L4_SYNC)
ptpv2-l4-delay-req(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ)
ptpv2-l2-sync (HWTSTAMP_FILTER_PTP_V2_L2_SYNC)
ptpv2-l2-delay-req(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ)
ptpv2-event   (HWTSTAMP_FILTER_PTP_V2_EVENT)
ptpv2-sync(HWTSTAMP_FILTER_PTP_V2_SYNC)
ptpv2-delay-req   (HWTSTAMP_FILTER_PTP_V2_DELAY_REQ)

ethtool -i eth0
driver: e1000e
version: 5.19.17-rt10-yocto-preempt-rt
firmware-version: 2.3-4
expansion-rom-version:
bus-info: :00:1f.6
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes

lspci
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (17)
I219-LM (rev 11)
___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH v2] Don't re-arm fault clearing timer on unrelated netlink events

2022-12-07 Thread Richard Cochran
On Wed, Nov 23, 2022 at 03:50:30PM -0800, davidjm via Linuxptp-devel wrote:
> Set the timer only when an event causes the port to transition to the
> FAULTY state, rather than potentially re-arming the timeout when an
> event occurs while the port was already FAULTY.
> 
> Concretely this occurs when a port is in fault, perhaps due to a
> single time out while polling for tx-timestamp. If any other port in the
> system (including unrelated ones ptp4l does not even know about) cause
> netlink messages to be sent. As it stands, clock_poll() will note that
> the port is in fault (from before, not due to the current event) and
> reset the timeout to its original value.
> 
> If such unrelated netlink messages arrive at a regular enough cadence
> the timeout may be repeatedly reset, not trigger on time (if at all) and
> the port may not get a chance to clear its fault, perhaps indefinitely.
> 
> Signed-off-by: David Mirabito 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] port: Avoid faults with vclocks and PHC from command line.

2022-12-07 Thread Richard Cochran
On Tue, Nov 22, 2022 at 05:07:16PM +0100, Miroslav Lichvar wrote:
> After commit afeabf3c90ed ("ptp4l: add VLAN over bond support") the
> TS_LABEL_CHANGED flag was set on link status changes when the used
> PHC index was different from the PHC index of the interface.
> 
> This caused the port to be constantly switching to the faulty state when
> using vclocks, or a different PHC device was forced with the -p option,
> where it is expected the used PHC doesn't match the interface's PHC.
> 
> Rework port_link_status() and port_change_phc() to avoid setting the
> flag and switch the clock only in the cases where it is expected.
> 
> Fixes: afeabf3c90ed ("ptp4l: add VLAN over bond support")
> Signed-off-by: Miroslav Lichvar 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH 2/2] phc_ctl: use PTP_CLOCK_GETCAPS2 ioctl if available

2022-12-07 Thread Richard Cochran
On Thu, Nov 17, 2022 at 02:15:23PM -0800, Jacob Keller wrote:
> On 11/17/2022 1:34 PM, Geva, Erez wrote:

> > The problem is the fallback works only on build.
> > But if the build system is newer than the running system, the fallback
> > will fail, as you will use the PTP_CLOCK_GETCAPS2 which does not exist
> > on the running old system.
> > 
> 
> Fair. We likely have the same problem with some of the other "2" ioctls,
> since they're handled in a similar way. I think we do the Right(TM) thing
> for the sysoff.c where we probe the kernel at run-time. This could be done
> here but is probably not really worth it considering that PTP_CLOCK_GETCAPS
> functions the same way as PTP_CLOCK_GETCAPS2 for all kernels I checked... So
> I guess this is somewhat less likely.

Jacob, do you want to have phc_ctl fall back to PTP_CLOCK_GETCAPS at
run time if PTP_CLOCK_GETCAPS2 fails?

> I'm not sure if our other PTP ioctls are checked properly like this at run
> time...

Maybe, but only because of sloppiness.  Better to support older
kernels at run time, as this is more user friendly.

Working on embedded systems over the years, I've have often been that
user, and, believe me, it is super annoying when the latest greatest
App isn't backwards compatible.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] makefile: use conditional assignment for KBUILD_OUTPUT

2022-12-07 Thread Richard Cochran
On Wed, Nov 23, 2022 at 08:23:46AM +0800, changqing...@eng.windriver.com wrote:
> From: Changqing Li 
> 
> Refer [1],from make 4.4, all variables that are marked as export will
> also be passed to the shell started by the shell function. use "=" will
> make KBUILD_OUTPUT always empty for shell function, use "?=" to make
> "export KBUILD_OUTPUT" in enrironment can work.
> 
> [snip of 4.4 NEWS]
> * WARNING: Backward-incompatibility!
>Previously makefile variables marked as export were not exported to 
> commands
>started by the $(shell ...) function.  Now, all exported variables are
>exported to $(shell ...).
> [snip]
> 
> [1] 
> https://git.savannah.gnu.org/cgit/make.git/tree/NEWS?h=4.4&id=ed493f6c9116cc217b99c2cfa6a95f15803235a2#n74
> 
> Signed-off-by: Changqing Li 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] remove C99 style loop variable declarations

2022-12-07 Thread Richard Cochran
On Wed, Nov 16, 2022 at 11:48:32AM -0800, Jacob Keller wrote:
> When building the tlv.c file, the following warning may occur when
> operating in C89 mode:

Jacob, this patch doesn't apply any more.  Can you rebase it please?

Thanks,
Richard


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


[Linuxptp-devel] [PATCH v3 2/4] [Interface Rate TLV] adding speed field information for interface

2022-12-07 Thread SyncMonk Technologies
Get the interface speed related information using ethtool

Signed-off-by: Greg Armstrong 
Signed-off-by: Leon Goldin 
Signed-off-by: Devasish Dey 
Signed-off-by: Vipin Sharma 
---
 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


[Linuxptp-devel] [PATCH v3 3/4] [Interface Rate TLV] organization TLV support for interface rate

2022-12-07 Thread SyncMonk Technologies
adding interface rate TLV as defined by ITU-T G.8275.2 Annex D to
enable master to communicate PTP port interface rate to slave.

Signed-off-by: Greg Armstrong 
Signed-off-by: Leon Goldin 
Signed-off-by: Devasish Dey 
Signed-off-by: Vipin Sharma 
---
 config.c   |  1 +
 pdt.h  |  1 +
 port.c |  1 +
 port_private.h |  1 +
 tlv.c  |  1 +
 tlv.h  | 14 ++
 6 files changed, 19 insertions(+)

diff --git a/config.c b/config.c
index 08e3346..2fa95fc 100644
--- a/config.c
+++ b/config.c
@@ -267,6 +267,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("inhibit_delay_req", 0, 0, 1),
PORT_ITEM_INT("inhibit_multicast_service", 0, 0, 1),
GLOB_ITEM_INT("initial_delay", 0, 0, INT_MAX),
+   PORT_ITEM_INT("interface_rate_tlv", 0, 0, 1),
GLOB_ITEM_INT("kernel_leap", 1, 0, 1),
GLOB_ITEM_STR("leapfile", NULL),
PORT_ITEM_INT("logAnnounceInterval", 1, INT8_MIN, INT8_MAX),
diff --git a/pdt.h b/pdt.h
index e46b218..1ad23d4 100644
--- a/pdt.h
+++ b/pdt.h
@@ -39,6 +39,7 @@ typedef uint16_t  UInteger16;
 typedef int32_t   Integer32;
 typedef uint32_t  UInteger32;
 typedef int64_t   Integer64;
+typedef uint64_t  UInteger64;
 typedef uint8_t   Octet;
 
 #endif
diff --git a/port.c b/port.c
index 7fd50dd..85cfa4a 100644
--- a/port.c
+++ b/port.c
@@ -1854,6 +1854,7 @@ int port_initialize(struct port *p)
p->neighborPropDelayThresh = config_get_int(cfg, p->name, 
"neighborPropDelayThresh");
p->min_neighbor_prop_delay = config_get_int(cfg, p->name, 
"min_neighbor_prop_delay");
p->delay_response_timeout  = config_get_int(cfg, p->name, 
"delay_response_timeout");
+   p->iface_rate_tlv  = config_get_int(cfg, p->name, 
"interface_rate_tlv");
 
if (config_get_int(cfg, p->name, "asCapable") == AS_CAPABLE_TRUE) {
p->asCapable = ALWAYS_CAPABLE;
diff --git a/port_private.h b/port_private.h
index d27dceb..d6487eb 100644
--- a/port_private.h
+++ b/port_private.h
@@ -145,6 +145,7 @@ struct port {
UInteger8   versionNumber; /* UInteger4 */
UInteger8   delay_response_counter;
UInteger8   delay_response_timeout;
+   booliface_rate_tlv;
struct PortStatsstats;
struct PortServiceStatsservice_stats;
/* foreignMasterDS */
diff --git a/tlv.c b/tlv.c
index 1c13460..35bee4f 100644
--- a/tlv.c
+++ b/tlv.c
@@ -35,6 +35,7 @@
(tlv->length < sizeof(struct type) - sizeof(struct TLV))
 
 uint8_t ieee8021_id[3] = { IEEE_802_1_COMMITTEE };
+uint8_t itu_t_id[3] = { ITU_T_COMMITTEE };
 
 static TAILQ_HEAD(tlv_pool, tlv_extra) tlv_pool =
TAILQ_HEAD_INITIALIZER(tlv_pool);
diff --git a/tlv.h b/tlv.h
index 8966696..ec22e2f 100644
--- a/tlv.h
+++ b/tlv.h
@@ -395,6 +395,20 @@ struct tlv_extra {
};
 };
 
+/* Organizationally Unique Identifiers */
+#define ITU_T_COMMITTEE 0x00, 0x19, 0xA7
+extern uint8_t itu_t_id[3];
+
+struct msg_interface_rate_tlv {
+   Enumeration16 type;
+   UInteger16length;
+   Octet id[3];
+   Octet subtype[3];
+   UInteger64interfaceBitPeriod;
+   UInteger16numberOfBitsBeforeTimestamp;
+   UInteger16numberOfBitsAfterTimestamp;
+} PACKED;
+
 /**
  * Allocates a new tlv_extra structure.
  * @return  Pointer to a new structure on success or NULL otherwise.
-- 
2.34.1



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


[Linuxptp-devel] [PATCH v3 4/4] [Interface Rate TLV] adding delay asymmetry calculation

2022-12-07 Thread SyncMonk Technologies
Delay asymmetry calculation based on the PTP port interface speed of
master obtained from TLV and the slave interface rate obtained by ethtool.

v3: updating network/host byte order handling.
v1: initial commit

Signed-off-by: Greg Armstrong 
Signed-off-by: Leon Goldin 
Signed-off-by: Devasish Dey 
Signed-off-by: Vipin Sharma 
---
 interface.c   | 10 ++
 interface.h   |  7 +++
 port_private.h|  1 +
 port_signaling.c  | 39 ---
 ptp4l.8   |  7 +++
 tlv.c | 29 +
 unicast_service.c | 32 
 7 files changed, 122 insertions(+), 3 deletions(-)

diff --git a/interface.c b/interface.c
index 3157e8c..02d530e 100644
--- a/interface.c
+++ b/interface.c
@@ -94,3 +94,13 @@ int interface_get_vclock(struct interface *iface)
 {
return iface->vclock;
 }
+
+uint64_t interface_bitperiod(struct interface *iface)
+{
+   if (!iface->if_info.valid)
+   return 0;
+
+   /* Megabits per secon converted to attoseconds per bit. */
+   return 1ULL/ iface->if_info.speed;
+}
+
diff --git a/interface.h b/interface.h
index f4b9545..7c9a6bd 100644
--- a/interface.h
+++ b/interface.h
@@ -113,4 +113,11 @@ void interface_set_vclock(struct interface *iface, int 
vclock);
  */
 int interface_get_vclock(struct interface *iface);
 
+/**
+ * Obtains the interface bit period based on the speed.
+ * @param iface  The interface of interest.
+ * @return   if valid speed return interface bitperiod in atto seconds.
+ */
+uint64_t interface_bitperiod(struct interface *iface);
+
 #endif
diff --git a/port_private.h b/port_private.h
index d6487eb..6ad4af8 100644
--- a/port_private.h
+++ b/port_private.h
@@ -146,6 +146,7 @@ struct port {
UInteger8   delay_response_counter;
UInteger8   delay_response_timeout;
booliface_rate_tlv;
+   Integer64   portAsymmetry;
struct PortStatsstats;
struct PortServiceStatsservice_stats;
/* foreignMasterDS */
diff --git a/port_signaling.c b/port_signaling.c
index ed217c0..75a0689 100644
--- a/port_signaling.c
+++ b/port_signaling.c
@@ -103,10 +103,37 @@ static int process_interval_request(struct port *p,
return 0;
 }
 
+static int process_interface_rate(struct port *p,
+ struct msg_interface_rate_tlv *r)
+{
+   Integer64 delayAsymmetry;
+   doublensDelay;
+   Integer64 slaveBitPeriod;
+   Integer64 masterBitPeriod;
+
+   if (p->iface_rate_tlv && interface_ifinfo_valid(p->iface)) {
+   slaveBitPeriod = interface_bitperiod(p->iface);
+   masterBitPeriod = r->interfaceBitPeriod;
+
+   /* Delay Asymmetry Calculation */
+   nsDelay = (masterBitPeriod - slaveBitPeriod) / (2 * 1.0e9);
+   delayAsymmetry =
+   (r->numberOfBitsAfterTimestamp - 
r->numberOfBitsBeforeTimestamp)  * nsDelay;
+
+   if (delayAsymmetry != p->portAsymmetry) {
+   p->asymmetry += ((delayAsymmetry - p->portAsymmetry) << 
16);
+   p->portAsymmetry = delayAsymmetry;
+   }
+   }
+   return 0;
+}
+
 int process_signaling(struct port *p, struct ptp_message *m)
 {
struct tlv_extra *extra;
+   struct organization_tlv *org;
struct msg_interval_req_tlv *r;
+   struct msg_interface_rate_tlv *rate;
int err = 0, result;
 
switch (p->state) {
@@ -160,11 +187,17 @@ int process_signaling(struct port *p, struct ptp_message 
*m)
break;
 
case TLV_ORGANIZATION_EXTENSION:
-   r = (struct msg_interval_req_tlv *) extra->tlv;
+   org = (struct organization_tlv *)extra->tlv;
 
-   if (0 == memcmp(r->id, ieee8021_id, 
sizeof(ieee8021_id)) &&
-   r->subtype[0] == 0 && r->subtype[1] == 0 && 
r->subtype[2] == 2)
+   if (0 == memcmp(org->id, ieee8021_id, 
sizeof(ieee8021_id)) &&
+   org->subtype[0] == 0 && org->subtype[1] == 0 && 
org->subtype[2] == 2) {
+   r = (struct msg_interval_req_tlv *) extra->tlv;
err = process_interval_request(p, r);
+   } else if (0 == memcmp(org->id, itu_t_id, 
sizeof(itu_t_id)) &&
+  org->subtype[0] == 0 && org->subtype[1] == 0 
&& org->subtype[2] == 2) {
+   rate = (struct msg_interface_rate_tlv *) 
extra->tlv;
+   err = process_interface_rate(p, rate);
+   }
break;
}
}
diff --git a/ptp4l.8 b/ptp4l.8
index cd6299f..e96d090 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -697,6 +697,13 @@ The default is 0 (disabled).
 Print messages to the s

[Linuxptp-devel] [PATCH v3 1/4] [Interface Rate TLV] function to support get interface speed via ethtool

2022-12-07 Thread SyncMonk Technologies
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.

v1: initial commit.
v2: updating comments and data types.
v3: updating Boolean data type to bool from 
---
 sk.c | 71 
 sk.h | 19 
 2 files changed, 90 insertions(+)

diff --git a/sk.c b/sk.c
index d27abff..1d1a656 100644
--- a/sk.c
+++ b/sk.c
@@ -205,6 +205,77 @@ 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[],
+* 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..4cee3d7 100644
--- a/sk.h
+++ b/sk.h
@@ -20,6 +20,7 @@
 #ifndef HAVE_SK_H
 #define HAVE_SK_H
 
+#include 
 #include "address.h"
 #include "transport.h"
 
@@ -49,6 +50,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 {
+   bool valid;
+   int speed;
+};
+
 /**
  * Obtains a socket suitable for use with sk_interface_index().
  * @return  An open socket on success, -1 otherwise.
@@ -78,6 +89,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.34.1



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