net/mlx5: Convert scaled ppm values outside the s32 range for PHC frequency adjustments
authorRahul Rameshbabu <rrameshbabu@nvidia.com>
Fri, 25 Aug 2023 03:29:50 +0000 (20:29 -0700)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 15 Nov 2023 19:34:30 +0000 (11:34 -0800)
Represent scaled ppm as ppb to the device when the value in scaled ppm is
not representable as a 32-bit signed integer. mlx5 devices only support a
32-bit field for the frequency adjustment value in units of either scaled
ppm or ppb.

Since mlx5 devices only support a 32-bit field for the frequency adjustment
value independent of unit used, limit the maximum frequency adjustment to
S32_MAX ppb.

Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c

index ca7691930f6b0ebcf0ec67c6edb9767f73b02c6d..1daa4b01951323c0fa33d0b1f5569b025a0bf2d0 100644 (file)
@@ -393,10 +393,12 @@ static int mlx5_ptp_freq_adj_real_time(struct mlx5_core_dev *mdev, long scaled_p
 
        MLX5_SET(mtutc_reg, in, operation, MLX5_MTUTC_OPERATION_ADJUST_FREQ_UTC);
 
-       if (MLX5_CAP_MCAM_FEATURE(mdev, mtutc_freq_adj_units)) {
+       if (MLX5_CAP_MCAM_FEATURE(mdev, mtutc_freq_adj_units) &&
+           scaled_ppm <= S32_MAX && scaled_ppm >= S32_MIN) {
+               /* HW scaled_ppm support on mlx5 devices only supports a 32-bit value */
                MLX5_SET(mtutc_reg, in, freq_adj_units,
                         MLX5_MTUTC_FREQ_ADJ_UNITS_SCALED_PPM);
-               MLX5_SET(mtutc_reg, in, freq_adjustment, scaled_ppm);
+               MLX5_SET(mtutc_reg, in, freq_adjustment, (s32)scaled_ppm);
        } else {
                MLX5_SET(mtutc_reg, in, freq_adj_units, MLX5_MTUTC_FREQ_ADJ_UNITS_PPB);
                MLX5_SET(mtutc_reg, in, freq_adjustment, scaled_ppm_to_ppb(scaled_ppm));