1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2018-2019 Hisilicon Limited. */
4 #include <linux/device.h>
6 #include "hclge_debugfs.h"
7 #include "hclge_main.h"
11 static struct hclge_dbg_reg_type_info hclge_dbg_reg_info[] = {
12 { .reg_type = "bios common",
13 .dfx_msg = &hclge_dbg_bios_common_reg[0],
14 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_bios_common_reg),
15 .offset = HCLGE_DBG_DFX_BIOS_OFFSET,
16 .cmd = HCLGE_OPC_DFX_BIOS_COMMON_REG } },
18 .dfx_msg = &hclge_dbg_ssu_reg_0[0],
19 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_ssu_reg_0),
20 .offset = HCLGE_DBG_DFX_SSU_0_OFFSET,
21 .cmd = HCLGE_OPC_DFX_SSU_REG_0 } },
23 .dfx_msg = &hclge_dbg_ssu_reg_1[0],
24 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_ssu_reg_1),
25 .offset = HCLGE_DBG_DFX_SSU_1_OFFSET,
26 .cmd = HCLGE_OPC_DFX_SSU_REG_1 } },
28 .dfx_msg = &hclge_dbg_ssu_reg_2[0],
29 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_ssu_reg_2),
30 .offset = HCLGE_DBG_DFX_SSU_2_OFFSET,
31 .cmd = HCLGE_OPC_DFX_SSU_REG_2 } },
32 { .reg_type = "igu egu",
33 .dfx_msg = &hclge_dbg_igu_egu_reg[0],
34 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_igu_egu_reg),
35 .offset = HCLGE_DBG_DFX_IGU_OFFSET,
36 .cmd = HCLGE_OPC_DFX_IGU_EGU_REG } },
38 .dfx_msg = &hclge_dbg_rpu_reg_0[0],
39 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_rpu_reg_0),
40 .offset = HCLGE_DBG_DFX_RPU_0_OFFSET,
41 .cmd = HCLGE_OPC_DFX_RPU_REG_0 } },
43 .dfx_msg = &hclge_dbg_rpu_reg_1[0],
44 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_rpu_reg_1),
45 .offset = HCLGE_DBG_DFX_RPU_1_OFFSET,
46 .cmd = HCLGE_OPC_DFX_RPU_REG_1 } },
48 .dfx_msg = &hclge_dbg_ncsi_reg[0],
49 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_ncsi_reg),
50 .offset = HCLGE_DBG_DFX_NCSI_OFFSET,
51 .cmd = HCLGE_OPC_DFX_NCSI_REG } },
53 .dfx_msg = &hclge_dbg_rtc_reg[0],
54 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_rtc_reg),
55 .offset = HCLGE_DBG_DFX_RTC_OFFSET,
56 .cmd = HCLGE_OPC_DFX_RTC_REG } },
58 .dfx_msg = &hclge_dbg_ppp_reg[0],
59 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_ppp_reg),
60 .offset = HCLGE_DBG_DFX_PPP_OFFSET,
61 .cmd = HCLGE_OPC_DFX_PPP_REG } },
63 .dfx_msg = &hclge_dbg_rcb_reg[0],
64 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_rcb_reg),
65 .offset = HCLGE_DBG_DFX_RCB_OFFSET,
66 .cmd = HCLGE_OPC_DFX_RCB_REG } },
68 .dfx_msg = &hclge_dbg_tqp_reg[0],
69 .reg_msg = { .msg_num = ARRAY_SIZE(hclge_dbg_tqp_reg),
70 .offset = HCLGE_DBG_DFX_TQP_OFFSET,
71 .cmd = HCLGE_OPC_DFX_TQP_REG } },
74 static int hclge_dbg_get_dfx_bd_num(struct hclge_dev *hdev, int offset)
76 struct hclge_desc desc[HCLGE_GET_DFX_REG_TYPE_CNT];
81 ret = hclge_query_bd_num_cmd_send(hdev, desc);
83 dev_err(&hdev->pdev->dev,
84 "get dfx bdnum fail, ret = %d\n", ret);
88 entries_per_desc = ARRAY_SIZE(desc[0].data);
89 index = offset % entries_per_desc;
90 return le32_to_cpu(desc[offset / entries_per_desc].data[index]);
93 static int hclge_dbg_cmd_send(struct hclge_dev *hdev,
94 struct hclge_desc *desc_src,
95 int index, int bd_num,
96 enum hclge_opcode_type cmd)
98 struct hclge_desc *desc = desc_src;
101 hclge_cmd_setup_basic_desc(desc, cmd, true);
102 desc->data[0] = cpu_to_le32(index);
104 for (i = 1; i < bd_num; i++) {
105 desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
107 hclge_cmd_setup_basic_desc(desc, cmd, true);
110 ret = hclge_cmd_send(&hdev->hw, desc_src, bd_num);
112 dev_err(&hdev->pdev->dev,
113 "cmd(0x%x) send fail, ret = %d\n", cmd, ret);
117 static void hclge_dbg_dump_reg_common(struct hclge_dev *hdev,
118 struct hclge_dbg_reg_type_info *reg_info,
123 const char *s = &cmd_buf[strlen(reg_info->reg_type) + IDX_OFFSET];
124 struct hclge_dbg_dfx_message *dfx_message = reg_info->dfx_msg;
125 struct hclge_dbg_reg_common_msg *reg_msg = ®_info->reg_msg;
126 struct hclge_desc *desc_src;
127 struct hclge_desc *desc;
128 int entries_per_desc;
135 ret = kstrtouint(s, 0, &index);
136 index = (ret != 0) ? 0 : index;
139 bd_num = hclge_dbg_get_dfx_bd_num(hdev, reg_msg->offset);
141 dev_err(&hdev->pdev->dev, "get cmd(%d) bd num(%d) failed\n",
142 reg_msg->offset, bd_num);
146 buf_len = sizeof(struct hclge_desc) * bd_num;
147 desc_src = kzalloc(buf_len, GFP_KERNEL);
149 dev_err(&hdev->pdev->dev, "call kzalloc failed\n");
154 ret = hclge_dbg_cmd_send(hdev, desc, index, bd_num, reg_msg->cmd);
160 entries_per_desc = ARRAY_SIZE(desc->data);
161 min_num = min_t(int, bd_num * entries_per_desc, reg_msg->msg_num);
164 for (i = 0; i < min_num; i++) {
165 if (i > 0 && (i % entries_per_desc) == 0)
167 if (dfx_message->flag)
168 dev_info(&hdev->pdev->dev, "%s: 0x%x\n",
169 dfx_message->message,
170 le32_to_cpu(desc->data[i % entries_per_desc]));
178 static void hclge_dbg_dump_dcb(struct hclge_dev *hdev, const char *cmd_buf)
180 struct device *dev = &hdev->pdev->dev;
181 struct hclge_dbg_bitmap_cmd *bitmap;
182 enum hclge_opcode_type cmd;
183 int rq_id, pri_id, qset_id;
184 int port_id, nq_id, pg_id;
185 struct hclge_desc desc[2];
189 cnt = sscanf(cmd_buf, "%i %i %i %i %i %i",
190 &port_id, &pri_id, &pg_id, &rq_id, &nq_id, &qset_id);
192 dev_err(&hdev->pdev->dev,
193 "dump dcb: bad command parameter, cnt=%d\n", cnt);
197 cmd = HCLGE_OPC_QSET_DFX_STS;
198 ret = hclge_dbg_cmd_send(hdev, desc, qset_id, 1, cmd);
200 goto err_dcb_cmd_send;
202 bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
203 dev_info(dev, "roce_qset_mask: 0x%x\n", bitmap->bit0);
204 dev_info(dev, "nic_qs_mask: 0x%x\n", bitmap->bit1);
205 dev_info(dev, "qs_shaping_pass: 0x%x\n", bitmap->bit2);
206 dev_info(dev, "qs_bp_sts: 0x%x\n", bitmap->bit3);
208 cmd = HCLGE_OPC_PRI_DFX_STS;
209 ret = hclge_dbg_cmd_send(hdev, desc, pri_id, 1, cmd);
211 goto err_dcb_cmd_send;
213 bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
214 dev_info(dev, "pri_mask: 0x%x\n", bitmap->bit0);
215 dev_info(dev, "pri_cshaping_pass: 0x%x\n", bitmap->bit1);
216 dev_info(dev, "pri_pshaping_pass: 0x%x\n", bitmap->bit2);
218 cmd = HCLGE_OPC_PG_DFX_STS;
219 ret = hclge_dbg_cmd_send(hdev, desc, pg_id, 1, cmd);
221 goto err_dcb_cmd_send;
223 bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
224 dev_info(dev, "pg_mask: 0x%x\n", bitmap->bit0);
225 dev_info(dev, "pg_cshaping_pass: 0x%x\n", bitmap->bit1);
226 dev_info(dev, "pg_pshaping_pass: 0x%x\n", bitmap->bit2);
228 cmd = HCLGE_OPC_PORT_DFX_STS;
229 ret = hclge_dbg_cmd_send(hdev, desc, port_id, 1, cmd);
231 goto err_dcb_cmd_send;
233 bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
234 dev_info(dev, "port_mask: 0x%x\n", bitmap->bit0);
235 dev_info(dev, "port_shaping_pass: 0x%x\n", bitmap->bit1);
237 cmd = HCLGE_OPC_SCH_NQ_CNT;
238 ret = hclge_dbg_cmd_send(hdev, desc, nq_id, 1, cmd);
240 goto err_dcb_cmd_send;
242 dev_info(dev, "sch_nq_cnt: 0x%x\n", le32_to_cpu(desc[0].data[1]));
244 cmd = HCLGE_OPC_SCH_RQ_CNT;
245 ret = hclge_dbg_cmd_send(hdev, desc, nq_id, 1, cmd);
247 goto err_dcb_cmd_send;
249 dev_info(dev, "sch_rq_cnt: 0x%x\n", le32_to_cpu(desc[0].data[1]));
251 cmd = HCLGE_OPC_TM_INTERNAL_STS;
252 ret = hclge_dbg_cmd_send(hdev, desc, 0, 2, cmd);
254 goto err_dcb_cmd_send;
256 dev_info(dev, "pri_bp: 0x%x\n", le32_to_cpu(desc[0].data[1]));
257 dev_info(dev, "fifo_dfx_info: 0x%x\n", le32_to_cpu(desc[0].data[2]));
258 dev_info(dev, "sch_roce_fifo_afull_gap: 0x%x\n",
259 le32_to_cpu(desc[0].data[3]));
260 dev_info(dev, "tx_private_waterline: 0x%x\n",
261 le32_to_cpu(desc[0].data[4]));
262 dev_info(dev, "tm_bypass_en: 0x%x\n", le32_to_cpu(desc[0].data[5]));
263 dev_info(dev, "SSU_TM_BYPASS_EN: 0x%x\n", le32_to_cpu(desc[1].data[0]));
264 dev_info(dev, "SSU_RESERVE_CFG: 0x%x\n", le32_to_cpu(desc[1].data[1]));
266 cmd = HCLGE_OPC_TM_INTERNAL_CNT;
267 ret = hclge_dbg_cmd_send(hdev, desc, port_id, 1, cmd);
269 goto err_dcb_cmd_send;
271 dev_info(dev, "SCH_NIC_NUM: 0x%x\n", le32_to_cpu(desc[0].data[1]));
272 dev_info(dev, "SCH_ROCE_NUM: 0x%x\n", le32_to_cpu(desc[0].data[2]));
274 cmd = HCLGE_OPC_TM_INTERNAL_STS_1;
275 ret = hclge_dbg_cmd_send(hdev, desc, port_id, 1, cmd);
277 goto err_dcb_cmd_send;
279 dev_info(dev, "TC_MAP_SEL: 0x%x\n", le32_to_cpu(desc[0].data[1]));
280 dev_info(dev, "IGU_PFC_PRI_EN: 0x%x\n", le32_to_cpu(desc[0].data[2]));
281 dev_info(dev, "MAC_PFC_PRI_EN: 0x%x\n", le32_to_cpu(desc[0].data[3]));
282 dev_info(dev, "IGU_PRI_MAP_TC_CFG: 0x%x\n",
283 le32_to_cpu(desc[0].data[4]));
284 dev_info(dev, "IGU_TX_PRI_MAP_TC_CFG: 0x%x\n",
285 le32_to_cpu(desc[0].data[5]));
289 dev_err(&hdev->pdev->dev,
290 "failed to dump dcb dfx, cmd = %#x, ret = %d\n",
294 static void hclge_dbg_dump_reg_cmd(struct hclge_dev *hdev, const char *cmd_buf)
296 struct hclge_dbg_reg_type_info *reg_info;
297 bool has_dump = false;
300 for (i = 0; i < ARRAY_SIZE(hclge_dbg_reg_info); i++) {
301 reg_info = &hclge_dbg_reg_info[i];
302 if (!strncmp(cmd_buf, reg_info->reg_type,
303 strlen(reg_info->reg_type))) {
304 hclge_dbg_dump_reg_common(hdev, reg_info, cmd_buf);
309 if (strncmp(cmd_buf, "dcb", 3) == 0) {
310 hclge_dbg_dump_dcb(hdev, &cmd_buf[sizeof("dcb")]);
315 dev_info(&hdev->pdev->dev, "unknown command\n");
320 static void hclge_title_idx_print(struct hclge_dev *hdev, bool flag, int index,
321 char *title_buf, char *true_buf,
325 dev_info(&hdev->pdev->dev, "%s(%d): %s weight: %u\n",
326 title_buf, index, true_buf,
327 hdev->tm_info.pg_info[0].tc_dwrr[index]);
329 dev_info(&hdev->pdev->dev, "%s(%d): %s\n", title_buf, index,
333 static void hclge_dbg_dump_tc(struct hclge_dev *hdev)
335 struct hclge_ets_tc_weight_cmd *ets_weight;
336 struct hclge_desc desc;
339 if (!hnae3_dev_dcb_supported(hdev)) {
340 dev_info(&hdev->pdev->dev,
341 "Only DCB-supported dev supports tc\n");
345 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_ETS_TC_WEIGHT, true);
347 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
349 dev_err(&hdev->pdev->dev, "dump tc fail, ret = %d\n", ret);
353 ets_weight = (struct hclge_ets_tc_weight_cmd *)desc.data;
355 dev_info(&hdev->pdev->dev, "dump tc: %u tc enabled\n",
356 hdev->tm_info.num_tc);
357 dev_info(&hdev->pdev->dev, "weight_offset: %u\n",
358 ets_weight->weight_offset);
360 for (i = 0; i < HNAE3_MAX_TC; i++)
361 hclge_title_idx_print(hdev, ets_weight->tc_weight[i], i,
362 "tc", "no sp mode", "sp mode");
365 static void hclge_dbg_dump_tm_pg(struct hclge_dev *hdev)
367 struct hclge_port_shapping_cmd *port_shap_cfg_cmd;
368 struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
369 struct hclge_pg_shapping_cmd *pg_shap_cfg_cmd;
370 enum hclge_opcode_type cmd;
371 struct hclge_desc desc;
374 cmd = HCLGE_OPC_TM_PG_C_SHAPPING;
375 hclge_cmd_setup_basic_desc(&desc, cmd, true);
376 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
378 goto err_tm_pg_cmd_send;
380 pg_shap_cfg_cmd = (struct hclge_pg_shapping_cmd *)desc.data;
381 dev_info(&hdev->pdev->dev, "PG_C pg_id: %u\n", pg_shap_cfg_cmd->pg_id);
382 dev_info(&hdev->pdev->dev, "PG_C pg_shapping: 0x%x\n",
383 le32_to_cpu(pg_shap_cfg_cmd->pg_shapping_para));
385 cmd = HCLGE_OPC_TM_PG_P_SHAPPING;
386 hclge_cmd_setup_basic_desc(&desc, cmd, true);
387 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
389 goto err_tm_pg_cmd_send;
391 pg_shap_cfg_cmd = (struct hclge_pg_shapping_cmd *)desc.data;
392 dev_info(&hdev->pdev->dev, "PG_P pg_id: %u\n", pg_shap_cfg_cmd->pg_id);
393 dev_info(&hdev->pdev->dev, "PG_P pg_shapping: 0x%x\n",
394 le32_to_cpu(pg_shap_cfg_cmd->pg_shapping_para));
396 cmd = HCLGE_OPC_TM_PORT_SHAPPING;
397 hclge_cmd_setup_basic_desc(&desc, cmd, true);
398 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
400 goto err_tm_pg_cmd_send;
402 port_shap_cfg_cmd = (struct hclge_port_shapping_cmd *)desc.data;
403 dev_info(&hdev->pdev->dev, "PORT port_shapping: 0x%x\n",
404 le32_to_cpu(port_shap_cfg_cmd->port_shapping_para));
406 cmd = HCLGE_OPC_TM_PG_SCH_MODE_CFG;
407 hclge_cmd_setup_basic_desc(&desc, cmd, true);
408 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
410 goto err_tm_pg_cmd_send;
412 dev_info(&hdev->pdev->dev, "PG_SCH pg_id: %u\n",
413 le32_to_cpu(desc.data[0]));
415 cmd = HCLGE_OPC_TM_PRI_SCH_MODE_CFG;
416 hclge_cmd_setup_basic_desc(&desc, cmd, true);
417 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
419 goto err_tm_pg_cmd_send;
421 dev_info(&hdev->pdev->dev, "PRI_SCH pri_id: %u\n",
422 le32_to_cpu(desc.data[0]));
424 cmd = HCLGE_OPC_TM_QS_SCH_MODE_CFG;
425 hclge_cmd_setup_basic_desc(&desc, cmd, true);
426 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
428 goto err_tm_pg_cmd_send;
430 dev_info(&hdev->pdev->dev, "QS_SCH qs_id: %u\n",
431 le32_to_cpu(desc.data[0]));
433 if (!hnae3_dev_dcb_supported(hdev)) {
434 dev_info(&hdev->pdev->dev,
435 "Only DCB-supported dev supports tm mapping\n");
439 cmd = HCLGE_OPC_TM_BP_TO_QSET_MAPPING;
440 hclge_cmd_setup_basic_desc(&desc, cmd, true);
441 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
443 goto err_tm_pg_cmd_send;
445 bp_to_qs_map_cmd = (struct hclge_bp_to_qs_map_cmd *)desc.data;
446 dev_info(&hdev->pdev->dev, "BP_TO_QSET tc_id: %u\n",
447 bp_to_qs_map_cmd->tc_id);
448 dev_info(&hdev->pdev->dev, "BP_TO_QSET qs_group_id: 0x%x\n",
449 bp_to_qs_map_cmd->qs_group_id);
450 dev_info(&hdev->pdev->dev, "BP_TO_QSET qs_bit_map: 0x%x\n",
451 le32_to_cpu(bp_to_qs_map_cmd->qs_bit_map));
455 dev_err(&hdev->pdev->dev, "dump tm_pg fail(0x%x), ret = %d\n",
459 static void hclge_dbg_dump_tm(struct hclge_dev *hdev)
461 struct hclge_priority_weight_cmd *priority_weight;
462 struct hclge_pg_to_pri_link_cmd *pg_to_pri_map;
463 struct hclge_qs_to_pri_link_cmd *qs_to_pri_map;
464 struct hclge_nq_to_qs_link_cmd *nq_to_qs_map;
465 struct hclge_pri_shapping_cmd *shap_cfg_cmd;
466 struct hclge_pg_weight_cmd *pg_weight;
467 struct hclge_qs_weight_cmd *qs_weight;
468 enum hclge_opcode_type cmd;
469 struct hclge_desc desc;
472 cmd = HCLGE_OPC_TM_PG_TO_PRI_LINK;
473 hclge_cmd_setup_basic_desc(&desc, cmd, true);
474 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
476 goto err_tm_cmd_send;
478 pg_to_pri_map = (struct hclge_pg_to_pri_link_cmd *)desc.data;
479 dev_info(&hdev->pdev->dev, "dump tm\n");
480 dev_info(&hdev->pdev->dev, "PG_TO_PRI gp_id: %u\n",
481 pg_to_pri_map->pg_id);
482 dev_info(&hdev->pdev->dev, "PG_TO_PRI map: 0x%x\n",
483 pg_to_pri_map->pri_bit_map);
485 cmd = HCLGE_OPC_TM_QS_TO_PRI_LINK;
486 hclge_cmd_setup_basic_desc(&desc, cmd, true);
487 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
489 goto err_tm_cmd_send;
491 qs_to_pri_map = (struct hclge_qs_to_pri_link_cmd *)desc.data;
492 dev_info(&hdev->pdev->dev, "QS_TO_PRI qs_id: %u\n",
493 le16_to_cpu(qs_to_pri_map->qs_id));
494 dev_info(&hdev->pdev->dev, "QS_TO_PRI priority: %u\n",
495 qs_to_pri_map->priority);
496 dev_info(&hdev->pdev->dev, "QS_TO_PRI link_vld: %u\n",
497 qs_to_pri_map->link_vld);
499 cmd = HCLGE_OPC_TM_NQ_TO_QS_LINK;
500 hclge_cmd_setup_basic_desc(&desc, cmd, true);
501 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
503 goto err_tm_cmd_send;
505 nq_to_qs_map = (struct hclge_nq_to_qs_link_cmd *)desc.data;
506 dev_info(&hdev->pdev->dev, "NQ_TO_QS nq_id: %u\n",
507 le16_to_cpu(nq_to_qs_map->nq_id));
508 dev_info(&hdev->pdev->dev, "NQ_TO_QS qset_id: 0x%x\n",
509 le16_to_cpu(nq_to_qs_map->qset_id));
511 cmd = HCLGE_OPC_TM_PG_WEIGHT;
512 hclge_cmd_setup_basic_desc(&desc, cmd, true);
513 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
515 goto err_tm_cmd_send;
517 pg_weight = (struct hclge_pg_weight_cmd *)desc.data;
518 dev_info(&hdev->pdev->dev, "PG pg_id: %u\n", pg_weight->pg_id);
519 dev_info(&hdev->pdev->dev, "PG dwrr: %u\n", pg_weight->dwrr);
521 cmd = HCLGE_OPC_TM_QS_WEIGHT;
522 hclge_cmd_setup_basic_desc(&desc, cmd, true);
523 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
525 goto err_tm_cmd_send;
527 qs_weight = (struct hclge_qs_weight_cmd *)desc.data;
528 dev_info(&hdev->pdev->dev, "QS qs_id: %u\n",
529 le16_to_cpu(qs_weight->qs_id));
530 dev_info(&hdev->pdev->dev, "QS dwrr: %u\n", qs_weight->dwrr);
532 cmd = HCLGE_OPC_TM_PRI_WEIGHT;
533 hclge_cmd_setup_basic_desc(&desc, cmd, true);
534 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
536 goto err_tm_cmd_send;
538 priority_weight = (struct hclge_priority_weight_cmd *)desc.data;
539 dev_info(&hdev->pdev->dev, "PRI pri_id: %u\n", priority_weight->pri_id);
540 dev_info(&hdev->pdev->dev, "PRI dwrr: %u\n", priority_weight->dwrr);
542 cmd = HCLGE_OPC_TM_PRI_C_SHAPPING;
543 hclge_cmd_setup_basic_desc(&desc, cmd, true);
544 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
546 goto err_tm_cmd_send;
548 shap_cfg_cmd = (struct hclge_pri_shapping_cmd *)desc.data;
549 dev_info(&hdev->pdev->dev, "PRI_C pri_id: %u\n", shap_cfg_cmd->pri_id);
550 dev_info(&hdev->pdev->dev, "PRI_C pri_shapping: 0x%x\n",
551 le32_to_cpu(shap_cfg_cmd->pri_shapping_para));
553 cmd = HCLGE_OPC_TM_PRI_P_SHAPPING;
554 hclge_cmd_setup_basic_desc(&desc, cmd, true);
555 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
557 goto err_tm_cmd_send;
559 shap_cfg_cmd = (struct hclge_pri_shapping_cmd *)desc.data;
560 dev_info(&hdev->pdev->dev, "PRI_P pri_id: %u\n", shap_cfg_cmd->pri_id);
561 dev_info(&hdev->pdev->dev, "PRI_P pri_shapping: 0x%x\n",
562 le32_to_cpu(shap_cfg_cmd->pri_shapping_para));
564 hclge_dbg_dump_tm_pg(hdev);
569 dev_err(&hdev->pdev->dev, "dump tm fail(0x%x), ret = %d\n",
573 static void hclge_dbg_dump_tm_map(struct hclge_dev *hdev,
576 struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
577 struct hclge_nq_to_qs_link_cmd *nq_to_qs_map;
578 struct hclge_qs_to_pri_link_cmd *map;
579 struct hclge_tqp_tx_queue_tc_cmd *tc;
580 enum hclge_opcode_type cmd;
581 struct hclge_desc desc;
582 int queue_id, group_id;
588 ret = kstrtouint(cmd_buf, 0, &queue_id);
589 queue_id = (ret != 0) ? 0 : queue_id;
591 cmd = HCLGE_OPC_TM_NQ_TO_QS_LINK;
592 nq_to_qs_map = (struct hclge_nq_to_qs_link_cmd *)desc.data;
593 hclge_cmd_setup_basic_desc(&desc, cmd, true);
594 nq_to_qs_map->nq_id = cpu_to_le16(queue_id);
595 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
597 goto err_tm_map_cmd_send;
598 qset_id = le16_to_cpu(nq_to_qs_map->qset_id) & 0x3FF;
600 cmd = HCLGE_OPC_TM_QS_TO_PRI_LINK;
601 map = (struct hclge_qs_to_pri_link_cmd *)desc.data;
602 hclge_cmd_setup_basic_desc(&desc, cmd, true);
603 map->qs_id = cpu_to_le16(qset_id);
604 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
606 goto err_tm_map_cmd_send;
607 pri_id = map->priority;
609 cmd = HCLGE_OPC_TQP_TX_QUEUE_TC;
610 tc = (struct hclge_tqp_tx_queue_tc_cmd *)desc.data;
611 hclge_cmd_setup_basic_desc(&desc, cmd, true);
612 tc->queue_id = cpu_to_le16(queue_id);
613 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
615 goto err_tm_map_cmd_send;
616 tc_id = tc->tc_id & 0x7;
618 dev_info(&hdev->pdev->dev, "queue_id | qset_id | pri_id | tc_id\n");
619 dev_info(&hdev->pdev->dev, "%04d | %04d | %02d | %02d\n",
620 queue_id, qset_id, pri_id, tc_id);
622 if (!hnae3_dev_dcb_supported(hdev)) {
623 dev_info(&hdev->pdev->dev,
624 "Only DCB-supported dev supports tm mapping\n");
628 cmd = HCLGE_OPC_TM_BP_TO_QSET_MAPPING;
629 bp_to_qs_map_cmd = (struct hclge_bp_to_qs_map_cmd *)desc.data;
630 for (group_id = 0; group_id < 32; group_id++) {
631 hclge_cmd_setup_basic_desc(&desc, cmd, true);
632 bp_to_qs_map_cmd->tc_id = tc_id;
633 bp_to_qs_map_cmd->qs_group_id = group_id;
634 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
636 goto err_tm_map_cmd_send;
638 qset_maping[group_id] =
639 le32_to_cpu(bp_to_qs_map_cmd->qs_bit_map);
642 dev_info(&hdev->pdev->dev, "index | tm bp qset maping:\n");
645 for (group_id = 0; group_id < 4; group_id++) {
646 dev_info(&hdev->pdev->dev,
647 "%04d | %08x:%08x:%08x:%08x:%08x:%08x:%08x:%08x\n",
648 group_id * 256, qset_maping[(u32)(i + 7)],
649 qset_maping[(u32)(i + 6)], qset_maping[(u32)(i + 5)],
650 qset_maping[(u32)(i + 4)], qset_maping[(u32)(i + 3)],
651 qset_maping[(u32)(i + 2)], qset_maping[(u32)(i + 1)],
659 dev_err(&hdev->pdev->dev, "dump tqp map fail(0x%x), ret = %d\n",
663 static void hclge_dbg_dump_qos_pause_cfg(struct hclge_dev *hdev)
665 struct hclge_cfg_pause_param_cmd *pause_param;
666 struct hclge_desc desc;
669 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_MAC_PARA, true);
671 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
673 dev_err(&hdev->pdev->dev, "dump checksum fail, ret = %d\n",
678 pause_param = (struct hclge_cfg_pause_param_cmd *)desc.data;
679 dev_info(&hdev->pdev->dev, "dump qos pause cfg\n");
680 dev_info(&hdev->pdev->dev, "pause_trans_gap: 0x%x\n",
681 pause_param->pause_trans_gap);
682 dev_info(&hdev->pdev->dev, "pause_trans_time: 0x%x\n",
683 le16_to_cpu(pause_param->pause_trans_time));
686 static void hclge_dbg_dump_qos_pri_map(struct hclge_dev *hdev)
688 struct hclge_qos_pri_map_cmd *pri_map;
689 struct hclge_desc desc;
692 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_PRI_TO_TC_MAPPING, true);
694 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
696 dev_err(&hdev->pdev->dev,
697 "dump qos pri map fail, ret = %d\n", ret);
701 pri_map = (struct hclge_qos_pri_map_cmd *)desc.data;
702 dev_info(&hdev->pdev->dev, "dump qos pri map\n");
703 dev_info(&hdev->pdev->dev, "vlan_to_pri: 0x%x\n", pri_map->vlan_pri);
704 dev_info(&hdev->pdev->dev, "pri_0_to_tc: 0x%x\n", pri_map->pri0_tc);
705 dev_info(&hdev->pdev->dev, "pri_1_to_tc: 0x%x\n", pri_map->pri1_tc);
706 dev_info(&hdev->pdev->dev, "pri_2_to_tc: 0x%x\n", pri_map->pri2_tc);
707 dev_info(&hdev->pdev->dev, "pri_3_to_tc: 0x%x\n", pri_map->pri3_tc);
708 dev_info(&hdev->pdev->dev, "pri_4_to_tc: 0x%x\n", pri_map->pri4_tc);
709 dev_info(&hdev->pdev->dev, "pri_5_to_tc: 0x%x\n", pri_map->pri5_tc);
710 dev_info(&hdev->pdev->dev, "pri_6_to_tc: 0x%x\n", pri_map->pri6_tc);
711 dev_info(&hdev->pdev->dev, "pri_7_to_tc: 0x%x\n", pri_map->pri7_tc);
714 static void hclge_dbg_dump_qos_buf_cfg(struct hclge_dev *hdev)
716 struct hclge_tx_buff_alloc_cmd *tx_buf_cmd;
717 struct hclge_rx_priv_buff_cmd *rx_buf_cmd;
718 struct hclge_rx_priv_wl_buf *rx_priv_wl;
719 struct hclge_rx_com_wl *rx_packet_cnt;
720 struct hclge_rx_com_thrd *rx_com_thrd;
721 struct hclge_rx_com_wl *rx_com_wl;
722 enum hclge_opcode_type cmd;
723 struct hclge_desc desc[2];
726 cmd = HCLGE_OPC_TX_BUFF_ALLOC;
727 hclge_cmd_setup_basic_desc(desc, cmd, true);
728 ret = hclge_cmd_send(&hdev->hw, desc, 1);
730 goto err_qos_cmd_send;
732 dev_info(&hdev->pdev->dev, "dump qos buf cfg\n");
734 tx_buf_cmd = (struct hclge_tx_buff_alloc_cmd *)desc[0].data;
735 for (i = 0; i < HCLGE_MAX_TC_NUM; i++)
736 dev_info(&hdev->pdev->dev, "tx_packet_buf_tc_%d: 0x%x\n", i,
737 le16_to_cpu(tx_buf_cmd->tx_pkt_buff[i]));
739 cmd = HCLGE_OPC_RX_PRIV_BUFF_ALLOC;
740 hclge_cmd_setup_basic_desc(desc, cmd, true);
741 ret = hclge_cmd_send(&hdev->hw, desc, 1);
743 goto err_qos_cmd_send;
745 dev_info(&hdev->pdev->dev, "\n");
746 rx_buf_cmd = (struct hclge_rx_priv_buff_cmd *)desc[0].data;
747 for (i = 0; i < HCLGE_MAX_TC_NUM; i++)
748 dev_info(&hdev->pdev->dev, "rx_packet_buf_tc_%d: 0x%x\n", i,
749 le16_to_cpu(rx_buf_cmd->buf_num[i]));
751 dev_info(&hdev->pdev->dev, "rx_share_buf: 0x%x\n",
752 le16_to_cpu(rx_buf_cmd->shared_buf));
754 cmd = HCLGE_OPC_RX_COM_WL_ALLOC;
755 hclge_cmd_setup_basic_desc(desc, cmd, true);
756 ret = hclge_cmd_send(&hdev->hw, desc, 1);
758 goto err_qos_cmd_send;
760 rx_com_wl = (struct hclge_rx_com_wl *)desc[0].data;
761 dev_info(&hdev->pdev->dev, "\n");
762 dev_info(&hdev->pdev->dev, "rx_com_wl: high: 0x%x, low: 0x%x\n",
763 le16_to_cpu(rx_com_wl->com_wl.high),
764 le16_to_cpu(rx_com_wl->com_wl.low));
766 cmd = HCLGE_OPC_RX_GBL_PKT_CNT;
767 hclge_cmd_setup_basic_desc(desc, cmd, true);
768 ret = hclge_cmd_send(&hdev->hw, desc, 1);
770 goto err_qos_cmd_send;
772 rx_packet_cnt = (struct hclge_rx_com_wl *)desc[0].data;
773 dev_info(&hdev->pdev->dev,
774 "rx_global_packet_cnt: high: 0x%x, low: 0x%x\n",
775 le16_to_cpu(rx_packet_cnt->com_wl.high),
776 le16_to_cpu(rx_packet_cnt->com_wl.low));
777 dev_info(&hdev->pdev->dev, "\n");
779 if (!hnae3_dev_dcb_supported(hdev)) {
780 dev_info(&hdev->pdev->dev,
781 "Only DCB-supported dev supports rx priv wl\n");
784 cmd = HCLGE_OPC_RX_PRIV_WL_ALLOC;
785 hclge_cmd_setup_basic_desc(&desc[0], cmd, true);
786 desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
787 hclge_cmd_setup_basic_desc(&desc[1], cmd, true);
788 ret = hclge_cmd_send(&hdev->hw, desc, 2);
790 goto err_qos_cmd_send;
792 rx_priv_wl = (struct hclge_rx_priv_wl_buf *)desc[0].data;
793 for (i = 0; i < HCLGE_TC_NUM_ONE_DESC; i++)
794 dev_info(&hdev->pdev->dev,
795 "rx_priv_wl_tc_%d: high: 0x%x, low: 0x%x\n", i,
796 le16_to_cpu(rx_priv_wl->tc_wl[i].high),
797 le16_to_cpu(rx_priv_wl->tc_wl[i].low));
799 rx_priv_wl = (struct hclge_rx_priv_wl_buf *)desc[1].data;
800 for (i = 0; i < HCLGE_TC_NUM_ONE_DESC; i++)
801 dev_info(&hdev->pdev->dev,
802 "rx_priv_wl_tc_%d: high: 0x%x, low: 0x%x\n",
803 i + HCLGE_TC_NUM_ONE_DESC,
804 le16_to_cpu(rx_priv_wl->tc_wl[i].high),
805 le16_to_cpu(rx_priv_wl->tc_wl[i].low));
807 cmd = HCLGE_OPC_RX_COM_THRD_ALLOC;
808 hclge_cmd_setup_basic_desc(&desc[0], cmd, true);
809 desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
810 hclge_cmd_setup_basic_desc(&desc[1], cmd, true);
811 ret = hclge_cmd_send(&hdev->hw, desc, 2);
813 goto err_qos_cmd_send;
815 dev_info(&hdev->pdev->dev, "\n");
816 rx_com_thrd = (struct hclge_rx_com_thrd *)desc[0].data;
817 for (i = 0; i < HCLGE_TC_NUM_ONE_DESC; i++)
818 dev_info(&hdev->pdev->dev,
819 "rx_com_thrd_tc_%d: high: 0x%x, low: 0x%x\n", i,
820 le16_to_cpu(rx_com_thrd->com_thrd[i].high),
821 le16_to_cpu(rx_com_thrd->com_thrd[i].low));
823 rx_com_thrd = (struct hclge_rx_com_thrd *)desc[1].data;
824 for (i = 0; i < HCLGE_TC_NUM_ONE_DESC; i++)
825 dev_info(&hdev->pdev->dev,
826 "rx_com_thrd_tc_%d: high: 0x%x, low: 0x%x\n",
827 i + HCLGE_TC_NUM_ONE_DESC,
828 le16_to_cpu(rx_com_thrd->com_thrd[i].high),
829 le16_to_cpu(rx_com_thrd->com_thrd[i].low));
833 dev_err(&hdev->pdev->dev,
834 "dump qos buf cfg fail(0x%x), ret = %d\n", cmd, ret);
837 static void hclge_dbg_dump_mng_table(struct hclge_dev *hdev)
839 struct hclge_mac_ethertype_idx_rd_cmd *req0;
840 char printf_buf[HCLGE_DBG_BUF_LEN];
841 struct hclge_desc desc;
845 dev_info(&hdev->pdev->dev, "mng tab:\n");
846 memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
848 "entry|mac_addr |mask|ether|mask|vlan|mask",
849 HCLGE_DBG_BUF_LEN - 1);
850 strncat(printf_buf + strlen(printf_buf),
851 "|i_map|i_dir|e_type|pf_id|vf_id|q_id|drop\n",
852 HCLGE_DBG_BUF_LEN - strlen(printf_buf) - 1);
854 dev_info(&hdev->pdev->dev, "%s", printf_buf);
856 for (i = 0; i < HCLGE_DBG_MNG_TBL_MAX; i++) {
857 hclge_cmd_setup_basic_desc(&desc, HCLGE_MAC_ETHERTYPE_IDX_RD,
859 req0 = (struct hclge_mac_ethertype_idx_rd_cmd *)&desc.data;
860 req0->index = cpu_to_le16(i);
862 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
864 dev_err(&hdev->pdev->dev,
865 "call hclge_cmd_send fail, ret = %d\n", ret);
869 if (!req0->resp_code)
872 memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
873 snprintf(printf_buf, HCLGE_DBG_BUF_LEN,
874 "%02u |%02x:%02x:%02x:%02x:%02x:%02x|",
875 le16_to_cpu(req0->index),
876 req0->mac_addr[0], req0->mac_addr[1],
877 req0->mac_addr[2], req0->mac_addr[3],
878 req0->mac_addr[4], req0->mac_addr[5]);
880 snprintf(printf_buf + strlen(printf_buf),
881 HCLGE_DBG_BUF_LEN - strlen(printf_buf),
882 "%x |%04x |%x |%04x|%x |%02x |%02x |",
883 !!(req0->flags & HCLGE_DBG_MNG_MAC_MASK_B),
884 le16_to_cpu(req0->ethter_type),
885 !!(req0->flags & HCLGE_DBG_MNG_ETHER_MASK_B),
886 le16_to_cpu(req0->vlan_tag) & HCLGE_DBG_MNG_VLAN_TAG,
887 !!(req0->flags & HCLGE_DBG_MNG_VLAN_MASK_B),
888 req0->i_port_bitmap, req0->i_port_direction);
890 msg_egress_port = le16_to_cpu(req0->egress_port);
891 snprintf(printf_buf + strlen(printf_buf),
892 HCLGE_DBG_BUF_LEN - strlen(printf_buf),
893 "%x |%x |%02x |%04x|%x\n",
894 !!(msg_egress_port & HCLGE_DBG_MNG_E_TYPE_B),
895 msg_egress_port & HCLGE_DBG_MNG_PF_ID,
896 (msg_egress_port >> 3) & HCLGE_DBG_MNG_VF_ID,
897 le16_to_cpu(req0->egress_queue),
898 !!(msg_egress_port & HCLGE_DBG_MNG_DROP_B));
900 dev_info(&hdev->pdev->dev, "%s", printf_buf);
904 static int hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
907 struct hclge_fd_tcam_config_1_cmd *req1;
908 struct hclge_fd_tcam_config_2_cmd *req2;
909 struct hclge_fd_tcam_config_3_cmd *req3;
910 struct hclge_desc desc[3];
914 hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_FD_TCAM_OP, true);
915 desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
916 hclge_cmd_setup_basic_desc(&desc[1], HCLGE_OPC_FD_TCAM_OP, true);
917 desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
918 hclge_cmd_setup_basic_desc(&desc[2], HCLGE_OPC_FD_TCAM_OP, true);
920 req1 = (struct hclge_fd_tcam_config_1_cmd *)desc[0].data;
921 req2 = (struct hclge_fd_tcam_config_2_cmd *)desc[1].data;
922 req3 = (struct hclge_fd_tcam_config_3_cmd *)desc[2].data;
925 req1->xy_sel = sel_x ? 1 : 0;
926 req1->index = cpu_to_le32(loc);
928 ret = hclge_cmd_send(&hdev->hw, desc, 3);
932 dev_info(&hdev->pdev->dev, " read result tcam key %s(%u):\n",
933 sel_x ? "x" : "y", loc);
935 /* tcam_data0 ~ tcam_data1 */
936 req = (u32 *)req1->tcam_data;
937 for (i = 0; i < 2; i++)
938 dev_info(&hdev->pdev->dev, "%08x\n", *req++);
940 /* tcam_data2 ~ tcam_data7 */
941 req = (u32 *)req2->tcam_data;
942 for (i = 0; i < 6; i++)
943 dev_info(&hdev->pdev->dev, "%08x\n", *req++);
945 /* tcam_data8 ~ tcam_data12 */
946 req = (u32 *)req3->tcam_data;
947 for (i = 0; i < 5; i++)
948 dev_info(&hdev->pdev->dev, "%08x\n", *req++);
953 static int hclge_dbg_get_rules_location(struct hclge_dev *hdev, u16 *rule_locs)
955 struct hclge_fd_rule *rule;
956 struct hlist_node *node;
959 spin_lock_bh(&hdev->fd_rule_lock);
960 hlist_for_each_entry_safe(rule, node, &hdev->fd_rule_list, rule_node) {
961 rule_locs[cnt] = rule->location;
964 spin_unlock_bh(&hdev->fd_rule_lock);
966 if (cnt != hdev->hclge_fd_rule_num)
972 static void hclge_dbg_fd_tcam(struct hclge_dev *hdev)
974 int i, ret, rule_cnt;
977 if (!hnae3_dev_fd_supported(hdev)) {
978 dev_err(&hdev->pdev->dev,
979 "Only FD-supported dev supports dump fd tcam\n");
983 if (!hdev->hclge_fd_rule_num ||
984 !hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
987 rule_locs = kcalloc(hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1],
988 sizeof(u16), GFP_KERNEL);
992 rule_cnt = hclge_dbg_get_rules_location(hdev, rule_locs);
994 dev_err(&hdev->pdev->dev,
995 "failed to get rule number, ret = %d\n", rule_cnt);
1000 for (i = 0; i < rule_cnt; i++) {
1001 ret = hclge_dbg_fd_tcam_read(hdev, 0, true, rule_locs[i]);
1003 dev_err(&hdev->pdev->dev,
1004 "failed to get fd tcam key x, ret = %d\n", ret);
1009 ret = hclge_dbg_fd_tcam_read(hdev, 0, false, rule_locs[i]);
1011 dev_err(&hdev->pdev->dev,
1012 "failed to get fd tcam key y, ret = %d\n", ret);
1021 void hclge_dbg_dump_rst_info(struct hclge_dev *hdev)
1023 dev_info(&hdev->pdev->dev, "PF reset count: %u\n",
1024 hdev->rst_stats.pf_rst_cnt);
1025 dev_info(&hdev->pdev->dev, "FLR reset count: %u\n",
1026 hdev->rst_stats.flr_rst_cnt);
1027 dev_info(&hdev->pdev->dev, "GLOBAL reset count: %u\n",
1028 hdev->rst_stats.global_rst_cnt);
1029 dev_info(&hdev->pdev->dev, "IMP reset count: %u\n",
1030 hdev->rst_stats.imp_rst_cnt);
1031 dev_info(&hdev->pdev->dev, "reset done count: %u\n",
1032 hdev->rst_stats.reset_done_cnt);
1033 dev_info(&hdev->pdev->dev, "HW reset done count: %u\n",
1034 hdev->rst_stats.hw_reset_done_cnt);
1035 dev_info(&hdev->pdev->dev, "reset count: %u\n",
1036 hdev->rst_stats.reset_cnt);
1037 dev_info(&hdev->pdev->dev, "reset fail count: %u\n",
1038 hdev->rst_stats.reset_fail_cnt);
1039 dev_info(&hdev->pdev->dev, "vector0 interrupt enable status: 0x%x\n",
1040 hclge_read_dev(&hdev->hw, HCLGE_MISC_VECTOR_REG_BASE));
1041 dev_info(&hdev->pdev->dev, "reset interrupt source: 0x%x\n",
1042 hclge_read_dev(&hdev->hw, HCLGE_MISC_RESET_STS_REG));
1043 dev_info(&hdev->pdev->dev, "reset interrupt status: 0x%x\n",
1044 hclge_read_dev(&hdev->hw, HCLGE_MISC_VECTOR_INT_STS));
1045 dev_info(&hdev->pdev->dev, "hardware reset status: 0x%x\n",
1046 hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG));
1047 dev_info(&hdev->pdev->dev, "handshake status: 0x%x\n",
1048 hclge_read_dev(&hdev->hw, HCLGE_NIC_CSQ_DEPTH_REG));
1049 dev_info(&hdev->pdev->dev, "function reset status: 0x%x\n",
1050 hclge_read_dev(&hdev->hw, HCLGE_FUN_RST_ING));
1051 dev_info(&hdev->pdev->dev, "hdev state: 0x%lx\n", hdev->state);
1054 static void hclge_dbg_dump_serv_info(struct hclge_dev *hdev)
1056 dev_info(&hdev->pdev->dev, "last_serv_processed: %lu\n",
1057 hdev->last_serv_processed);
1058 dev_info(&hdev->pdev->dev, "last_serv_cnt: %lu\n",
1059 hdev->serv_processed_cnt);
1062 static void hclge_dbg_get_m7_stats_info(struct hclge_dev *hdev)
1064 struct hclge_desc *desc_src, *desc_tmp;
1065 struct hclge_get_m7_bd_cmd *req;
1066 struct hclge_desc desc;
1067 u32 bd_num, buf_len;
1070 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_M7_STATS_BD, true);
1072 req = (struct hclge_get_m7_bd_cmd *)desc.data;
1073 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1075 dev_err(&hdev->pdev->dev,
1076 "get firmware statistics bd number failed, ret = %d\n",
1081 bd_num = le32_to_cpu(req->bd_num);
1083 buf_len = sizeof(struct hclge_desc) * bd_num;
1084 desc_src = kzalloc(buf_len, GFP_KERNEL);
1086 dev_err(&hdev->pdev->dev,
1087 "allocate desc for get_m7_stats failed\n");
1091 desc_tmp = desc_src;
1092 ret = hclge_dbg_cmd_send(hdev, desc_tmp, 0, bd_num,
1093 HCLGE_OPC_M7_STATS_INFO);
1096 dev_err(&hdev->pdev->dev,
1097 "get firmware statistics failed, ret = %d\n", ret);
1101 for (i = 0; i < bd_num; i++) {
1102 dev_info(&hdev->pdev->dev, "0x%08x 0x%08x 0x%08x\n",
1103 le32_to_cpu(desc_tmp->data[0]),
1104 le32_to_cpu(desc_tmp->data[1]),
1105 le32_to_cpu(desc_tmp->data[2]));
1106 dev_info(&hdev->pdev->dev, "0x%08x 0x%08x 0x%08x\n",
1107 le32_to_cpu(desc_tmp->data[3]),
1108 le32_to_cpu(desc_tmp->data[4]),
1109 le32_to_cpu(desc_tmp->data[5]));
1117 #define HCLGE_CMD_NCL_CONFIG_BD_NUM 5
1119 static void hclge_ncl_config_data_print(struct hclge_dev *hdev,
1120 struct hclge_desc *desc, int *offset,
1123 #define HCLGE_CMD_DATA_NUM 6
1128 for (i = 0; i < HCLGE_CMD_NCL_CONFIG_BD_NUM; i++) {
1129 for (j = 0; j < HCLGE_CMD_DATA_NUM; j++) {
1130 if (i == 0 && j == 0)
1133 dev_info(&hdev->pdev->dev, "0x%04x | 0x%08x\n",
1135 le32_to_cpu(desc[i].data[j]));
1136 *offset += sizeof(u32);
1137 *length -= sizeof(u32);
1144 /* hclge_dbg_dump_ncl_config: print specified range of NCL_CONFIG file
1145 * @hdev: pointer to struct hclge_dev
1146 * @cmd_buf: string that contains offset and length
1148 static void hclge_dbg_dump_ncl_config(struct hclge_dev *hdev,
1149 const char *cmd_buf)
1151 #define HCLGE_MAX_NCL_CONFIG_OFFSET 4096
1152 #define HCLGE_NCL_CONFIG_LENGTH_IN_EACH_CMD (20 + 24 * 4)
1154 struct hclge_desc desc[HCLGE_CMD_NCL_CONFIG_BD_NUM];
1155 int bd_num = HCLGE_CMD_NCL_CONFIG_BD_NUM;
1161 ret = sscanf(cmd_buf, "%x %x", &offset, &length);
1162 if (ret != 2 || offset >= HCLGE_MAX_NCL_CONFIG_OFFSET ||
1163 length > HCLGE_MAX_NCL_CONFIG_OFFSET - offset) {
1164 dev_err(&hdev->pdev->dev, "Invalid offset or length.\n");
1167 if (offset < 0 || length <= 0) {
1168 dev_err(&hdev->pdev->dev, "Non-positive offset or length.\n");
1172 dev_info(&hdev->pdev->dev, "offset | data\n");
1174 while (length > 0) {
1176 if (length >= HCLGE_NCL_CONFIG_LENGTH_IN_EACH_CMD)
1177 data0 |= HCLGE_NCL_CONFIG_LENGTH_IN_EACH_CMD << 16;
1179 data0 |= length << 16;
1180 ret = hclge_dbg_cmd_send(hdev, desc, data0, bd_num,
1181 HCLGE_OPC_QUERY_NCL_CONFIG);
1185 hclge_ncl_config_data_print(hdev, desc, &offset, &length);
1189 static void hclge_dbg_dump_loopback(struct hclge_dev *hdev,
1190 const char *cmd_buf)
1192 struct phy_device *phydev = hdev->hw.mac.phydev;
1193 struct hclge_config_mac_mode_cmd *req_app;
1194 struct hclge_serdes_lb_cmd *req_serdes;
1195 struct hclge_desc desc;
1199 req_app = (struct hclge_config_mac_mode_cmd *)desc.data;
1200 req_serdes = (struct hclge_serdes_lb_cmd *)desc.data;
1202 dev_info(&hdev->pdev->dev, "mac id: %u\n", hdev->hw.mac.mac_id);
1204 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAC_MODE, true);
1205 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1207 dev_err(&hdev->pdev->dev,
1208 "failed to dump app loopback status, ret = %d\n", ret);
1212 loopback_en = hnae3_get_bit(le32_to_cpu(req_app->txrx_pad_fcs_loop_en),
1213 HCLGE_MAC_APP_LP_B);
1214 dev_info(&hdev->pdev->dev, "app loopback: %s\n",
1215 loopback_en ? "on" : "off");
1217 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK, true);
1218 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1220 dev_err(&hdev->pdev->dev,
1221 "failed to dump serdes loopback status, ret = %d\n",
1226 loopback_en = req_serdes->enable & HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
1227 dev_info(&hdev->pdev->dev, "serdes serial loopback: %s\n",
1228 loopback_en ? "on" : "off");
1230 loopback_en = req_serdes->enable &
1231 HCLGE_CMD_SERDES_PARALLEL_INNER_LOOP_B;
1232 dev_info(&hdev->pdev->dev, "serdes parallel loopback: %s\n",
1233 loopback_en ? "on" : "off");
1236 dev_info(&hdev->pdev->dev, "phy loopback: %s\n",
1237 phydev->loopback_enabled ? "on" : "off");
1240 /* hclge_dbg_dump_mac_tnl_status: print message about mac tnl interrupt
1241 * @hdev: pointer to struct hclge_dev
1243 static void hclge_dbg_dump_mac_tnl_status(struct hclge_dev *hdev)
1245 #define HCLGE_BILLION_NANO_SECONDS 1000000000
1247 struct hclge_mac_tnl_stats stats;
1248 unsigned long rem_nsec;
1250 dev_info(&hdev->pdev->dev, "Recently generated mac tnl interruption:\n");
1252 while (kfifo_get(&hdev->mac_tnl_log, &stats)) {
1253 rem_nsec = do_div(stats.time, HCLGE_BILLION_NANO_SECONDS);
1254 dev_info(&hdev->pdev->dev, "[%07lu.%03lu] status = 0x%x\n",
1255 (unsigned long)stats.time, rem_nsec / 1000,
1260 static void hclge_dbg_dump_qs_shaper_single(struct hclge_dev *hdev, u16 qsid)
1262 struct hclge_qs_shapping_cmd *shap_cfg_cmd;
1263 u8 ir_u, ir_b, ir_s, bs_b, bs_s;
1264 struct hclge_desc desc;
1268 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QCN_SHAPPING_CFG, true);
1270 shap_cfg_cmd = (struct hclge_qs_shapping_cmd *)desc.data;
1271 shap_cfg_cmd->qs_id = cpu_to_le16(qsid);
1273 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
1275 dev_err(&hdev->pdev->dev,
1276 "qs%u failed to get tx_rate, ret=%d\n",
1281 shapping_para = le32_to_cpu(shap_cfg_cmd->qs_shapping_para);
1282 ir_b = hclge_tm_get_field(shapping_para, IR_B);
1283 ir_u = hclge_tm_get_field(shapping_para, IR_U);
1284 ir_s = hclge_tm_get_field(shapping_para, IR_S);
1285 bs_b = hclge_tm_get_field(shapping_para, BS_B);
1286 bs_s = hclge_tm_get_field(shapping_para, BS_S);
1288 dev_info(&hdev->pdev->dev,
1289 "qs%u ir_b:%u, ir_u:%u, ir_s:%u, bs_b:%u, bs_s:%u\n",
1290 qsid, ir_b, ir_u, ir_s, bs_b, bs_s);
1293 static void hclge_dbg_dump_qs_shaper_all(struct hclge_dev *hdev)
1295 struct hnae3_knic_private_info *kinfo;
1296 struct hclge_vport *vport;
1299 for (vport_id = 0; vport_id <= pci_num_vf(hdev->pdev); vport_id++) {
1300 vport = &hdev->vport[vport_id];
1301 kinfo = &vport->nic.kinfo;
1303 dev_info(&hdev->pdev->dev, "qs cfg of vport%d:\n", vport_id);
1305 for (i = 0; i < kinfo->num_tc; i++) {
1306 u16 qsid = vport->qs_offset + i;
1308 hclge_dbg_dump_qs_shaper_single(hdev, qsid);
1313 static void hclge_dbg_dump_qs_shaper(struct hclge_dev *hdev,
1314 const char *cmd_buf)
1316 #define HCLGE_MAX_QSET_NUM 1024
1321 ret = kstrtou16(cmd_buf, 0, &qsid);
1323 hclge_dbg_dump_qs_shaper_all(hdev);
1327 if (qsid >= HCLGE_MAX_QSET_NUM) {
1328 dev_err(&hdev->pdev->dev, "qsid(%u) out of range[0-1023]\n",
1333 hclge_dbg_dump_qs_shaper_single(hdev, qsid);
1336 int hclge_dbg_run_cmd(struct hnae3_handle *handle, const char *cmd_buf)
1338 #define DUMP_REG "dump reg"
1339 #define DUMP_TM_MAP "dump tm map"
1340 #define DUMP_LOOPBACK "dump loopback"
1342 struct hclge_vport *vport = hclge_get_vport(handle);
1343 struct hclge_dev *hdev = vport->back;
1345 if (strncmp(cmd_buf, "dump fd tcam", 12) == 0) {
1346 hclge_dbg_fd_tcam(hdev);
1347 } else if (strncmp(cmd_buf, "dump tc", 7) == 0) {
1348 hclge_dbg_dump_tc(hdev);
1349 } else if (strncmp(cmd_buf, DUMP_TM_MAP, strlen(DUMP_TM_MAP)) == 0) {
1350 hclge_dbg_dump_tm_map(hdev, &cmd_buf[sizeof(DUMP_TM_MAP)]);
1351 } else if (strncmp(cmd_buf, "dump tm", 7) == 0) {
1352 hclge_dbg_dump_tm(hdev);
1353 } else if (strncmp(cmd_buf, "dump qos pause cfg", 18) == 0) {
1354 hclge_dbg_dump_qos_pause_cfg(hdev);
1355 } else if (strncmp(cmd_buf, "dump qos pri map", 16) == 0) {
1356 hclge_dbg_dump_qos_pri_map(hdev);
1357 } else if (strncmp(cmd_buf, "dump qos buf cfg", 16) == 0) {
1358 hclge_dbg_dump_qos_buf_cfg(hdev);
1359 } else if (strncmp(cmd_buf, "dump mng tbl", 12) == 0) {
1360 hclge_dbg_dump_mng_table(hdev);
1361 } else if (strncmp(cmd_buf, DUMP_REG, strlen(DUMP_REG)) == 0) {
1362 hclge_dbg_dump_reg_cmd(hdev, &cmd_buf[sizeof(DUMP_REG)]);
1363 } else if (strncmp(cmd_buf, "dump reset info", 15) == 0) {
1364 hclge_dbg_dump_rst_info(hdev);
1365 } else if (strncmp(cmd_buf, "dump serv info", 14) == 0) {
1366 hclge_dbg_dump_serv_info(hdev);
1367 } else if (strncmp(cmd_buf, "dump m7 info", 12) == 0) {
1368 hclge_dbg_get_m7_stats_info(hdev);
1369 } else if (strncmp(cmd_buf, "dump ncl_config", 15) == 0) {
1370 hclge_dbg_dump_ncl_config(hdev,
1371 &cmd_buf[sizeof("dump ncl_config")]);
1372 } else if (strncmp(cmd_buf, "dump mac tnl status", 19) == 0) {
1373 hclge_dbg_dump_mac_tnl_status(hdev);
1374 } else if (strncmp(cmd_buf, DUMP_LOOPBACK,
1375 strlen(DUMP_LOOPBACK)) == 0) {
1376 hclge_dbg_dump_loopback(hdev, &cmd_buf[sizeof(DUMP_LOOPBACK)]);
1377 } else if (strncmp(cmd_buf, "dump qs shaper", 14) == 0) {
1378 hclge_dbg_dump_qs_shaper(hdev,
1379 &cmd_buf[sizeof("dump qs shaper")]);
1381 dev_info(&hdev->pdev->dev, "unknown command\n");