From: Vanshika Shukla <vanshika.shu...@nxp.com>

Introduces basic statistics collection for ENETC4 PMD, including:

- Packet transmit/receive counts
- Byte transmit/receive counts
- Error counters (TX/RX drops, errors)

Signed-off-by: Apeksha Gupta <apeksha.gu...@nxp.com>
Signed-off-by: Gagandeep Singh <g.si...@nxp.com>
---
 doc/guides/nics/features/enetc4.ini |  1 +
 drivers/net/enetc/base/enetc4_hw.h  |  7 +++++
 drivers/net/enetc/base/enetc_hw.h   |  5 +++-
 drivers/net/enetc/enetc4_ethdev.c   | 42 +++++++++++++++++++++++++++++
 drivers/net/enetc/enetc4_vf.c       | 24 +++++++++++++++++
 5 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/enetc4.ini 
b/doc/guides/nics/features/enetc4.ini
index 55b3b95953..e814852d2d 100644
--- a/doc/guides/nics/features/enetc4.ini
+++ b/doc/guides/nics/features/enetc4.ini
@@ -4,6 +4,7 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Basic stats          = Y
 L3 checksum offload  = Y
 L4 checksum offload  = Y
 Queue start/stop     = Y
diff --git a/drivers/net/enetc/base/enetc4_hw.h 
b/drivers/net/enetc/base/enetc4_hw.h
index 114d27f34b..874cdc4775 100644
--- a/drivers/net/enetc/base/enetc4_hw.h
+++ b/drivers/net/enetc/base/enetc4_hw.h
@@ -103,6 +103,13 @@
 #define IFMODE_SGMII                   5
 #define PM_IF_MODE_ENA                 BIT(15)
 
+/* Station interface statistics */
+#define ENETC4_SIROCT0           0x300
+#define ENETC4_SIRFRM0           0x308
+#define ENETC4_SITOCT0           0x320
+#define ENETC4_SITFRM0           0x328
+#define ENETC4_SITDFCR           0x340
+
 /* general register accessors */
 #define enetc4_rd_reg(reg)     rte_read32((void *)(reg))
 #define enetc4_wr_reg(reg, val)  rte_write32((val), (void *)(reg))
diff --git a/drivers/net/enetc/base/enetc_hw.h 
b/drivers/net/enetc/base/enetc_hw.h
index 3cdfe23fc0..3208d91bc5 100644
--- a/drivers/net/enetc/base/enetc_hw.h
+++ b/drivers/net/enetc/base/enetc_hw.h
@@ -278,7 +278,10 @@ union enetc_rx_bd {
                union {
                        struct {
                                uint16_t flags;
-                               uint16_t error;
+                               uint8_t error;
+                               uint8_t resv:6;
+                               uint8_t r:1;
+                               uint8_t f:1;
                        };
                        uint32_t lstatus;
                };
diff --git a/drivers/net/enetc/enetc4_ethdev.c 
b/drivers/net/enetc/enetc4_ethdev.c
index 02f048aa3c..2db45ecf0c 100644
--- a/drivers/net/enetc/enetc4_ethdev.c
+++ b/drivers/net/enetc/enetc4_ethdev.c
@@ -484,6 +484,46 @@ enetc4_rx_queue_release(struct rte_eth_dev *dev, uint16_t 
qid)
        rte_free(rx_ring);
 }
 
