[11/35] net/mlx5/windows: support read clock

Message ID 20201217173037.11396-12-talshn@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series mlx5 Windows support - part #6 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tal Shnaiderman Dec. 17, 2020, 5:30 p.m. UTC
  This commit adds a new glue function query_rt_values to support the new
API mlx5_read_clock().

Signed-off-by: Tal Shnaiderman <talshn@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/mlx5_prm.h             |  1 +
 drivers/common/mlx5/windows/mlx5_glue.c    | 26 ++++++++++++++++++++++++++
 drivers/common/mlx5/windows/mlx5_glue.h    |  1 +
 drivers/common/mlx5/windows/mlx5_win_ext.h |  6 ++++++
 drivers/net/mlx5/windows/mlx5_ethdev_os.c  | 30 ++++++++++++++++++++++++++++++
 5 files changed, 64 insertions(+)
  

Patch

diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index d62d2558eb..ac42238d30 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -594,6 +594,7 @@  struct mlx5_modification_cmd {
 	};
 };
 
+typedef uint64_t u64;
 typedef uint32_t u32;
 typedef uint16_t u16;
 typedef uint8_t u8;
diff --git a/drivers/common/mlx5/windows/mlx5_glue.c b/drivers/common/mlx5/windows/mlx5_glue.c
index 3896cf0932..167531823b 100644
--- a/drivers/common/mlx5/windows/mlx5_glue.c
+++ b/drivers/common/mlx5/windows/mlx5_glue.c
@@ -283,6 +283,31 @@  mlx5_glue_devx_fs_rule_del(void *flow)
 	return devx_fs_rule_del(flow);
 }
 
+static int
+mlx5_glue_query_rt_values(void *ctx, void *devx_clock)
+{
+	struct mlx5_context *mlx5_ctx;
+	struct mlx5_devx_clock *clock;
+	int err;
+
+	if (!ctx) {
+		errno = EINVAL;
+		return errno;
+	}
+	mlx5_ctx = (struct mlx5_context *)ctx;
+	clock = (struct mlx5_devx_clock *)devx_clock;
+	err = devx_hca_clock_query(
+			mlx5_ctx->devx_ctx,
+			&clock->p_iseg_internal_timer,
+			&clock->clock_frequency_hz,
+			&clock->is_stable_clock_frequency);
+	if (err) {
+		errno = err;
+		return errno;
+	}
+	return 0;
+}
+
 alignas(RTE_CACHE_LINE_SIZE)
 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
 	.version = MLX5_GLUE_VERSION,
@@ -304,4 +329,5 @@  const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue){
 	.devx_fs_rule_add = mlx5_glue_devx_fs_rule_add,
 	.devx_fs_rule_del = mlx5_glue_devx_fs_rule_del,
 	.devx_query_eqn = mlx5_glue_devx_query_eqn,
+	.query_rt_values = mlx5_glue_query_rt_values,
 };
diff --git a/drivers/common/mlx5/windows/mlx5_glue.h b/drivers/common/mlx5/windows/mlx5_glue.h
index f2261ec7ac..bfaaa2a493 100644
--- a/drivers/common/mlx5/windows/mlx5_glue.h
+++ b/drivers/common/mlx5/windows/mlx5_glue.h
@@ -51,6 +51,7 @@  struct mlx5_glue {
 	void *(*devx_fs_rule_add)(void *ctx, void *in, uint32_t inlen);
 	int (*devx_fs_rule_del)(void *flow);
 	int (*devx_query_eqn)(void *context, uint32_t cpus, uint32_t *eqn);
+	int (*query_rt_values)(void *ctx, void *devx_clock);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
diff --git a/drivers/common/mlx5/windows/mlx5_win_ext.h b/drivers/common/mlx5/windows/mlx5_win_ext.h
index 8e697b30c1..a14a6ccc3d 100644
--- a/drivers/common/mlx5/windows/mlx5_win_ext.h
+++ b/drivers/common/mlx5/windows/mlx5_win_ext.h
@@ -34,6 +34,12 @@  struct mlx5_pd {
 	devx_device_ctx        *devx_ctx;
 };
 
+struct mlx5_devx_clock {
+	void *p_iseg_internal_timer;
+	u64 clock_frequency_hz;
+	int is_stable_clock_frequency;
+};
+
 #define GET_DEVX_CTX(ctx) (((mlx5_context_st *)ctx)->devx_ctx)
 #define GET_OBJ_CTX(obj)  (((mlx5_devx_obj_st *)obj)->devx_ctx)
 
diff --git a/drivers/net/mlx5/windows/mlx5_ethdev_os.c b/drivers/net/mlx5/windows/mlx5_ethdev_os.c
index c99eac9868..1b68a7b6e8 100644
--- a/drivers/net/mlx5/windows/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/windows/mlx5_ethdev_os.c
@@ -14,6 +14,7 @@ 
 #include <mlx5_win_ext.h>
 #include <mlx5_malloc.h>
 #include <mlx5.h>
+#include <mlx5_utils.h>
 
 /**
  * Get MAC address by querying netdevice.
@@ -284,3 +285,32 @@  int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
 	RTE_SET_USED(info);
 	return -ENOTSUP;
 }
+
+/**
+ * Get device current raw clock counter
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param[out] time
+ *   Current raw clock counter of the device.
+ *
+ * @return
+ *   0 if the clock has correctly been read
+ *   The value of errno in case of error
+ */
+int
+mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
+{
+	int err;
+	struct mlx5_devx_clock mlx5_clock;
+	struct mlx5_priv *priv = dev->data->dev_private;
+	mlx5_context_st *context_obj = (mlx5_context_st *)priv->sh->ctx;
+
+	err = mlx5_glue->query_rt_values(context_obj, &mlx5_clock);
+	if (err != 0) {
+		DRV_LOG(WARNING, "Could not query the clock");
+		return err;
+	}
+	*clock = *(uint64_t volatile *)mlx5_clock.p_iseg_internal_timer;
+	return 0;
+}