Skip to content

Commit 1b99678

Browse files
committed
net/mlx5: Generate PPS IN event on new function for shared clock
jira LE-3615 Rebuild_History Non-Buildable kernel-5.14.0-570.28.1.el9_6 commit-author Jianbo Liu <jianbol@nvidia.com> commit 39c1202 As a specific function (mdev) is chosen to send MTPPSE command to firmware, the event is generated only on that function. When that function is unloaded, the PPS event can't be forward to PTP device, even when there are other functions in the group, and PTP device is not destroyed. To resolve this problem, need to send MTPPSE again from new function, and dis-arm the event on old function after that. PPS events are handled by EQ notifier. The async EQs and notifiers are destroyed in mlx5_eq_table_destroy() which is called before mlx5_cleanup_clock(). During the period between mlx5_eq_table_destroy() and mlx5_cleanup_clock(), the events can't be handled. To avoid event loss, add mlx5_clock_unload() in mlx5_unload() to arm the event on other available function, and mlx5_clock_load in mlx5_load() for symmetry. 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> (cherry picked from commit 39c1202) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent b65c085 commit 1b99678

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

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

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct mlx5_clock_priv {
9090
struct mlx5_clock clock;
9191
struct mlx5_core_dev *mdev;
9292
struct mutex lock; /* protect mdev and used in PTP callbacks */
93+
struct mlx5_core_dev *event_mdev;
9394
};
9495

9596
static struct mlx5_clock_priv *clock_priv(struct mlx5_clock *clock)
@@ -691,6 +692,11 @@ static int mlx5_extts_configure(struct ptp_clock_info *ptp,
691692
goto unlock;
692693

693694
err = mlx5_set_mtppse(mdev, pin, 0, MLX5_EVENT_MODE_REPETETIVE & on);
695+
if (err)
696+
goto unlock;
697+
698+
clock->pps_info.pin_armed[pin] = on;
699+
clock_priv(clock)->event_mdev = mdev;
694700

695701
unlock:
696702
mlx5_clock_unlock(clock);
@@ -1417,6 +1423,90 @@ static void mlx5_shared_clock_unregister(struct mlx5_core_dev *mdev)
14171423
mlx5_devcom_unregister_component(mdev->clock_state->compdev);
14181424
}
14191425

1426+
static void mlx5_clock_arm_pps_in_event(struct mlx5_clock *clock,
1427+
struct mlx5_core_dev *new_mdev,
1428+
struct mlx5_core_dev *old_mdev)
1429+
{
1430+
struct ptp_clock_info *ptp_info = &clock->ptp_info;
1431+
struct mlx5_clock_priv *cpriv = clock_priv(clock);
1432+
int i;
1433+
1434+
for (i = 0; i < ptp_info->n_pins; i++) {
1435+
if (ptp_info->pin_config[i].func != PTP_PF_EXTTS ||
1436+
!clock->pps_info.pin_armed[i])
1437+
continue;
1438+
1439+
if (new_mdev) {
1440+
mlx5_set_mtppse(new_mdev, i, 0, MLX5_EVENT_MODE_REPETETIVE);
1441+
cpriv->event_mdev = new_mdev;
1442+
} else {
1443+
cpriv->event_mdev = NULL;
1444+
}
1445+
1446+
if (old_mdev)
1447+
mlx5_set_mtppse(old_mdev, i, 0, MLX5_EVENT_MODE_DISABLE);
1448+
}
1449+
}
1450+
1451+
void mlx5_clock_load(struct mlx5_core_dev *mdev)
1452+
{
1453+
struct mlx5_clock *clock = mdev->clock;
1454+
struct mlx5_clock_priv *cpriv;
1455+
1456+
if (!MLX5_CAP_GEN(mdev, device_frequency_khz))
1457+
return;
1458+
1459+
INIT_WORK(&mdev->clock_state->out_work, mlx5_pps_out);
1460+
MLX5_NB_INIT(&mdev->clock_state->pps_nb, mlx5_pps_event, PPS_EVENT);
1461+
mlx5_eq_notifier_register(mdev, &mdev->clock_state->pps_nb);
1462+
1463+
if (!clock->shared) {
1464+
mlx5_clock_arm_pps_in_event(clock, mdev, NULL);
1465+
return;
1466+
}
1467+
1468+
cpriv = clock_priv(clock);
1469+
mlx5_devcom_comp_lock(mdev->clock_state->compdev);
1470+
mlx5_clock_lock(clock);
1471+
if (mdev == cpriv->mdev && mdev != cpriv->event_mdev)
1472+
mlx5_clock_arm_pps_in_event(clock, mdev, cpriv->event_mdev);
1473+
mlx5_clock_unlock(clock);
1474+
mlx5_devcom_comp_unlock(mdev->clock_state->compdev);
1475+
}
1476+
1477+
void mlx5_clock_unload(struct mlx5_core_dev *mdev)
1478+
{
1479+
struct mlx5_core_dev *peer_dev, *next = NULL;
1480+
struct mlx5_clock *clock = mdev->clock;
1481+
struct mlx5_devcom_comp_dev *pos;
1482+
1483+
if (!MLX5_CAP_GEN(mdev, device_frequency_khz))
1484+
return;
1485+
1486+
if (!clock->shared) {
1487+
mlx5_clock_arm_pps_in_event(clock, NULL, mdev);
1488+
goto out;
1489+
}
1490+
1491+
mlx5_devcom_comp_lock(mdev->clock_state->compdev);
1492+
mlx5_devcom_for_each_peer_entry(mdev->clock_state->compdev, peer_dev, pos) {
1493+
if (peer_dev->clock && peer_dev != mdev) {
1494+
next = peer_dev;
1495+
break;
1496+
}
1497+
}
1498+
1499+
mlx5_clock_lock(clock);
1500+
if (mdev == clock_priv(clock)->event_mdev)
1501+
mlx5_clock_arm_pps_in_event(clock, next, mdev);
1502+
mlx5_clock_unlock(clock);
1503+
mlx5_devcom_comp_unlock(mdev->clock_state->compdev);
1504+
1505+
out:
1506+
mlx5_eq_notifier_unregister(mdev, &mdev->clock_state->pps_nb);
1507+
cancel_work_sync(&mdev->clock_state->out_work);
1508+
}
1509+
14201510
static struct mlx5_clock null_clock;
14211511

