net: hns3: refactor the debugfs process
[linux-block.git] / drivers / net / ethernet / hisilicon / hns3 / hns3pf / hclge_debugfs.c
index 6b1d197df88118601bf6f4aa2294198fc14c70b4..7f1abdff25b0af118f411b70f602893fb9eaac09 100644 (file)
@@ -1541,18 +1541,17 @@ static void hclge_dbg_dump_ncl_config(struct hclge_dev *hdev,
        }
 }
 
-static void hclge_dbg_dump_loopback(struct hclge_dev *hdev,
-                                   const char *cmd_buf)
+static void hclge_dbg_dump_loopback(struct hclge_dev *hdev)
 {
        struct phy_device *phydev = hdev->hw.mac.phydev;
        struct hclge_config_mac_mode_cmd *req_app;
-       struct hclge_serdes_lb_cmd *req_serdes;
+       struct hclge_common_lb_cmd *req_common;
        struct hclge_desc desc;
        u8 loopback_en;
        int ret;
 
        req_app = (struct hclge_config_mac_mode_cmd *)desc.data;
-       req_serdes = (struct hclge_serdes_lb_cmd *)desc.data;
+       req_common = (struct hclge_common_lb_cmd *)desc.data;
 
        dev_info(&hdev->pdev->dev, "mac id: %u\n", hdev->hw.mac.mac_id);
 
@@ -1569,27 +1568,33 @@ static void hclge_dbg_dump_loopback(struct hclge_dev *hdev,
        dev_info(&hdev->pdev->dev, "app loopback: %s\n",
                 loopback_en ? "on" : "off");
 
-       hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK, true);
+       hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMMON_LOOPBACK, true);
        ret = hclge_cmd_send(&hdev->hw, &desc, 1);
        if (ret) {
                dev_err(&hdev->pdev->dev,
-                       "failed to dump serdes loopback status, ret = %d\n",
+                       "failed to dump common loopback status, ret = %d\n",
                        ret);
                return;
        }
 
-       loopback_en = req_serdes->enable & HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+       loopback_en = req_common->enable & HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
        dev_info(&hdev->pdev->dev, "serdes serial loopback: %s\n",
                 loopback_en ? "on" : "off");
 
-       loopback_en = req_serdes->enable &
+       loopback_en = req_common->enable &
                        HCLGE_CMD_SERDES_PARALLEL_INNER_LOOP_B;
        dev_info(&hdev->pdev->dev, "serdes parallel loopback: %s\n",
                 loopback_en ? "on" : "off");
 
-       if (phydev)
+       if (phydev) {
                dev_info(&hdev->pdev->dev, "phy loopback: %s\n",
                         phydev->loopback_enabled ? "on" : "off");
+       } else if (hnae3_dev_phy_imp_supported(hdev)) {
+               loopback_en = req_common->enable &
+                             HCLGE_CMD_GE_PHY_INNER_LOOP_B;
+               dev_info(&hdev->pdev->dev, "phy loopback: %s\n",
+                        loopback_en ? "on" : "off");
+       }
 }
 
 /* hclge_dbg_dump_mac_tnl_status: print message about mac tnl interrupt
@@ -1772,7 +1777,7 @@ int hclge_dbg_run_cmd(struct hnae3_handle *handle, const char *cmd_buf)
                hclge_dbg_dump_mac_tnl_status(hdev);
        } else if (strncmp(cmd_buf, DUMP_LOOPBACK,
                   strlen(DUMP_LOOPBACK)) == 0) {
-               hclge_dbg_dump_loopback(hdev, &cmd_buf[sizeof(DUMP_LOOPBACK)]);
+               hclge_dbg_dump_loopback(hdev);
        } else if (strncmp(cmd_buf, "dump qs shaper", 14) == 0) {
                hclge_dbg_dump_qs_shaper(hdev,
                                         &cmd_buf[sizeof("dump qs shaper")]);
@@ -1795,21 +1800,33 @@ int hclge_dbg_run_cmd(struct hnae3_handle *handle, const char *cmd_buf)
        return 0;
 }
 
-int hclge_dbg_read_cmd(struct hnae3_handle *handle, const char *cmd_buf,
+static const struct hclge_dbg_func hclge_dbg_cmd_func[] = {
+       {
+               .cmd = HNAE3_DBG_CMD_TM_NODES,
+               .dbg_dump = hclge_dbg_dump_tm_nodes,
+       },
+       {
+               .cmd = HNAE3_DBG_CMD_TM_PRI,
+               .dbg_dump = hclge_dbg_dump_tm_pri,
+       },
+       {
+               .cmd = HNAE3_DBG_CMD_TM_QSET,
+               .dbg_dump = hclge_dbg_dump_tm_qset,
+       },
+};
+
+int hclge_dbg_read_cmd(struct hnae3_handle *handle, enum hnae3_dbg_cmd cmd,
                       char *buf, int len)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
        struct hclge_dev *hdev = vport->back;
+       u32 i;
 
-       if (strncmp(cmd_buf, HNAE3_DBG_TM_NODES,
-                   strlen(HNAE3_DBG_TM_NODES)) == 0)
-               return hclge_dbg_dump_tm_nodes(hdev, buf, len);
-       else if (strncmp(cmd_buf, HNAE3_DBG_TM_PRI,
-                        strlen(HNAE3_DBG_TM_PRI)) == 0)
-               return hclge_dbg_dump_tm_pri(hdev, buf, len);
-       else if (strncmp(cmd_buf, HNAE3_DBG_TM_QSET,
-                        strlen(HNAE3_DBG_TM_QSET)) == 0)
-               return hclge_dbg_dump_tm_qset(hdev, buf, len);
+       for (i = 0; i < ARRAY_SIZE(hclge_dbg_cmd_func); i++) {
+               if (cmd == hclge_dbg_cmd_func[i].cmd)
+                       return hclge_dbg_cmd_func[i].dbg_dump(hdev, buf, len);
+       }
 
+       dev_err(&hdev->pdev->dev, "invalid command(%d)\n", cmd);
        return -EINVAL;
 }