Skip to contentSkip to conversation

ptp: Introduce strict checking of external time stamp options.

PATCH In review Richard Cochran 2 participants 4 messages Nov 14, 2019

Subsystems (9)
lore
Share & tools
lore

Richard Cochran

author maintainer
#0 lore raw

PATCH 8/13 ptp: Introduce strict checking of external time stamp options.

User space may request time stamps on rising edges, falling edges, or both. However, the particular mode may or may not be supported in the hardware or in the driver. This patch adds a "strict" flag that tells drivers to ensure that the requested mode will be honored.

---
 drivers/net/dsa/mv88e6xxx/ptp.c                     | 3 ++-
 drivers/net/ethernet/intel/igb/igb_ptp.c            | 3 ++-
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 3 ++-
 drivers/net/ethernet/renesas/ravb_ptp.c             | 3 ++-
 drivers/net/phy/dp83640.c                           | 3 ++-
 drivers/ptp/ptp_chardev.c                           | 2 ++
 include/uapi/linux/ptp_clock.h                      | 4 +++-
 7 files changed, 15 insertions(+), 6 deletions(-)
drivers/net/dsa/mv88e6xxx/ptp.c +2 -1
index 076e622a64d6..3b1985902f95 100644
@@ -276,7 +276,8 @@ static int mv88e6352_ptp_enable_extts(struct mv88e6xxx_chip *chip,
 	/* Reject requests with unsupported flags */
 	if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 				PTP_RISING_EDGE |
-				PTP_FALLING_EDGE))
+				PTP_FALLING_EDGE |
+				PTP_STRICT_FLAGS))
 		return -EOPNOTSUPP;
 
 	pin = ptp_find_pin(chip->ptp_clock, PTP_PF_EXTTS, rq->extts.index);
drivers/net/ethernet/intel/igb/igb_ptp.c +2 -1
index 0bce3e0f1af0..3fd60715bca7 100644
@@ -524,7 +524,8 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp,
 		/* Reject requests with unsupported flags */
 		if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 					PTP_RISING_EDGE |
-					PTP_FALLING_EDGE))
+					PTP_FALLING_EDGE |
+					PTP_STRICT_FLAGS))
 			return -EOPNOTSUPP;
 
 		if (on) {
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -1
index 9a40f24e3193..819097d9b583 100644
@@ -239,7 +239,8 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp,
 	/* Reject requests with unsupported flags */
 	if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 				PTP_RISING_EDGE |
-				PTP_FALLING_EDGE))
+				PTP_FALLING_EDGE |
+				PTP_STRICT_FLAGS))
 		return -EOPNOTSUPP;
 
 	if (rq->extts.index >= clock->ptp_info.n_pins)
drivers/net/ethernet/renesas/ravb_ptp.c +2 -1
index 666dbee48097..6984bd5b7da9 100644
@@ -185,7 +185,8 @@ 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_FALLING_EDGE |
+			   PTP_STRICT_FLAGS))
 		return -EOPNOTSUPP;
 
 	if (req->index)
drivers/net/phy/dp83640.c +2 -1
index 2781b0e2d947..3bba2bea3a88 100644
@@ -472,7 +472,8 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
 		/* Reject requests with unsupported flags */
 		if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 					PTP_RISING_EDGE |
-					PTP_FALLING_EDGE))
+					PTP_FALLING_EDGE |
+					PTP_STRICT_FLAGS))
 			return -EOPNOTSUPP;
 		index = rq->extts.index;
 		if (index >= N_EXT_TS)
drivers/ptp/ptp_chardev.c +2 -0
index cbbe1237ff8d..9d72ab593f13 100644
@@ -150,6 +150,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 			break;
 		}
 		if (cmd == PTP_EXTTS_REQUEST2) {
+			/* Tell the drivers to check the flags carefully. */
+			req.extts.flags |= PTP_STRICT_FLAGS;
 			/* Make sure no reserved bit is set. */
 			if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
 			    req.extts.rsv[0] || req.extts.rsv[1]) {
include/uapi/linux/ptp_clock.h +3 -1
index 304059b1609d..9dc9d0079e98 100644
@@ -31,6 +31,7 @@
 #define PTP_ENABLE_FEATURE (1<<0)
 #define PTP_RISING_EDGE    (1<<1)
 #define PTP_FALLING_EDGE   (1<<2)
+#define PTP_STRICT_FLAGS   (1<<3)
 #define PTP_EXTTS_EDGES    (PTP_RISING_EDGE | PTP_FALLING_EDGE)
 
 /*
@@ -38,7 +39,8 @@
  */
 #define PTP_EXTTS_VALID_FLAGS	(PTP_ENABLE_FEATURE |	\
 				 PTP_RISING_EDGE |	\
-				 PTP_FALLING_EDGE)
+				 PTP_FALLING_EDGE |	\
+				 PTP_STRICT_FLAGS)
 
 /*
  * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
Signature · 1 line
2.20.1
#1 lore raw
Quoted 15 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, November 14, 2019 10:45 AM
To: netdev at vger.kernel.org
Cc: intel-wired-lan at lists.osuosl.org; David Miller <[email protected]>; Brandon Streiff <[email protected]>; Hall, Christopher S <[email protected]>; Eugenia Emantayev <[email protected]>; Felipe Balbi <[email protected]>; Feras Daoud <[email protected]>; Keller, Jacob E <[email protected]>; Kirsher, Jeffrey T <[email protected]>; Sergei Shtylyov <[email protected]>; Stefan Sorensen <[email protected]>
Subject: [PATCH net 08/13] ptp: Introduce strict checking of external time stamp options.

Quoted 5 lines

User space may request time stamps on rising edges, falling edges, or both. However, the particular mode may or may not be supported in the hardware or in the driver. This patch adds a "strict" flag that tells drivers to ensure that the requested mode will be honored.

So, this patch adds the flag *and* modifies the drivers to accept it, but not actually enable strict checking?

I'd prefer if this flag got added, and the drivers were modified in separate patches to both allow the flag and to perform the strict check.. that feels like a cleaner patch boundary.

That would ofcourse break the drivers that reject the strict command until they're fixed in follow-on commands.. hmm

Thanks,
Jake

Quoted 126 lines
---
 drivers/net/dsa/mv88e6xxx/ptp.c                     | 3 ++-
 drivers/net/ethernet/intel/igb/igb_ptp.c            | 3 ++-
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 3 ++-
 drivers/net/ethernet/renesas/ravb_ptp.c             | 3 ++-
 drivers/net/phy/dp83640.c                           | 3 ++-
 drivers/ptp/ptp_chardev.c                           | 2 ++
 include/uapi/linux/ptp_clock.h                      | 4 +++-
 7 files changed, 15 insertions(+), 6 deletions(-)
drivers/net/dsa/mv88e6xxx/ptp.c +2 -1
index 076e622a64d6..3b1985902f95 100644
@@ -276,7 +276,8 @@ static int mv88e6352_ptp_enable_extts(struct
 mv88e6xxx_chip *chip,
 	/* Reject requests with unsupported flags */
 	if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 				PTP_RISING_EDGE |
-				PTP_FALLING_EDGE))
+				PTP_FALLING_EDGE |
+				PTP_STRICT_FLAGS))
 		return -EOPNOTSUPP;
 
drivers/net/dsa/mv88e6xxx/ptp.c +0 -0
 	pin = ptp_find_pin(chip->ptp_clock, PTP_PF_EXTTS, rq->extts.index);
drivers/net/ethernet/intel/igb/igb_ptp.c +2 -1
index 0bce3e0f1af0..3fd60715bca7 100644
@@ -524,7 +524,8 @@ static int igb_ptp_feature_enable_i210(struct
 ptp_clock_info *ptp,
 		/* Reject requests with unsupported flags */
 		if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 					PTP_RISING_EDGE |
-					PTP_FALLING_EDGE))
+					PTP_FALLING_EDGE |
+					PTP_STRICT_FLAGS))
 			return -EOPNOTSUPP;
 
drivers/net/ethernet/intel/igb/igb_ptp.c +0 -0
 		if (on) {
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -1
index 9a40f24e3193..819097d9b583 100644
@@ -239,7 +239,8 @@ static int mlx5_extts_configure(struct ptp_clock_info
 *ptp,
 	/* Reject requests with unsupported flags */
 	if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 				PTP_RISING_EDGE |
-				PTP_FALLING_EDGE))
+				PTP_FALLING_EDGE |
+				PTP_STRICT_FLAGS))
 		return -EOPNOTSUPP;
 
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +0 -0
 	if (rq->extts.index >= clock->ptp_info.n_pins)
drivers/net/ethernet/renesas/ravb_ptp.c +2 -1
index 666dbee48097..6984bd5b7da9 100644
@@ -185,7 +185,8 @@ 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_FALLING_EDGE |
+			   PTP_STRICT_FLAGS))
 		return -EOPNOTSUPP;
 
 	if (req->index)
drivers/net/phy/dp83640.c +2 -1
index 2781b0e2d947..3bba2bea3a88 100644
@@ -472,7 +472,8 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
 		/* Reject requests with unsupported flags */
 		if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
 					PTP_RISING_EDGE |
-					PTP_FALLING_EDGE))
+					PTP_FALLING_EDGE |
+					PTP_STRICT_FLAGS))
 			return -EOPNOTSUPP;
 		index = rq->extts.index;
 		if (index >= N_EXT_TS)
drivers/ptp/ptp_chardev.c +2 -0
index cbbe1237ff8d..9d72ab593f13 100644
@@ -150,6 +150,8 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd,
 unsigned long arg)
 			break;
 		}
 		if (cmd == PTP_EXTTS_REQUEST2) {
+			/* Tell the drivers to check the flags carefully. */
+			req.extts.flags |= PTP_STRICT_FLAGS;
 			/* Make sure no reserved bit is set. */
 			if ((req.extts.flags & ~PTP_EXTTS_VALID_FLAGS) ||
drivers/ptp/ptp_chardev.c +0 -0
 			    req.extts.rsv[0] || req.extts.rsv[1]) {
include/uapi/linux/ptp_clock.h +3 -2
index 304059b1609d..9dc9d0079e98 100644
@@ -31,6 +31,7 @@
 #define PTP_ENABLE_FEATURE (1<<0)
 #define PTP_RISING_EDGE    (1<<1)
 #define PTP_FALLING_EDGE   (1<<2)
+#define PTP_STRICT_FLAGS   (1<<3)
 #define PTP_EXTTS_EDGES    (PTP_RISING_EDGE | PTP_FALLING_EDGE)
 
 /*
@@ -38,7 +39,8 @@
  */
 #define PTP_EXTTS_VALID_FLAGS	(PTP_ENABLE_FEATURE |	\
 				 PTP_RISING_EDGE |	\
-				 PTP_FALLING_EDGE)
+				 PTP_FALLING_EDGE |	\
+				 PTP_STRICT_FLAGS)
 
 /*
  * flag fields valid for the original PTP_EXTTS_REQUEST ioctl.
--

2.20.1

author maintainer
#2 lore raw
Quoted 5 lines · Jacob E

So, this patch adds the flag *and* modifies the drivers to accept it, but not actually enable strict checking?

I'd prefer if this flag got added, and the drivers were modified in separate patches to both allow the flag and to perform the strict check.. that feels like a cleaner patch boundary.

That would ofcourse break the drivers that reject the strict command until they're fixed in follow-on commands.. hmm

You are right, but if anything I'd squash the following four driver patches into this one. I left the series in little steps just to make review easier. Strictly speaking, if you were to do a git bisect from the introduction of the "2" ioctls until here, you would find drivers' acceptance of the new flags changing. But it is too late to fix that, and I doubt anyone will care.

IMHO it *is* important to have v5.4 with strict checking.

Thanks,
Richard

#3 lore raw
Quoted 33 lines

-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, November 14, 2019 11:44 AM
To: Keller, Jacob E <[email protected]>
Cc: netdev at vger.kernel.org; intel-wired-lan at lists.osuosl.org; David Miller <[email protected]>; Brandon Streiff <[email protected]>; Hall, Christopher S <[email protected]>; Eugenia Emantayev <[email protected]>; Felipe Balbi <[email protected]>; Feras Daoud <[email protected]>; Kirsher, Jeffrey T <[email protected]>; Sergei Shtylyov <[email protected]>; Stefan Sorensen <[email protected]>
Subject: Re: [PATCH net 08/13] ptp: Introduce strict checking of external time stamp options.

Quoted 1 line · Jacob E

So, this patch adds the flag *and* modifies the drivers to accept it, but not

actually enable strict checking?

Quoted 2 lines

I'd prefer if this flag got added, and the drivers were modified in separate

patches to both allow the flag and to perform the strict check.. that feels like a cleaner patch boundary.

Quoted 2 lines

That would ofcourse break the drivers that reject the strict command until

they're fixed in follow-on commands.. hmm

You are right, but if anything I'd squash the following four driver patches into this one. I left the series in little steps just to make review easier. Strictly speaking, if you were to do a git bisect from the introduction of the "2" ioctls until here, you would find drivers' acceptance of the new flags changing. But it is too late to fix that, and I doubt anyone will care.

Quoted 4 lines

IMHO it *is* important to have v5.4 with strict checking.

Thanks,
Richard

Yes I agree. I think the series is good as is, and having this fixed before the ioctls have been in a full release makes sense.

Thanks,
Jake