octeontx2-pf: Implement offload stats ndo for representors
authorGeetha sowjanya <gakula@marvell.com>
Thu, 7 Nov 2024 16:08:37 +0000 (21:38 +0530)
committerDavid S. Miller <davem@davemloft.net>
Wed, 13 Nov 2024 11:57:11 +0000 (11:57 +0000)
Implement the offload stat ndo by fetching the HW stats
of rx/tx queues attached to the representor.

Signed-off-by: Geetha sowjanya <gakula@marvell.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
drivers/net/ethernet/marvell/octeontx2/nic/rep.c

index 46a4480..523ecb7 100644 (file)
@@ -83,6 +83,7 @@ int otx2_update_rq_stats(struct otx2_nic *pfvf, int qidx)
        otx2_nix_rq_op_stats(&rq->stats, pfvf, qidx);
        return 1;
 }
+EXPORT_SYMBOL(otx2_update_rq_stats);
 
 int otx2_update_sq_stats(struct otx2_nic *pfvf, int qidx)
 {
@@ -99,6 +100,7 @@ int otx2_update_sq_stats(struct otx2_nic *pfvf, int qidx)
        otx2_nix_sq_op_stats(&sq->stats, pfvf, qidx);
        return 1;
 }
+EXPORT_SYMBOL(otx2_update_sq_stats);
 
 void otx2_get_dev_stats(struct otx2_nic *pfvf)
 {
index 15e7750..1806d05 100644 (file)
@@ -31,6 +31,45 @@ MODULE_DEVICE_TABLE(pci, rvu_rep_id_table);
 static int rvu_rep_notify_pfvf(struct otx2_nic *priv, u16 event,
                               struct rep_event *data);
 
+static int
+rvu_rep_sp_stats64(const struct net_device *dev,
+                  struct rtnl_link_stats64 *stats)
+{
+       struct rep_dev *rep = netdev_priv(dev);
+       struct otx2_nic *priv = rep->mdev;
+       struct otx2_rcv_queue *rq;
+       struct otx2_snd_queue *sq;
+       u16 qidx = rep->rep_id;
+
+       otx2_update_rq_stats(priv, qidx);
+       rq = &priv->qset.rq[qidx];
+
+       otx2_update_sq_stats(priv, qidx);
+       sq = &priv->qset.sq[qidx];
+
+       stats->tx_bytes = sq->stats.bytes;
+       stats->tx_packets = sq->stats.pkts;
+       stats->rx_bytes = rq->stats.bytes;
+       stats->rx_packets = rq->stats.pkts;
+       return 0;
+}
+
+static bool
+rvu_rep_has_offload_stats(const struct net_device *dev, int attr_id)
+{
+       return attr_id == IFLA_OFFLOAD_XSTATS_CPU_HIT;
+}
+
+static int
+rvu_rep_get_offload_stats(int attr_id, const struct net_device *dev,
+                         void *sp)
+{
+       if (attr_id == IFLA_OFFLOAD_XSTATS_CPU_HIT)
+               return rvu_rep_sp_stats64(dev, (struct rtnl_link_stats64 *)sp);
+
+       return -EINVAL;
+}
+
 static int rvu_rep_dl_port_fn_hw_addr_get(struct devlink_port *port,
                                          u8 *hw_addr, int *hw_addr_len,
                                          struct netlink_ext_ack *extack)
@@ -326,6 +365,8 @@ static const struct net_device_ops rvu_rep_netdev_ops = {
        .ndo_start_xmit         = rvu_rep_xmit,
        .ndo_get_stats64        = rvu_rep_get_stats64,
        .ndo_change_mtu         = rvu_rep_change_mtu,
+       .ndo_has_offload_stats  = rvu_rep_has_offload_stats,
+       .ndo_get_offload_stats  = rvu_rep_get_offload_stats,
 };
 
 static int rvu_rep_napi_init(struct otx2_nic *priv,