From: Jiawen Wu <jiawenwu@trustnetic.com>
To: netdev@vger.kernel.org
Cc: Mengyuan Lou <mengyuanlou@net-swift.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Russell King <linux@armlinux.org.uk>,
Simon Horman <horms@kernel.org>,
Michal Swiatkowski <michal.swiatkowski@linux.intel.com>,
Jacob Keller <jacob.e.keller@intel.com>,
Kees Cook <kees@kernel.org>, Joe Damato <joe@dama.to>,
Larysa Zaremba <larysa.zaremba@intel.com>,
Abdun Nihaal <abdun.nihaal@gmail.com>,
Breno Leitao <leitao@debian.org>,
Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH net-next v7 8/9] net: libwx: wrap-around and reset qmprc counter
Date: Tue, 7 Apr 2026 10:56:15 +0800 [thread overview]
Message-ID: <20260407025616.33652-9-jiawenwu@trustnetic.com> (raw)
In-Reply-To: <20260407025616.33652-1-jiawenwu@trustnetic.com>
The WX_PX_MPRC registers are not clear-on-read hardware counters. The
previous implementation directly read and accumulated these 32-bit values
into a 64-bit software counter. Now implement a rd32_wrap() helper
function to calculate the delta counter to correct the statistic.
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
drivers/net/ethernet/wangxun/libwx/wx_hw.c | 10 ++++++----
drivers/net/ethernet/wangxun/libwx/wx_type.h | 17 +++++++++++++++++
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
index 31259f69c0e2..57d6671ec618 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c
@@ -2915,11 +2915,10 @@ void wx_update_stats(struct wx *wx)
hwstats->fdirmiss += rd32(wx, WX_RDB_FDIR_MISS);
}
- /* qmprc is not cleared on read, manual reset it */
- hwstats->qmprc = 0;
for (i = wx->num_vfs * wx->num_rx_queues_per_pool;
i < wx->mac.max_rx_queues; i++)
- hwstats->qmprc += rd32(wx, WX_PX_MPRC(i));
+ hwstats->qmprc += rd32_wrap(wx, WX_PX_MPRC(i),
+ &wx->last_stats.qmprc[i]);
spin_unlock(&wx->hw_stats_lock);
}
@@ -2936,8 +2935,11 @@ void wx_clear_hw_cntrs(struct wx *wx)
{
u16 i = 0;
- for (i = 0; i < wx->mac.max_rx_queues; i++)
+ for (i = wx->num_vfs * wx->num_rx_queues_per_pool;
+ i < wx->mac.max_rx_queues; i++) {
wr32(wx, WX_PX_MPRC(i), 0);
+ wx->last_stats.qmprc[i] = 0;
+ }
rd32(wx, WX_RDM_PKT_CNT);
rd32(wx, WX_TDM_PKT_CNT);
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h
index 7831c5035be8..3c5a351974dd 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
@@ -1182,6 +1182,10 @@ struct wx_hw_stats {
u64 fdirmiss;
};
+struct wx_last_stats {
+ u32 qmprc[128];
+};
+
enum wx_state {
WX_STATE_RESETTING,
WX_STATE_SWFW_BUSY,
@@ -1354,6 +1358,7 @@ struct wx {
bool default_up;
struct wx_hw_stats stats;
+ struct wx_last_stats last_stats;
spinlock_t hw_stats_lock; /* spinlock for accessing to hw stats */
u64 tx_busy;
u64 non_eop_descs;
@@ -1464,6 +1469,18 @@ wr32ptp(struct wx *wx, u32 reg, u32 value)
return wr32(wx, reg + 0xB500, value);
}
+static inline u32
+rd32_wrap(struct wx *wx, u32 reg, u32 *last)
+{
+ u32 val, delta;
+
+ val = rd32(wx, reg);
+ delta = val - *last;
+ *last = val;
+
+ return delta;
+}
+
/* On some domestic CPU platforms, sometimes IO is not synchronized with
* flushing memory, here use readl() to flush PCI read and write.
*/
--
2.48.1
next prev parent reply other threads:[~2026-04-07 2:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 2:56 [PATCH net-next v7 0/9] Wangxun improvement Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 1/9] net: ngbe: remove netdev->ethtool->wol_enabled setting Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 2/9] net: ngbe: move the WOL functions to libwx Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 3/9] net: ngbe: remove redundant macros Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 4/9] net: wangxun: replace busy-wait reset flag with kernel mutex Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 5/9] net: wangxun: move ethtool_ops.set_channels into libwx Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 6/9] net: wangxun: reorder timer and work sync cancellations Jiawen Wu
2026-04-07 2:56 ` [PATCH net-next v7 7/9] net: wangxun: schedule hardware stats update in watchdog Jiawen Wu
2026-04-07 2:56 ` Jiawen Wu [this message]
2026-04-07 2:56 ` [PATCH net-next v7 9/9] net: libwx: improve flow control setting Jiawen Wu
2026-04-12 15:50 ` [PATCH net-next v7 0/9] Wangxun improvement patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260407025616.33652-9-jiawenwu@trustnetic.com \
--to=jiawenwu@trustnetic.com \
--cc=abdun.nihaal@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=joe@dama.to \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=larysa.zaremba@intel.com \
--cc=leitao@debian.org \
--cc=linux@armlinux.org.uk \
--cc=mengyuanlou@net-swift.com \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox