Skip to content

Commit d9f3e9e

Browse files
jacob-kellerkuba-moo
authored andcommitted
net: ptp: introduce .supported_perout_flags to ptp_clock_info
The PTP_PEROUT_REQUEST2 ioctl has gained support for flags specifying specific output behavior including PTP_PEROUT_ONE_SHOT, PTP_PEROUT_DUTY_CYCLE, PTP_PEROUT_PHASE. Driver authors are notorious for not checking the flags of the request. This results in misinterpreting the request, generating an output signal that does not match the requested value. It is anticipated that even more flags will be added in the future, resulting in even more broken requests. Expecting these issues to be caught during review or playing whack-a-mole after the fact is not a great solution. Instead, introduce the supported_perout_flags field in the ptp_clock_info structure. Update the core character device logic to explicitly reject any request which has a flag not on this list. This ensures that drivers must 'opt in' to the flags they support. Drivers which don't set the .supported_perout_flags field will not need to check that unsupported flags aren't passed, as the core takes care of this. Update the drivers which do support flags to set this new field. Note the following driver files set n_per_out to a non-zero value but did not check the flags at all: • drivers/ptp/ptp_clockmatrix.c • drivers/ptp/ptp_idt82p33.c • drivers/ptp/ptp_fc3.c • drivers/net/ethernet/ti/am65-cpts.c • drivers/net/ethernet/aquantia/atlantic/aq_ptp.c • drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c • drivers/net/dsa/sja1105/sja1105_ptp.c • drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c • drivers/net/ethernet/mscc/ocelot_vsc7514.c • drivers/net/ethernet/intel/i40e/i40e_ptp.c Reviewed-by: Vadim Fedorenko <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Reviewed-by: Kory Maincent <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7c571ac commit d9f3e9e

File tree

15 files changed

+21
-57
lines changed

15 files changed

+21
-57
lines changed

