net/sfc: add basic statistics
authorAndrew Rybchenko <arybchenko@solarflare.com>
Thu, 15 Dec 2016 12:50:54 +0000 (12:50 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 17 Jan 2017 18:40:50 +0000 (19:40 +0100)
Does not implement any deprecated statistics.
No per-queue statistics yet.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andrew Lee <alee@solarflare.com>
Reviewed-by: Robert Stonehouse <rstonehouse@solarflare.com>
doc/guides/nics/features/sfc_efx.ini
doc/guides/nics/sfc_efx.rst
drivers/net/sfc/efsys.h
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_port.c

index 67df1c6..f55a988 100644 (file)
@@ -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
index 36d0974..cbb51de 100644 (file)
@@ -48,6 +48,8 @@ SFC EFX PMD has support for:
 
 - IPv4/IPv6 TCP/UDP transmit checksum offload
 
+- Port hardware statistics
+
 
 Non-supported Features
 ----------------------
index d48eb4c..fe8615f 100644 (file)
@@ -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
 
index 7e61d0c..913da8c 100644 (file)
@@ -125,6 +125,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 */
@@ -238,6 +244,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
index 77f22f8..3a92cac 100644 (file)
@@ -323,12 +323,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,
index c124181..d8ff097 100644 (file)
 #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");
 }