[Linuxptp-devel] [PATCH] Add support for DELAY_REQ and SYNC packets rx_filter

2023-11-13 Thread IlorDash
From: Ilya Orazov 

Added adv_rx_filter config that allows to send SIOCSHWTSTAMP ioctl with
HWTSTAMP_FILTER_PTP_XXX_SYNC or HWTSTAMP_FILTER_PTP_XXX_DELAY_REQ
rx filters based on whether the Device is Slave or Master respectively.
This Feature is added for all transport levels.

I’m using Ethernet controller with PTP support, which requires to
determine which PTP packet on Rx it must timestamp: SYNC or DELAY_REQ
packets based on whether the device is Slave or Masterrespectively.
Unfortunately, I’ve found out that ptp4l can’t send SIOCSHWTSTAMP ioctl
with HWTSTAMP_FILTER_PTP_XXX_SYNC or HWTSTAMP_FILTER_PTP_XXX_DELAY_REQ
rx filters, and sends only EVENT rx filters to device driver.

Device driver can only get info about the current PTP port state
from ptp4l, because it doesn’t have direct access to it.
I assumed, if these filters are defined in Kernel, they might be used in
ptp4l utility to fix this. So I added adv_rx_filter config that allows
to send SIOCSHWTSTAMP ioctl with HWTSTAMP_FILTER_PTP_XXX_SYNC or
HWTSTAMP_FILTER_PTP_XXX_DELAY_REQ rx filters for all transport levels.

Signed-off-by: Ilya Orazov 
---
 config.c|  1 +
 port.c  | 17 ++
 ptp4l.8 |  8 +++
 ptp4l.c |  1 +
 raw.c   | 13 +++
 sk.c| 56 -
 sk.h| 15 
 transport.c |  7 ++
 transport.h |  5 
 transport_private.h |  3 +++
 udp.c   | 14 
 udp6.c  | 14 
 12 files changed, 148 insertions(+), 6 deletions(-)

diff --git a/config.c b/config.c
index b104f1b..642b78c 100644
--- a/config.c
+++ b/config.c
@@ -268,6 +268,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("G.8275.portDS.localPriority", 128, 1, UINT8_MAX),
GLOB_ITEM_INT("gmCapable", 1, 0, 1),
GLOB_ITEM_ENU("hwts_filter", HWTS_FILTER_NORMAL, hwts_filter_enu),
+   GLOB_ITEM_INT("adv_rx_filter", 0, 0, 1),
PORT_ITEM_INT("hybrid_e2e", 0, 0, 1),
PORT_ITEM_INT("ignore_source_id", 0, 0, 1),
PORT_ITEM_INT("ignore_transport_specific", 0, 0, 1),
diff --git a/port.c b/port.c
index 5803cd3..2376925 100644
--- a/port.c
+++ b/port.c
@@ -3526,6 +3526,23 @@ int port_state_update(struct port *p, enum fsm_event 
event, int mdiff)
p->unicast_state_dirty = true;
}
if (next != p->state) {
+   if (sk_adv_rx_filter == 1) {
+   pr_debug("port state update prev %d next %d", p->state,
+next);
+
+   if ((next == PS_MASTER) || (next == PS_GRAND_MASTER))
+   transport_update_rx_filter(p->trp, p->iface,
+  >fda,
+  p->timestamping,
+  true);
+
+   if (next == PS_UNCALIBRATED)
+   transport_update_rx_filter(p->trp, p->iface,
+  >fda,
+  p->timestamping,
+  false);
+   }
+
port_show_transition(p, next, event);
p->state = next;
port_notify_event(p, NOTIFY_PORT_STATE);
diff --git a/ptp4l.8 b/ptp4l.8
index 40c66c2..9d838eb 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -142,6 +142,14 @@ See UNICAST DISCOVERY OPTIONS, below.
 
 .SH PORT OPTIONS
 
+.TP
+.B adv_rx_filter
+Enable support of HWTSTAMP_FILTER_PTP_XX_SYNC and 
HWTSTAMP_FILTER_PTP_XX_DELAY_REQ.
+Some Ethernet controllers doesn't support PTP event packets,
+thus they must be provided with correct rx_filter for timestamping required 
packets
+(SYNC or DELAY_REQ) depends on whether it's Slave or Master respectively.
+The default is 0 or disabled.
+
 .TP
 .B announceReceiptTimeout
 The number of missed Announce messages before the last Announce messages
diff --git a/ptp4l.c b/ptp4l.c
index c61175b..8f9531a 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -191,6 +191,7 @@ int main(int argc, char *argv[])
sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");
sk_hwts_filter_mode = config_get_int(cfg, NULL, "hwts_filter");
+   sk_adv_rx_filter = config_get_int(cfg, NULL, "adv_rx_filter");
 
if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) {
config_set_int(cfg, "kernel_leap", 0);
diff --git a/raw.c b/raw.c
index 1b978f0..7af3b2a 100644
--- a/raw.c
+++ b/raw.c
@@ -363,6 +363,18 @@ no_mac:
return -1;
 }
 
+static int raw_update_rx_filter(struct interface *iface, struct fdarray *fda,
+   enum timestamp_type ts_type, bool is_master)
+{
+   int 

Re: [Linuxptp-devel] [RFC PATCH 0/1] Support for Port level Perforamnce Monitoring Counters

2023-11-13 Thread Erez
I think Richard means using the SUBSCRIBE_EVENTS_NP.
Adding new events, and make sure the ptp4l sends all the statistics you
need together.

Erez

On Sat, 11 Nov 2023 at 19:02, Luigi 'Comio' Mantellini <
luigi.mantell...@gmail.com> wrote:

> Thanks for your time.
>
> What do you mean with "PUSH" message?
>
> I agree with you in order to keep it simple.
>
> ciao
>
> luigi
>
>
>
> Il giorno ven 10 nov 2023 alle ore 17:58 Richard Cochran <
> richardcoch...@gmail.com> ha scritto:
>
>> On Fri, Nov 10, 2023 at 07:58:14AM +0100, Luigi 'Comio' Mantellini wrote:
>>
>> > Using just polling on UDS is a bad idea IMHO because you need to
>> capture at
>> > the exact same time point all counters of all ports spending a lot of
>> > effort and cpu.
>>
>> So make it into a PUSH message.
>>
>> > It's better to have the gathering
>> > under the hood and a way to inquiry the system.
>>
>> No, I disagree.  It should be done externally, because most people
>> don't want or need this.  These statistics are a waste of time, and I
>> won't make the program more complex just to support silly stuff.
>>
>> Thanks,
>> Richard
>>
>
>
> --
> *Luigi 'Comio' Mantellini*
> My Professional Profile 
>
> *"UNIX is very simple, it just needs a genius to understand its
> simplicity." [cit.]*
>
> ___
> Linuxptp-devel mailing list
> Linuxptp-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
>
___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel