ptp: Introduce strict checking of external time stamp options.
authorRichard Cochran <richardcochran@gmail.com>
Thu, 14 Nov 2019 18:45:02 +0000 (10:45 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Nov 2019 20:48:32 +0000 (12:48 -0800)
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.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/mv88e6xxx/ptp.c
drivers/net/ethernet/intel/igb/igb_ptp.c
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
drivers/net/ethernet/renesas/ravb_ptp.c
drivers/net/phy/dp83640.c
drivers/ptp/ptp_chardev.c
include/uapi/linux/ptp_clock.h

index 076e622a64d63494582c34efd5ddf00a40f3dadf..3b1985902f9530709f5d9dbae79f66079c805375 100644 (file)
@@ -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);
index 0bce3e0f1af0d5fb3402bf70a660155b2430bdd6..3fd60715bca7482c8b877f7bb435d2253cc4a3f7 100644 (file)
@@ -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) {
index 9a40f24e31930a92c07f6006b574714ea53eca82..819097d9b583b3c9acf3cb93b3355abd51696d84 100644 (file)
@@ -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)
index 666dbee48097ba32db675dae07940ddd834b8588..6984bd5b7da91f59cecb522d3ba4c5f355a538e2 100644 (file)
@@ -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)
index 2781b0e2d9474a65fece12998aae1964ee0e4328..3bba2bea3a885c14e8a59605ba782ad7b95ab720 100644 (file)
@@ -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)
index cbbe1237ff8d3ee8d5843ce1e189a98b0e8210e3..9d72ab593f13fde1d29862461cbc2a63fb322baa 100644 (file)
@@ -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]) {
index 304059b1609d25338fc532c9fcfb5e44c447c41c..9dc9d0079e98442be9e9f3f3fb3ce78069524593 100644 (file)
@@ -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.