From patchwork Sat Jul 8 15:45:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Rybchenko X-Patchwork-Id: 26654 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 6B54A235; Sat, 8 Jul 2017 17:45:30 +0200 (CEST) Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 73A6220F for ; Sat, 8 Jul 2017 17:45:29 +0200 (CEST) Received: from pure.maildistiller.com (unknown [10.110.50.29]) by dispatch1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTP id ECFAB80055; Sat, 8 Jul 2017 15:45:27 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from mx4-us4.ppe-hosted.com (unknown [10.110.49.251]) by pure.maildistiller.com (Proofpoint Essentials ESMTP Server) with ESMTPS id DC3E28004F; Sat, 8 Jul 2017 15:45:25 +0000 (UTC) Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx4-us4.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id BAEAD60060; Sat, 8 Jul 2017 15:45:25 +0000 (UTC) Received: from ocex03.SolarFlarecom.com (10.20.40.36) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Sat, 8 Jul 2017 08:45:22 -0700 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25 via Frontend Transport; Sat, 8 Jul 2017 08:45:22 -0700 Received: from uklogin.uk.solarflarecom.com (uklogin.uk.solarflarecom.com [10.17.10.10]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id v68FjHtJ032120; Sat, 8 Jul 2017 16:45:21 +0100 Received: from uklogin.uk.solarflarecom.com (localhost.localdomain [127.0.0.1]) by uklogin.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id v68FjHpJ001544; Sat, 8 Jul 2017 16:45:17 +0100 From: Andrew Rybchenko To: CC: Ivan Malov Date: Sat, 8 Jul 2017 16:45:15 +0100 Message-ID: <1499528715-1510-1-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 MIME-Version: 1.0 X-MDID: 1499528727-83S7AKph1gHd Subject: [dpdk-dev] [PATCH] net/sfc: add support for xstats retrieval by ID X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ivan Malov Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko Reviewed-by: Remy Horton --- drivers/net/sfc/sfc.h | 1 + drivers/net/sfc/sfc_ethdev.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ drivers/net/sfc/sfc_port.c | 5 +++ 3 files changed, 87 insertions(+) diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index d287413..6d2a6e5 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -164,6 +164,7 @@ struct sfc_port { rte_spinlock_t mac_stats_lock; uint64_t *mac_stats_buf; + unsigned int mac_stats_nb_supported; efsys_mem_t mac_stats_dma_mem; boolean_t mac_stats_reset_pending; uint16_t mac_stats_update_period_ms; diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 6b06f08..12bcd6f 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -666,6 +666,85 @@ sfc_xstats_get_names(struct rte_eth_dev *dev, } static int +sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, + uint64_t *values, unsigned int n) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + uint64_t *mac_stats; + unsigned int nb_supported = 0; + unsigned int nb_written = 0; + unsigned int i; + int ret; + int rc; + + if (unlikely(values == NULL) || + unlikely((ids == NULL) && (n < port->mac_stats_nb_supported))) + return port->mac_stats_nb_supported; + + rte_spinlock_lock(&port->mac_stats_lock); + + rc = sfc_port_update_mac_stats(sa); + if (rc != 0) { + SFC_ASSERT(rc > 0); + ret = -rc; + goto unlock; + } + + mac_stats = port->mac_stats_buf; + + for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) { + if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) + continue; + + if ((ids == NULL) || (ids[nb_written] == nb_supported)) + values[nb_written++] = mac_stats[i]; + + ++nb_supported; + } + + ret = nb_written; + +unlock: + rte_spinlock_unlock(&port->mac_stats_lock); + + return ret; +} + +static int +sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, + const uint64_t *ids, unsigned int size) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + unsigned int nb_supported = 0; + unsigned int nb_written = 0; + unsigned int i; + + if (unlikely(xstats_names == NULL) || + unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) + return port->mac_stats_nb_supported; + + for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) { + if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) + continue; + + if ((ids == NULL) || (ids[nb_written] == nb_supported)) { + char *name = xstats_names[nb_written++].name; + + strncpy(name, efx_mac_stat_name(sa->nic, i), + sizeof(xstats_names[0].name)); + name[sizeof(xstats_names[0].name) - 1] = '\0'; + } + + ++nb_supported; + } + + return nb_written; +} + +static int sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) { struct sfc_adapter *sa = dev->data->dev_private; @@ -1406,6 +1485,8 @@ static const struct eth_dev_ops sfc_eth_dev_ops = { .rxq_info_get = sfc_rx_queue_info_get, .txq_info_get = sfc_tx_queue_info_get, .fw_version_get = sfc_fw_version_get, + .xstats_get_by_id = sfc_xstats_get_by_id, + .xstats_get_names_by_id = sfc_xstats_get_names_by_id, }; /** diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index e7eea9f..5bd7fad 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -151,6 +151,7 @@ sfc_port_start(struct sfc_adapter *sa) uint32_t phy_adv_cap; const uint32_t phy_pause_caps = ((1u << EFX_PHY_CAP_PAUSE) | (1u << EFX_PHY_CAP_ASYM)); + unsigned int i; sfc_log_init(sa, "entry"); @@ -222,6 +223,10 @@ sfc_port_start(struct sfc_adapter *sa) efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask, sizeof(port->mac_stats_mask)); + for (i = 0, port->mac_stats_nb_supported = 0; i < EFX_MAC_NSTATS; ++i) + if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) + port->mac_stats_nb_supported++; + port->mac_stats_update_generation = 0; if (port->mac_stats_update_period_ms != 0) {