14221512
int mlx5_init_clock(struct mlx5_core_dev *mdev)
@@ -1456,10 +1546,6 @@ int mlx5_init_clock(struct mlx5_core_dev *mdev)
14561546
}
14571547
}
14581548

1459-
INIT_WORK(&mdev->clock_state->out_work, mlx5_pps_out);
1460-
MLX5_NB_INIT(&mdev->clock_state->pps_nb, mlx5_pps_event, PPS_EVENT);
1461-
mlx5_eq_notifier_register(mdev, &mdev->clock_state->pps_nb);
1462-
14631549
return 0;
14641550
}
14651551

@@ -1468,9 +1554,6 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)
14681554
if (!MLX5_CAP_GEN(mdev, device_frequency_khz))
14691555
return;
14701556

1471-
mlx5_eq_notifier_unregister(mdev, &mdev->clock_state->pps_nb);
1472-
cancel_work_sync(&mdev->clock_state->out_work);
1473-
14741557
if (mdev->clock->shared)
14751558
mlx5_shared_clock_unregister(mdev);
14761559
else

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct mlx5_pps {
4242
u8 enabled;
4343
u64 min_npps_period;
4444
u64 min_out_pulse_duration_ns;
45+
bool pin_armed[MAX_PIN_NUM];
4546
};
4647

4748
struct mlx5_timer {
@@ -84,6 +85,8 @@ typedef ktime_t (*cqe_ts_to_ns)(struct mlx5_clock *, u64);
8485
#if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
8586
int mlx5_init_clock(struct mlx5_core_dev *mdev);
8687
void mlx5_cleanup_clock(struct mlx5_core_dev *mdev);
88+
void mlx5_clock_load(struct mlx5_core_dev *mdev);
89+
void mlx5_clock_unload(struct mlx5_core_dev *mdev);
8790

8891
static inline int mlx5_clock_get_ptp_index(struct mlx5_core_dev *mdev)
8992
{
@@ -117,6 +120,8 @@ static inline ktime_t mlx5_real_time_cyc2time(struct mlx5_clock *clock,
117120
#else
118121
static inline int mlx5_init_clock(struct mlx5_core_dev *mdev) { return 0; }
119122
static inline void mlx5_cleanup_clock(struct mlx5_core_dev *mdev) {}
123+
static inline void mlx5_clock_load(struct mlx5_core_dev *mdev) {}
124+
static inline void mlx5_clock_unload(struct mlx5_core_dev *mdev) {}
120125
static inline int mlx5_clock_get_ptp_index(struct mlx5_core_dev *mdev)
121126
{
122127
return -1;

drivers/net/ethernet/mellanox/mlx5/core/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@ static int mlx5_load(struct mlx5_core_dev *dev)
13581358
goto err_eq_table;
13591359
}
13601360

1361+
mlx5_clock_load(dev);
1362+
13611363
err = mlx5_fw_tracer_init(dev->tracer);
13621364
if (err) {
13631365
mlx5_core_err(dev, "Failed to init FW tracer %d\n", err);
@@ -1441,6 +1443,7 @@ static int mlx5_load(struct mlx5_core_dev *dev)
14411443
mlx5_hv_vhca_cleanup(dev->hv_vhca);
14421444
mlx5_fw_reset_events_stop(dev);
14431445
mlx5_fw_tracer_cleanup(dev->tracer);
1446+
mlx5_clock_unload(dev);
14441447
mlx5_eq_table_destroy(dev);
14451448
err_eq_table:
14461449
mlx5_irq_table_destroy(dev);
@@ -1467,6 +1470,7 @@ static void mlx5_unload(struct mlx5_core_dev *dev)
14671470
mlx5_hv_vhca_cleanup(dev->hv_vhca);
14681471
mlx5_fw_reset_events_stop(dev);
14691472
mlx5_fw_tracer_cleanup(dev->tracer);
1473+
mlx5_clock_unload(dev);
14701474
mlx5_eq_table_destroy(dev);
14711475
mlx5_irq_table_destroy(dev);
14721476
mlx5_pagealloc_stop(dev);

0 commit comments

Comments
 (0)