net/sfc: support statistics reset
authorIvan Malov <ivan.malov@oktetlabs.ru>
Fri, 3 Mar 2017 12:49:25 +0000 (12:49 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 13:52:52 +0000 (15:52 +0200)
Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_port.c

index 8c6c02f..655328f 100644 (file)
@@ -153,6 +153,7 @@ struct sfc_port {
        rte_spinlock_t                  mac_stats_lock;
        uint64_t                        *mac_stats_buf;
        efsys_mem_t                     mac_stats_dma_mem;
+       boolean_t                       mac_stats_reset_pending;
 
        uint32_t                mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES];
 };
@@ -281,6 +282,7 @@ 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);
+int sfc_port_reset_mac_stats(struct sfc_adapter *sa);
 int sfc_set_rx_mode(struct sfc_adapter *sa);
 
 
index 71587fb..cac01ac 100644 (file)
@@ -525,6 +525,27 @@ unlock:
        rte_spinlock_unlock(&port->mac_stats_lock);
 }
 
+static void
+sfc_stats_reset(struct rte_eth_dev *dev)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
+       int rc;
+
+       if (sa->state != SFC_ADAPTER_STARTED) {
+               /*
+                * The operation cannot be done if port is not started; it
+                * will be scheduled to be done during the next port start
+                */
+               port->mac_stats_reset_pending = B_TRUE;
+               return;
+       }
+
+       rc = sfc_port_reset_mac_stats(sa);
+       if (rc != 0)
+               sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
+}
+
 static int
 sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
               unsigned int xstats_count)
@@ -1200,7 +1221,9 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
        .allmulticast_disable           = sfc_dev_allmulti_disable,
        .link_update                    = sfc_dev_link_update,
        .stats_get                      = sfc_stats_get,
+       .stats_reset                    = sfc_stats_reset,
        .xstats_get                     = sfc_xstats_get,
+       .xstats_reset                   = sfc_stats_reset,
        .xstats_get_names               = sfc_xstats_get_names,
        .dev_infos_get                  = sfc_dev_infos_get,
        .dev_supported_ptypes_get       = sfc_dev_supported_ptypes_get,
index 5998a99..e2f5043 100644 (file)
@@ -61,6 +61,19 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa)
        return 0;
 }
 
+int
+sfc_port_reset_mac_stats(struct sfc_adapter *sa)
+{
+       struct sfc_port *port = &sa->port;
+       int rc;
+
+       rte_spinlock_lock(&port->mac_stats_lock);
+       rc = efx_mac_stats_clear(sa->nic);
+       rte_spinlock_unlock(&port->mac_stats_lock);
+
+       return rc;
+}
+
 static int
 sfc_port_init_dev_link(struct sfc_adapter *sa)
 {
@@ -140,6 +153,15 @@ sfc_port_start(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_mac_filter_set;
 
+       if (port->mac_stats_reset_pending) {
+               rc = sfc_port_reset_mac_stats(sa);
+               if (rc != 0)
+                       sfc_err(sa, "statistics reset failed (requested "
+                                   "before the port was started)");
+
+               port->mac_stats_reset_pending = B_FALSE;
+       }
+
        efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask,
                               sizeof(port->mac_stats_mask));
 
@@ -237,6 +259,8 @@ sfc_port_init(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_mac_stats_dma_alloc;
 
+       port->mac_stats_reset_pending = B_FALSE;
+
        sfc_log_init(sa, "done");
        return 0;