]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
050b90e95e00a418c71ca8135c471f4c029dfd71
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / hisilicon / hns3 / hns3pf / hclge_debugfs.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2018-2019 Hisilicon Limited. */
3
4 #include <linux/device.h>
5
6 #include "hclge_cmd.h"
7 #include "hclge_main.h"
8 #include "hclge_tm.h"
9 #include "hnae3.h"
10
11 static void hclge_title_idx_print(struct hclge_dev *hdev, bool flag, int index,
12 char *title_buf, char *true_buf,
13 char *false_buf)
14 {
15 if (flag)
16 dev_info(&hdev->pdev->dev, "%s(%d): %s\n", title_buf, index,
17 true_buf);
18 else
19 dev_info(&hdev->pdev->dev, "%s(%d): %s\n", title_buf, index,
20 false_buf);
21 }
22
23 static void hclge_dbg_dump_tc(struct hclge_dev *hdev)
24 {
25 struct hclge_ets_tc_weight_cmd *ets_weight;
26 struct hclge_desc desc;
27 int i, ret;
28
29 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_ETS_TC_WEIGHT, true);
30
31 ret = hclge_cmd_send(&hdev->hw, &desc, 1);
32 if (ret) {
33 dev_err(&hdev->pdev->dev, "dump tc fail, status is %d.\n", ret);
34 return;
35 }
36
37 ets_weight = (struct hclge_ets_tc_weight_cmd *)desc.data;
38
39 dev_info(&hdev->pdev->dev, "dump tc\n");
40 dev_info(&hdev->pdev->dev, "weight_offset: %u\n",
41 ets_weight->weight_offset);
42
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");
46 }
47
48 static void hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
49 bool sel_x, u32 loc)
50 {
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];
55 int ret, i;
56 u32 *req;
57
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);
63
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;
67
68 req1->stage = stage;
69 req1->xy_sel = sel_x ? 1 : 0;
70 req1->index = cpu_to_le32(loc);
71
72 ret = hclge_cmd_send(&hdev->hw, desc, 3);
73 if (ret)
74 return;
75
76 dev_info(&hdev->pdev->dev, " read result tcam key %s(%u):\n",
77 sel_x ? "x" : "y", loc);
78
79 req = (u32 *)req1->tcam_data;
80 for (i = 0; i < 2; i++)
81 dev_info(&hdev->pdev->dev, "%08x\n", *req++);
82
83 req = (u32 *)req2->tcam_data;
84 for (i = 0; i < 6; i++)
85 dev_info(&hdev->pdev->dev, "%08x\n", *req++);
86
87 req = (u32 *)req3->tcam_data;
88 for (i = 0; i < 5; i++)
89 dev_info(&hdev->pdev->dev, "%08x\n", *req++);
90 }
91
92 static void hclge_dbg_fd_tcam(struct hclge_dev *hdev)
93 {
94 u32 i;
95
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);
99 }
100 }
101
102 int hclge_dbg_run_cmd(struct hnae3_handle *handle, char *cmd_buf)
103 {
104 struct hclge_vport *vport = hclge_get_vport(handle);
105 struct hclge_dev *hdev = vport->back;
106
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);
111 } else {
112 dev_info(&hdev->pdev->dev, "unknown command\n");
113 return -EINVAL;
114 }
115
116 return 0;
117 }