net: hns3: refine MAC pause statistics querying function
authorYufeng Mo <moyufeng@huawei.com>
Fri, 9 Aug 2019 02:31:16 +0000 (10:31 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 9 Aug 2019 20:44:33 +0000 (13:44 -0700)
This patch refines the interface for querying MAC pause
statistics, and adds structure hns3_mac_stats to keep the
count of TX & RX.

Signed-off-by: Yufeng Mo <moyufeng@huawei.com>
Reviewed-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hnae3.h
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

index a4624db3b5d50938adb952deaf0fb4a0d7ea253f..43740ee9d8d8d4909308ff4ce14bb9fc31ac37a2 100644 (file)
@@ -91,6 +91,11 @@ struct hnae3_queue {
        u16 rx_desc_num;/* total number of rx desc */
 };
 
+struct hns3_mac_stats {
+       u64 tx_pause_cnt;
+       u64 rx_pause_cnt;
+};
+
 /*hnae3 loop mode*/
 enum hnae3_loop {
        HNAE3_LOOP_APP,
@@ -298,6 +303,8 @@ struct hnae3_ae_dev {
  *   Remove multicast address from mac table
  * update_stats()
  *   Update Old network device statistics
+ * get_mac_stats()
+ *   get mac pause statistics including tx_cnt and rx_cnt
  * get_ethtool_stats()
  *   Get ethtool network device statistics
  * get_strings()
@@ -426,8 +433,8 @@ struct hnae3_ae_ops {
        void (*update_stats)(struct hnae3_handle *handle,
                             struct net_device_stats *net_stats);
        void (*get_stats)(struct hnae3_handle *handle, u64 *data);
-       void (*get_mac_pause_stats)(struct hnae3_handle *handle, u64 *tx_cnt,
-                                   u64 *rx_cnt);
+       void (*get_mac_stats)(struct hnae3_handle *handle,
+                             struct hns3_mac_stats *mac_stats);
        void (*get_strings)(struct hnae3_handle *handle,
                            u32 stringset, u8 *data);
        int (*get_sset_count)(struct hnae3_handle *handle, int stringset);
index df08f9ec06016a0ca276b69e2e952e3e558330f7..1750f80341e7ec1d7d3218f3ab26ad96e858b679 100644 (file)
@@ -1726,15 +1726,12 @@ static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev)
        /* When mac received many pause frames continuous, it's unable to send
         * packets, which may cause tx timeout
         */
-       if (h->ae_algo->ops->update_stats &&
-           h->ae_algo->ops->get_mac_pause_stats) {
-               u64 tx_pause_cnt, rx_pause_cnt;
+       if (h->ae_algo->ops->get_mac_stats) {
+               struct hns3_mac_stats mac_stats;
 
-               h->ae_algo->ops->update_stats(h, &ndev->stats);
-               h->ae_algo->ops->get_mac_pause_stats(h, &tx_pause_cnt,
-                                                    &rx_pause_cnt);
+               h->ae_algo->ops->get_mac_stats(h, &mac_stats);
                netdev_info(ndev, "tx_pause_cnt: %llu, rx_pause_cnt: %llu\n",
-                           tx_pause_cnt, rx_pause_cnt);
+                           mac_stats.tx_pause_cnt, mac_stats.rx_pause_cnt);
        }
 
        hw_head = readl_relaxed(tx_ring->tqp->io_base +
index 7d7ab9e66383c25b9f711aa47e73eebf4df976c8..13152753c75d4bd1786f28c290b21d3f2fa611e5 100644 (file)
@@ -750,14 +750,16 @@ static void hclge_get_stats(struct hnae3_handle *handle, u64 *data)
        p = hclge_tqps_get_stats(handle, p);
 }
 
-static void hclge_get_mac_pause_stat(struct hnae3_handle *handle, u64 *tx_cnt,
-                                    u64 *rx_cnt)
+static void hclge_get_mac_stat(struct hnae3_handle *handle,
+                              struct hns3_mac_stats *mac_stats)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
        struct hclge_dev *hdev = vport->back;
 
-       *tx_cnt = hdev->hw_stats.mac_stats.mac_tx_mac_pause_num;
-       *rx_cnt = hdev->hw_stats.mac_stats.mac_rx_mac_pause_num;
+       hclge_update_stats(handle, NULL);
+
+       mac_stats->tx_pause_cnt = hdev->hw_stats.mac_stats.mac_tx_mac_pause_num;
+       mac_stats->rx_pause_cnt = hdev->hw_stats.mac_stats.mac_rx_mac_pause_num;
 }
 
 static int hclge_parse_func_status(struct hclge_dev *hdev,
@@ -9798,7 +9800,7 @@ static const struct hnae3_ae_ops hclge_ops = {
        .set_mtu = hclge_set_mtu,
        .reset_queue = hclge_reset_tqp,
        .get_stats = hclge_get_stats,
-       .get_mac_pause_stats = hclge_get_mac_pause_stat,
+       .get_mac_stats = hclge_get_mac_stat,
        .update_stats = hclge_update_stats,
        .get_strings = hclge_get_strings,
        .get_sset_count = hclge_get_sset_count,