xref: /linux/drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_tqp_stats.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2021-2021 Hisilicon Limited.
3 
4 #include <linux/err.h>
5 
6 #include "hnae3.h"
7 #include "hclge_comm_cmd.h"
8 #include "hclge_comm_tqp_stats.h"
9 
hclge_comm_tqps_get_stats(struct hnae3_handle * handle,u64 * data)10 u64 *hclge_comm_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
11 {
12 	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
13 	struct hclge_comm_tqp *tqp;
14 	u64 *buff = data;
15 	u16 i;
16 
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;
20 	}
21 
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;
25 	}
26 
27 	return buff;
28 }
29 EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_stats);
30 
hclge_comm_tqps_get_sset_count(struct hnae3_handle * handle)31 int hclge_comm_tqps_get_sset_count(struct hnae3_handle *handle)
32 {
33 	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
34 
35 	return kinfo->num_tqps * HCLGE_COMM_QUEUE_PAIR_SIZE;
36 }
37 EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_sset_count);
38 
hclge_comm_tqps_get_strings(struct hnae3_handle * handle,u8 * data)39 u8 *hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
40 {
41 	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
42 	u8 *buff = data;
43 	u16 i;
44 
45 	for (i = 0; i < kinfo->num_tqps; i++) {
46 		struct hclge_comm_tqp *tqp =
47 			container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
48 		snprintf(buff, ETH_GSTRING_LEN, "txq%u_pktnum_rcd", tqp->index);
49 		buff += ETH_GSTRING_LEN;
50 	}
51 
52 	for (i = 0; i < kinfo->num_tqps; i++) {
53 		struct hclge_comm_tqp *tqp =
54 			container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
55 		snprintf(buff, ETH_GSTRING_LEN, "rxq%u_pktnum_rcd", tqp->index);
56 		buff += ETH_GSTRING_LEN;
57 	}
58 
59 	return buff;
60 }
61 EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_strings);
62 
hclge_comm_tqps_update_stats(struct hnae3_handle * handle,struct hclge_comm_hw * hw)63 int hclge_comm_tqps_update_stats(struct hnae3_handle *handle,
64 				 struct hclge_comm_hw *hw)
65 {
66 	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
67 	struct hclge_comm_tqp *tqp;
68 	struct hclge_desc desc;
69 	int ret;
70 	u16 i;
71 
72 	for (i = 0; i < kinfo->num_tqps; i++) {
73 		tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
74 		hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_RX_STATS,
75 						true);
76 
77 		desc.data[0] = cpu_to_le32(tqp->index);
78 		ret = hclge_comm_cmd_send(hw, &desc, 1);
79 		if (ret) {
80 			dev_err(&hw->cmq.csq.pdev->dev,
81 				"failed to get tqp stat, ret = %d, rx = %u.\n",
82 				ret, i);
83 			return ret;
84 		}
85 		tqp->tqp_stats.rcb_rx_ring_pktnum_rcd +=
86 			le32_to_cpu(desc.data[1]);
87 
88 		hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_TX_STATS,
89 						true);
90 
91 		desc.data[0] = cpu_to_le32(tqp->index);
92 		ret = hclge_comm_cmd_send(hw, &desc, 1);
93 		if (ret) {
94 			dev_err(&hw->cmq.csq.pdev->dev,
95 				"failed to get tqp stat, ret = %d, tx = %u.\n",
96 				ret, i);
97 			return ret;
98 		}
99 		tqp->tqp_stats.rcb_tx_ring_pktnum_rcd +=
100 			le32_to_cpu(desc.data[1]);
101 	}
102 
103 	return 0;
104 }
105 EXPORT_SYMBOL_GPL(hclge_comm_tqps_update_stats);
106 
hclge_comm_reset_tqp_stats(struct hnae3_handle * handle)107 void hclge_comm_reset_tqp_stats(struct hnae3_handle *handle)
108 {
109 	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
110 	struct hclge_comm_tqp *tqp;
111 	struct hnae3_queue *queue;
112 	u16 i;
113 
114 	for (i = 0; i < kinfo->num_tqps; i++) {
115 		queue = kinfo->tqp[i];
116 		tqp = container_of(queue, struct hclge_comm_tqp, q);
117 		memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));
118 	}
119 }
120 EXPORT_SYMBOL_GPL(hclge_comm_reset_tqp_stats);
121