diff --git a/lib/mqnic/mqnic.h b/lib/mqnic/mqnic.h index c27166e43..997af6e66 100644 --- a/lib/mqnic/mqnic.h +++ b/lib/mqnic/mqnic.h @@ -227,6 +227,10 @@ uint32_t mqnic_get_core_clk_nom_freq_hz(struct mqnic *dev); uint32_t mqnic_get_ref_clk_nom_freq_hz(struct mqnic *dev); uint32_t mqnic_get_core_clk_freq_hz(struct mqnic *dev); uint32_t mqnic_get_clk_freq_hz(struct mqnic *dev, int ch); +uint64_t mqnic_core_clk_cycles_to_ns(struct mqnic *dev, uint64_t cycles); +uint64_t mqnic_core_clk_ns_to_cycles(struct mqnic *dev, uint64_t ns); +uint64_t mqnic_ref_clk_cycles_to_ns(struct mqnic *dev, uint64_t cycles); +uint64_t mqnic_ref_clk_ns_to_cycles(struct mqnic *dev, uint64_t ns); // mqnic_stats.c void mqnic_stats_init(struct mqnic *dev); diff --git a/lib/mqnic/mqnic_clk_info.c b/lib/mqnic/mqnic_clk_info.c index 76421e2f4..b9c193da6 100644 --- a/lib/mqnic/mqnic_clk_info.c +++ b/lib/mqnic/mqnic_clk_info.c @@ -80,3 +80,35 @@ uint32_t mqnic_get_clk_freq_hz(struct mqnic *dev, int ch) return mqnic_reg_read32(dev->clk_info_rb->regs, MQNIC_RB_CLK_INFO_FREQ_BASE + ch*4); } + +uint64_t mqnic_core_clk_cycles_to_ns(struct mqnic *dev, uint64_t cycles) +{ + if (!dev->clk_info_rb || !dev->core_clk_nom_per_ns_denom) + return 0; + + return (cycles * (uint64_t)dev->core_clk_nom_per_ns_num) / (uint64_t)dev->core_clk_nom_per_ns_denom; +} + +uint64_t mqnic_core_clk_ns_to_cycles(struct mqnic *dev, uint64_t ns) +{ + if (!dev->clk_info_rb || !dev->core_clk_nom_per_ns_num) + return 0; + + return (ns * (uint64_t)dev->core_clk_nom_per_ns_denom) / (uint64_t)dev->core_clk_nom_per_ns_num; +} + +uint64_t mqnic_ref_clk_cycles_to_ns(struct mqnic *dev, uint64_t cycles) +{ + if (!dev->clk_info_rb || !dev->ref_clk_nom_per_ns_denom) + return 0; + + return (cycles * (uint64_t)dev->ref_clk_nom_per_ns_num) / (uint64_t)dev->ref_clk_nom_per_ns_denom; +} + +uint64_t mqnic_ref_clk_ns_to_cycles(struct mqnic *dev, uint64_t ns) +{ + if (!dev->clk_info_rb || !dev->ref_clk_nom_per_ns_num) + return 0; + + return (ns * (uint64_t)dev->ref_clk_nom_per_ns_denom) / (uint64_t)dev->ref_clk_nom_per_ns_num; +}