net: hns3: add support for querying pfc puase packets statistic
authorPeng Li <lipeng321@huawei.com>
Sat, 10 Mar 2018 03:29:27 +0000 (11:29 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 12 Mar 2018 02:53:32 +0000 (22:53 -0400)
This patch add support for querying pfc puase packets statistic
in hclge_ieee_getpfc, which is used to tell user how many pfc
puase packets have been sent and received by this mac port.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h

index 407cfabe6d2122c6b509e67b8c828be336b94e96..955f0e3d5c954e61b96962fe09170a9175c9bfb1 100644 (file)
@@ -205,9 +205,11 @@ static int hclge_ieee_setets(struct hnae3_handle *h, struct ieee_ets *ets)
 
 static int hclge_ieee_getpfc(struct hnae3_handle *h, struct ieee_pfc *pfc)
 {
+       u64 requests[HNAE3_MAX_TC], indications[HNAE3_MAX_TC];
        struct hclge_vport *vport = hclge_get_vport(h);
        struct hclge_dev *hdev = vport->back;
        u8 i, j, pfc_map, *prio_tc;
+       int ret;
 
        memset(pfc, 0, sizeof(*pfc));
        pfc->pfc_cap = hdev->pfc_max;
@@ -222,6 +224,18 @@ static int hclge_ieee_getpfc(struct hnae3_handle *h, struct ieee_pfc *pfc)
                }
        }
 
+       ret = hclge_pfc_tx_stats_get(hdev, requests);
+       if (ret)
+               return ret;
+
+       ret = hclge_pfc_rx_stats_get(hdev, indications);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
+               pfc->requests[i] = requests[i];
+               pfc->indications[i] = indications[i];
+       }
        return 0;
 }
 
index 4134a829c8948944f2336bfa4aa8a912776596d6..885f25cd7be49fa7669341d629abcef706fe9ffc 100644 (file)
@@ -23,6 +23,9 @@ enum hclge_shaper_level {
        HCLGE_SHAPER_LVL_PF     = 1,
 };
 
+#define HCLGE_TM_PFC_PKT_GET_CMD_NUM   3
+#define HCLGE_TM_PFC_NUM_GET_PER_CMD   3
+
 #define HCLGE_SHAPER_BS_U_DEF  5
 #define HCLGE_SHAPER_BS_S_DEF  20
 
@@ -112,6 +115,56 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
        return 0;
 }
 
+static int hclge_pfc_stats_get(struct hclge_dev *hdev,
+                              enum hclge_opcode_type opcode, u64 *stats)
+{
+       struct hclge_desc desc[HCLGE_TM_PFC_PKT_GET_CMD_NUM];
+       int ret, i, j;
+
+       if (!(opcode == HCLGE_OPC_QUERY_PFC_RX_PKT_CNT ||
+             opcode == HCLGE_OPC_QUERY_PFC_TX_PKT_CNT))
+               return -EINVAL;
+
+       for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
+               hclge_cmd_setup_basic_desc(&desc[i], opcode, true);
+               if (i != (HCLGE_TM_PFC_PKT_GET_CMD_NUM - 1))
+                       desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+               else
+                       desc[i].flag &= ~cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+       }
+
+       ret = hclge_cmd_send(&hdev->hw, desc, HCLGE_TM_PFC_PKT_GET_CMD_NUM);
+       if (ret) {
+               dev_err(&hdev->pdev->dev,
+                       "Get pfc pause stats fail, ret = %d.\n", ret);
+               return ret;
+       }
+
+       for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
+               struct hclge_pfc_stats_cmd *pfc_stats =
+                               (struct hclge_pfc_stats_cmd *)desc[i].data;
+
+               for (j = 0; j < HCLGE_TM_PFC_NUM_GET_PER_CMD; j++) {
+                       u32 index = i * HCLGE_TM_PFC_PKT_GET_CMD_NUM + j;
+
+                       if (index < HCLGE_MAX_TC_NUM)
+                               stats[index] =
+                                       le64_to_cpu(pfc_stats->pkt_num[j]);
+               }
+       }
+       return 0;
+}
+
+int hclge_pfc_rx_stats_get(struct hclge_dev *hdev, u64 *stats)
+{
+       return hclge_pfc_stats_get(hdev, HCLGE_OPC_QUERY_PFC_RX_PKT_CNT, stats);
+}
+
+int hclge_pfc_tx_stats_get(struct hclge_dev *hdev, u64 *stats)
+{
+       return hclge_pfc_stats_get(hdev, HCLGE_OPC_QUERY_PFC_TX_PKT_CNT, stats);
+}
+
 int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx)
 {
        struct hclge_desc desc;
index c30c85b54ffcd7fd68594c7c4286ed25fec3ced4..2dbe177581e982c1ecf3e115a6cf9d078f680df3 100644 (file)
@@ -109,6 +109,10 @@ struct hclge_cfg_pause_param_cmd {
        __le16 pause_trans_time;
 };
 
+struct hclge_pfc_stats_cmd {
+       __le64 pkt_num[3];
+};
+
 struct hclge_port_shapping_cmd {
        __le32 port_shapping_para;
 };
@@ -130,4 +134,6 @@ int hclge_tm_map_cfg(struct hclge_dev *hdev);
 int hclge_tm_init_hw(struct hclge_dev *hdev);
 int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx);
 int hclge_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr);
+int hclge_pfc_rx_stats_get(struct hclge_dev *hdev, u64 *stats);
+int hclge_pfc_tx_stats_get(struct hclge_dev *hdev, u64 *stats);
 #endif