1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2018-2019 Hisilicon Limited. */
4 #include <linux/device.h>
7 #include "hclge_main.h"
11 static void hclge_title_idx_print(struct hclge_dev
*hdev
, bool flag
, int index
,
12 char *title_buf
, char *true_buf
,
16 dev_info(&hdev
->pdev
->dev
, "%s(%d): %s\n", title_buf
, index
,
19 dev_info(&hdev
->pdev
->dev
, "%s(%d): %s\n", title_buf
, index
,
23 static void hclge_dbg_dump_tc(struct hclge_dev
*hdev
)
25 struct hclge_ets_tc_weight_cmd
*ets_weight
;
26 struct hclge_desc desc
;
29 hclge_cmd_setup_basic_desc(&desc
, HCLGE_OPC_ETS_TC_WEIGHT
, true);
31 ret
= hclge_cmd_send(&hdev
->hw
, &desc
, 1);
33 dev_err(&hdev
->pdev
->dev
, "dump tc fail, status is %d.\n", ret
);
37 ets_weight
= (struct hclge_ets_tc_weight_cmd
*)desc
.data
;
39 dev_info(&hdev
->pdev
->dev
, "dump tc\n");
40 dev_info(&hdev
->pdev
->dev
, "weight_offset: %u\n",
41 ets_weight
->weight_offset
);
43 for (i
= 0; i
< HNAE3_MAX_TC
; i
++)
44 hclge_title_idx_print(hdev
, ets_weight
->tc_weight
[i
], i
,
45 "tc", "no sp mode", "sp mode");
48 static void hclge_dbg_fd_tcam_read(struct hclge_dev
*hdev
, u8 stage
,
51 struct hclge_fd_tcam_config_1_cmd
*req1
;
52 struct hclge_fd_tcam_config_2_cmd
*req2
;
53 struct hclge_fd_tcam_config_3_cmd
*req3
;
54 struct hclge_desc desc
[3];
58 hclge_cmd_setup_basic_desc(&desc
[0], HCLGE_OPC_FD_TCAM_OP
, true);
59 desc
[0].flag
|= cpu_to_le16(HCLGE_CMD_FLAG_NEXT
);
60 hclge_cmd_setup_basic_desc(&desc
[1], HCLGE_OPC_FD_TCAM_OP
, true);
61 desc
[1].flag
|= cpu_to_le16(HCLGE_CMD_FLAG_NEXT
);
62 hclge_cmd_setup_basic_desc(&desc
[2], HCLGE_OPC_FD_TCAM_OP
, true);
64 req1
= (struct hclge_fd_tcam_config_1_cmd
*)desc
[0].data
;
65 req2
= (struct hclge_fd_tcam_config_2_cmd
*)desc
[1].data
;
66 req3
= (struct hclge_fd_tcam_config_3_cmd
*)desc
[2].data
;
69 req1
->xy_sel
= sel_x
? 1 : 0;
70 req1
->index
= cpu_to_le32(loc
);
72 ret
= hclge_cmd_send(&hdev
->hw
, desc
, 3);
76 dev_info(&hdev
->pdev
->dev
, " read result tcam key %s(%u):\n",
77 sel_x
? "x" : "y", loc
);
79 req
= (u32
*)req1
->tcam_data
;
80 for (i
= 0; i
< 2; i
++)
81 dev_info(&hdev
->pdev
->dev
, "%08x\n", *req
++);
83 req
= (u32
*)req2
->tcam_data
;
84 for (i
= 0; i
< 6; i
++)
85 dev_info(&hdev
->pdev
->dev
, "%08x\n", *req
++);
87 req
= (u32
*)req3
->tcam_data
;
88 for (i
= 0; i
< 5; i
++)
89 dev_info(&hdev
->pdev
->dev
, "%08x\n", *req
++);
92 static void hclge_dbg_fd_tcam(struct hclge_dev
*hdev
)
96 for (i
= 0; i
< hdev
->fd_cfg
.rule_num
[0]; i
++) {
97 hclge_dbg_fd_tcam_read(hdev
, 0, true, i
);
98 hclge_dbg_fd_tcam_read(hdev
, 0, false, i
);
102 int hclge_dbg_run_cmd(struct hnae3_handle
*handle
, char *cmd_buf
)
104 struct hclge_vport
*vport
= hclge_get_vport(handle
);
105 struct hclge_dev
*hdev
= vport
->back
;
107 if (strncmp(cmd_buf
, "dump fd tcam", 12) == 0) {
108 hclge_dbg_fd_tcam(hdev
);
109 } else if (strncmp(cmd_buf
, "dump tc", 7) == 0) {
110 hclge_dbg_dump_tc(hdev
);
112 dev_info(&hdev
->pdev
->dev
, "unknown command\n");