]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: hns3: modify hclgevf_init_client_instance()
authorHuazhong Tan <tanhuazhong@huawei.com>
Tue, 28 May 2019 09:02:58 +0000 (17:02 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 29 May 2019 00:39:01 +0000 (17:39 -0700)
hclgevf_init_client_instance() is a little bloated and there is
some duplicated code. This patch adds some cleanup for it.

Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c

index 8b3f8fdd44920604701a0ded6a146bb28257dd93..9d5a4f817048daa2b3ed81178d3c7be74d91f3fd 100644 (file)
@@ -2253,6 +2253,48 @@ static void hclgevf_info_show(struct hclgevf_dev *hdev)
        dev_info(dev, "VF info end.\n");
 }
 
+static int hclgevf_init_nic_client_instance(struct hnae3_ae_dev *ae_dev,
+                                           struct hnae3_client *client)
+{
+       struct hclgevf_dev *hdev = ae_dev->priv;
+       int ret;
+
+       ret = client->ops->init_instance(&hdev->nic);
+       if (ret)
+               return ret;
+
+       set_bit(HCLGEVF_STATE_NIC_REGISTERED, &hdev->state);
+       hnae3_set_client_init_flag(client, ae_dev, 1);
+
+       if (netif_msg_drv(&hdev->nic))
+               hclgevf_info_show(hdev);
+
+       return 0;
+}
+
+static int hclgevf_init_roce_client_instance(struct hnae3_ae_dev *ae_dev,
+                                            struct hnae3_client *client)
+{
+       struct hclgevf_dev *hdev = ae_dev->priv;
+       int ret;
+
+       if (!hnae3_dev_roce_supported(hdev) || !hdev->roce_client ||
+           !hdev->nic_client)
+               return 0;
+
+       ret = hclgevf_init_roce_base_info(hdev);
+       if (ret)
+               return ret;
+
+       ret = client->ops->init_instance(&hdev->roce);
+       if (ret)
+               return ret;
+
+       hnae3_set_client_init_flag(client, ae_dev, 1);
+
+       return 0;
+}
+
 static int hclgevf_init_client_instance(struct hnae3_client *client,
                                        struct hnae3_ae_dev *ae_dev)
 {
@@ -2264,29 +2306,15 @@ static int hclgevf_init_client_instance(struct hnae3_client *client,
                hdev->nic_client = client;
                hdev->nic.client = client;
 
-               ret = client->ops->init_instance(&hdev->nic);
+               ret = hclgevf_init_nic_client_instance(ae_dev, client);
                if (ret)
                        goto clear_nic;
 
-               hnae3_set_client_init_flag(client, ae_dev, 1);
-               set_bit(HCLGEVF_STATE_NIC_REGISTERED, &hdev->state);
-
-               if (netif_msg_drv(&hdev->nic))
-                       hclgevf_info_show(hdev);
-
-               if (hdev->roce_client && hnae3_dev_roce_supported(hdev)) {
-                       struct hnae3_client *rc = hdev->roce_client;
-
-                       ret = hclgevf_init_roce_base_info(hdev);
-                       if (ret)
-                               goto clear_roce;
-                       ret = rc->ops->init_instance(&hdev->roce);
-                       if (ret)
-                               goto clear_roce;
+               ret = hclgevf_init_roce_client_instance(ae_dev,
+                                                       hdev->roce_client);
+               if (ret)
+                       goto clear_roce;
 
-                       hnae3_set_client_init_flag(hdev->roce_client, ae_dev,
-                                                  1);
-               }
                break;
        case HNAE3_CLIENT_UNIC:
                hdev->nic_client = client;
@@ -2304,17 +2332,10 @@ static int hclgevf_init_client_instance(struct hnae3_client *client,
                        hdev->roce.client = client;
                }
 
-               if (hdev->roce_client && hdev->nic_client) {
-                       ret = hclgevf_init_roce_base_info(hdev);
-                       if (ret)
-                               goto clear_roce;
-
-                       ret = client->ops->init_instance(&hdev->roce);
-                       if (ret)
-                               goto clear_roce;
-               }
+               ret = hclgevf_init_roce_client_instance(ae_dev, client);
+               if (ret)
+                       goto clear_roce;
 
-               hnae3_set_client_init_flag(client, ae_dev, 1);
                break;
        default:
                return -EINVAL;