aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaolo Abeni <pabeni@redhat.com>2025-03-20 08:50:08 +0100
committerPaolo Abeni <pabeni@redhat.com>2025-03-20 08:50:09 +0100
commit0142bbd21da64210287963722f7b25d26748ecf0 (patch)
tree089f3f3c79486feb09d3cf300c8794634217ae34
parentMerge branch 'support-loopback-mode-speed-selection' (diff)
parentptp: ocp: reject unsupported periodic output flags (diff)
downloadwireguard-linux-0142bbd21da64210287963722f7b25d26748ecf0.tar.xz
wireguard-linux-0142bbd21da64210287963722f7b25d26748ecf0.zip
Merge branch 'net-ptp-fix-egregious-supported-flag-checks'
Jacob Keller says: ==================== net: ptp: fix egregious supported flag checks In preparation for adding .supported_extts_flags and .supported_perout_flags to the ptp_clock_info structure, fix a couple of places where drivers get existing flag gets grossly incorrect. The igb driver claims 82580 supports strictly validating PTP_RISING_EDGE and PTP_FALLING_EDGE, but doesn't actually check the flags. Fix the driver to require that the request match both edges, as this is implied by the datasheet description. The renesas driver also claims to support strict flag checking, but does not actually check the flags either. I do not have the data sheet for this device, so I do not know what edge it timestamps. For simplicity, just reject all requests with PTP_STRICT_FLAGS. This essentially prevents the PTP_EXTTS_REQUEST2 ioctl from working. Updating to correctly validate the flags will require someone who has the hardware to confirm the behavior. The lan743x driver supports (and strictly validates) that the request is either PTP_RISING_EDGE or PTP_FALLING_EDGE but not both. However, it does not check the flags are one of the known valid flags. Thus, requests for PTP_EXT_OFF (and any future flag) will be accepted and misinterpreted. Add the appropriate check to reject unsupported PTP_EXT_OFF requests and future proof against new flags. The broadcom PHY driver checks that PTP_PEROUT_PHASE is not set. This appears to be an attempt at rejecting unsupported flags. It is not robust against flag additions such as the PTP_PEROUT_ONE_SHOT, or anything added in the future. Fix this by instead checking against the negation of the supported PTP_PEROUT_DUTY_CYCLE instead. The ptp_ocp driver supports PTP_PEROUT_PHASE and PTP_PEROUT_DUTY_CYCLE, but does not check unsupported flags. Add the appropriate check to ensure PTP_PEROUT_ONE_SHOT and any future flags are rejected as unsupported. These are changes compile-tested, but I do not have hardware to validate the behavior. There are a number of other drivers which enable periodic output or external timestamp requests, but which do not check flags at all. We could go through each of these drivers one-by-one and meticulously add a flag check. Instead, these drivers will be covered only by the upcoming .supported_extts_flags and .supported_perout_flags checks in a net-next series. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> ==================== Link: https://patch.msgid.link/20250312-jk-net-fixes-supported-extts-flags-v2-0-ea930ba82459@intel.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ptp.c6
-rw-r--r--drivers/net/ethernet/microchip/lan743x_ptp.c6
-rw-r--r--drivers/net/ethernet/renesas/ravb_ptp.c3
-rw-r--r--drivers/net/phy/bcm-phy-ptp.c3
-rw-r--r--drivers/ptp/ptp_ocp.c4
5 files changed, 19 insertions, 3 deletions
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index f94570556120..f323e1c1989f 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -509,6 +509,12 @@ static int igb_ptp_feature_enable_82580(struct ptp_clock_info *ptp,
PTP_STRICT_FLAGS))
return -EOPNOTSUPP;
+ /* Both the rising and falling edge are timestamped */
+ if (rq->extts.flags & PTP_STRICT_FLAGS &&
+ (rq->extts.flags & PTP_ENABLE_FEATURE) &&
+ (rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
+ return -EOPNOTSUPP;
+
if (on) {
pin = ptp_find_pin(igb->ptp_clock, PTP_PF_EXTTS,
rq->extts.index);
diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
index 4a777b449ecd..0be44dcb3393 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.c
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
@@ -942,6 +942,12 @@ static int lan743x_ptp_io_extts(struct lan743x_adapter *adapter, int on,
extts = &ptp->extts[index];
+ if (extts_request->flags & ~(PTP_ENABLE_FEATURE |
+ PTP_RISING_EDGE |
+ PTP_FALLING_EDGE |
+ PTP_STRICT_FLAGS))
+ return -EOPNOTSUPP;
+
if (on) {
extts_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, index);
if (extts_pin < 0)
diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index 6e4ef7af27bf..b4365906669f 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -179,8 +179,7 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,
/* Reject requests with unsupported flags */
if (req->flags & ~(PTP_ENABLE_FEATURE |
PTP_RISING_EDGE |
- PTP_FALLING_EDGE |
- PTP_STRICT_FLAGS))
+ PTP_FALLING_EDGE))
return -EOPNOTSUPP;
if (req->index)
diff --git a/drivers/net/phy/bcm-phy-ptp.c b/drivers/net/phy/bcm-phy-ptp.c
index 208e8f561e06..eba8b5fb1365 100644
--- a/drivers/net/phy/bcm-phy-ptp.c
+++ b/drivers/net/phy/bcm-phy-ptp.c
@@ -597,7 +597,8 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv,
period = BCM_MAX_PERIOD_8NS; /* write nonzero value */
- if (req->flags & PTP_PEROUT_PHASE)
+ /* Reject unsupported flags */
+ if (req->flags & ~PTP_PEROUT_DUTY_CYCLE)
return -EOPNOTSUPP;
if (req->flags & PTP_PEROUT_DUTY_CYCLE)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 34c616bd0a02..b25635c5c745 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2090,6 +2090,10 @@ ptp_ocp_signal_from_perout(struct ptp_ocp *bp, int gen,
{
struct ptp_ocp_signal s = { };
+ if (req->flags & ~(PTP_PEROUT_DUTY_CYCLE |
+ PTP_PEROUT_PHASE))
+ return -EOPNOTSUPP;
+
s.polarity = bp->signal[gen].polarity;
s.period = ktime_set(req->period.sec, req->period.nsec);
if (!s.period)