Re: [Linuxptp-devel] [PATCH] phc_ctl: add pin_cfg command to display pin functions

2022-10-27 Thread Keller, Jacob E



> -Original Message-
> From: Miroslav Lichvar 
> Sent: Thursday, October 27, 2022 8:00 AM
> To: Keller, Jacob E 
> Cc: linuxptp-devel@lists.sourceforge.net
> Subject: Re: [Linuxptp-devel] [PATCH] phc_ctl: add pin_cfg command to display
> pin functions
> 
> On Thu, Oct 27, 2022 at 03:32:48AM -0700, Jacob Keller wrote:
> > Add a new function to phc_ctl to display the devices pin configuration
> > data. First, obtain the device capabilities to determine the number of
> > pins. Then, for each pin, print the name, function, and channel
> > information.
> 
> Nice feature. In a quick test, it printed the state correctly after
> setting it with "testptp -L".
> 
> Do you plan to add also pin_set?
> 
> --
> Miroslav Lichvar

I just found this while looking through patches I forgot to send. I think 
pin_set might be useful so I can go ahead and try to follow up with that.

Thanks,
Jake


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


Re: [Linuxptp-devel] [PATCH] phc_ctl: add pin_cfg command to display pin functions

2022-10-27 Thread Geva, Erez
Already have it in
https://github.com/erezgeva/libptpmgmt/blob/master/src/ptp.h

Erez 

-Original Message-
From: Miroslav Lichvar  
Sent: Thursday, 27 October 2022 17:00
To: Jacob Keller 
Cc: linuxptp-devel@lists.sourceforge.net
Subject: Re: [Linuxptp-devel] [PATCH] phc_ctl: add pin_cfg command to display 
pin functions

On Thu, Oct 27, 2022 at 03:32:48AM -0700, Jacob Keller wrote:
> Add a new function to phc_ctl to display the devices pin configuration 
> data. First, obtain the device capabilities to determine the number of 
> pins. Then, for each pin, print the name, function, and channel 
> information.

Nice feature. In a quick test, it printed the state correctly after setting it 
with "testptp -L".

Do you plan to add also pin_set?

--
Miroslav Lichvar



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Flinuxptp-develdata=05%7C01%7Cerez.geva.ext%40siemens.com%7C251d114a1038480f9d8c08dab82c36a2%7C38ae3bcd95794fd4addab42e1495d55a%7C1%7C0%7C638024797280276161%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7Csdata=Mmcyv9SWoG8j5HkvEwD%2F7wADQXidByNzHOAdNqX36wc%3Dreserved=0

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


Re: [Linuxptp-devel] [PATCH] phc_ctl: add pin_cfg command to display pin functions

2022-10-27 Thread Miroslav Lichvar
On Thu, Oct 27, 2022 at 03:32:48AM -0700, Jacob Keller wrote:
> Add a new function to phc_ctl to display the devices pin configuration
> data. First, obtain the device capabilities to determine the number of
> pins. Then, for each pin, print the name, function, and channel
> information.

Nice feature. In a quick test, it printed the state correctly after
setting it with "testptp -L".

Do you plan to add also pin_set?

-- 
Miroslav Lichvar



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


Re: [Linuxptp-devel] [PATCH] config: allow fractional freq_est_interval

2022-10-27 Thread Miroslav Lichvar
On Thu, Oct 27, 2022 at 03:29:40AM -0700, Jacob Keller wrote:
> --- a/config.c
> +++ b/config.c
> @@ -254,7 +254,7 @@ struct config_item config_tab[] = {
>   GLOB_ITEM_DBL("first_step_threshold", 0.2, 0.0, DBL_MAX),
>   PORT_ITEM_INT("follow_up_info", 0, 0, 1),
>   GLOB_ITEM_INT("free_running", 0, 0, 1),
> - PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
> + PORT_ITEM_INT("freq_est_interval", 1, INT_MIN, INT_MAX),
>   GLOB_ITEM_INT("G.8275.defaultDS.localPriority", 128, 1, UINT8_MAX),
>   PORT_ITEM_INT("G.8275.portDS.localPriority", 128, 1, UINT8_MAX),
>   GLOB_ITEM_INT("gmCapable", 1, 0, 1),

Looks good to me.

Thanks,

-- 
Miroslav Lichvar



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


[Linuxptp-devel] [PATCH] phc_ctl: add pin_cfg command to display pin functions

2022-10-27 Thread Jacob Keller
Add a new function to phc_ctl to display the devices pin configuration
data. First, obtain the device capabilities to determine the number of
pins. Then, for each pin, print the name, function, and channel
information.

Signed-off-by: Jacob Keller 
---
 phc_ctl.c | 73 +++
 1 file changed, 73 insertions(+)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c40a23..1d1b0ab61020 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -114,6 +114,7 @@ static void usage(const char *progname)
"  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
"  cmp compare PHC offset to CLOCK_REALTIME\n"
"  capsdisplay device capabilities (default if no 
command given)\n"
+   "  pin_cfg display device pin configuration\n"
"  wait   pause between commands\n"
"\n",
progname);
@@ -320,6 +321,77 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
return 0;
 }
 
