broadcom: report the supported flags for ancillary features
Subsystems (4)
cover broadcom: report the supported flags for ancillary features
James Clark reported off list that the broadcom PHY PTP driver was incorrectly handling PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls since the conversion to the .supported_*_flags fields. This series fixes the driver to correctly report its flags through the .supported_perout_flags and .supported_extts_flags fields. It also contains an update to comment the behavior of the PTP_STRICT_FLAGS being always enabled for PTP_EXTTS_REQUEST2.
I plan to follow up this series with some improvements to the PTP documentation better explaining each flag and the expectation of the driver APIs.
---
Jacob Keller (3):
broadcom: fix support for PTP_PEROUT_DUTY_CYCLE
broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl
ptp: document behavior of PTP_STRICT_FLAGS
include/uapi/linux/ptp_clock.h | 3 +++ drivers/net/phy/bcm-phy-ptp.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-)
---
base-commit: cbf658dd09419f1ef9de11b9604e950bdd5c170b
change-id: 20250918-jk-fix-bcm-phy-supported-flags-0796dddf7954
Best regards,
Signature · 1 line
Jacob Keller <[email protected]>
PATCH 1/3 broadcom: fix support for PTP_PEROUT_DUTY_CYCLE
The bcm_ptp_perout_locked() function has support for handling PTP_PEROUT_DUTY_CYCLE, but its not listed in the supported_perout_flags. Attempts to use the duty cycle support will be rejected since commit d9f3e9ecc456 ("net: ptp: introduce .supported_perout_flags to ptp_clock_info"), as this flag accidentally missed while doing the conversion.
Drop the unnecessary supported flags check from the bcm_ptp_perout_locked() function and correctly set the supported_perout_flags. This fixes use of the PTP_PEROUT_DUTY_CYCLE support for the broadcom driver.
--- drivers/net/phy/bcm-phy-ptp.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/phy/bcm-phy-ptp.c +1 -4
@@ -597,10 +597,6 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv, period =BCM_MAX_PERIOD_8NS ;/* write nonzero value */ -/* Reject unsupported flags */ -if (req->flags & ~PTP_PEROUT_DUTY_CYCLE ) -return -EOPNOTSUPP ; -if (req->flags &PTP_PEROUT_DUTY_CYCLE ) pulse =ktime_to_ns (ktime_set (req->on.sec, req->on.nsec));else
@@ -741,6 +737,7 @@ static const struct ptp_clock_info bcm_ptp_clock_info = { .n_pins = 1, .n_per_out = 1, .n_ext_ts = 1, + .supported_perout_flags = PTP_PEROUT_DUTY_CYCLE, }; static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
Signature · 1 line
2.51.0.rc1.197.g6d975e95c9d7
Re: [PATCH net 1/3] broadcom: fix support for PTP_PEROUT_DUTY_CYCLE
Quoted 35 lines · Jacob Keller
The
bcm_ptp_perout_locked()function has support for handlingPTP_PEROUT_DUTY_CYCLE, but its not listed in thesupported_perout_flags. Attempts to use the duty cycle support will be rejected since commitd9f3e9ecc456("net: ptp: introduce .supported_perout_flags toptp_clock_info"), as this flag accidentally missed while doing the conversion.Drop the unnecessary supported flags check from the
bcm_ptp_perout_locked()function and correctly set thesupported_perout_flags. This fixes use of thePTP_PEROUT_DUTY_CYCLEsupport for the broadcom driver.Reported-by James Clark <[email protected]>Fixes d9f3e9ecc456 ("net: ptp: introduce .supported_perout_flags to ptp_clock_info")Signed-off-by Jacob Keller <[email protected]>--- drivers/net/phy/bcm-phy-ptp.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/net/phy/bcm-phy-ptp.c +0
-4@@ -597,10 +597,6 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv, period =BCM_MAX_PERIOD_8NS ;/* write nonzero value */ -/* Reject unsupported flags */ -if (req->flags & ~PTP_PEROUT_DUTY_CYCLE ) -return -EOPNOTSUPP ; -if (req->flags &PTP_PEROUT_DUTY_CYCLE ) pulse =ktime_to_ns (ktime_set (req->on.sec, req->on.nsec));else
drivers/net/phy/bcm-phy-ptp.c static const struct ptp_clock_info bcm_ptp_clock_info = { · line 743
Quoted 7 lines
drivers/net/phy/bcm-phy-ptp.c +1
-0@@ -741,6 +737,7 @@ static const struct ptp_clock_info bcm_ptp_clock_info = { .n_pins = 1, .n_per_out = 1, .n_ext_ts = 1, + .supported_perout_flags = PTP_PEROUT_DUTY_CYCLE, }; static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
PATCH 2/3 broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Jacob KellerCommit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") modified the PTP core kernel logic to validate the supported flags for the PTP_EXTTS_REQUEST ioctls, rather than relying on each individual driver correctly checking its flags.
The bcm_ptp_enable() function implements support for PTP_CLK_REQ_EXTTS, but does not check the flags, and does not forward the request structure into bcm_ptp_extts_locked().
When originally converting the bcm-phy-ptp.c code, it was unclear what edges the hardware actually timestamped. Thus, no flags were initialized in the .supported_extts_flags field. This results in the kernel automatically rejecting all userspace requests for the PTP_EXTTS_REQUEST2 ioctl.
This occurs because the PTP_STRICT_FLAGS is always assumed when operating under PTP_EXTTS_REQUEST2. This has been the case since the flags introduction by commit 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.").
The bcm-phy-ptp.c logic never properly supported strict flag validation, as it previously ignored all flags including both PTP_STRICT_FLAGS and the PTP_FALLING_EDGE and PTP_RISING_EDGE flags.
Reports from users in the field prove that the hardware timestamps the rising edge. Encode this in the .supported_extts_flags field. This re-enables support for the PTP_EXTTS_REQUEST2 ioctl.
--- drivers/net/phy/bcm-phy-ptp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/phy/bcm-phy-ptp.c +1 -0
@@ -738,6 +738,7 @@ static const struct ptp_clock_info bcm_ptp_clock_info = { .n_per_out = 1, .n_ext_ts = 1, .supported_perout_flags = PTP_PEROUT_DUTY_CYCLE, + .supported_extts_flags = PTP_STRICT_FLAGS | PTP_RISING_EDGE, }; static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
Signature · 1 line
2.51.0.rc1.197.g6d975e95c9d7
Re: [PATCH net 2/3] broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl
Quoted 40 lines · Jacob Keller
Commit
7c571ac57d9d("net: ptp: introduce .supported_extts_flags toptp_clock_info") modified the PTP core kernel logic to validate the supported flags for thePTP_EXTTS_REQUESTioctls, rather than relying on each individual driver correctly checking its flags.The
bcm_ptp_enable()function implements support forPTP_CLK_REQ_EXTTS, but does not check the flags, and does not forward the request structure intobcm_ptp_extts_locked().When originally converting the
bcm-phy-ptp.ccode, it was unclear what edges the hardware actually timestamped. Thus, no flags were initialized in the .supported_extts_flags field. This results in the kernel automatically rejecting all userspace requests for thePTP_EXTTS_REQUEST2ioctl.This occurs because the
PTP_STRICT_FLAGSis always assumed when operating underPTP_EXTTS_REQUEST2. This has been the case since the flags introduction by commit6138e687c7b6("ptp: Introduce strict checking of external time stamp options.").The
bcm-phy-ptp.clogic never properly supported strict flag validation, as it previously ignored all flags including bothPTP_STRICT_FLAGSand thePTP_FALLING_EDGEandPTP_RISING_EDGEflags.Reports from users in the field prove that the hardware timestamps the rising edge. Encode this in the .supported_extts_flags field. This re-enables support for the
PTP_EXTTS_REQUEST2ioctl.Reported-by James Clark <[email protected]>Fixes 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info")Signed-off-by Jacob Keller <[email protected]>--- drivers/net/phy/bcm-phy-ptp.c | 1 + 1 file changed, 1 insertion(+)drivers/net/phy/bcm-phy-ptp.c +0
-0
drivers/net/phy/bcm-phy-ptp.c static const struct ptp_clock_info bcm_ptp_clock_info = { · line 744
Quoted 7 lines
drivers/net/phy/bcm-phy-ptp.c +1
-0@@ -738,6 +738,7 @@ static const struct ptp_clock_info bcm_ptp_clock_info = { .n_per_out = 1, .n_ext_ts = 1, .supported_perout_flags = PTP_PEROUT_DUTY_CYCLE, + .supported_extts_flags = PTP_STRICT_FLAGS | PTP_RISING_EDGE, }; static void bcm_ptp_txtstamp(struct mii_timestamper *mii_ts,
PATCH 3/3 ptp: document behavior of PTP_STRICT_FLAGS
In reply to Jacob KellerCommit 6138e687c7b6 ("ptp: Introduce strict checking of external time stamp options.") added the PTP_STRICT_FLAGS to the set of flags supported for the external timestamp request ioctl.
It is only supported by PTP_EXTTS_REQUEST2, as it was introduced the introduction of the new ioctls. Further, the kernel has always set this flag for PTP_EXTTS_REQUEST2 regardless of whether or not the user requested the behavior.
This effectively means that the flag is not useful for userspace. If the user issues a PTP_EXTTS_REQUEST ioctl, the flag is ignored due to not being supported on the old ioctl. If the user issues a PTP_EXTTS_REQUEST2 ioctl, the flag will be set by the kernel regardless of whether the user set the flag in their structure.
Add a comment documenting this behavior in the uAPI header file.
--- include/uapi/linux/ptp_clock.h | 3 +++ 1 file changed, 3 insertions(+)
include/uapi/linux/ptp_clock.h +3 -0
@@ -37,6 +37,9 @@/* * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl. +* +* Note: PTP_STRICT_FLAGS is always enabled by the kernel for +* PTP_EXTTS_REQUEST2 regardless of whether it is set by userspace. */ #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \ PTP_RISING_EDGE | \
Signature · 1 line
2.51.0.rc1.197.g6d975e95c9d7
Re: [PATCH net 3/3] ptp: document behavior of PTP_STRICT_FLAGS
Quoted 28 lines · Jacob Keller
Commit
6138e687c7b6("ptp: Introduce strict checking of external time stamp options.") added thePTP_STRICT_FLAGSto the set of flags supported for the external timestamp request ioctl.It is only supported by
PTP_EXTTS_REQUEST2, as it was introduced the introduction of the new ioctls. Further, the kernel has always set this flag forPTP_EXTTS_REQUEST2regardless of whether or not the user requested the behavior.This effectively means that the flag is not useful for userspace. If the user issues a
PTP_EXTTS_REQUESTioctl, the flag is ignored due to not being supported on the old ioctl. If the user issues aPTP_EXTTS_REQUEST2ioctl, the flag will be set by the kernel regardless of whether the user set the flag in their structure.Add a comment documenting this behavior in the uAPI header file.
Signed-off-by Jacob Keller <[email protected]>--- include/uapi/linux/ptp_clock.h | 3 +++ 1 file changed, 3 insertions(+)include/uapi/linux/ptp_clock.h +0
-0
include/uapi/linux/ptp_clock.h line 45
Quoted 9 lines
include/uapi/linux/ptp_clock.h +3
-0@@ -37,6 +37,9 @@/* * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl. +* +* Note: PTP_STRICT_FLAGS is always enabled by the kernel for +* PTP_EXTTS_REQUEST2 regardless of whether it is set by userspace. */ #define PTP_EXTTS_VALID_FLAGS (PTP_ENABLE_FEATURE | \ PTP_RISING_EDGE | \
Quoted 8 lines · Jacob Keller
James Clark reported off list that the broadcom PHY PTP driver was incorrectly handling
PTP_EXTTS_REQUESTandPTP_PEROUT_REQUESTioctls since the conversion to the .supported_*_flags fields. This series fixes the driver to correctly report its flags through the .supported_perout_flags and .supported_extts_flags fields. It also contains an update to comment the behavior of thePTP_STRICT_FLAGSbeing always enabled forPTP_EXTTS_REQUEST2.
Quoted 5 lines
I plan to follow up this series with some improvements to the PTP documentation better explaining each flag and the expectation of the driver APIs.
Signed-off-by Jacob Keller <[email protected]>
For series:
Quoted 8 lines · On Thu, 18 Sep 2025 17:33:15 -0700 Jacob Keller <[email protected]>…
James Clark reported off list that the broadcom PHY PTP driver was incorrectly handling
PTP_EXTTS_REQUESTandPTP_PEROUT_REQUESTioctls since the conversion to the .supported_*_flags fields. This series fixes the driver to correctly report its flags through the .supported_perout_flags and .supported_extts_flags fields. It also contains an update to comment the behavior of thePTP_STRICT_FLAGSbeing always enabled forPTP_EXTTS_REQUEST2.
Quoted 5 lines
I plan to follow up this series with some improvements to the PTP documentation better explaining each flag and the expectation of the driver APIs.
Signed-off-by Jacob Keller <[email protected]>
Thank you!
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Jakub Kicinski
maintainerQuoted 7 lines · On Thu, 18 Sep 2025 17:33:15 -0700 Jacob Keller wrote:
James Clark reported off list that the broadcom PHY PTP driver was incorrectly handling
PTP_EXTTS_REQUESTandPTP_PEROUT_REQUESTioctls since the conversion to the .supported_*_flags fields. This series fixes the driver to correctly report its flags through the .supported_perout_flags and .supported_extts_flags fields. It also contains an update to comment the behavior of thePTP_STRICT_FLAGSbeing always enabled forPTP_EXTTS_REQUEST2.
James, would you be willing to test and send an official Tested-by tag?
James Clark
Tested-byQuoted 11 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 18 Sep 2025 17:33:15 -0700 Jacob Keller wrote:
James Clark reported off list that the broadcom PHY PTP driver was incorrectly handling
PTP_EXTTS_REQUESTandPTP_PEROUT_REQUESTioctls since the conversion to the .supported_*_flags fields. This series fixes the driver to correctly report its flags through the .supported_perout_flags and .supported_extts_flags fields. It also contains an update to comment the behavior of thePTP_STRICT_FLAGSbeing always enabled forPTP_EXTTS_REQUEST2.James, would you be willing to test and send an official Tested-by tag?
I have tested this on a Raspberry Pi CM4: PTP_EXTTS_REQUEST2 and PTP_PEROUT_REQUEST2 both work. Thanks!
Going forward, I have got myself setup to be able to build and install a vanilla kernel on a CM4, so if there is stuff that needs testing on bcm-phy-ptp, just Cc me.
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 18 Sep 2025 17:33:15 -0700 you wrote:
James Clark reported off list that the broadcom PHY PTP driver was incorrectly handling
PTP_EXTTS_REQUESTandPTP_PEROUT_REQUESTioctls since the conversion to the .supported_*_flags fields. This series fixes the driver to correctly report its flags through the .supported_perout_flags and .supported_extts_flags fields. It also contains an update to comment the behavior of thePTP_STRICT_FLAGSbeing always enabled forPTP_EXTTS_REQUEST2.[...]
Here is the summary with links:
- [net,1/3] broadcom: fix support for PTP_PEROUT_DUTY_CYCLE
https://git.kernel.org/netdev/net/c/6e6c88d85623 - [net,2/3] broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl https://git.kernel.org/netdev/net/c/3200fdd4021d - [net,3/3] ptp: document behavior of PTP_STRICT_FLAGS https://git.kernel.org/netdev/net/c/cd875625b475
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html