From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nbfkord-smmo03.seg.att.com (nbfkord-smmo03.seg.att.com [209.65.160.84]) by dpdk.org (Postfix) with ESMTP id 545BB4CC5 for ; Thu, 15 Dec 2016 13:52:13 +0100 (CET) Received: from unknown [12.187.104.26] (EHLO nbfkord-smmo03.seg.att.com) by nbfkord-smmo03.seg.att.com(mxl_mta-7.2.4-7) with ESMTP id df192585.2b6320a40940.1049156.00-2452.2166151.nbfkord-smmo03.seg.att.com (envelope-from ); Thu, 15 Dec 2016 12:52:13 +0000 (UTC) X-MXL-Hash: 585291fd4692ec2f-646dc98b84c7553a0712cb6eff2eb1d9ef95d472 Received: from unknown [12.187.104.26] by nbfkord-smmo03.seg.att.com(mxl_mta-7.2.4-7) with SMTP id bf192585.0.1049147.00-2344.2166140.nbfkord-smmo03.seg.att.com (envelope-from ); Thu, 15 Dec 2016 12:52:12 +0000 (UTC) X-MXL-Hash: 585291fc366ac0ae-fc80da512c5d01237207034cc46de38a7321c250 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; Thu, 15 Dec 2016 04:52:05 -0800 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; Thu, 15 Dec 2016 04:52:05 -0800 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 uBFCq3NW006349; Thu, 15 Dec 2016 12:52:03 GMT 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 uBFCpcec010431; Thu, 15 Dec 2016 12:52:03 GMT From: Andrew Rybchenko To: CC: Date: Thu, 15 Dec 2016 12:50:54 +0000 Message-ID: <1481806283-10387-4-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1481806283-10387-1-git-send-email-arybchenko@solarflare.com> References: <1480664691-26561-1-git-send-email-arybchenko@solarflare.com> <1481806283-10387-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-AnalysisOut: [v=2.1 cv=HuVwbhnS c=1 sm=1 tr=0 a=8BlWFWvVlq5taO8ncb8nKg==] X-AnalysisOut: [:17 a=n5n_aSjo0skA:10 a=zRKbQ67AAAAA:8 a=ZpSYQmD0NXlPBGYmY] X-AnalysisOut: [kEA:9 a=PA03WX8tBzeizutn5_OT:22] X-Spam: [F=0.3805549990; CM=0.500; S=0.380(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [12.187.104.26] Subject: [dpdk-dev] [PATCH v2 03/32] net/sfc: implement ethdev hook to get basic statistics 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: , X-List-Received-Date: Thu, 15 Dec 2016 12:52:14 -0000 Does not implement any deprecated statistics. No per-queue statistics yet. Signed-off-by: Andrew Rybchenko Reviewed-by: Andrew Lee Reviewed-by: Robert Stonehouse --- doc/guides/nics/features/sfc_efx.ini | 1 + doc/guides/nics/sfc_efx.rst | 2 + drivers/net/sfc/efsys.h | 2 +- drivers/net/sfc/sfc.h | 7 ++++ drivers/net/sfc/sfc_ethdev.c | 69 +++++++++++++++++++++++++++++++++ drivers/net/sfc/sfc_port.c | 75 ++++++++++++++++++++++++++++++++++++ 6 files changed, 155 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/features/sfc_efx.ini b/doc/guides/nics/features/sfc_efx.ini index 67df1c6..f55a988 100644 --- a/doc/guides/nics/features/sfc_efx.ini +++ b/doc/guides/nics/features/sfc_efx.ini @@ -7,6 +7,7 @@ Link status = Y L3 checksum offload = P L4 checksum offload = P +Basic stats = Y BSD nic_uio = Y Linux UIO = Y Linux VFIO = Y diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst index 36d0974..cbb51de 100644 --- a/doc/guides/nics/sfc_efx.rst +++ b/doc/guides/nics/sfc_efx.rst @@ -48,6 +48,8 @@ SFC EFX PMD has support for: - IPv4/IPv6 TCP/UDP transmit checksum offload +- Port hardware statistics + Non-supported Features ---------------------- diff --git a/drivers/net/sfc/efsys.h b/drivers/net/sfc/efsys.h index d48eb4c..fe8615f 100644 --- a/drivers/net/sfc/efsys.h +++ b/drivers/net/sfc/efsys.h @@ -178,7 +178,7 @@ prefetch_read_once(const volatile void *addr) #define EFSYS_OPT_MCDI_LOGGING 1 #define EFSYS_OPT_MCDI_PROXY_AUTH 0 -#define EFSYS_OPT_MAC_STATS 0 +#define EFSYS_OPT_MAC_STATS 1 #define EFSYS_OPT_LOOPBACK 0 diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 00b186f..e9f5183 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -122,6 +122,12 @@ struct sfc_port { unsigned int flow_ctrl; boolean_t flow_ctrl_autoneg; size_t pdu; + + rte_spinlock_t mac_stats_lock; + uint64_t *mac_stats_buf; + efsys_mem_t mac_stats_dma_mem; + + uint32_t mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES]; }; /* Adapter private data */ @@ -235,6 +241,7 @@ int sfc_port_start(struct sfc_adapter *sa); void sfc_port_stop(struct sfc_adapter *sa); void sfc_port_link_mode_to_info(efx_link_mode_t link_mode, struct rte_eth_link *link_info); +int sfc_port_update_mac_stats(struct sfc_adapter *sa); #ifdef __cplusplus diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 1df227e..f31330c 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -324,12 +324,81 @@ sfc_tx_queue_release(void *queue) sfc_adapter_unlock(sa); } +static void +sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + uint64_t *mac_stats; + + rte_spinlock_lock(&port->mac_stats_lock); + + if (sfc_port_update_mac_stats(sa) != 0) + goto unlock; + + mac_stats = port->mac_stats_buf; + + if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, + EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) { + stats->ipackets = + mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] + + mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] + + mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS]; + stats->opackets = + mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] + + mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] + + mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS]; + stats->ibytes = + mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] + + mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] + + mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES]; + stats->obytes = + mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] + + mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] + + mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES]; + stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_OVERFLOW]; + stats->ierrors = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS]; + stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS]; + } else { + stats->ipackets = mac_stats[EFX_MAC_RX_PKTS]; + stats->opackets = mac_stats[EFX_MAC_TX_PKTS]; + stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS]; + stats->obytes = mac_stats[EFX_MAC_TX_OCTETS]; + /* + * Take into account stats which are whenever supported + * on EF10. If some stat is not supported by current + * firmware variant or HW revision, it is guaranteed + * to be zero in mac_stats. + */ + stats->imissed = + mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] + + mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] + + mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] + + mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] + + mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] + + mac_stats[EFX_MAC_PM_TRUNC_QBB] + + mac_stats[EFX_MAC_PM_DISCARD_QBB] + + mac_stats[EFX_MAC_PM_DISCARD_MAPPING] + + mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] + + mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS]; + stats->ierrors = + mac_stats[EFX_MAC_RX_FCS_ERRORS] + + mac_stats[EFX_MAC_RX_ALIGN_ERRORS] + + mac_stats[EFX_MAC_RX_JABBER_PKTS]; + /* no oerrors counters supported on EF10 */ + } + +unlock: + rte_spinlock_unlock(&port->mac_stats_lock); +} + static const struct eth_dev_ops sfc_eth_dev_ops = { .dev_configure = sfc_dev_configure, .dev_start = sfc_dev_start, .dev_stop = sfc_dev_stop, .dev_close = sfc_dev_close, .link_update = sfc_dev_link_update, + .stats_get = sfc_stats_get, .dev_infos_get = sfc_dev_infos_get, .rx_queue_setup = sfc_rx_queue_setup, .rx_queue_release = sfc_rx_queue_release, diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index c124181..d8ff097 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -32,6 +32,34 @@ #include "sfc.h" #include "sfc_log.h" +/** + * Update MAC statistics in the buffer. + * + * @param sa Adapter + * + * @return Status code + * @retval 0 Success + * @retval EAGAIN Try again + * @retval ENOMEM Memory allocation failure + */ +int +sfc_port_update_mac_stats(struct sfc_adapter *sa) +{ + struct sfc_port *port = &sa->port; + int rc; + + SFC_ASSERT(rte_spinlock_is_locked(&port->mac_stats_lock)); + + if (sa->state != SFC_ADAPTER_STARTED) + return EINVAL; + + rc = efx_mac_stats_update(sa->nic, &port->mac_stats_dma_mem, + port->mac_stats_buf, NULL); + if (rc != 0) + return rc; + + return 0; +} int sfc_port_start(struct sfc_adapter *sa) @@ -67,6 +95,19 @@ sfc_port_start(struct sfc_adapter *sa) if (rc != 0) goto fail_mac_filter_set; + efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask, + sizeof(port->mac_stats_mask)); + + /* Update MAC stats using periodic DMA. + * Common code always uses 1000ms update period, so period_ms + * parameter only needs to be non-zero to start updates. + */ + sfc_log_init(sa, "request MAC stats DMA'ing"); + rc = efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem, + 1000, B_FALSE); + if (rc != 0) + goto fail_mac_stats_periodic; + sfc_log_init(sa, "disable MAC drain"); rc = efx_mac_drain(sa->nic, B_FALSE); if (rc != 0) @@ -76,6 +117,10 @@ sfc_port_start(struct sfc_adapter *sa) return 0; fail_mac_drain: + (void)efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem, + 0, B_FALSE); + +fail_mac_stats_periodic: fail_mac_filter_set: fail_mac_addr_set: fail_mac_pdu_set: @@ -95,6 +140,10 @@ sfc_port_stop(struct sfc_adapter *sa) sfc_log_init(sa, "entry"); efx_mac_drain(sa->nic, B_TRUE); + + (void)efx_mac_stats_periodic(sa->nic, &sa->port.mac_stats_dma_mem, + 0, B_FALSE); + efx_port_fini(sa->nic); efx_filter_fini(sa->nic); @@ -106,6 +155,7 @@ sfc_port_init(struct sfc_adapter *sa) { const struct rte_eth_dev_data *dev_data = sa->eth_dev->data; struct sfc_port *port = &sa->port; + int rc; sfc_log_init(sa, "entry"); @@ -118,15 +168,40 @@ sfc_port_init(struct sfc_adapter *sa) else port->pdu = EFX_MAC_PDU(dev_data->mtu); + rte_spinlock_init(&port->mac_stats_lock); + + rc = ENOMEM; + port->mac_stats_buf = rte_calloc_socket("mac_stats_buf", EFX_MAC_NSTATS, + sizeof(uint64_t), 0, + sa->socket_id); + if (port->mac_stats_buf == NULL) + goto fail_mac_stats_buf_alloc; + + rc = sfc_dma_alloc(sa, "mac_stats", 0, EFX_MAC_STATS_SIZE, + sa->socket_id, &port->mac_stats_dma_mem); + if (rc != 0) + goto fail_mac_stats_dma_alloc; + sfc_log_init(sa, "done"); return 0; + +fail_mac_stats_dma_alloc: + rte_free(port->mac_stats_buf); +fail_mac_stats_buf_alloc: + sfc_log_init(sa, "failed %d", rc); + return rc; } void sfc_port_fini(struct sfc_adapter *sa) { + struct sfc_port *port = &sa->port; + sfc_log_init(sa, "entry"); + sfc_dma_free(sa, &port->mac_stats_dma_mem); + rte_free(port->mac_stats_buf); + sfc_log_init(sa, "done"); } -- 2.5.5