Skip to content

Commit 0142bbd

Browse files
author
Paolo Abeni
committed
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>
2 parents f0417e0 + 8dcfc91 commit 0142bbd

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

drivers/net/ethernet/intel/igb/igb_ptp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ static int igb_ptp_feature_enable_82580(struct ptp_clock_info *ptp,
509509
PTP_STRICT_FLAGS))
510510
return -EOPNOTSUPP;
511511

512+
/* Both the rising and falling edge are timestamped */
513+
if (rq->extts.flags & PTP_STRICT_FLAGS &&
514+
(rq->extts.flags & PTP_ENABLE_FEATURE) &&
515+
(rq->extts.flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
516+
return -EOPNOTSUPP;
517+
512518
if (on) {
513519
pin = ptp_find_pin(igb->ptp_clock, PTP_PF_EXTTS,
514520
rq->extts.index);

drivers/net/ethernet/microchip/lan743x_ptp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,12 @@ static int lan743x_ptp_io_extts(struct lan743x_adapter *adapter, int on,
942942

943943
extts = &ptp->extts[index];
944944

945+
if (extts_request->flags & ~(PTP_ENABLE_FEATURE |
946+
PTP_RISING_EDGE |
947+
PTP_FALLING_EDGE |
948+
PTP_STRICT_FLAGS))
949+
return -EOPNOTSUPP;
950+
945951
if (on) {
946952
extts_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, index);
947953
if (extts_pin < 0)

drivers/net/ethernet/renesas/ravb_ptp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ static int ravb_ptp_extts(struct ptp_clock_info *ptp,
179179
/* Reject requests with unsupported flags */
180180
if (req->flags & ~(PTP_ENABLE_FEATURE |
181181
PTP_RISING_EDGE |
182-
PTP_FALLING_EDGE |
183-
PTP_STRICT_FLAGS))
182+
PTP_FALLING_EDGE))
184183
return -EOPNOTSUPP;
185184

186185
if (req->index)

drivers/net/phy/bcm-phy-ptp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ static int bcm_ptp_perout_locked(struct bcm_ptp_private *priv,
597597

598598
period = BCM_MAX_PERIOD_8NS; /* write nonzero value */
599599

600-
if (req->flags & PTP_PEROUT_PHASE)
600+
/* Reject unsupported flags */
601+
if (req->flags & ~PTP_PEROUT_DUTY_CYCLE)
601602
return -EOPNOTSUPP;
602603

603604
if (req->flags & PTP_PEROUT_DUTY_CYCLE)

drivers/ptp/ptp_ocp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,10 @@ ptp_ocp_signal_from_perout(struct ptp_ocp *bp, int gen,
20902090
{
20912091
struct ptp_ocp_signal s = { };
20922092

2093+
if (req->flags & ~(PTP_PEROUT_DUTY_CYCLE |
2094+
PTP_PEROUT_PHASE))
2095+
return -EOPNOTSUPP;
2096+
20932097
s.polarity = bp->signal[gen].polarity;
20942098
s.period = ktime_set(req->period.sec, req->period.nsec);
20952099
if (!s.period)

0 commit comments

Comments
 (0)