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 5B883A00C2; Mon, 23 May 2022 18:12:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0A2C442B81; Mon, 23 May 2022 18:11:33 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 062AD4280B for ; Mon, 23 May 2022 18:11:31 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24NAvL82020425 for ; Mon, 23 May 2022 09:11:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=WRK71imUJqtV8MoDM64xYjMofiiJ2L8Jafm+mAwcy/E=; b=Rnl7yZK8e2aMeQjthPX19yOjcptUK4dpNBti3kHGYaqNOck27xrmj0Cd9q2lnsK85n34 j0SfZNTnRVqsLUovJBE3Nl8AfPZmmA6FWV6NCiRaiKX8wv+ULNpkN6jOogB/duVel+SY 6YNjjLhlwGbQMqApsA19Ia6cR5NkYckMpCAIEr6dN/YVyaBykLFN0qRkAM0+ZHvJCAiO My+wvjrn0ofaaN3FU5PSI5yuNyZ33ujYBn7LfxONsrmfA0dZHVsoKbq6OtdcCT4H1lPc HaFYq6TtWgaAqqIpbLQJIxO+QeCXAsdE9QnGI4mJJhFHqQEjIUDhch4wGwLUrFkOKFfu bg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3g6wepetak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 23 May 2022 09:11:31 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 May 2022 09:11:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 23 May 2022 09:11:29 -0700 Received: from localhost.localdomain (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id ADE8D3F70A5; Mon, 23 May 2022 09:11:28 -0700 (PDT) From: Harman Kalra To: , Harman Kalra Subject: [PATCH v2 08/11] net/octeontx: implement xstats Date: Mon, 23 May 2022 21:40:57 +0530 Message-ID: <20220523161100.86280-8-hkalra@marvell.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220523161100.86280-1-hkalra@marvell.com> References: <20220517173941.189330-2-hkalra@marvell.com> <20220523161100.86280-1-hkalra@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: Dc6pv7qw4BGA7-F7u0FCvRBFBZnUN288 X-Proofpoint-ORIG-GUID: Dc6pv7qw4BGA7-F7u0FCvRBFBZnUN288 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-23_07,2022-05-23_01,2022-02-23_01 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 Adding support for xstats eth operations. Signed-off-by: Harman Kalra --- drivers/net/octeontx/base/octeontx_bgx.c | 17 +++ drivers/net/octeontx/base/octeontx_bgx.h | 3 + drivers/net/octeontx/octeontx_ethdev.c | 126 +++++++++++++++++++++++ drivers/net/octeontx/octeontx_stats.h | 41 ++++++++ 4 files changed, 187 insertions(+) create mode 100644 drivers/net/octeontx/octeontx_stats.h diff --git a/drivers/net/octeontx/base/octeontx_bgx.c b/drivers/net/octeontx/base/octeontx_bgx.c index 1c6fa05ebc..81a8cbecaf 100644 --- a/drivers/net/octeontx/base/octeontx_bgx.c +++ b/drivers/net/octeontx/base/octeontx_bgx.c @@ -144,6 +144,23 @@ octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat) return res; } +int +octeontx_bgx_port_xstats(int port, octeontx_mbox_bgx_port_stats_t *stats) +{ + struct octeontx_mbox_hdr hdr; + int len = sizeof(octeontx_mbox_bgx_port_stats_t); + int res; + + hdr.coproc = OCTEONTX_BGX_COPROC; + hdr.msg = MBOX_BGX_PORT_GET_STATS; + hdr.vfid = port; + + res = octeontx_mbox_send(&hdr, NULL, 0, stats, len); + if (res < 0) + return -EACCES; + return res; +} + int octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats) { diff --git a/drivers/net/octeontx/base/octeontx_bgx.h b/drivers/net/octeontx/base/octeontx_bgx.h index e4cfa3e73a..c5662202ac 100644 --- a/drivers/net/octeontx/base/octeontx_bgx.h +++ b/drivers/net/octeontx/base/octeontx_bgx.h @@ -117,6 +117,8 @@ typedef struct octeontx_mbox_bgx_port_stats { uint64_t rx_oversize_errors; uint64_t rx_fragmented_errors; uint64_t rx_jabber_errors; + uint64_t rx_pause_packets; + uint64_t tx_pause_packets; } octeontx_mbox_bgx_port_stats_t; struct octeontx_mbox_bgx_port_mac_filter { @@ -161,6 +163,7 @@ int octeontx_bgx_port_get_config(int port, octeontx_mbox_bgx_port_conf_t *conf); int octeontx_bgx_port_status(int port, octeontx_mbox_bgx_port_status_t *stat); int octeontx_bgx_port_stats(int port, octeontx_mbox_bgx_port_stats_t *stats); int octeontx_bgx_port_stats_clr(int port); +int octeontx_bgx_port_xstats(int port, octeontx_mbox_bgx_port_stats_t *stats); int octeontx_bgx_port_link_status(int port); int octeontx_bgx_port_promisc_set(int port, int en); int octeontx_bgx_port_mac_set(int port, uint8_t *mac_addr); diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c index 9351fcb5c7..c15014bdde 100644 --- a/drivers/net/octeontx/octeontx_ethdev.c +++ b/drivers/net/octeontx/octeontx_ethdev.c @@ -25,6 +25,7 @@ #include "octeontx_ethdev.h" #include "octeontx_rxtx.h" #include "octeontx_logs.h" +#include "octeontx_stats.h" /* Useful in stopping/closing event device if no of * eth ports are using it. @@ -846,6 +847,127 @@ octeontx_dev_link_update(struct rte_eth_dev *dev, return rte_eth_linkstatus_set(dev, &link); } +static inline int octeontx_dev_total_xstat(void) +{ + return NUM_BGX_XSTAT; +} + +static int +octeontx_port_xstats(struct octeontx_nic *nic, struct rte_eth_xstat *xstats, + unsigned int n) +{ + octeontx_mbox_bgx_port_stats_t bgx_stats; + int stat_cnt, res, si, i; + + res = octeontx_bgx_port_xstats(nic->port_id, &bgx_stats); + if (res < 0) { + octeontx_log_err("failed to get port stats %d", nic->port_id); + return res; + } + + si = 0; + /* Fill BGX stats */ + stat_cnt = (n > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : n; + n = n - stat_cnt; + for (i = 0; i < stat_cnt; i++) { + xstats[si].id = si; + xstats[si].value = *(uint64_t *)(((char *)&bgx_stats) + + octeontx_bgx_xstats[i].soffset); + si++; + } + /*TODO: Similarly fill rest of HW stats */ + + return si; +} + +static int +octeontx_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, + uint64_t *stat_val, unsigned int n) +{ + unsigned int i, xstat_cnt = octeontx_dev_total_xstat(); + struct octeontx_nic *nic = octeontx_pmd_priv(dev); + struct rte_eth_xstat xstats[xstat_cnt]; + + octeontx_port_xstats(nic, xstats, xstat_cnt); + for (i = 0; i < n; i++) { + if (ids[i] >= xstat_cnt) { + PMD_INIT_LOG(ERR, "out of range id value"); + return -1; + } + stat_val[i] = xstats[ids[i]].value; + } + return n; +} + +static int +octeontx_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused, + struct rte_eth_xstat_name *xstats_names, + unsigned int size) +{ + int stat_cnt, si, i; + + if (xstats_names) { + si = 0; + /* Fill BGX stats */ + stat_cnt = (size > NUM_BGX_XSTAT) ? NUM_BGX_XSTAT : size; + size = size - stat_cnt; + for (i = 0; i < stat_cnt; i++) { + strlcpy(xstats_names[si].name, + octeontx_bgx_xstats[i].sname, + sizeof(xstats_names[si].name)); + si++; + } + /*TODO: Similarly fill rest of HW stats */ + return si; + } else { + return octeontx_dev_total_xstat(); + } +} + +static void build_xstat_names(struct rte_eth_xstat_name *xstat_names) +{ + unsigned int i; + + for (i = 0; i < NUM_BGX_XSTAT; i++) { + strlcpy(xstat_names[i].name, octeontx_bgx_xstats[i].sname, + RTE_ETH_XSTATS_NAME_SIZE); + } +} + +static int +octeontx_dev_xstats_get_names_by_id(struct rte_eth_dev *dev __rte_unused, + const uint64_t *ids, + struct rte_eth_xstat_name *stat_names, + unsigned int n) +{ + unsigned int i, xstat_cnt = octeontx_dev_total_xstat(); + struct rte_eth_xstat_name xstat_names[xstat_cnt]; + + build_xstat_names(xstat_names); + for (i = 0; i < n; i++) { + if (ids[i] >= xstat_cnt) { + PMD_INIT_LOG(ERR, "out of range id value"); + return -1; + } + strlcpy(stat_names[i].name, xstat_names[ids[i]].name, + sizeof(stat_names[i].name)); + } + /*TODO: Similarly fill rest of HW stats */ + + return n; +} + +static int +octeontx_dev_xstats_get(struct rte_eth_dev *dev, + struct rte_eth_xstat *xstats, + unsigned int n) +{ + struct octeontx_nic *nic = octeontx_pmd_priv(dev); + + PMD_INIT_FUNC_TRACE(); + return octeontx_port_xstats(nic, xstats, n); +} + static int octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { @@ -1354,6 +1476,10 @@ static const struct eth_dev_ops octeontx_dev_ops = { .pool_ops_supported = octeontx_pool_ops, .flow_ctrl_get = octeontx_dev_flow_ctrl_get, .flow_ctrl_set = octeontx_dev_flow_ctrl_set, + .xstats_get = octeontx_dev_xstats_get, + .xstats_get_by_id = octeontx_dev_xstats_get_by_id, + .xstats_get_names = octeontx_dev_xstats_get_names, + .xstats_get_names_by_id = octeontx_dev_xstats_get_names_by_id, }; /* Create Ethdev interface per BGX LMAC ports */ diff --git a/drivers/net/octeontx/octeontx_stats.h b/drivers/net/octeontx/octeontx_stats.h new file mode 100644 index 0000000000..95e03a993d --- /dev/null +++ b/drivers/net/octeontx/octeontx_stats.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2017 Cavium, Inc + */ + +#ifndef __OCTEONTX_STATS_H__ +#define __OCTEONTX_STATS_H__ + +#define BGX_XSTAT(stat) \ + {#stat, offsetof(octeontx_mbox_bgx_port_stats_t, stat)} +struct octeontx_xstats { + char sname[RTE_ETH_XSTATS_NAME_SIZE]; + uint32_t soffset; +}; + +struct octeontx_xstats octeontx_bgx_xstats[] = { + BGX_XSTAT(rx_packets), + BGX_XSTAT(tx_packets), + BGX_XSTAT(rx_broadcast_packets), + BGX_XSTAT(multicast), + BGX_XSTAT(tx_multicast_packets), + BGX_XSTAT(tx_broadcast_packets), + BGX_XSTAT(rx_undersized_errors), + BGX_XSTAT(rx_oversize_errors), + BGX_XSTAT(rx_jabber_errors), + BGX_XSTAT(rx_crc_errors), + BGX_XSTAT(collisions), + BGX_XSTAT(tx_1_to_64_packets), + BGX_XSTAT(tx_65_to_127_packets), + BGX_XSTAT(tx_128_to_255_packets), + BGX_XSTAT(tx_256_to_511_packets), + BGX_XSTAT(tx_512_to_1023_packets), + BGX_XSTAT(tx_1024_to_1522_packets), + BGX_XSTAT(tx_1523_to_max_packets), + BGX_XSTAT(rx_fragmented_errors), + BGX_XSTAT(rx_pause_packets), + BGX_XSTAT(tx_pause_packets), +}; + +#define NUM_BGX_XSTAT \ + (sizeof(octeontx_bgx_xstats) / sizeof(struct octeontx_xstats)) +#endif /* __OCTEONTX_STATS_H__ */ -- 2.18.0