1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2021-2021 Hisilicon Limited.
7 #include "hclge_comm_cmd.h"
8 #include "hclge_comm_tqp_stats.h"
10 u64 *hclge_comm_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
12 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
13 struct hclge_comm_tqp *tqp;
17 for (i = 0; i < kinfo->num_tqps; i++) {
18 tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
19 *buff++ = tqp->tqp_stats.rcb_tx_ring_pktnum_rcd;
22 for (i = 0; i < kinfo->num_tqps; i++) {
23 tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
24 *buff++ = tqp->tqp_stats.rcb_rx_ring_pktnum_rcd;
30 int hclge_comm_tqps_get_sset_count(struct hnae3_handle *handle)
32 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
34 return kinfo->num_tqps * HCLGE_COMM_QUEUE_PAIR_SIZE;
37 u8 *hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
39 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
43 for (i = 0; i < kinfo->num_tqps; i++) {
44 struct hclge_comm_tqp *tqp =
45 container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
46 snprintf(buff, ETH_GSTRING_LEN, "txq%u_pktnum_rcd", tqp->index);
47 buff += ETH_GSTRING_LEN;
50 for (i = 0; i < kinfo->num_tqps; i++) {
51 struct hclge_comm_tqp *tqp =
52 container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
53 snprintf(buff, ETH_GSTRING_LEN, "rxq%u_pktnum_rcd", tqp->index);
54 buff += ETH_GSTRING_LEN;
60 int hclge_comm_tqps_update_stats(struct hnae3_handle *handle,
61 struct hclge_comm_hw *hw)
63 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
64 struct hclge_comm_tqp *tqp;
65 struct hclge_desc desc;
69 for (i = 0; i < kinfo->num_tqps; i++) {
70 tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
71 hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_RX_STATS,
74 desc.data[0] = cpu_to_le32(tqp->index);
75 ret = hclge_comm_cmd_send(hw, &desc, 1);
77 dev_err(&hw->cmq.csq.pdev->dev,
78 "failed to get tqp stat, ret = %d, rx = %u.\n",
82 tqp->tqp_stats.rcb_rx_ring_pktnum_rcd +=
83 le32_to_cpu(desc.data[1]);
85 hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_TX_STATS,
88 desc.data[0] = cpu_to_le32(tqp->index & 0x1ff);
89 ret = hclge_comm_cmd_send(hw, &desc, 1);
91 dev_err(&hw->cmq.csq.pdev->dev,
92 "failed to get tqp stat, ret = %d, tx = %u.\n",
96 tqp->tqp_stats.rcb_tx_ring_pktnum_rcd +=
97 le32_to_cpu(desc.data[1]);
103 void hclge_comm_reset_tqp_stats(struct hnae3_handle *handle)
105 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
106 struct hclge_comm_tqp *tqp;
107 struct hnae3_queue *queue;
110 for (i = 0; i < kinfo->num_tqps; i++) {
111 queue = kinfo->tqp[i];
112 tqp = container_of(queue, struct hclge_comm_tqp, q);
113 memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));