From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 15E6446027; Thu, 9 Jan 2025 05:04:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29A3840E49; Thu, 9 Jan 2025 05:03:59 +0100 (CET) Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by mails.dpdk.org (Postfix) with ESMTP id 2670540E21 for ; Thu, 9 Jan 2025 05:03:55 +0100 (CET) X-QQ-mid: bizesmtp84t1736395430tf2n98jj X-QQ-Originating-IP: F3JnUVE5LJ4x3TdvMX8geKYHyKzvrM2tNuZqCacMLEg= Received: from DSK-zaiyuwang.trustnetic.com ( [218.72.126.41]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 09 Jan 2025 12:03:49 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1667985426445252396 From: Zaiyu Wang To: dev@dpdk.org Cc: Zaiyu Wang , Jiawen Wu Subject: [PATCH 11/15] net/ngbe: add stats and xstats ops for VF device Date: Thu, 9 Jan 2025 12:02:21 +0800 Message-Id: <20250109040227.1016-12-zaiyuwang@trustnetic.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20250109040227.1016-1-zaiyuwang@trustnetic.com> References: <20250109040227.1016-1-zaiyuwang@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvrgz:qybglogicsvrgz5a-1 X-QQ-XMAILINFO: OezICTd8VoKrNZbaAbJJ1dXMBthDrkdFHWLFdUA3bBhOSe1jFhzpTGHJ H3nDgi26tcEaH0Ut7vfWWuHLSOYFxytSp489BoeL3Oa450YYjY4eDnZwT0vF9C/+37OI1ia QyrQSIgniz3Fqmn+AWJeBezI7ZjdVV2zIv7hi/13eYb3W3ch31ISPVLRIkRmpM4LLNk70fk x7c3FQvD3f7kPpdZaYt5xkr94qu3lvR/WOWA2En3Q5ViCe7/2VnvzqHSvXqQqenYwMuXLN6 gOjGLMW9/3Eee9cUqEi9wmUWDPUY61OPzV1anwXC9+ttKATvVr0fIyUKV9DvVS0HozUy8tp eG1JErTC3or8YlPettYePHwqNnnqOG8428tbQT+enLyshN2rLU0uOu/2KM4a9fXNHCdDbti iMjnOLmOfoRgEEVOui5FL5xWvQA8KavsajYO8zJPkim+LjY9Wmsbu0U8DDq5pmQ224wvehm AZNWo0wsmaWw7jm3Na6n39/LIOwTtMszBzi8Ysw7vLtyRHgDHdZED+6Xh36FAIM72sXBu93 m0P32PRdsbAvIZKnVCZpPhL0knme+VsSxFAD+MjhboBDKq8kVJ+hac6gAoRZg6cY/vFyl9T C3GjfiIGnTBJP+K7HF1uD2H4rXyMqFLuQwb1zqfFZpZqG4WXpinx73n6y3hftVxF5dxXL9p 2u4RcjH3sHD4MW+oQ0AG0G+KG/gHMqjYrOuQAld/CxthHrpjLRDNg0AFmlb+yuCTw7XVJe9 6tsOTWq47bC3XcXpZbkUNGvfqbh5R1EKYGhmmXehMUJL/jMvI/mnchPmfMGAcyqreCJ9HWm fBdCMc9hTV25F70cErJyV1NidJ1j1HPjY72VYdVa3XAQHdJEUSlanYIW9rpAUvvLzI+F9j/ TmcdDDa23Yu9WDyHYMhinNAzd2/DvREVJF6And+KjcqHmvrYivEquRzh2U0mmY97iGbCy98 KFx9C11VtFLE4DCKin6IEoLWXKlTXYmxIJWrAqCmaCG1fywg9RAipjW1Xde5Tnt7bkzEjab 63WpzO5fxpWLerWcmweptVVaaaHTDaRsJODiP+cA== X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= X-QQ-RECHKSPAM: 0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add support to get stats and extended stats by reading hardware registers Signed-off-by: Zaiyu Wang --- doc/guides/nics/features/ngbe_vf.ini | 2 + drivers/net/ngbe/base/ngbe_vf.h | 32 +++++++ drivers/net/ngbe/ngbe_ethdev_vf.c | 137 +++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) diff --git a/doc/guides/nics/features/ngbe_vf.ini b/doc/guides/nics/features/ngbe_vf.ini index b5c4981195..0c26db73f9 100644 --- a/doc/guides/nics/features/ngbe_vf.ini +++ b/doc/guides/nics/features/ngbe_vf.ini @@ -24,6 +24,8 @@ Rx descriptor status = Y Tx descriptor status = Y Inner L3 checksum = P Inner L4 checksum = P +Basic stats = Y +Extended stats = Y Multiprocess aware = Y Linux = Y ARMv8 = Y diff --git a/drivers/net/ngbe/base/ngbe_vf.h b/drivers/net/ngbe/base/ngbe_vf.h index 5cf225dd35..abe1655f8e 100644 --- a/drivers/net/ngbe/base/ngbe_vf.h +++ b/drivers/net/ngbe/base/ngbe_vf.h @@ -11,6 +11,38 @@ #define NGBE_VF_MAX_TX_QUEUES 1 #define NGBE_VF_MAX_RX_QUEUES 1 +struct ngbevf_hw_stats { + u64 base_vfgprc; + u64 base_vfgptc; + u64 base_vfgorc; + u64 base_vfgotc; + u64 base_vfmprc; + + u64 last_vfgprc; + u64 last_vfgptc; + u64 last_vfgorc; + u64 last_vfgotc; + u64 last_vfmprc; + u64 last_vfbprc; + u64 last_vfmptc; + u64 last_vfbptc; + + u64 vfgprc; + u64 vfgptc; + u64 vfgorc; + u64 vfgotc; + u64 vfmprc; + u64 vfbprc; + u64 vfmptc; + u64 vfbptc; + + u64 saved_reset_vfgprc; + u64 saved_reset_vfgptc; + u64 saved_reset_vfgorc; + u64 saved_reset_vfgotc; + u64 saved_reset_vfmprc; +}; + s32 ngbe_init_ops_vf(struct ngbe_hw *hw); s32 ngbe_init_hw_vf(struct ngbe_hw *hw); s32 ngbe_start_hw_vf(struct ngbe_hw *hw); diff --git a/drivers/net/ngbe/ngbe_ethdev_vf.c b/drivers/net/ngbe/ngbe_ethdev_vf.c index 1f3f957d8a..434776b26b 100644 --- a/drivers/net/ngbe/ngbe_ethdev_vf.c +++ b/drivers/net/ngbe/ngbe_ethdev_vf.c @@ -67,6 +67,13 @@ static const struct rte_eth_desc_lim tx_desc_lim = { static const struct eth_dev_ops ngbevf_eth_dev_ops; +static const struct rte_ngbe_xstats_name_off rte_ngbevf_stats_strings[] = { + {"rx_multicast_packets", offsetof(struct ngbevf_hw_stats, vfmprc)}, +}; + +#define NGBEVF_NB_XSTATS (sizeof(rte_ngbevf_stats_strings) / \ + sizeof(rte_ngbevf_stats_strings[0])) + /* * Negotiate mailbox API version with the PF. * After reset API version is always set to the basic one (ngbe_mbox_api_10). @@ -182,6 +189,9 @@ eth_ngbevf_dev_init(struct rte_eth_dev *eth_dev) /* init_mailbox_params */ hw->mbx.init_params(hw); + /* Reset the hw statistics */ + ngbevf_dev_stats_reset(eth_dev); + /* Disable the interrupts for VF */ ngbevf_intr_disable(eth_dev); @@ -301,6 +311,128 @@ static struct rte_pci_driver rte_ngbevf_pmd = { .remove = eth_ngbevf_pci_remove, }; +static int ngbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, unsigned int limit) +{ + unsigned int i; + + if (limit < NGBEVF_NB_XSTATS && xstats_names != NULL) + return -ENOMEM; + + if (xstats_names != NULL) + for (i = 0; i < NGBEVF_NB_XSTATS; i++) + snprintf(xstats_names[i].name, + sizeof(xstats_names[i].name), + "%s", rte_ngbevf_stats_strings[i].name); + return NGBEVF_NB_XSTATS; +} + +static void +ngbevf_update_stats(struct rte_eth_dev *dev) +{ + struct ngbe_hw *hw = ngbe_dev_hw(dev); + struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *) + NGBE_DEV_STATS(dev); + + /* Good Rx packet, include VF loopback */ + NGBE_UPDCNT32(NGBE_QPRXPKT(0), + hw_stats->last_vfgprc, hw_stats->vfgprc); + + /* Good Rx octets, include VF loopback */ + NGBE_UPDCNT36(NGBE_QPRXOCTL(0), + hw_stats->last_vfgorc, hw_stats->vfgorc); + + /* Rx Multicst Packet */ + NGBE_UPDCNT32(NGBE_QPRXMPKT(0), + hw_stats->last_vfmprc, hw_stats->vfmprc); + + /* Rx Broadcast Packet */ + NGBE_UPDCNT32(NGBE_QPRXBPKT(0), + hw_stats->last_vfbprc, hw_stats->vfbprc); + + hw->rx_loaded = 0; + + /* Good Tx packet, include VF loopback */ + NGBE_UPDCNT32(NGBE_QPTXPKT(0), + hw_stats->last_vfgptc, hw_stats->vfgptc); + + /* Good Tx octets, include VF loopback */ + NGBE_UPDCNT36(NGBE_QPTXOCTL(0), + hw_stats->last_vfgotc, hw_stats->vfgotc); + + /* Tx Multicst Packet */ + NGBE_UPDCNT32(NGBE_QPTXMPKT(0), + hw_stats->last_vfmprc, hw_stats->vfmprc); + + /* Tx Broadcast Packet */ + NGBE_UPDCNT32(NGBE_QPTXBPKT(0), + hw_stats->last_vfbptc, hw_stats->vfbptc); + + hw->offset_loaded = 0; +} + +static int +ngbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, + unsigned int n) +{ + struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *) + NGBE_DEV_STATS(dev); + unsigned int i; + + if (n < NGBEVF_NB_XSTATS) + return NGBEVF_NB_XSTATS; + + ngbevf_update_stats(dev); + + if (!xstats) + return 0; + + /* Extended stats */ + for (i = 0; i < NGBEVF_NB_XSTATS; i++) { + xstats[i].id = i; + xstats[i].value = *(uint64_t *)(((char *)hw_stats) + + rte_ngbevf_stats_strings[i].offset); + } + + return NGBEVF_NB_XSTATS; +} + +static int +ngbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *) + NGBE_DEV_STATS(dev); + + ngbevf_update_stats(dev); + + if (stats == NULL) + return -EINVAL; + + stats->ipackets = hw_stats->vfgprc; + stats->ibytes = hw_stats->vfgorc; + stats->opackets = hw_stats->vfgptc; + stats->obytes = hw_stats->vfgotc; + return 0; +} + +static int +ngbevf_dev_stats_reset(struct rte_eth_dev *dev) +{ + struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *) + NGBE_DEV_STATS(dev); + + /* Sync HW register to the last stats */ + ngbevf_dev_stats_get(dev, NULL); + + /* reset HW current stats*/ + hw_stats->vfgprc = 0; + hw_stats->vfgorc = 0; + hw_stats->vfgptc = 0; + hw_stats->vfgotc = 0; + + return 0; +} + static int ngbevf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) @@ -947,6 +1079,11 @@ ngbevf_dev_interrupt_handler(void *param) static const struct eth_dev_ops ngbevf_eth_dev_ops = { .dev_configure = ngbevf_dev_configure, .link_update = ngbevf_dev_link_update, + .stats_get = ngbevf_dev_stats_get, + .xstats_get = ngbevf_dev_xstats_get, + .stats_reset = ngbevf_dev_stats_reset, + .xstats_reset = ngbevf_dev_stats_reset, + .xstats_get_names = ngbevf_dev_xstats_get_names, .promiscuous_enable = ngbevf_dev_promiscuous_enable, .promiscuous_disable = ngbevf_dev_promiscuous_disable, .allmulticast_enable = ngbevf_dev_allmulticast_enable, -- 2.21.0.windows.1