net/sfc: prepare to add more xstats
authorIvan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Fri, 23 Jul 2021 13:15:13 +0000 (16:15 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Fri, 23 Jul 2021 21:26:45 +0000 (23:26 +0200)
Move getting MAC stats code that involves locking to separate functions
to simplify addition of new xstats.

Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_port.c

index 1594f93..58b8c2c 100644 (file)
@@ -423,6 +423,10 @@ 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, boolean_t manual_update);
+int sfc_port_get_mac_stats(struct sfc_adapter *sa, struct rte_eth_xstat *xstats,
+                          unsigned int xstats_count, unsigned int *nb_written);
+int sfc_port_get_mac_stats_by_id(struct sfc_adapter *sa, const uint64_t *ids,
+                                uint64_t *values, unsigned int n);
 int sfc_port_reset_mac_stats(struct sfc_adapter *sa);
 int sfc_set_rx_mode(struct sfc_adapter *sa);
 int sfc_set_rx_mode_unchecked(struct sfc_adapter *sa);
index f0567a7..dd7e5c2 100644 (file)
@@ -726,41 +726,17 @@ sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 {
        struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
        struct sfc_port *port = &sa->port;
-       uint64_t *mac_stats;
-       int rc;
-       unsigned int i;
-       int nstats = 0;
-
-       sfc_adapter_lock(sa);
+       unsigned int nb_written = 0;
+       unsigned int nb_supp;
 
        if (unlikely(xstats == NULL)) {
-               nstats = port->mac_stats_nb_supported;
-               goto unlock;
-       }
-
-       rc = sfc_port_update_mac_stats(sa, B_FALSE);
-       if (rc != 0) {
-               SFC_ASSERT(rc > 0);
-               nstats = -rc;
-               goto unlock;
-       }
-
-       mac_stats = port->mac_stats_buf;
-
-       for (i = 0; i < EFX_MAC_NSTATS; ++i) {
-               if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
-                       if (nstats < (int)xstats_count) {
-                               xstats[nstats].id = nstats;
-                               xstats[nstats].value = mac_stats[i];
-                       }
-                       nstats++;
-               }
+               sfc_adapter_lock(sa);
+               nb_supp = port->mac_stats_nb_supported;
+               sfc_adapter_unlock(sa);
+               return nb_supp;
        }
 
-unlock:
-       sfc_adapter_unlock(sa);
-
-       return nstats;
+       return sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written);
 }
 
 static int
@@ -798,44 +774,11 @@ sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
                     uint64_t *values, unsigned int n)
 {
        struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
-       struct sfc_port *port = &sa->port;
-       uint64_t *mac_stats;
-       unsigned int i;
-       int ret;
-       int rc;
 
        if (unlikely(ids == NULL || values == NULL))
                return -EINVAL;
 
-       sfc_adapter_lock(sa);
-
-       rc = sfc_port_update_mac_stats(sa, B_FALSE);
-       if (rc != 0) {
-               SFC_ASSERT(rc > 0);
-               ret = -rc;
-               goto unlock;
-       }
-
-       mac_stats = port->mac_stats_buf;
-
-       SFC_ASSERT(port->mac_stats_nb_supported <=
-                  RTE_DIM(port->mac_stats_by_id));
-
-       for (i = 0; i < n; i++) {
-               if (ids[i] < port->mac_stats_nb_supported) {
-                       values[i] = mac_stats[port->mac_stats_by_id[ids[i]]];
-               } else {
-                       ret = i;
-                       goto unlock;
-               }
-       }
-
-       ret = n;
-
-unlock:
-       sfc_adapter_unlock(sa);
-
-       return ret;
+       return sfc_port_get_mac_stats_by_id(sa, ids, values, n);
 }
 
 static int
index 8c432c1..f6689a1 100644 (file)
@@ -636,3 +636,83 @@ sfc_port_link_mode_to_info(efx_link_mode_t link_mode,
 
        link_info->link_autoneg = ETH_LINK_AUTONEG;
 }
+
+int
+sfc_port_get_mac_stats(struct sfc_adapter *sa, struct rte_eth_xstat *xstats,
+                      unsigned int xstats_count, unsigned int *nb_written)
+{
+       struct sfc_port *port = &sa->port;
+       uint64_t *mac_stats;
+       unsigned int i;
+       int nstats = 0;
+       int ret;
+
+       sfc_adapter_lock(sa);
+
+       ret = sfc_port_update_mac_stats(sa, B_FALSE);
+       if (ret != 0) {
+               SFC_ASSERT(ret > 0);
+               ret = -ret;
+               goto unlock;
+       }
+
+       mac_stats = port->mac_stats_buf;
+
+       for (i = 0; i < EFX_MAC_NSTATS; ++i) {
+               if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
+                       if (nstats < (int)xstats_count) {
+                               xstats[nstats].id = nstats;
+                               xstats[nstats].value = mac_stats[i];
+                               (*nb_written)++;
+                       }
+                       nstats++;
+               }
+       }
+       ret = nstats;
+
+unlock:
+       sfc_adapter_unlock(sa);
+
+       return ret;
+}
+
+int
+sfc_port_get_mac_stats_by_id(struct sfc_adapter *sa, const uint64_t *ids,
+                            uint64_t *values, unsigned int n)
+{
+       struct sfc_port *port = &sa->port;
+       uint64_t *mac_stats;
+       unsigned int i;
+       int ret;
+       int rc;
+
+       sfc_adapter_lock(sa);
+
+       rc = sfc_port_update_mac_stats(sa, B_FALSE);
+       if (rc != 0) {
+               SFC_ASSERT(rc > 0);
+               ret = -rc;
+               goto unlock;
+       }
+
+       mac_stats = port->mac_stats_buf;
+
+       SFC_ASSERT(port->mac_stats_nb_supported <=
+                  RTE_DIM(port->mac_stats_by_id));
+
+       for (i = 0; i < n; i++) {
+               if (ids[i] < port->mac_stats_nb_supported) {
+                       values[i] = mac_stats[port->mac_stats_by_id[ids[i]]];
+               } else {
+                       ret = i;
+                       goto unlock;
+               }
+       }
+
+       ret = n;
+
+unlock:
+       sfc_adapter_unlock(sa);
+
+       return ret;
+}