1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2019 Hisilicon Limited.
7 #include <rte_common.h>
8 #include <rte_ethdev.h>
10 #include <rte_malloc.h>
11 #include <rte_spinlock.h>
13 #include "hns3_ethdev.h"
14 #include "hns3_rxtx.h"
15 #include "hns3_logs.h"
16 #include "hns3_regs.h"
19 static const struct hns3_xstats_name_offset hns3_mac_strings[] = {
20 {"mac_tx_mac_pause_num",
21 HNS3_MAC_STATS_OFFSET(mac_tx_mac_pause_num)},
22 {"mac_rx_mac_pause_num",
23 HNS3_MAC_STATS_OFFSET(mac_rx_mac_pause_num)},
24 {"mac_tx_control_pkt_num",
25 HNS3_MAC_STATS_OFFSET(mac_tx_ctrl_pkt_num)},
26 {"mac_rx_control_pkt_num",
27 HNS3_MAC_STATS_OFFSET(mac_rx_ctrl_pkt_num)},
28 {"mac_tx_pfc_pkt_num",
29 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pause_pkt_num)},
30 {"mac_tx_pfc_pri0_pkt_num",
31 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri0_pkt_num)},
32 {"mac_tx_pfc_pri1_pkt_num",
33 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri1_pkt_num)},
34 {"mac_tx_pfc_pri2_pkt_num",
35 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri2_pkt_num)},
36 {"mac_tx_pfc_pri3_pkt_num",
37 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri3_pkt_num)},
38 {"mac_tx_pfc_pri4_pkt_num",
39 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri4_pkt_num)},
40 {"mac_tx_pfc_pri5_pkt_num",
41 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri5_pkt_num)},
42 {"mac_tx_pfc_pri6_pkt_num",
43 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri6_pkt_num)},
44 {"mac_tx_pfc_pri7_pkt_num",
45 HNS3_MAC_STATS_OFFSET(mac_tx_pfc_pri7_pkt_num)},
46 {"mac_rx_pfc_pkt_num",
47 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pause_pkt_num)},
48 {"mac_rx_pfc_pri0_pkt_num",
49 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri0_pkt_num)},
50 {"mac_rx_pfc_pri1_pkt_num",
51 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri1_pkt_num)},
52 {"mac_rx_pfc_pri2_pkt_num",
53 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri2_pkt_num)},
54 {"mac_rx_pfc_pri3_pkt_num",
55 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri3_pkt_num)},
56 {"mac_rx_pfc_pri4_pkt_num",
57 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri4_pkt_num)},
58 {"mac_rx_pfc_pri5_pkt_num",
59 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri5_pkt_num)},
60 {"mac_rx_pfc_pri6_pkt_num",
61 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri6_pkt_num)},
62 {"mac_rx_pfc_pri7_pkt_num",
63 HNS3_MAC_STATS_OFFSET(mac_rx_pfc_pri7_pkt_num)},
64 {"mac_tx_total_pkt_num",
65 HNS3_MAC_STATS_OFFSET(mac_tx_total_pkt_num)},
66 {"mac_tx_total_oct_num",
67 HNS3_MAC_STATS_OFFSET(mac_tx_total_oct_num)},
68 {"mac_tx_good_pkt_num",
69 HNS3_MAC_STATS_OFFSET(mac_tx_good_pkt_num)},
70 {"mac_tx_bad_pkt_num",
71 HNS3_MAC_STATS_OFFSET(mac_tx_bad_pkt_num)},
72 {"mac_tx_good_oct_num",
73 HNS3_MAC_STATS_OFFSET(mac_tx_good_oct_num)},
74 {"mac_tx_bad_oct_num",
75 HNS3_MAC_STATS_OFFSET(mac_tx_bad_oct_num)},
76 {"mac_tx_uni_pkt_num",
77 HNS3_MAC_STATS_OFFSET(mac_tx_uni_pkt_num)},
78 {"mac_tx_multi_pkt_num",
79 HNS3_MAC_STATS_OFFSET(mac_tx_multi_pkt_num)},
80 {"mac_tx_broad_pkt_num",
81 HNS3_MAC_STATS_OFFSET(mac_tx_broad_pkt_num)},
82 {"mac_tx_undersize_pkt_num",
83 HNS3_MAC_STATS_OFFSET(mac_tx_undersize_pkt_num)},
84 {"mac_tx_oversize_pkt_num",
85 HNS3_MAC_STATS_OFFSET(mac_tx_oversize_pkt_num)},
86 {"mac_tx_64_oct_pkt_num",
87 HNS3_MAC_STATS_OFFSET(mac_tx_64_oct_pkt_num)},
88 {"mac_tx_65_127_oct_pkt_num",
89 HNS3_MAC_STATS_OFFSET(mac_tx_65_127_oct_pkt_num)},
90 {"mac_tx_128_255_oct_pkt_num",
91 HNS3_MAC_STATS_OFFSET(mac_tx_128_255_oct_pkt_num)},
92 {"mac_tx_256_511_oct_pkt_num",
93 HNS3_MAC_STATS_OFFSET(mac_tx_256_511_oct_pkt_num)},
94 {"mac_tx_512_1023_oct_pkt_num",
95 HNS3_MAC_STATS_OFFSET(mac_tx_512_1023_oct_pkt_num)},
96 {"mac_tx_1024_1518_oct_pkt_num",
97 HNS3_MAC_STATS_OFFSET(mac_tx_1024_1518_oct_pkt_num)},
98 {"mac_tx_1519_2047_oct_pkt_num",
99 HNS3_MAC_STATS_OFFSET(mac_tx_1519_2047_oct_pkt_num)},
100 {"mac_tx_2048_4095_oct_pkt_num",
101 HNS3_MAC_STATS_OFFSET(mac_tx_2048_4095_oct_pkt_num)},
102 {"mac_tx_4096_8191_oct_pkt_num",
103 HNS3_MAC_STATS_OFFSET(mac_tx_4096_8191_oct_pkt_num)},
104 {"mac_tx_8192_9216_oct_pkt_num",
105 HNS3_MAC_STATS_OFFSET(mac_tx_8192_9216_oct_pkt_num)},
106 {"mac_tx_9217_12287_oct_pkt_num",
107 HNS3_MAC_STATS_OFFSET(mac_tx_9217_12287_oct_pkt_num)},
108 {"mac_tx_12288_16383_oct_pkt_num",
109 HNS3_MAC_STATS_OFFSET(mac_tx_12288_16383_oct_pkt_num)},
110 {"mac_tx_1519_max_good_pkt_num",
111 HNS3_MAC_STATS_OFFSET(mac_tx_1519_max_good_oct_pkt_num)},
112 {"mac_tx_1519_max_bad_pkt_num",
113 HNS3_MAC_STATS_OFFSET(mac_tx_1519_max_bad_oct_pkt_num)},
114 {"mac_rx_total_pkt_num",
115 HNS3_MAC_STATS_OFFSET(mac_rx_total_pkt_num)},
116 {"mac_rx_total_oct_num",
117 HNS3_MAC_STATS_OFFSET(mac_rx_total_oct_num)},
118 {"mac_rx_good_pkt_num",
119 HNS3_MAC_STATS_OFFSET(mac_rx_good_pkt_num)},
120 {"mac_rx_bad_pkt_num",
121 HNS3_MAC_STATS_OFFSET(mac_rx_bad_pkt_num)},
122 {"mac_rx_good_oct_num",
123 HNS3_MAC_STATS_OFFSET(mac_rx_good_oct_num)},
124 {"mac_rx_bad_oct_num",
125 HNS3_MAC_STATS_OFFSET(mac_rx_bad_oct_num)},
126 {"mac_rx_uni_pkt_num",
127 HNS3_MAC_STATS_OFFSET(mac_rx_uni_pkt_num)},
128 {"mac_rx_multi_pkt_num",
129 HNS3_MAC_STATS_OFFSET(mac_rx_multi_pkt_num)},
130 {"mac_rx_broad_pkt_num",
131 HNS3_MAC_STATS_OFFSET(mac_rx_broad_pkt_num)},
132 {"mac_rx_undersize_pkt_num",
133 HNS3_MAC_STATS_OFFSET(mac_rx_undersize_pkt_num)},
134 {"mac_rx_oversize_pkt_num",
135 HNS3_MAC_STATS_OFFSET(mac_rx_oversize_pkt_num)},
136 {"mac_rx_64_oct_pkt_num",
137 HNS3_MAC_STATS_OFFSET(mac_rx_64_oct_pkt_num)},
138 {"mac_rx_65_127_oct_pkt_num",
139 HNS3_MAC_STATS_OFFSET(mac_rx_65_127_oct_pkt_num)},
140 {"mac_rx_128_255_oct_pkt_num",
141 HNS3_MAC_STATS_OFFSET(mac_rx_128_255_oct_pkt_num)},
142 {"mac_rx_256_511_oct_pkt_num",
143 HNS3_MAC_STATS_OFFSET(mac_rx_256_511_oct_pkt_num)},
144 {"mac_rx_512_1023_oct_pkt_num",
145 HNS3_MAC_STATS_OFFSET(mac_rx_512_1023_oct_pkt_num)},
146 {"mac_rx_1024_1518_oct_pkt_num",
147 HNS3_MAC_STATS_OFFSET(mac_rx_1024_1518_oct_pkt_num)},
148 {"mac_rx_1519_2047_oct_pkt_num",
149 HNS3_MAC_STATS_OFFSET(mac_rx_1519_2047_oct_pkt_num)},
150 {"mac_rx_2048_4095_oct_pkt_num",
151 HNS3_MAC_STATS_OFFSET(mac_rx_2048_4095_oct_pkt_num)},
152 {"mac_rx_4096_8191_oct_pkt_num",
153 HNS3_MAC_STATS_OFFSET(mac_rx_4096_8191_oct_pkt_num)},
154 {"mac_rx_8192_9216_oct_pkt_num",
155 HNS3_MAC_STATS_OFFSET(mac_rx_8192_9216_oct_pkt_num)},
156 {"mac_rx_9217_12287_oct_pkt_num",
157 HNS3_MAC_STATS_OFFSET(mac_rx_9217_12287_oct_pkt_num)},
158 {"mac_rx_12288_16383_oct_pkt_num",
159 HNS3_MAC_STATS_OFFSET(mac_rx_12288_16383_oct_pkt_num)},
160 {"mac_rx_1519_max_good_pkt_num",
161 HNS3_MAC_STATS_OFFSET(mac_rx_1519_max_good_oct_pkt_num)},
162 {"mac_rx_1519_max_bad_pkt_num",
163 HNS3_MAC_STATS_OFFSET(mac_rx_1519_max_bad_oct_pkt_num)},
164 {"mac_tx_fragment_pkt_num",
165 HNS3_MAC_STATS_OFFSET(mac_tx_fragment_pkt_num)},
166 {"mac_tx_undermin_pkt_num",
167 HNS3_MAC_STATS_OFFSET(mac_tx_undermin_pkt_num)},
168 {"mac_tx_jabber_pkt_num",
169 HNS3_MAC_STATS_OFFSET(mac_tx_jabber_pkt_num)},
170 {"mac_tx_err_all_pkt_num",
171 HNS3_MAC_STATS_OFFSET(mac_tx_err_all_pkt_num)},
172 {"mac_tx_from_app_good_pkt_num",
173 HNS3_MAC_STATS_OFFSET(mac_tx_from_app_good_pkt_num)},
174 {"mac_tx_from_app_bad_pkt_num",
175 HNS3_MAC_STATS_OFFSET(mac_tx_from_app_bad_pkt_num)},
176 {"mac_rx_fragment_pkt_num",
177 HNS3_MAC_STATS_OFFSET(mac_rx_fragment_pkt_num)},
178 {"mac_rx_undermin_pkt_num",
179 HNS3_MAC_STATS_OFFSET(mac_rx_undermin_pkt_num)},
180 {"mac_rx_jabber_pkt_num",
181 HNS3_MAC_STATS_OFFSET(mac_rx_jabber_pkt_num)},
182 {"mac_rx_fcs_err_pkt_num",
183 HNS3_MAC_STATS_OFFSET(mac_rx_fcs_err_pkt_num)},
184 {"mac_rx_send_app_good_pkt_num",
185 HNS3_MAC_STATS_OFFSET(mac_rx_send_app_good_pkt_num)},
186 {"mac_rx_send_app_bad_pkt_num",
187 HNS3_MAC_STATS_OFFSET(mac_rx_send_app_bad_pkt_num)}
190 static const struct hns3_xstats_name_offset hns3_error_int_stats_strings[] = {
191 {"MAC_AFIFO_TNL_INT_R",
192 HNS3_ERR_INT_STATS_FIELD_OFFSET(mac_afifo_tnl_int_cnt)},
193 {"PPU_MPF_ABNORMAL_INT_ST2_MSIX",
194 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppu_mpf_abn_int_st2_msix_cnt)},
195 {"SSU_PORT_BASED_ERR_INT_MSIX",
196 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_port_based_pf_int_cnt)},
197 {"PPP_PF_ABNORMAL_INT_ST0",
198 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppp_pf_abnormal_int_cnt)},
199 {"PPU_PF_ABNORMAL_INT_ST_MSIX",
200 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppu_pf_abnormal_int_msix_cnt)},
201 {"IMP_TCM_ECC_INT_STS",
202 HNS3_ERR_INT_STATS_FIELD_OFFSET(imp_tcm_ecc_int_cnt)},
203 {"CMDQ_MEM_ECC_INT_STS",
204 HNS3_ERR_INT_STATS_FIELD_OFFSET(cmdq_mem_ecc_int_cnt)},
205 {"IMP_RD_POISON_INT_STS",
206 HNS3_ERR_INT_STATS_FIELD_OFFSET(imp_rd_poison_int_cnt)},
207 {"TQP_INT_ECC_INT_STS",
208 HNS3_ERR_INT_STATS_FIELD_OFFSET(tqp_int_ecc_int_cnt)},
210 HNS3_ERR_INT_STATS_FIELD_OFFSET(msix_ecc_int_cnt)},
211 {"SSU_ECC_MULTI_BIT_INT_0",
212 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_ecc_multi_bit_int_0_cnt)},
213 {"SSU_ECC_MULTI_BIT_INT_1",
214 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_ecc_multi_bit_int_1_cnt)},
215 {"SSU_COMMON_ERR_INT",
216 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_common_ecc_int_cnt)},
218 HNS3_ERR_INT_STATS_FIELD_OFFSET(igu_int_cnt)},
219 {"PPP_MPF_ABNORMAL_INT_ST1",
220 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppp_mpf_abnormal_int_st1_cnt)},
221 {"PPP_MPF_ABNORMAL_INT_ST3",
222 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppp_mpf_abnormal_int_st3_cnt)},
223 {"PPU_MPF_ABNORMAL_INT_ST1",
224 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppu_mpf_abnormal_int_st1_cnt)},
225 {"PPU_MPF_ABNORMAL_INT_ST2_RAS",
226 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppu_mpf_abn_int_st2_ras_cnt)},
227 {"PPU_MPF_ABNORMAL_INT_ST3",
228 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppu_mpf_abnormal_int_st3_cnt)},
230 HNS3_ERR_INT_STATS_FIELD_OFFSET(tm_sch_int_cnt)},
232 HNS3_ERR_INT_STATS_FIELD_OFFSET(qcn_fifo_int_cnt)},
234 HNS3_ERR_INT_STATS_FIELD_OFFSET(qcn_ecc_int_cnt)},
236 HNS3_ERR_INT_STATS_FIELD_OFFSET(ncsi_ecc_int_cnt)},
237 {"SSU_PORT_BASED_ERR_INT_RAS",
238 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_port_based_err_int_cnt)},
239 {"SSU_FIFO_OVERFLOW_INT",
240 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_fifo_overflow_int_cnt)},
242 HNS3_ERR_INT_STATS_FIELD_OFFSET(ssu_ets_tcg_int_cnt)},
243 {"IGU_EGU_TNL_INT_STS",
244 HNS3_ERR_INT_STATS_FIELD_OFFSET(igu_egu_tnl_int_cnt)},
245 {"PPU_PF_ABNORMAL_INT_ST_RAS",
246 HNS3_ERR_INT_STATS_FIELD_OFFSET(ppu_pf_abnormal_int_ras_cnt)},
249 /* The statistic of reset */
250 static const struct hns3_xstats_name_offset hns3_reset_stats_strings[] = {
252 HNS3_RESET_STATS_FIELD_OFFSET(request_cnt)},
254 HNS3_RESET_STATS_FIELD_OFFSET(global_cnt)},
256 HNS3_RESET_STATS_FIELD_OFFSET(imp_cnt)},
258 HNS3_RESET_STATS_FIELD_OFFSET(exec_cnt)},
259 {"RESET_SUCCESS_CNT",
260 HNS3_RESET_STATS_FIELD_OFFSET(success_cnt)},
262 HNS3_RESET_STATS_FIELD_OFFSET(fail_cnt)},
264 HNS3_RESET_STATS_FIELD_OFFSET(merge_cnt)}
267 /* The statistic of errors in Rx BD */
268 static const struct hns3_xstats_name_offset hns3_rx_bd_error_strings[] = {
269 {"RX_PKT_LEN_ERRORS",
270 HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(pkt_len_errors)},
272 HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l2_errors)},
273 {"RX_L3_CHECKSUM_ERRORS",
274 HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l3_csum_erros)},
275 {"RX_L4_CHECKSUM_ERRORS",
276 HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(l4_csum_erros)},
277 {"RX_OL3_CHECKSUM_ERRORS",
278 HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(ol3_csum_erros)},
279 {"RX_OL4_CHECKSUM_ERRORS",
280 HNS3_RX_BD_ERROR_STATS_FIELD_OFFSET(ol4_csum_erros)}
283 /* The statistic of the Tx errors */
284 static const struct hns3_xstats_name_offset hns3_tx_errors_strings[] = {
285 {"TX_OVER_LENGTH_PKT_CNT",
286 HNS3_TX_ERROR_STATS_FIELD_OFFSET(over_length_pkt_cnt)},
287 {"TX_EXCEED_LIMITED_BD_PKT_CNT",
288 HNS3_TX_ERROR_STATS_FIELD_OFFSET(exceed_limit_bd_pkt_cnt)},
289 {"TX_EXCEED_LIMITED_BD_PKT_REASSEMBLE_FAIL_CNT",
290 HNS3_TX_ERROR_STATS_FIELD_OFFSET(exceed_limit_bd_reassem_fail)},
291 {"TX_UNSUPPORTED_TUNNEL_PKT_CNT",
292 HNS3_TX_ERROR_STATS_FIELD_OFFSET(unsupported_tunnel_pkt_cnt)},
293 {"TX_QUEUE_FULL_CNT",
294 HNS3_TX_ERROR_STATS_FIELD_OFFSET(queue_full_cnt)},
295 {"TX_SHORT_PKT_PAD_FAIL_CNT",
296 HNS3_TX_ERROR_STATS_FIELD_OFFSET(pkt_padding_fail_cnt)}
299 /* The statistic of rx queue */
300 static const struct hns3_xstats_name_offset hns3_rx_queue_strings[] = {
301 {"RX_QUEUE_FBD", HNS3_RING_RX_FBDNUM_REG}
304 /* The statistic of tx queue */
305 static const struct hns3_xstats_name_offset hns3_tx_queue_strings[] = {
306 {"TX_QUEUE_FBD", HNS3_RING_TX_FBDNUM_REG}
309 #define HNS3_NUM_MAC_STATS (sizeof(hns3_mac_strings) / \
310 sizeof(hns3_mac_strings[0]))
312 #define HNS3_NUM_ERROR_INT_XSTATS (sizeof(hns3_error_int_stats_strings) / \
313 sizeof(hns3_error_int_stats_strings[0]))
315 #define HNS3_NUM_RESET_XSTATS (sizeof(hns3_reset_stats_strings) / \
316 sizeof(hns3_reset_stats_strings[0]))
318 #define HNS3_NUM_RX_BD_ERROR_XSTATS (sizeof(hns3_rx_bd_error_strings) / \
319 sizeof(hns3_rx_bd_error_strings[0]))
321 #define HNS3_NUM_TX_ERRORS_XSTATS (sizeof(hns3_tx_errors_strings) / \
322 sizeof(hns3_tx_errors_strings[0]))
324 #define HNS3_NUM_RX_QUEUE_STATS (sizeof(hns3_rx_queue_strings) / \
325 sizeof(hns3_rx_queue_strings[0]))
327 #define HNS3_NUM_TX_QUEUE_STATS (sizeof(hns3_tx_queue_strings) / \
328 sizeof(hns3_tx_queue_strings[0]))
330 #define HNS3_FIX_NUM_STATS (HNS3_NUM_MAC_STATS + HNS3_NUM_ERROR_INT_XSTATS + \
331 HNS3_NUM_RESET_XSTATS)
334 * Query all the MAC statistics data of Network ICL command ,opcode id: 0x0034.
335 * This command is used before send 'query_mac_stat command', the descriptor
336 * number of 'query_mac_stat command' must match with reg_num in this command.
338 * Pointer to structure hns3_hw.
343 hns3_update_mac_stats(struct hns3_hw *hw, const uint32_t desc_num)
345 uint64_t *data = (uint64_t *)(&hw->mac_stats);
346 struct hns3_cmd_desc *desc;
351 desc = rte_malloc("hns3_mac_desc",
352 desc_num * sizeof(struct hns3_cmd_desc), 0);
354 hns3_err(hw, "Mac_update_stats alloced desc malloc fail");
358 hns3_cmd_setup_basic_desc(desc, HNS3_OPC_STATS_MAC_ALL, true);
359 ret = hns3_cmd_send(hw, desc, desc_num);
361 hns3_err(hw, "Update complete MAC pkt stats fail : %d", ret);
366 for (i = 0; i < desc_num; i++) {
367 /* For special opcode 0034, only the first desc has the head */
369 desc_data = (uint64_t *)(&desc[i].data[0]);
370 n = HNS3_RD_FIRST_STATS_NUM;
372 desc_data = (uint64_t *)(&desc[i]);
373 n = HNS3_RD_OTHER_STATS_NUM;
376 for (k = 0; k < n; k++) {
377 *data += rte_le_to_cpu_64(*desc_data);
388 * Query Mac stat reg num command ,opcode id: 0x0033.
389 * This command is used before send 'query_mac_stat command', the descriptor
390 * number of 'query_mac_stat command' must match with reg_num in this command.
392 * Pointer to structure rte_eth_stats.
397 hns3_mac_query_reg_num(struct rte_eth_dev *dev, uint32_t *desc_num)
399 struct hns3_adapter *hns = dev->data->dev_private;
400 struct hns3_hw *hw = &hns->hw;
401 struct hns3_cmd_desc desc;
406 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_MAC_REG_NUM, true);
407 ret = hns3_cmd_send(hw, &desc, 1);
412 * The num of MAC statistics registers that are provided by IMP in this
415 desc_data = (uint32_t *)(&desc.data[0]);
416 reg_num = rte_le_to_cpu_32(*desc_data);
419 * The descriptor number of 'query_additional_mac_stat command' is
420 * '1 + (reg_num-3)/4 + ((reg_num-3)%4 !=0)';
421 * This value is 83 in this version
423 *desc_num = 1 + ((reg_num - 3) >> 2) +
424 (uint32_t)(((reg_num - 3) & 0x3) ? 1 : 0);
430 hns3_query_update_mac_stats(struct rte_eth_dev *dev)
432 struct hns3_adapter *hns = dev->data->dev_private;
433 struct hns3_hw *hw = &hns->hw;
437 ret = hns3_mac_query_reg_num(dev, &desc_num);
439 ret = hns3_update_mac_stats(hw, desc_num);
441 hns3_err(hw, "Query mac reg num fail : %d", ret);
445 /* Get tqp stats from register */
447 hns3_update_tqp_stats(struct hns3_hw *hw)
449 struct hns3_tqp_stats *stats = &hw->tqp_stats;
450 struct hns3_cmd_desc desc;
455 for (i = 0; i < hw->tqps_num; i++) {
456 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_RX_STATUS,
459 desc.data[0] = rte_cpu_to_le_32((uint32_t)i &
461 ret = hns3_cmd_send(hw, &desc, 1);
463 hns3_err(hw, "Failed to query RX No.%d queue stat: %d",
467 cnt = rte_le_to_cpu_32(desc.data[1]);
468 stats->rcb_rx_ring_pktnum_rcd += cnt;
469 stats->rcb_rx_ring_pktnum[i] += cnt;
471 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_QUERY_TX_STATUS,
474 desc.data[0] = rte_cpu_to_le_32((uint32_t)i &
476 ret = hns3_cmd_send(hw, &desc, 1);
478 hns3_err(hw, "Failed to query TX No.%d queue stat: %d",
482 cnt = rte_le_to_cpu_32(desc.data[1]);
483 stats->rcb_tx_ring_pktnum_rcd += cnt;
484 stats->rcb_tx_ring_pktnum[i] += cnt;
491 * Query tqp tx queue statistics ,opcode id: 0x0B03.
492 * Query tqp rx queue statistics ,opcode id: 0x0B13.
493 * Get all statistics of a port.
495 * Pointer to Ethernet device.
497 * Pointer to structure rte_eth_stats.
502 hns3_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *rte_stats)
504 struct hns3_adapter *hns = eth_dev->data->dev_private;
505 struct hns3_hw *hw = &hns->hw;
506 struct hns3_tqp_stats *stats = &hw->tqp_stats;
507 struct hns3_rx_queue *rxq;
508 struct hns3_tx_queue *txq;
514 /* Update tqp stats by read register */
515 ret = hns3_update_tqp_stats(hw);
517 hns3_err(hw, "Update tqp stats fail : %d", ret);
521 /* Get the error stats of received packets */
522 num = RTE_MIN(RTE_ETHDEV_QUEUE_STAT_CNTRS, eth_dev->data->nb_rx_queues);
523 for (i = 0; i != num; ++i) {
524 rxq = eth_dev->data->rx_queues[i];
526 cnt = rxq->l2_errors + rxq->pkt_len_errors;
527 rte_stats->q_errors[i] = cnt;
528 rte_stats->q_ipackets[i] =
529 stats->rcb_rx_ring_pktnum[i] - cnt;
530 rte_stats->ierrors += cnt;
533 /* Get the error stats of transmitted packets */
534 num = RTE_MIN(RTE_ETHDEV_QUEUE_STAT_CNTRS, eth_dev->data->nb_tx_queues);
535 for (i = 0; i < num; i++) {
536 txq = eth_dev->data->tx_queues[i];
538 rte_stats->q_opackets[i] = stats->rcb_tx_ring_pktnum[i];
541 rte_stats->oerrors = 0;
542 rte_stats->ipackets = stats->rcb_rx_ring_pktnum_rcd -
544 rte_stats->opackets = stats->rcb_tx_ring_pktnum_rcd -
546 rte_stats->rx_nombuf = eth_dev->data->rx_mbuf_alloc_failed;
552 hns3_stats_reset(struct rte_eth_dev *eth_dev)
554 struct hns3_adapter *hns = eth_dev->data->dev_private;
555 struct hns3_hw *hw = &hns->hw;
556 struct hns3_tqp_stats *stats = &hw->tqp_stats;
557 struct hns3_cmd_desc desc_reset;
558 struct hns3_rx_queue *rxq;
559 struct hns3_tx_queue *txq;
564 * If this is a reset xstats is NULL, and we have cleared the
565 * registers by reading them.
567 for (i = 0; i < hw->tqps_num; i++) {
568 hns3_cmd_setup_basic_desc(&desc_reset, HNS3_OPC_QUERY_RX_STATUS,
570 desc_reset.data[0] = rte_cpu_to_le_32((uint32_t)i &
572 ret = hns3_cmd_send(hw, &desc_reset, 1);
574 hns3_err(hw, "Failed to reset RX No.%d queue stat: %d",
579 hns3_cmd_setup_basic_desc(&desc_reset, HNS3_OPC_QUERY_TX_STATUS,
581 desc_reset.data[0] = rte_cpu_to_le_32((uint32_t)i &
583 ret = hns3_cmd_send(hw, &desc_reset, 1);
585 hns3_err(hw, "Failed to reset TX No.%d queue stat: %d",
591 /* Clear the Rx BD errors stats */
592 for (i = 0; i != eth_dev->data->nb_rx_queues; ++i) {
593 rxq = eth_dev->data->rx_queues[i];
595 rxq->pkt_len_errors = 0;
597 rxq->l3_csum_erros = 0;
598 rxq->l4_csum_erros = 0;
599 rxq->ol3_csum_erros = 0;
600 rxq->ol4_csum_erros = 0;
604 /* Clear the Tx errors stats */
605 for (i = 0; i != eth_dev->data->nb_tx_queues; ++i) {
606 txq = eth_dev->data->tx_queues[i];
608 txq->over_length_pkt_cnt = 0;
609 txq->exceed_limit_bd_pkt_cnt = 0;
610 txq->exceed_limit_bd_reassem_fail = 0;
611 txq->unsupported_tunnel_pkt_cnt = 0;
612 txq->queue_full_cnt = 0;
613 txq->pkt_padding_fail_cnt = 0;
617 memset(stats, 0, sizeof(struct hns3_tqp_stats));
623 hns3_mac_stats_reset(__rte_unused struct rte_eth_dev *dev)
625 struct hns3_adapter *hns = dev->data->dev_private;
626 struct hns3_hw *hw = &hns->hw;
627 struct hns3_mac_stats *mac_stats = &hw->mac_stats;
630 ret = hns3_query_update_mac_stats(dev);
632 hns3_err(hw, "Clear Mac stats fail : %d", ret);
636 memset(mac_stats, 0, sizeof(struct hns3_mac_stats));
641 /* This function calculates the number of xstats based on the current config */
643 hns3_xstats_calc_num(struct rte_eth_dev *dev)
645 struct hns3_adapter *hns = dev->data->dev_private;
646 int bderr_stats = dev->data->nb_rx_queues * HNS3_NUM_RX_BD_ERROR_XSTATS;
647 int tx_err_stats = dev->data->nb_tx_queues * HNS3_NUM_TX_ERRORS_XSTATS;
648 int rx_queue_stats = dev->data->nb_rx_queues * HNS3_NUM_RX_QUEUE_STATS;
649 int tx_queue_stats = dev->data->nb_tx_queues * HNS3_NUM_TX_QUEUE_STATS;
652 return bderr_stats + tx_err_stats + rx_queue_stats +
653 tx_queue_stats + HNS3_NUM_RESET_XSTATS;
655 return bderr_stats + tx_err_stats + rx_queue_stats +
656 tx_queue_stats + HNS3_FIX_NUM_STATS;
660 hns3_get_queue_stats(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
663 struct hns3_adapter *hns = dev->data->dev_private;
664 struct hns3_hw *hw = &hns->hw;
668 /* Get rx queue stats */
669 for (j = 0; j < dev->data->nb_rx_queues; j++) {
670 for (i = 0; i < HNS3_NUM_RX_QUEUE_STATS; i++) {
671 reg_offset = HNS3_TQP_REG_OFFSET +
672 HNS3_TQP_REG_SIZE * j;
673 xstats[*count].value = hns3_read_dev(hw,
674 reg_offset + hns3_rx_queue_strings[i].offset);
675 xstats[*count].id = *count;
680 /* Get tx queue stats */
681 for (j = 0; j < dev->data->nb_tx_queues; j++) {
682 for (i = 0; i < HNS3_NUM_TX_QUEUE_STATS; i++) {
683 reg_offset = HNS3_TQP_REG_OFFSET +
684 HNS3_TQP_REG_SIZE * j;
685 xstats[*count].value = hns3_read_dev(hw,
686 reg_offset + hns3_tx_queue_strings[i].offset);
687 xstats[*count].id = *count;
695 hns3_error_int_stats_add(struct hns3_adapter *hns, const char *err)
697 struct hns3_pf *pf = &hns->pf;
701 for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) {
702 if (strcmp(hns3_error_int_stats_strings[i].name, err) == 0) {
703 addr = (char *)&pf->abn_int_stats +
704 hns3_error_int_stats_strings[i].offset;
705 *(uint64_t *)addr += 1;
711 * Retrieve extended(tqp | Mac) statistics of an Ethernet device.
713 * Pointer to Ethernet device.
715 * A pointer to a table of structure of type *rte_eth_xstat*
716 * to be filled with device statistics ids and values.
717 * This parameter can be set to NULL if n is 0.
719 * The size of the xstats array (number of elements).
721 * 0 on fail, count(The size of the statistics elements) on success.
724 hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
727 struct hns3_adapter *hns = dev->data->dev_private;
728 struct hns3_pf *pf = &hns->pf;
729 struct hns3_hw *hw = &hns->hw;
730 struct hns3_mac_stats *mac_stats = &hw->mac_stats;
731 struct hns3_reset_stats *reset_stats = &hw->reset.stats;
732 struct hns3_rx_queue *rxq;
733 struct hns3_tx_queue *txq;
742 count = hns3_xstats_calc_num(dev);
749 /* Update Mac stats */
750 ret = hns3_query_update_mac_stats(dev);
752 hns3_err(hw, "Update Mac stats fail : %d", ret);
756 /* Get MAC stats from hw->hw_xstats.mac_stats struct */
757 for (i = 0; i < HNS3_NUM_MAC_STATS; i++) {
758 addr = (char *)mac_stats + hns3_mac_strings[i].offset;
759 xstats[count].value = *(uint64_t *)addr;
760 xstats[count].id = count;
764 for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) {
765 addr = (char *)&pf->abn_int_stats +
766 hns3_error_int_stats_strings[i].offset;
767 xstats[count].value = *(uint64_t *)addr;
768 xstats[count].id = count;
773 /* Get the reset stat */
774 for (i = 0; i < HNS3_NUM_RESET_XSTATS; i++) {
775 addr = (char *)reset_stats + hns3_reset_stats_strings[i].offset;
776 xstats[count].value = *(uint64_t *)addr;
777 xstats[count].id = count;
781 /* Get the Rx BD errors stats */
782 for (j = 0; j < dev->data->nb_rx_queues; j++) {
783 for (i = 0; i < HNS3_NUM_RX_BD_ERROR_XSTATS; i++) {
784 rxq = dev->data->rx_queues[j];
785 addr = (char *)rxq + hns3_rx_bd_error_strings[i].offset;
786 xstats[count].value = *(uint64_t *)addr;
787 xstats[count].id = count;
792 /* Get the Tx errors stats */
793 for (j = 0; j < dev->data->nb_tx_queues; j++) {
794 for (i = 0; i < HNS3_NUM_TX_ERRORS_XSTATS; i++) {
795 txq = dev->data->tx_queues[j];
796 addr = (char *)txq + hns3_tx_errors_strings[i].offset;
797 xstats[count].value = *(uint64_t *)addr;
798 xstats[count].id = count;
803 hns3_get_queue_stats(dev, xstats, &count);
808 * Retrieve names of extended statistics of an Ethernet device.
810 * There is an assumption that 'xstat_names' and 'xstats' arrays are matched
812 * xstats_names[i].name => xstats[i].value
814 * And the array index is same with id field of 'struct rte_eth_xstat':
817 * This assumption makes key-value pair matching less flexible but simpler.
820 * Pointer to Ethernet device.
821 * @param xstats_names
822 * An rte_eth_xstat_name array of at least *size* elements to
823 * be filled. If set to NULL, the function returns the required number
826 * The size of the xstats_names array (number of elements).
828 * - A positive value lower or equal to size: success. The return value
829 * is the number of entries filled in the stats table.
832 hns3_dev_xstats_get_names(struct rte_eth_dev *dev,
833 struct rte_eth_xstat_name *xstats_names,
834 __rte_unused unsigned int size)
836 struct hns3_adapter *hns = dev->data->dev_private;
837 int cnt_stats = hns3_xstats_calc_num(dev);
841 if (xstats_names == NULL)
844 /* Note: size limited checked in rte_eth_xstats_get_names() */
846 /* Get MAC name from hw->hw_xstats.mac_stats struct */
847 for (i = 0; i < HNS3_NUM_MAC_STATS; i++) {
848 snprintf(xstats_names[count].name,
849 sizeof(xstats_names[count].name),
850 "%s", hns3_mac_strings[i].name);
854 for (i = 0; i < HNS3_NUM_ERROR_INT_XSTATS; i++) {
855 snprintf(xstats_names[count].name,
856 sizeof(xstats_names[count].name),
857 "%s", hns3_error_int_stats_strings[i].name);
861 for (i = 0; i < HNS3_NUM_RESET_XSTATS; i++) {
862 snprintf(xstats_names[count].name,
863 sizeof(xstats_names[count].name),
864 "%s", hns3_reset_stats_strings[i].name);
868 for (j = 0; j < dev->data->nb_rx_queues; j++) {
869 for (i = 0; i < HNS3_NUM_RX_BD_ERROR_XSTATS; i++) {
870 snprintf(xstats_names[count].name,
871 sizeof(xstats_names[count].name),
873 hns3_rx_bd_error_strings[i].name);
878 for (j = 0; j < dev->data->nb_tx_queues; j++) {
879 for (i = 0; i < HNS3_NUM_TX_ERRORS_XSTATS; i++) {
880 snprintf(xstats_names[count].name,
881 sizeof(xstats_names[count].name),
883 hns3_tx_errors_strings[i].name);
888 for (j = 0; j < dev->data->nb_rx_queues; j++) {
889 for (i = 0; i < HNS3_NUM_RX_QUEUE_STATS; i++) {
890 snprintf(xstats_names[count].name,
891 sizeof(xstats_names[count].name),
892 "rx_q%u%s", j, hns3_rx_queue_strings[i].name);
897 for (j = 0; j < dev->data->nb_tx_queues; j++) {
898 for (i = 0; i < HNS3_NUM_TX_QUEUE_STATS; i++) {
899 snprintf(xstats_names[count].name,
900 sizeof(xstats_names[count].name),
901 "tx_q%u%s", j, hns3_tx_queue_strings[i].name);
910 * Retrieve extended statistics of an Ethernet device.
913 * Pointer to Ethernet device.
915 * A pointer to an ids array passed by application. This tells which
916 * statistics values function should retrieve. This parameter
917 * can be set to NULL if size is 0. In this case function will retrieve
918 * all avalible statistics.
920 * A pointer to a table to be filled with device statistics values.
922 * The size of the ids array (number of elements).
924 * - A positive value lower or equal to size: success. The return value
925 * is the number of entries filled in the stats table.
926 * - A positive value higher than size: error, the given statistics table
927 * is too small. The return value corresponds to the size that should
928 * be given to succeed. The entries in the table are not valid and
929 * shall not be used by the caller.
933 hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
934 uint64_t *values, uint32_t size)
936 const uint32_t cnt_stats = hns3_xstats_calc_num(dev);
937 struct hns3_adapter *hns = dev->data->dev_private;
938 struct rte_eth_xstat *values_copy;
939 struct hns3_hw *hw = &hns->hw;
940 uint32_t count_value;
945 if (ids == NULL || size < cnt_stats)
948 /* Update tqp stats by read register */
949 ret = hns3_update_tqp_stats(hw);
951 hns3_err(hw, "Update tqp stats fail : %d", ret);
955 len = cnt_stats * sizeof(struct rte_eth_xstat);
956 values_copy = rte_zmalloc("hns3_xstats_values", len, 0);
957 if (values_copy == NULL) {
958 hns3_err(hw, "Failed to allocate %" PRIx64 " bytes needed "
959 "to store statistics values", len);
963 count_value = hns3_dev_xstats_get(dev, values_copy, cnt_stats);
964 if (count_value != cnt_stats) {
965 rte_free(values_copy);
969 for (i = 0; i < size; i++) {
970 if (ids[i] >= cnt_stats) {
971 hns3_err(hw, "ids[%d] (%" PRIx64 ") is invalid, "
972 "should < %u", i, ids[i], cnt_stats);
973 rte_free(values_copy);
976 memcpy(&values[i], &values_copy[ids[i]].value,
980 rte_free(values_copy);
985 * Retrieve names of extended statistics of an Ethernet device.
988 * Pointer to Ethernet device.
989 * @param xstats_names
990 * An rte_eth_xstat_name array of at least *size* elements to
991 * be filled. If set to NULL, the function returns the required number
994 * IDs array given by app to retrieve specific statistics
996 * The size of the xstats_names array (number of elements).
998 * - A positive value lower or equal to size: success. The return value
999 * is the number of entries filled in the stats table.
1000 * - A positive value higher than size: error, the given statistics table
1001 * is too small. The return value corresponds to the size that should
1002 * be given to succeed. The entries in the table are not valid and
1003 * shall not be used by the caller.
1006 hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
1007 struct rte_eth_xstat_name *xstats_names,
1008 const uint64_t *ids, uint32_t size)
1010 const uint32_t cnt_stats = hns3_xstats_calc_num(dev);
1011 struct hns3_adapter *hns = dev->data->dev_private;
1012 struct rte_eth_xstat_name *names_copy;
1013 struct hns3_hw *hw = &hns->hw;
1017 if (ids == NULL || xstats_names == NULL)
1020 len = cnt_stats * sizeof(struct rte_eth_xstat_name);
1021 names_copy = rte_zmalloc("hns3_xstats_names", len, 0);
1022 if (names_copy == NULL) {
1023 hns3_err(hw, "Failed to allocate %" PRIx64 " bytes needed "
1024 "to store statistics names", len);
1028 (void)hns3_dev_xstats_get_names(dev, names_copy, cnt_stats);
1030 for (i = 0; i < size; i++) {
1031 if (ids[i] >= cnt_stats) {
1032 hns3_err(hw, "ids[%d] (%" PRIx64 ") is invalid, "
1033 "should < %u", i, ids[i], cnt_stats);
1034 rte_free(names_copy);
1037 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
1038 "%s", names_copy[ids[i]].name);
1041 rte_free(names_copy);
1046 hns3_dev_xstats_reset(struct rte_eth_dev *dev)
1048 struct hns3_adapter *hns = dev->data->dev_private;
1049 struct hns3_pf *pf = &hns->pf;
1052 /* Clear tqp stats */
1053 ret = hns3_stats_reset(dev);
1057 /* Clear reset stats */
1058 memset(&hns->hw.reset.stats, 0, sizeof(struct hns3_reset_stats));
1063 /* HW registers are cleared on read */
1064 ret = hns3_mac_stats_reset(dev);
1068 /* Clear error stats */
1069 memset(&pf->abn_int_stats, 0, sizeof(struct hns3_err_msix_intr_stats));