From 66f305c46cf5326c1454ee4c8898a654305021bb Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Thu, 24 Nov 2022 01:41:31 -0800 Subject: [PATCH] modules/mqnic: Added helper methods for converting cycle counts to/from time Signed-off-by: Alex Forencich --- modules/mqnic/mqnic.h | 4 ++++ modules/mqnic/mqnic_clk_info.c | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/modules/mqnic/mqnic.h b/modules/mqnic/mqnic.h index 3884f5379..23ce0405f 100644 --- a/modules/mqnic/mqnic.h +++ b/modules/mqnic/mqnic.h @@ -586,6 +586,10 @@ u32 mqnic_get_core_clk_nom_freq_hz(struct mqnic_dev *mdev); u32 mqnic_get_ref_clk_nom_freq_hz(struct mqnic_dev *mdev); u32 mqnic_get_core_clk_freq_hz(struct mqnic_dev *mdev); u32 mqnic_get_clk_freq_hz(struct mqnic_dev *mdev, int ch); +u64 mqnic_core_clk_cycles_to_ns(struct mqnic_dev *mdev, u64 cycles); +u64 mqnic_core_clk_ns_to_cycles(struct mqnic_dev *mdev, u64 ns); +u64 mqnic_ref_clk_cycles_to_ns(struct mqnic_dev *mdev, u64 cycles); +u64 mqnic_ref_clk_ns_to_cycles(struct mqnic_dev *mdev, u64 ns); // mqnic_stats.c void mqnic_stats_init(struct mqnic_dev *mdev); diff --git a/modules/mqnic/mqnic_clk_info.c b/modules/mqnic/mqnic_clk_info.c index 7194e7812..5a9490a7a 100644 --- a/modules/mqnic/mqnic_clk_info.c +++ b/modules/mqnic/mqnic_clk_info.c @@ -88,3 +88,39 @@ u32 mqnic_get_clk_freq_hz(struct mqnic_dev *mdev, int ch) return ioread32(mdev->clk_info_rb->regs + MQNIC_RB_CLK_INFO_FREQ_BASE + ch*4); } EXPORT_SYMBOL(mqnic_get_clk_freq_hz); + +u64 mqnic_core_clk_cycles_to_ns(struct mqnic_dev *mdev, u64 cycles) +{ + if (!mdev->clk_info_rb || !mdev->core_clk_nom_per_ns_denom) + return 0; + + return (cycles * (u64)mdev->core_clk_nom_per_ns_num) / (u64)mdev->core_clk_nom_per_ns_denom; +} +EXPORT_SYMBOL(mqnic_core_clk_cycles_to_ns); + +u64 mqnic_core_clk_ns_to_cycles(struct mqnic_dev *mdev, u64 ns) +{ + if (!mdev->clk_info_rb || !mdev->core_clk_nom_per_ns_num) + return 0; + + return (ns * (u64)mdev->core_clk_nom_per_ns_denom) / (u64)mdev->core_clk_nom_per_ns_num; +} +EXPORT_SYMBOL(mqnic_core_clk_ns_to_cycles); + +u64 mqnic_ref_clk_cycles_to_ns(struct mqnic_dev *mdev, u64 cycles) +{ + if (!mdev->clk_info_rb || !mdev->ref_clk_nom_per_ns_denom) + return 0; + + return (cycles * (u64)mdev->ref_clk_nom_per_ns_num) / (u64)mdev->ref_clk_nom_per_ns_denom; +} +EXPORT_SYMBOL(mqnic_ref_clk_cycles_to_ns); + +u64 mqnic_ref_clk_ns_to_cycles(struct mqnic_dev *mdev, u64 ns) +{ + if (!mdev->clk_info_rb || !mdev->ref_clk_nom_per_ns_num) + return 0; + + return (ns * (u64)mdev->ref_clk_nom_per_ns_denom) / (u64)mdev->ref_clk_nom_per_ns_num; +} +EXPORT_SYMBOL(mqnic_ref_clk_ns_to_cycles);