+static const char *pin_func_string(unsigned int func)
+{
+   switch (func) {
+   case PTP_PF_NONE:
+   return "no function";
+   case PTP_PF_EXTTS:
+   return "external timestamping";
+   case PTP_PF_PEROUT:
+   return "periodic output";
+   case PTP_PF_PHYSYNC:
+   return "phy sync";
+   default:
+   return "unknown function";
+   }
+}
+
+static int do_pin_cfg(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   struct ptp_clock_caps caps;
+   struct ptp_pin_desc pin_desc;
+   unsigned int index;
+
+   if (clkid == CLOCK_REALTIME) {
+   pr_warning("CLOCK_REALTIME is not a PHC device.");
+   return 0;
+   }
+
+   /* Get device capabilities first */
+   if (ioctl(CLOCKID_TO_FD(clkid), PTP_CLOCK_GETCAPS, )) {
+   pr_err("get capabilities failed: %s",
+   strerror(errno));
+   return -1;
+   }
+
+   if (caps.n_pins == 0) {
+   pr_notice("device has no configurable pins");
+   return (0);
+   }
+
+   pr_notice("device has %d configurable input/output pins",
+   caps.n_pins);
+
+   /* For each pin, read its configuration */
+   for (index = 0; index < caps.n_pins; index++) {
+   memset(_desc, 0, sizeof(pin_desc));
+   pin_desc.index = index;
+
+   if (ioctl(CLOCKID_TO_FD(clkid), PTP_PIN_GETFUNC, _desc)) {
+   pr_warning("get pin configuration for pin %d failed: 
%s",
+   index,
+   strerror(errno));
+   /* keep going */
+   continue;
+   }
+
+   if (pin_desc.func == PTP_PF_NONE) {
+   pr_notice("pin %d [%s] is not configured",
+   pin_desc.index,
+   pin_desc.name);
+   } else {
+   pr_notice("pin %d [%s] performing %s using channel %d",
+   pin_desc.index,
+   pin_desc.name,
+   pin_func_string(pin_desc.func),
+   pin_desc.chan);
+   }
+   }
+
+   return 0;
+}
+
 static int do_cmp(clockid_t clkid, int cmdc, char *cmdv[])
 {
int64_t sys_offset, delay;
@@ -403,6 +475,7 @@ static const struct cmd_t all_commands[] = {
{ "freq", _freq },
{ "cmp", _cmp },
{ "caps", _caps },
+   { "pin_cfg", _pin_cfg },
{ "wait", _wait },
{ 0, 0 }
 };
-- 
2.38.0.83.gd420dda05763



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


[Linuxptp-devel] [PATCH] config: allow fractional freq_est_interval

2022-10-27 Thread Jacob Keller
The freq_est_interval value is documented as the time interval over which
to estimate the ratio between the local and peer clock frequencies when
operating in free_running mode.

It is documented as a power of two in seconds, similar to the
summary_interval and the various intervals between packets.

The configuration forces this value to be positive, meaning that fractional
estimation intervals are not supported.A This appears to have been the case
since commit 0513c3b15b8a ("config: Apply more strict input validation to
almost all config file options").

Because of this, when operating in free_running mode it is not possible to
get an output of the estimated ratio faster than once a second, even if
your configuration has a sync rate that is higher.

The commit which enforced this positive boundary did not provide any
justification for why the freq_est_interval cannot be negative. Fix the
specification in the configuration table to correctly allow such intervals.

Fixes: 0513c3b15b8a ("config: Apply more strict input validation to almost all 
config file options")
Signed-off-by: Jacob Keller 
---
 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.c b/config.c
index e454c91ff0a1..67bf6a40d5c9 100644
--- a/config.c
+++ b/config.c
@@ -254,7 +254,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_DBL("first_step_threshold", 0.2, 0.0, DBL_MAX),
PORT_ITEM_INT("follow_up_info", 0, 0, 1),
GLOB_ITEM_INT("free_running", 0, 0, 1),
-   PORT_ITEM_INT("freq_est_interval", 1, 0, INT_MAX),
+   PORT_ITEM_INT("freq_est_interval", 1, INT_MIN, INT_MAX),
GLOB_ITEM_INT("G.8275.defaultDS.localPriority", 128, 1, UINT8_MAX),
PORT_ITEM_INT("G.8275.portDS.localPriority", 128, 1, UINT8_MAX),
GLOB_ITEM_INT("gmCapable", 1, 0, 1),
-- 
2.38.0.83.gd420dda05763



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