drivers/net/dsa/sja1105/sja1105_ptp.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,6 @@ static int sja1105_per_out_enable(struct sja1105_private *priv,
737737
if (perout->index != 0)
738738
return -EOPNOTSUPP;
739739

740-
/* Reject requests with unsupported flags */
741-
if (perout->flags)
742-
return -EOPNOTSUPP;
743-
744740
mutex_lock(&ptp_data->lock);
745741

746742
rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,9 +1797,6 @@ static int ice_ptp_cfg_perout(struct ice_pf *pf, struct ptp_perout_request *rq,
17971797
struct ice_hw *hw = &pf->hw;
17981798
int pin_desc_idx;
17991799

1800-
if (rq->flags & ~PTP_PEROUT_PHASE)
1801-
return -EOPNOTSUPP;
1802-
18031800
pin_desc_idx = ice_ptp_find_pin_idx(pf, PTP_PF_PEROUT, rq->index);
18041801
if (pin_desc_idx < 0)
18051802
return -EIO;
@@ -2735,6 +2732,7 @@ static void ice_ptp_set_caps(struct ice_pf *pf)
27352732
info->supported_extts_flags = PTP_RISING_EDGE |
27362733
PTP_FALLING_EDGE |
27372734
PTP_STRICT_FLAGS;
2735+
info->supported_perout_flags = PTP_PEROUT_PHASE;
27382736

27392737
switch (pf->hw.mac_type) {
27402738
case ICE_MAC_E810:

drivers/net/ethernet/intel/igc/igc_ptp.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ static int igc_ptp_feature_enable_i225(struct ptp_clock_info *ptp,
293293
return 0;
294294

295295
case PTP_CLK_REQ_PEROUT:
296-
/* Reject requests with unsupported flags */
297-
if (rq->perout.flags)
298-
return -EOPNOTSUPP;
299-
300296
if (on) {
301297
pin = ptp_find_pin(igc->ptp_clock, PTP_PF_PEROUT,
302298
rq->perout.index);

drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,6 @@ static int perout_conf_npps_real_time(struct mlx5_core_dev *mdev, struct ptp_clo
813813
return 0;
814814
}
815815

816-
static bool mlx5_perout_verify_flags(struct mlx5_core_dev *mdev, unsigned int flags)
817-
{
818-
return ((!mlx5_npps_real_time_supported(mdev) && flags) ||
819-
(mlx5_npps_real_time_supported(mdev) && flags & ~PTP_PEROUT_DUTY_CYCLE));
820-
}
821-
822816
static int mlx5_perout_configure(struct ptp_clock_info *ptp,
823817
struct ptp_clock_request *rq,
824818
int on)
@@ -854,12 +848,6 @@ static int mlx5_perout_configure(struct ptp_clock_info *ptp,
854848
goto unlock;
855849
}
856850

857-
/* Reject requests with unsupported flags */
858-
if (mlx5_perout_verify_flags(mdev, rq->perout.flags)) {
859-
err = -EOPNOTSUPP;
860-
goto unlock;
861-
}
862-
863851
if (on) {
864852
pin_mode = MLX5_PIN_MODE_OUT;
865853
pattern = MLX5_OUT_PATTERN_PERIODIC;
@@ -1031,6 +1019,9 @@ static void mlx5_init_pin_config(struct mlx5_core_dev *mdev)
10311019
PTP_FALLING_EDGE |
10321020
PTP_STRICT_FLAGS;
10331021

1022+
if (mlx5_npps_real_time_supported(mdev))
1023+
clock->ptp_info.supported_perout_flags = PTP_PEROUT_DUTY_CYCLE;
1024+
10341025
for (i = 0; i < clock->ptp_info.n_pins; i++) {
10351026
snprintf(clock->ptp_info.pin_config[i].name,
10361027
sizeof(clock->ptp_info.pin_config[i].name),

drivers/net/ethernet/microchip/lan743x_ptp.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,6 @@ static int lan743x_ptp_perout(struct lan743x_adapter *adapter, int on,
463463
struct lan743x_ptp_perout *perout = &ptp->perout[index];
464464
int ret = 0;
465465

466-
/* Reject requests with unsupported flags */
467-
if (perout_request->flags & ~PTP_PEROUT_DUTY_CYCLE)
468-
return -EOPNOTSUPP;
469-
470466
if (on) {
471467
perout_pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT,
472468
perout_request->index);
@@ -1540,6 +1536,7 @@ int lan743x_ptp_open(struct lan743x_adapter *adapter)
15401536
ptp->ptp_clock_info.supported_extts_flags = PTP_RISING_EDGE |
15411537
PTP_FALLING_EDGE |
15421538
PTP_STRICT_FLAGS;
1539+
ptp->ptp_clock_info.supported_perout_flags = PTP_PEROUT_DUTY_CYCLE;
15431540
ptp->ptp_clock_info.pin_config = ptp->pin_config;
15441541
ptp->ptp_clock_info.adjfine = lan743x_ptpci_adjfine;
15451542
ptp->ptp_clock_info.adjtime = lan743x_ptpci_adjtime;

drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,6 @@ static int lan966x_ptp_perout(struct ptp_clock_info *ptp,
815815
bool pps = false;
816816
int pin;
817817

818-
if (rq->perout.flags & ~(PTP_PEROUT_DUTY_CYCLE |
819-
PTP_PEROUT_PHASE))
820-
return -EOPNOTSUPP;
821-
822818
pin = ptp_find_pin(phc->clock, PTP_PF_PEROUT, rq->perout.index);
823819
if (pin == -1 || pin >= LAN966X_PHC_PINS_NUM)
824820
return -EINVAL;
@@ -974,6 +970,8 @@ static struct ptp_clock_info lan966x_ptp_clock_info = {
974970
.n_pins = LAN966X_PHC_PINS_NUM,
975971
.supported_extts_flags = PTP_RISING_EDGE |
976972
PTP_STRICT_FLAGS,
973+
.supported_perout_flags = PTP_PEROUT_DUTY_CYCLE |
974+
PTP_PEROUT_PHASE,
977975
};
978976

979977
static int lan966x_ptp_phc_init(struct lan966x *lan966x,

drivers/net/ethernet/mscc/ocelot_ptp.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ int ocelot_ptp_enable(struct ptp_clock_info *ptp,
211211

212212
switch (rq->type) {
213213
case PTP_CLK_REQ_PEROUT:
214-
/* Reject requests with unsupported flags */
215-
if (rq->perout.flags & ~(PTP_PEROUT_DUTY_CYCLE |
216-
PTP_PEROUT_PHASE))
217-
return -EOPNOTSUPP;
218-
219214
pin = ptp_find_pin(ocelot->ptp_clock, PTP_PF_PEROUT,
220215
rq->perout.index);
221216
if (pin == 0)

drivers/net/ethernet/mscc/ocelot_vsc7514.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ static struct ptp_clock_info ocelot_ptp_clock_info = {
108108
.n_ext_ts = 0,
109109
.n_per_out = OCELOT_PTP_PINS_NUM,
110110
.n_pins = OCELOT_PTP_PINS_NUM,
111+
.supported_perout_flags = PTP_PEROUT_DUTY_CYCLE |
112+
PTP_PEROUT_PHASE,
111113
.pps = 0,
112114
.gettime64 = ocelot_ptp_gettime64,
113115
.settime64 = ocelot_ptp_settime64,

drivers/net/ethernet/renesas/ravb_ptp.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ static int ravb_ptp_perout(struct ptp_clock_info *ptp,
206206
unsigned long flags;
207207
int error = 0;
208208

209-
/* Reject requests with unsupported flags */
210-
if (req->flags)
211-
return -EOPNOTSUPP;
212-
213209
if (req->index)
214210
return -EINVAL;
215211

drivers/net/phy/dp83640.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,6 @@ static int ptp_dp83640_enable(struct ptp_clock_info *ptp,
506506
return 0;
507507

508508
case PTP_CLK_REQ_PEROUT:
509-
/* Reject requests with unsupported flags */
510-
if (rq->perout.flags)
511-
return -EOPNOTSUPP;
512509
if (rq->perout.index >= N_PER_OUT)
513510
return -EINVAL;
514511
return periodic_output(clock, rq, on, rq->perout.index);

0 commit comments

Comments
 (0)