+static
+int enetc4_stats_get(struct rte_eth_dev *dev,
+                   struct rte_eth_stats *stats)
+{
+       struct enetc_eth_hw *hw =
+               ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct enetc_hw *enetc_hw = &hw->hw;
+
+       /*
+        * Total received packets, bad + good, if we want to get counters
+        * of only good received packets then use ENETC4_PM_RFRM,
+        * ENETC4_PM_TFRM registers.
+        */
+       stats->ipackets = enetc4_port_rd(enetc_hw, ENETC4_PM_RPKT(0));
+       stats->opackets = enetc4_port_rd(enetc_hw, ENETC4_PM_TPKT(0));
+       stats->ibytes =  enetc4_port_rd(enetc_hw, ENETC4_PM_REOCT(0));
+       stats->obytes = enetc4_port_rd(enetc_hw, ENETC4_PM_TEOCT(0));
+       /*
+        * Dropped + Truncated packets, use ENETC4_PM_RDRNTP(0) for without
+        * truncated packets
+        */
+       stats->imissed = enetc4_port_rd(enetc_hw, ENETC4_PM_RDRP(0));
+       stats->ierrors = enetc4_port_rd(enetc_hw, ENETC4_PM_RERR(0));
+       stats->oerrors = enetc4_port_rd(enetc_hw, ENETC4_PM_TERR(0));
+
+       return 0;
+}
+
+static int
+enetc4_stats_reset(struct rte_eth_dev *dev)
+{
+       struct enetc_eth_hw *hw =
+               ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct enetc_hw *enetc_hw = &hw->hw;
+
+       enetc4_port_wr(enetc_hw, ENETC4_PM0_STAT_CONFIG, ENETC4_CLEAR_STATS);
+
+       return 0;
+}
+
 int
 enetc4_dev_close(struct rte_eth_dev *dev)
 {
@@ -668,6 +708,8 @@ static const struct eth_dev_ops enetc4_ops = {
        .dev_stop             = enetc4_dev_stop,
        .dev_close            = enetc4_dev_close,
        .dev_infos_get        = enetc4_dev_infos_get,
+       .stats_get            = enetc4_stats_get,
+       .stats_reset          = enetc4_stats_reset,
        .rx_queue_setup       = enetc4_rx_queue_setup,
        .rx_queue_start       = enetc4_rx_queue_start,
        .rx_queue_stop        = enetc4_rx_queue_stop,
diff --git a/drivers/net/enetc/enetc4_vf.c b/drivers/net/enetc/enetc4_vf.c
index 0c68229a8d..0d35fc2e1c 100644
--- a/drivers/net/enetc/enetc4_vf.c
+++ b/drivers/net/enetc/enetc4_vf.c
@@ -26,6 +26,29 @@ enetc4_vf_dev_start(struct rte_eth_dev *dev __rte_unused)
        return 0;
 }
 
+static int
+enetc4_vf_stats_get(struct rte_eth_dev *dev,
+                   struct rte_eth_stats *stats)
+{
+       struct enetc_eth_hw *hw =
+               ENETC_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       struct enetc_hw *enetc_hw = &hw->hw;
+       struct enetc_bdr *rx_ring;
+       uint8_t i;
+
+       PMD_INIT_FUNC_TRACE();
+       stats->ipackets = enetc4_rd(enetc_hw, ENETC4_SIRFRM0);
+       stats->opackets = enetc4_rd(enetc_hw, ENETC4_SITFRM0);
+       stats->ibytes = enetc4_rd(enetc_hw, ENETC4_SIROCT0);
+       stats->obytes = enetc4_rd(enetc_hw, ENETC4_SITOCT0);
+       stats->oerrors = enetc4_rd(enetc_hw, ENETC4_SITDFCR);
+       for (i = 0; i < dev->data->nb_rx_queues; i++) {
+               rx_ring = dev->data->rx_queues[i];
+               stats->ierrors += rx_ring->ierrors;
+       }
+       return 0;
+}
+
 /*
  * The set of PCI devices this driver supports
  */
@@ -41,6 +64,7 @@ static const struct eth_dev_ops enetc4_vf_ops = {
        .dev_stop             = enetc4_vf_dev_stop,
        .dev_close            = enetc4_dev_close,
        .dev_infos_get        = enetc4_dev_infos_get,
+       .stats_get            = enetc4_vf_stats_get,
        .rx_queue_setup       = enetc4_rx_queue_setup,
        .rx_queue_start       = enetc4_rx_queue_start,
        .rx_queue_stop        = enetc4_rx_queue_stop,
-- 
2.25.1

Reply via email to