From 979b7b6030a355cd5bee889c203368b491d61622 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Wed, 23 Nov 2022 17:49:38 -0800 Subject: [PATCH] modules/mqnic: Add statistics counter read support to mqnic kernel module Signed-off-by: Alex Forencich --- modules/mqnic/Makefile | 1 + modules/mqnic/mqnic.h | 10 ++++++ modules/mqnic/mqnic_main.c | 1 + modules/mqnic/mqnic_stats.c | 63 +++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 modules/mqnic/mqnic_stats.c diff --git a/modules/mqnic/Makefile b/modules/mqnic/Makefile index 664f54b4d..b2efcae7d 100644 --- a/modules/mqnic/Makefile +++ b/modules/mqnic/Makefile @@ -15,6 +15,7 @@ mqnic-y += mqnic_ptp.o mqnic-y += mqnic_i2c.o mqnic-y += mqnic_board.o mqnic-y += mqnic_clk_info.o +mqnic-y += mqnic_stats.o mqnic-y += mqnic_tx.o mqnic-y += mqnic_rx.o mqnic-y += mqnic_cq.o diff --git a/modules/mqnic/mqnic.h b/modules/mqnic/mqnic.h index fa5a34704..3884f5379 100644 --- a/modules/mqnic/mqnic.h +++ b/modules/mqnic/mqnic.h @@ -168,6 +168,7 @@ struct mqnic_dev { struct mqnic_reg_block *rb_list; struct mqnic_reg_block *fw_id_rb; struct mqnic_reg_block *if_rb; + struct mqnic_reg_block *stats_rb; struct mqnic_reg_block *clk_info_rb; struct mqnic_reg_block *phc_rb; @@ -185,6 +186,11 @@ struct mqnic_dev { u32 app_id; + u32 stats_offset; + u32 stats_count; + u32 stats_stride; + u32 stats_flags; + u32 core_clk_nom_per_ns_num; u32 core_clk_nom_per_ns_denom; u32 core_clk_nom_freq_hz; @@ -581,6 +587,10 @@ 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); +// mqnic_stats.c +void mqnic_stats_init(struct mqnic_dev *mdev); +u64 mqnic_stats_read(struct mqnic_dev *mdev, int index); + // mqnic_eq.c int mqnic_create_eq_ring(struct mqnic_if *interface, struct mqnic_eq_ring **ring_ptr, int index, u8 __iomem *hw_addr); diff --git a/modules/mqnic/mqnic_main.c b/modules/mqnic/mqnic_main.c index e66b4e3d1..f33a33b8d 100644 --- a/modules/mqnic/mqnic_main.c +++ b/modules/mqnic/mqnic_main.c @@ -334,6 +334,7 @@ static int mqnic_common_probe(struct mqnic_dev *mqnic) } mqnic_clk_info_init(mqnic); + mqnic_stats_init(mqnic); mqnic->phc_rb = mqnic_find_reg_block(mqnic->rb_list, MQNIC_RB_PHC_TYPE, MQNIC_RB_PHC_VER, 0); diff --git a/modules/mqnic/mqnic_stats.c b/modules/mqnic/mqnic_stats.c new file mode 100644 index 000000000..27d163178 --- /dev/null +++ b/modules/mqnic/mqnic_stats.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: BSD-2-Clause-Views +/* + * Copyright 2022, The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * official policies, either expressed or implied, of The Regents of the + * University of California. + */ + +#include "mqnic.h" + +void mqnic_stats_init(struct mqnic_dev *mdev) +{ + mdev->stats_rb = mqnic_find_reg_block(mdev->rb_list, MQNIC_RB_STATS_TYPE, MQNIC_RB_STATS_VER, 0); + + if (!mdev->stats_rb) + return; + + mdev->stats_offset = ioread32(mdev->stats_rb->regs + MQNIC_RB_STATS_REG_OFFSET); + mdev->stats_count = ioread32(mdev->stats_rb->regs + MQNIC_RB_STATS_REG_COUNT); + mdev->stats_stride = ioread32(mdev->stats_rb->regs + MQNIC_RB_STATS_REG_STRIDE); + mdev->stats_flags = ioread32(mdev->stats_rb->regs + MQNIC_RB_STATS_REG_FLAGS); +} + +u64 mqnic_stats_read(struct mqnic_dev *mdev, int index) +{ + u64 val; + + if (!mdev->stats_rb || index < 0 || index >= mdev->stats_count) + return 0; + + val = (u64)ioread32(mdev->hw_addr + mdev->stats_offset + index*8 + 0); + val |= (u64)ioread32(mdev->hw_addr + mdev->stats_offset + index*8 + 4) << 32; + + return val; +} +EXPORT_SYMBOL(mqnic_stats_read);