Skip to content

Commit 574998c

Browse files
Jianbo LiuPaolo Abeni
authored andcommitted
net/mlx5: Add devcom component for the clock shared by functions
Add new devcom component for hardware clock. When it is running in real time mode, the functions are grouped by the identify they query. According to firmware document, the clock identify size is 64 bits, so it's safe to memcpy to component key, as the key size is also 64 bits. Signed-off-by: Jianbo Liu <jianbol@nvidia.com> Reviewed-by: Carolina Jubran <cjubran@nvidia.com> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent f9beaf4 commit 574998c

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include <linux/cpufeature.h>
4444
#endif /* CONFIG_X86 */
4545

46+
#define MLX5_RT_CLOCK_IDENTITY_SIZE MLX5_FLD_SZ_BYTES(mrtcq_reg, rt_clock_identity)
47+
4648
enum {
4749
MLX5_PIN_MODE_IN = 0x0,
4850
MLX5_PIN_MODE_OUT = 0x1,
@@ -77,6 +79,10 @@ enum {
7779
MLX5_MTUTC_OPERATION_ADJUST_TIME_EXTENDED_MAX = 200000,
7880
};
7981

82+
struct mlx5_clock_dev_state {
83+
struct mlx5_devcom_comp_dev *compdev;
84+
};
85+
8086
struct mlx5_clock_priv {
8187
struct mlx5_clock clock;
8288
struct mlx5_core_dev *mdev;
@@ -109,6 +115,22 @@ static bool mlx5_modify_mtutc_allowed(struct mlx5_core_dev *mdev)
109115
return MLX5_CAP_MCAM_FEATURE(mdev, ptpcyc2realtime_modify);
110116
}
111117

118+
static int mlx5_clock_identity_get(struct mlx5_core_dev *mdev,
119+
u8 identify[MLX5_RT_CLOCK_IDENTITY_SIZE])
120+
{
121+
u32 out[MLX5_ST_SZ_DW(mrtcq_reg)] = {};
122+
u32 in[MLX5_ST_SZ_DW(mrtcq_reg)] = {};
123+
int err;
124+
125+
err = mlx5_core_access_reg(mdev, in, sizeof(in),
126+
out, sizeof(out), MLX5_REG_MRTCQ, 0, 0);
127+
if (!err)
128+
memcpy(identify, MLX5_ADDR_OF(mrtcq_reg, out, rt_clock_identity),
129+
MLX5_RT_CLOCK_IDENTITY_SIZE);
130+
131+
return err;
132+
}
133+
112134
static u32 mlx5_ptp_shift_constant(u32 dev_freq_khz)
113135
{
114136
/* Optimal shift constant leads to corrections above just 1 scaled ppm.
@@ -1231,11 +1253,26 @@ static int mlx5_clock_alloc(struct mlx5_core_dev *mdev)
12311253
return 0;
12321254
}
12331255

1256+
static void mlx5_shared_clock_register(struct mlx5_core_dev *mdev, u64 key)
1257+
{
1258+
mdev->clock_state->compdev = mlx5_devcom_register_component(mdev->priv.devc,
1259+
MLX5_DEVCOM_SHARED_CLOCK,
1260+
key, NULL, mdev);
1261+
}
1262+
1263+
static void mlx5_shared_clock_unregister(struct mlx5_core_dev *mdev)
1264+
{
1265+
mlx5_devcom_unregister_component(mdev->clock_state->compdev);
1266+
}
1267+
12341268
static struct mlx5_clock null_clock;
12351269

12361270
int mlx5_init_clock(struct mlx5_core_dev *mdev)
12371271
{
1272+
u8 identity[MLX5_RT_CLOCK_IDENTITY_SIZE];
1273+
struct mlx5_clock_dev_state *clock_state;
12381274
struct mlx5_clock *clock;
1275+
u64 key;
12391276
int err;
12401277

12411278
if (!MLX5_CAP_GEN(mdev, device_frequency_khz)) {
@@ -1244,9 +1281,26 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev)
12441281
return 0;
12451282
}
12461283

1284+
clock_state = kzalloc(sizeof(*clock_state), GFP_KERNEL);
1285+
if (!clock_state)
1286+
return -ENOMEM;
1287+
mdev->clock_state = clock_state;
1288+
1289+
if (MLX5_CAP_MCAM_REG3(mdev, mrtcq) && mlx5_real_time_mode(mdev)) {
1290+
if (mlx5_clock_identity_get(mdev, identity)) {
1291+
mlx5_core_warn(mdev, "failed to get rt clock identity, create ptp dev per function\n");
1292+
} else {
1293+
memcpy(&key, &identity, sizeof(key));
1294+
mlx5_shared_clock_register(mdev, key);
1295+
}
1296+
}
1297+
12471298
err = mlx5_clock_alloc(mdev);
1248-
if (err)
1299+
if (err) {
1300+
kfree(clock_state);
1301+
mdev->clock_state = NULL;
12491302
return err;
1303+
}
12501304
clock = mdev->clock;
12511305

12521306
INIT_WORK(&clock->pps_info.out_work, mlx5_pps_out);
@@ -1267,4 +1321,7 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)
12671321
cancel_work_sync(&clock->pps_info.out_work);
12681322

12691323
mlx5_clock_free(mdev);
1324+
mlx5_shared_clock_unregister(mdev);
1325+
kfree(mdev->clock_state);
1326+
mdev->clock_state = NULL;
12701327
}

drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum mlx5_devcom_component {
1111
MLX5_DEVCOM_MPV,
1212
MLX5_DEVCOM_HCA_PORTS,
1313
MLX5_DEVCOM_SD_GROUP,
14+
MLX5_DEVCOM_SHARED_CLOCK,
1415
MLX5_DEVCOM_NUM_COMPONENTS,
1516
};
1617

include/linux/mlx5/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ struct mlx5_rsvd_gids {
679679
};
680680

681681
struct mlx5_clock;
682+
struct mlx5_clock_dev_state;
682683
struct mlx5_dm;
683684
struct mlx5_fw_tracer;
684685
struct mlx5_vxlan;
@@ -763,6 +764,7 @@ struct mlx5_core_dev {
763764
struct mlx5_fpga_device *fpga;
764765
#endif
765766
struct mlx5_clock *clock;
767+
struct mlx5_clock_dev_state *clock_state;
766768
struct mlx5_ib_clock_info *clock_info;
767769
struct mlx5_fw_tracer *tracer;
768770
struct mlx5_rsc_dump *rsc_dump;

0 commit comments

Comments
 (0)