]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
octeontx2-pf: Add ndo_get_stats64
authorGeetha sowjanya <gakula@marvell.com>
Mon, 27 Jan 2020 13:05:27 +0000 (18:35 +0530)
committerDavid S. Miller <davem@davemloft.net>
Mon, 27 Jan 2020 13:33:39 +0000 (14:33 +0100)
Added ndo_get_stats64 which returns stats maintained by HW.

Signed-off-by: Geetha sowjanya <gakula@marvell.com>
Signed-off-by: Sunil Goutham <sgoutham@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c

index c674171104c9c5d2bc67c1185db5376cd0afb85c..c4be7872d9f4939a9281a5059af1be9c904403f6 100644 (file)
 #include "otx2_common.h"
 #include "otx2_struct.h"
 
+void otx2_get_dev_stats(struct otx2_nic *pfvf)
+{
+       struct otx2_dev_stats *dev_stats = &pfvf->hw.dev_stats;
+
+#define OTX2_GET_RX_STATS(reg) \
+        otx2_read64(pfvf, NIX_LF_RX_STATX(reg))
+#define OTX2_GET_TX_STATS(reg) \
+        otx2_read64(pfvf, NIX_LF_TX_STATX(reg))
+
+       dev_stats->rx_bytes = OTX2_GET_RX_STATS(RX_OCTS);
+       dev_stats->rx_drops = OTX2_GET_RX_STATS(RX_DROP);
+       dev_stats->rx_bcast_frames = OTX2_GET_RX_STATS(RX_BCAST);
+       dev_stats->rx_mcast_frames = OTX2_GET_RX_STATS(RX_MCAST);
+       dev_stats->rx_ucast_frames = OTX2_GET_RX_STATS(RX_UCAST);
+       dev_stats->rx_frames = dev_stats->rx_bcast_frames +
+                              dev_stats->rx_mcast_frames +
+                              dev_stats->rx_ucast_frames;
+
+       dev_stats->tx_bytes = OTX2_GET_TX_STATS(TX_OCTS);
+       dev_stats->tx_drops = OTX2_GET_TX_STATS(TX_DROP);
+       dev_stats->tx_bcast_frames = OTX2_GET_TX_STATS(TX_BCAST);
+       dev_stats->tx_mcast_frames = OTX2_GET_TX_STATS(TX_MCAST);
+       dev_stats->tx_ucast_frames = OTX2_GET_TX_STATS(TX_UCAST);
+       dev_stats->tx_frames = dev_stats->tx_bcast_frames +
+                              dev_stats->tx_mcast_frames +
+                              dev_stats->tx_ucast_frames;
+}
+
+void otx2_get_stats64(struct net_device *netdev,
+                     struct rtnl_link_stats64 *stats)
+{
+       struct otx2_nic *pfvf = netdev_priv(netdev);
+       struct otx2_dev_stats *dev_stats;
+
+       otx2_get_dev_stats(pfvf);
+
+       dev_stats = &pfvf->hw.dev_stats;
+       stats->rx_bytes = dev_stats->rx_bytes;
+       stats->rx_packets = dev_stats->rx_frames;
+       stats->rx_dropped = dev_stats->rx_drops;
+       stats->multicast = dev_stats->rx_mcast_frames;
+
+       stats->tx_bytes = dev_stats->tx_bytes;
+       stats->tx_packets = dev_stats->tx_frames;
+       stats->tx_dropped = dev_stats->tx_drops;
+}
+
 /* Sync MAC address with RVU AF */
 static int otx2_hw_set_mac_addr(struct otx2_nic *pfvf, u8 *mac)
 {
index 1598396870af7410abd286ddd77eb3e3e12235f7..ce7a552b478aacddc48e9bad747cc91326dd0fbe 100644 (file)
@@ -81,6 +81,49 @@ enum otx2_errcodes_re {
        ERRCODE_IL4_CSUM = 0x22,
 };
 
+/* NIX TX stats */
+enum nix_stat_lf_tx {
+       TX_UCAST        = 0x0,
+       TX_BCAST        = 0x1,
+       TX_MCAST        = 0x2,
+       TX_DROP         = 0x3,
+       TX_OCTS         = 0x4,
+       TX_STATS_ENUM_LAST,
+};
+
+/* NIX RX stats */
+enum nix_stat_lf_rx {
+       RX_OCTS         = 0x0,
+       RX_UCAST        = 0x1,
+       RX_BCAST        = 0x2,
+       RX_MCAST        = 0x3,
+       RX_DROP         = 0x4,
+       RX_DROP_OCTS    = 0x5,
+       RX_FCS          = 0x6,
+       RX_ERR          = 0x7,
+       RX_DRP_BCAST    = 0x8,
+       RX_DRP_MCAST    = 0x9,
+       RX_DRP_L3BCAST  = 0xa,
+       RX_DRP_L3MCAST  = 0xb,
+       RX_STATS_ENUM_LAST,
+};
+
+struct otx2_dev_stats {
+       u64 rx_bytes;
+       u64 rx_frames;
+       u64 rx_ucast_frames;
+       u64 rx_bcast_frames;
+       u64 rx_mcast_frames;
+       u64 rx_drops;
+
+       u64 tx_bytes;
+       u64 tx_frames;
+       u64 tx_ucast_frames;
+       u64 tx_bcast_frames;
+       u64 tx_mcast_frames;
+       u64 tx_drops;
+};
+
 /* Driver counted stats */
 struct otx2_drv_stats {
        atomic_t rx_fcs_errs;
@@ -142,6 +185,7 @@ struct otx2_hw {
        cpumask_var_t           *affinity_mask;
 
        /* Stats */
+       struct otx2_dev_stats   dev_stats;
        struct otx2_drv_stats   drv_stats;
 };
 
@@ -545,6 +589,11 @@ void mbox_handler_nix_lf_alloc(struct otx2_nic *pfvf,
 void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
                                  struct nix_txsch_alloc_rsp *rsp);
 
+/* Device stats APIs */
+void otx2_get_dev_stats(struct otx2_nic *pfvf);
+void otx2_get_stats64(struct net_device *netdev,
+                     struct rtnl_link_stats64 *stats);
+
 int otx2_open(struct net_device *netdev);
 int otx2_stop(struct net_device *netdev);
 #endif /* OTX2_COMMON_H */
index d0809369c36708ace81e04e0122869945a28d585..3092634ef2915c9b82308897fff3fdcaf03d4af7 100644 (file)
@@ -1073,6 +1073,7 @@ static const struct net_device_ops otx2_netdev_ops = {
        .ndo_set_rx_mode        = otx2_set_rx_mode,
        .ndo_set_features       = otx2_set_features,
        .ndo_tx_timeout         = otx2_tx_timeout,
+       .ndo_get_stats64        = otx2_get_stats64,
 };
 
 static int otx2_check_pf_usable(struct otx2_nic *nic)