]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: hns3: get FD rules location before dump in debugfs
authorYufeng Mo <moyufeng@huawei.com>
Thu, 19 Dec 2019 06:57:43 +0000 (14:57 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 21 Dec 2019 05:20:39 +0000 (21:20 -0800)
Currently, the dump FD tcam mode in debugfs is to query all FD tcams,
including empty rules, which is unnecessary. This patch modify to
find the position of useful rules before dump FD tcam, so that it does
not need to query empty rules.

This patch also modifies some help information in debugfs.

Signed-off-by: Yufeng Mo <moyufeng@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c

index 92a99e4fdda562bb635e99e102c497fb54493240..f3d4cbd28913ef7cd94bb54c5119b9601cc5be06 100644 (file)
@@ -886,8 +886,8 @@ static void hclge_dbg_dump_mng_table(struct hclge_dev *hdev)
        }
 }
 
-static void hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
-                                  bool sel_x, u32 loc)
+static int hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
+                                 bool sel_x, u32 loc)
 {
        struct hclge_fd_tcam_config_1_cmd *req1;
        struct hclge_fd_tcam_config_2_cmd *req2;
@@ -912,7 +912,7 @@ static void hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
 
        ret = hclge_cmd_send(&hdev->hw, desc, 3);
        if (ret)
-               return;
+               return ret;
 
        dev_info(&hdev->pdev->dev, " read result tcam key %s(%u):\n",
                 sel_x ? "x" : "y", loc);
@@ -931,16 +931,76 @@ static void hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
        req = (u32 *)req3->tcam_data;
        for (i = 0; i < 5; i++)
                dev_info(&hdev->pdev->dev, "%08x\n", *req++);
+
+       return ret;
+}
+
+static int hclge_dbg_get_rules_location(struct hclge_dev *hdev, u16 *rule_locs)
+{
+       struct hclge_fd_rule *rule;
+       struct hlist_node *node;
+       int cnt = 0;
+
+       spin_lock_bh(&hdev->fd_rule_lock);
+       hlist_for_each_entry_safe(rule, node, &hdev->fd_rule_list, rule_node) {
+               rule_locs[cnt] = rule->location;
+               cnt++;
+       }
+       spin_unlock_bh(&hdev->fd_rule_lock);
+
+       if (cnt != hdev->hclge_fd_rule_num)
+               return -EINVAL;
+
+       return cnt;
 }
 
 static void hclge_dbg_fd_tcam(struct hclge_dev *hdev)
 {
-       u32 i;
+       int i, ret, rule_cnt;
+       u16 *rule_locs;
+
+       if (!hnae3_dev_fd_supported(hdev)) {
+               dev_err(&hdev->pdev->dev,
+                       "Only FD-supported dev supports dump fd tcam\n");
+               return;
+       }
+
+       if (!hdev->hclge_fd_rule_num ||
+           !hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1])
+               return;
+
+       rule_locs = kcalloc(hdev->fd_cfg.rule_num[HCLGE_FD_STAGE_1],
+                           sizeof(u16), GFP_KERNEL);
+       if (!rule_locs)
+               return;
 
-       for (i = 0; i < hdev->fd_cfg.rule_num[0]; i++) {
-               hclge_dbg_fd_tcam_read(hdev, 0, true, i);
-               hclge_dbg_fd_tcam_read(hdev, 0, false, i);
+       rule_cnt = hclge_dbg_get_rules_location(hdev, rule_locs);
+       if (rule_cnt <= 0) {
+               dev_err(&hdev->pdev->dev,
+                       "failed to get rule number, ret = %d\n", rule_cnt);
+               kfree(rule_locs);
+               return;
        }
+
+       for (i = 0; i < rule_cnt; i++) {
+               ret = hclge_dbg_fd_tcam_read(hdev, 0, true, rule_locs[i]);
+               if (ret) {
+                       dev_err(&hdev->pdev->dev,
+                               "failed to get fd tcam key x, ret = %d\n", ret);
+                       kfree(rule_locs);
+                       return;
+               }
+
+               ret = hclge_dbg_fd_tcam_read(hdev, 0, false, rule_locs[i]);
+               if (ret) {
+                       dev_err(&hdev->pdev->dev,
+                               "failed to get fd tcam key y, ret = %d\n", ret);
+                       kfree(rule_locs);
+                       return;
+               }
+       }
+
+       kfree(rule_locs);
 }
 
 void hclge_dbg_dump_rst_info(struct hclge_dev *hdev)