net/mlx5: Clock, Use async events chain
authorSaeed Mahameed <saeedm@mellanox.com>
Tue, 20 Nov 2018 22:12:21 +0000 (14:12 -0800)
committerSaeed Mahameed <saeedm@mellanox.com>
Mon, 26 Nov 2018 21:39:33 +0000 (13:39 -0800)
Remove the explicit call to mlx5_pps_event on MLX5_EVENT_TYPE_PPS_EVENT
and let clock logic to register its own handler when its ready.

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/eq.c
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.h
include/linux/mlx5/driver.h

index 8aabd23d216606e67366bf278988e2f06423ad89..e5fcce9ca107501c1c081e7323eadc0edaaf2210 100644 (file)
@@ -417,10 +417,6 @@ static irqreturn_t mlx5_eq_async_int(int irq, void *eq_ptr)
                        mlx5_port_module_event(dev, eqe);
                        break;
 
-               case MLX5_EVENT_TYPE_PPS_EVENT:
-                       mlx5_pps_event(dev, eqe);
-                       break;
-
                case MLX5_EVENT_TYPE_TEMP_WARN_EVENT:
                        mlx5_temp_warning_event(dev, eqe);
                        break;
index 0d90b1b4a3d388c2793de0a8f688c605f3c3abfd..d27c239e7d6cc3402fca8f23757b55a0aaccdf4d 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/clocksource.h>
 #include <linux/highmem.h>
 #include <rdma/mlx5-abi.h>
+#include "lib/eq.h"
 #include "en.h"
 #include "clock.h"
 
@@ -439,16 +440,17 @@ static void mlx5_get_pps_caps(struct mlx5_core_dev *mdev)
        clock->pps_info.pin_caps[7] = MLX5_GET(mtpps_reg, out, cap_pin_7_mode);
 }
 
-void mlx5_pps_event(struct mlx5_core_dev *mdev,
-                   struct mlx5_eqe *eqe)
+static int mlx5_pps_event(struct notifier_block *nb,
+                         unsigned long type, void *data)
 {
-       struct mlx5_clock *clock = &mdev->clock;
+       struct mlx5_clock *clock = mlx5_nb_cof(nb, struct mlx5_clock, pps_nb);
+       struct mlx5_core_dev *mdev = clock->mdev;
        struct ptp_clock_event ptp_event;
-       struct timespec64 ts;
-       u64 nsec_now, nsec_delta;
        u64 cycles_now, cycles_delta;
+       u64 nsec_now, nsec_delta, ns;
+       struct mlx5_eqe *eqe = data;
        int pin = eqe->data.pps.pin;
-       s64 ns;
+       struct timespec64 ts;
        unsigned long flags;
 
        switch (clock->ptp_info.pin_config[pin].func) {
@@ -463,6 +465,7 @@ void mlx5_pps_event(struct mlx5_core_dev *mdev,
                } else {
                        ptp_event.type = PTP_CLOCK_EXTTS;
                }
+               /* TODOL clock->ptp can be NULL if ptp_clock_register failes */
                ptp_clock_event(clock->ptp, &ptp_event);
                break;
        case PTP_PF_PEROUT:
@@ -481,8 +484,11 @@ void mlx5_pps_event(struct mlx5_core_dev *mdev,
                write_sequnlock_irqrestore(&clock->lock, flags);
                break;
        default:
-               mlx5_core_err(mdev, " Unhandled event\n");
+               mlx5_core_err(mdev, " Unhandled clock PPS event, func %d\n",
+                             clock->ptp_info.pin_config[pin].func);
        }
+
+       return NOTIFY_OK;
 }
 
 void mlx5_init_clock(struct mlx5_core_dev *mdev)
@@ -567,6 +573,9 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
                               PTR_ERR(clock->ptp));
                clock->ptp = NULL;
        }
+
+       MLX5_NB_INIT(&clock->pps_nb, mlx5_pps_event, PPS_EVENT);
+       mlx5_eq_notifier_register(mdev, &clock->pps_nb);
 }
 
 void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)
@@ -576,6 +585,7 @@ void mlx5_cleanup_clock(struct mlx5_core_dev *mdev)
        if (!MLX5_CAP_GEN(mdev, device_frequency_khz))
                return;
 
+       mlx5_eq_notifier_unregister(mdev, &clock->pps_nb);
        if (clock->ptp) {
                ptp_clock_unregister(clock->ptp);
                clock->ptp = NULL;
index 263cb6e2aeee52e5bbdbd698ab3556531529a14a..31600924bdc367824b2ed9ae199dbc05d17177d7 100644 (file)
@@ -36,7 +36,6 @@
 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
 void mlx5_init_clock(struct mlx5_core_dev *mdev);
 void mlx5_cleanup_clock(struct mlx5_core_dev *mdev);
-void mlx5_pps_event(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe);
 
 static inline int mlx5_clock_get_ptp_index(struct mlx5_core_dev *mdev)
 {
@@ -60,8 +59,6 @@ static inline ktime_t mlx5_timecounter_cyc2time(struct mlx5_clock *clock,
 #else
 static inline void mlx5_init_clock(struct mlx5_core_dev *mdev) {}
 static inline void mlx5_cleanup_clock(struct mlx5_core_dev *mdev) {}
-static inline void mlx5_pps_event(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe) {}
-
 static inline int mlx5_clock_get_ptp_index(struct mlx5_core_dev *mdev)
 {
        return -1;
index f41e6713df10cbd93735b98111b7ffe94ae7db8f..99a23db9a929fa04ad3c98219f3a22ba75d5f7d5 100644 (file)
@@ -50,6 +50,7 @@
 #include <linux/mlx5/device.h>
 #include <linux/mlx5/doorbell.h>
 #include <linux/mlx5/srq.h>
+#include <linux/mlx5/eq.h>
 #include <linux/timecounter.h>
 #include <linux/ptp_clock_kernel.h>
 
@@ -671,6 +672,8 @@ struct mlx5_pps {
 };
 
 struct mlx5_clock {
+       struct mlx5_core_dev      *mdev;
+       struct mlx5_nb             pps_nb;
        seqlock_t                  lock;
        struct cyclecounter        cycles;
        struct timecounter         tc;
@@ -678,7 +681,6 @@ struct mlx5_clock {
        u32                        nominal_c_mult;
        unsigned long              overflow_period;
        struct delayed_work        overflow_work;
-       struct mlx5_core_dev      *mdev;
        struct ptp_clock          *ptp;
        struct ptp_clock_info      ptp_info;
        struct mlx5_pps            pps_info;