]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
net: hns3: Fix for information of phydev lost problem when down/up
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / hisilicon / hns3 / hns3pf / hclge_main.c
index 27bfcfc232f55e26f063a90afa85688eb9598a27..226855ff5436ea924468e0d47813940a6bb59e26 100644 (file)
@@ -1,11 +1,5 @@
-/*
- * Copyright (c) 2016-2017 Hisilicon Limited.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (c) 2016-2017 Hisilicon Limited.
 
 #include <linux/acpi.h>
 #include <linux/device.h>
@@ -793,9 +787,10 @@ static int hclge_get_sset_count(struct hnae3_handle *handle, int stringset)
                    hdev->hw.mac.speed == HCLGE_MAC_SPEED_1G) {
                        count += 1;
                        handle->flags |= HNAE3_SUPPORT_MAC_LOOPBACK;
-               } else {
-                       count = -EOPNOTSUPP;
                }
+
+               count++;
+               handle->flags |= HNAE3_SUPPORT_SERDES_LOOPBACK;
        } else if (stringset == ETH_SS_STATS) {
                count = ARRAY_SIZE(g_mac_stats_string) +
                        ARRAY_SIZE(g_all_32bit_stats_string) +
@@ -938,6 +933,9 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
        hdev->pkt_buf_size = __le16_to_cpu(req->buf_size) << HCLGE_BUF_UNIT_S;
 
        if (hnae3_dev_roce_supported(hdev)) {
+               hdev->roce_base_msix_offset =
+               hnae3_get_field(__le16_to_cpu(req->msixcap_localid_ba_rocee),
+                               HCLGE_MSIX_OFT_ROCEE_M, HCLGE_MSIX_OFT_ROCEE_S);
                hdev->num_roce_msi =
                hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number),
                                HCLGE_PF_VEC_NUM_M, HCLGE_PF_VEC_NUM_S);
@@ -945,7 +943,8 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
                /* PF should have NIC vectors and Roce vectors,
                 * NIC vectors are queued before Roce vectors.
                 */
-               hdev->num_msi = hdev->num_roce_msi  + HCLGE_ROCE_VECTOR_OFFSET;
+               hdev->num_msi = hdev->num_roce_msi  +
+                               hdev->roce_base_msix_offset;
        } else {
                hdev->num_msi =
                hnae3_get_field(__le16_to_cpu(req->pf_intr_vector_number),
@@ -1268,35 +1267,37 @@ static int hclge_map_tqps_to_func(struct hclge_dev *hdev, u16 func_id,
        return ret;
 }
 
-static int  hclge_assign_tqp(struct hclge_vport *vport,
-                            struct hnae3_queue **tqp, u16 num_tqps)
+static int  hclge_assign_tqp(struct hclge_vport *vport)
 {
+       struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
        struct hclge_dev *hdev = vport->back;
        int i, alloced;
 
        for (i = 0, alloced = 0; i < hdev->num_tqps &&
-            alloced < num_tqps; i++) {
+            alloced < kinfo->num_tqps; i++) {
                if (!hdev->htqp[i].alloced) {
                        hdev->htqp[i].q.handle = &vport->nic;
                        hdev->htqp[i].q.tqp_index = alloced;
-                       tqp[alloced] = &hdev->htqp[i].q;
+                       hdev->htqp[i].q.desc_num = kinfo->num_desc;
+                       kinfo->tqp[alloced] = &hdev->htqp[i].q;
                        hdev->htqp[i].alloced = true;
                        alloced++;
                }
        }
-       vport->alloc_tqps = num_tqps;
+       vport->alloc_tqps = kinfo->num_tqps;
 
        return 0;
 }
 
-static int hclge_knic_setup(struct hclge_vport *vport, u16 num_tqps)
+static int hclge_knic_setup(struct hclge_vport *vport,
+                           u16 num_tqps, u16 num_desc)
 {
        struct hnae3_handle *nic = &vport->nic;
        struct hnae3_knic_private_info *kinfo = &nic->kinfo;
        struct hclge_dev *hdev = vport->back;
        int i, ret;
 
-       kinfo->num_desc = hdev->num_desc;
+       kinfo->num_desc = num_desc;
        kinfo->rx_buf_len = hdev->rx_buf_len;
        kinfo->num_tc = min_t(u16, num_tqps, hdev->tm_info.num_tc);
        kinfo->rss_size
@@ -1323,7 +1324,7 @@ static int hclge_knic_setup(struct hclge_vport *vport, u16 num_tqps)
        if (!kinfo->tqp)
                return -ENOMEM;
 
-       ret = hclge_assign_tqp(vport, kinfo->tqp, kinfo->num_tqps);
+       ret = hclge_assign_tqp(vport);
        if (ret)
                dev_err(&hdev->pdev->dev, "fail to assign TQPs %d.\n", ret);
 
@@ -1389,7 +1390,7 @@ static int hclge_vport_setup(struct hclge_vport *vport, u16 num_tqps)
        nic->numa_node_mask = hdev->numa_node_mask;
 
        if (hdev->ae_dev->dev_type == HNAE3_DEV_KNIC) {
-               ret = hclge_knic_setup(vport, num_tqps);
+               ret = hclge_knic_setup(vport, num_tqps, hdev->num_desc);
                if (ret) {
                        dev_err(&hdev->pdev->dev, "knic setup failed %d\n",
                                ret);
@@ -2043,7 +2044,7 @@ static int hclge_init_msi(struct hclge_dev *hdev)
        hdev->num_msi_left = vectors;
        hdev->base_msi_vector = pdev->irq;
        hdev->roce_base_vector = hdev->base_msi_vector +
-                               HCLGE_ROCE_VECTOR_OFFSET;
+                               hdev->roce_base_msix_offset;
 
        hdev->vector_status = devm_kcalloc(&pdev->dev, hdev->num_msi,
                                           sizeof(u16), GFP_KERNEL);
@@ -2636,7 +2637,6 @@ static void hclge_misc_irq_uninit(struct hclge_dev *hdev)
 static int hclge_notify_client(struct hclge_dev *hdev,
                               enum hnae3_reset_notify_type type)
 {
-       struct hnae3_client *rclient = hdev->roce_client;
        struct hnae3_client *client = hdev->nic_client;
        struct hnae3_handle *handle;
        int ret;
@@ -2653,19 +2653,36 @@ static int hclge_notify_client(struct hclge_dev *hdev,
                                "notify nic client failed %d", ret);
                        return ret;
                }
+       }
 
-               if (rclient && rclient->ops->reset_notify) {
-                       handle = &hdev->vport[i].roce;
-                       ret = rclient->ops->reset_notify(handle, type);
-                       if (ret) {
-                               dev_err(&hdev->pdev->dev,
-                                       "notify roce client failed %d", ret);
-                               return ret;
-                       }
+       return 0;
+}
+
+static int hclge_notify_roce_client(struct hclge_dev *hdev,
+                                   enum hnae3_reset_notify_type type)
+{
+       struct hnae3_client *client = hdev->roce_client;
+       struct hnae3_handle *handle;
+       int ret = 0;
+       u16 i;
+
+       if (!client)
+               return 0;
+
+       if (!client->ops->reset_notify)
+               return -EOPNOTSUPP;
+
+       for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
+               handle = &hdev->vport[i].roce;
+               ret = client->ops->reset_notify(handle, type);
+               if (ret) {
+                       dev_err(&hdev->pdev->dev,
+                               "notify roce client failed %d", ret);
+                       return ret;
                }
        }
 
-       return 0;
+       return ret;
 }
 
 static int hclge_reset_wait(struct hclge_dev *hdev)
@@ -2816,6 +2833,10 @@ static void hclge_reset(struct hclge_dev *hdev)
 
        /* perform reset of the stack & ae device for a client */
        handle = &hdev->vport[0].nic;
+
+       hclge_notify_roce_client(hdev, HNAE3_DOWN_CLIENT);
+       hclge_notify_roce_client(hdev, HNAE3_UNINIT_CLIENT);
+
        rtnl_lock();
        hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
 
@@ -2834,6 +2855,9 @@ static void hclge_reset(struct hclge_dev *hdev)
        hclge_notify_client(hdev, HNAE3_UP_CLIENT);
        handle->last_reset_time = jiffies;
        rtnl_unlock();
+
+       hclge_notify_roce_client(hdev, HNAE3_INIT_CLIENT);
+       hclge_notify_roce_client(hdev, HNAE3_UP_CLIENT);
 }
 
 static void hclge_reset_event(struct hnae3_handle *handle)
@@ -3692,6 +3716,55 @@ static int hclge_set_mac_loopback(struct hclge_dev *hdev, bool en)
        return ret;
 }
 
+static int hclge_set_serdes_loopback(struct hclge_dev *hdev, bool en)
+{
+#define HCLGE_SERDES_RETRY_MS  10
+#define HCLGE_SERDES_RETRY_NUM 100
+       struct hclge_serdes_lb_cmd *req;
+       struct hclge_desc desc;
+       int ret, i = 0;
+
+       req = (struct hclge_serdes_lb_cmd *)&desc.data[0];
+       hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK, false);
+
+       if (en) {
+               req->enable = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+               req->mask = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+       } else {
+               req->mask = HCLGE_CMD_SERDES_SERIAL_INNER_LOOP_B;
+       }
+
+       ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+       if (ret) {
+               dev_err(&hdev->pdev->dev,
+                       "serdes loopback set fail, ret = %d\n", ret);
+               return ret;
+       }
+
+       do {
+               msleep(HCLGE_SERDES_RETRY_MS);
+               hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SERDES_LOOPBACK,
+                                          true);
+               ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+               if (ret) {
+                       dev_err(&hdev->pdev->dev,
+                               "serdes loopback get, ret = %d\n", ret);
+                       return ret;
+               }
+       } while (++i < HCLGE_SERDES_RETRY_NUM &&
+                !(req->result & HCLGE_CMD_SERDES_DONE_B));
+
+       if (!(req->result & HCLGE_CMD_SERDES_DONE_B)) {
+               dev_err(&hdev->pdev->dev, "serdes loopback set timeout\n");
+               return -EBUSY;
+       } else if (!(req->result & HCLGE_CMD_SERDES_SUCCESS_B)) {
+               dev_err(&hdev->pdev->dev, "serdes loopback set failed in fw\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
 static int hclge_set_loopback(struct hnae3_handle *handle,
                              enum hnae3_loop loop_mode, bool en)
 {
@@ -3703,6 +3776,9 @@ static int hclge_set_loopback(struct hnae3_handle *handle,
        case HNAE3_MAC_INTER_LOOP_MAC:
                ret = hclge_set_mac_loopback(hdev, en);
                break;
+       case HNAE3_MAC_INTER_LOOP_SERDES:
+               ret = hclge_set_serdes_loopback(hdev, en);
+               break;
        default:
                ret = -ENOTSUPP;
                dev_err(&hdev->pdev->dev,
@@ -3751,7 +3827,7 @@ static int hclge_ae_start(struct hnae3_handle *handle)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
        struct hclge_dev *hdev = vport->back;
-       int i, ret;
+       int i;
 
        for (i = 0; i < vport->alloc_tqps; i++)
                hclge_tqp_enable(hdev, i, 0, true);
@@ -3765,9 +3841,7 @@ static int hclge_ae_start(struct hnae3_handle *handle)
        /* reset tqp stats */
        hclge_reset_tqp_stats(handle);
 
-       ret = hclge_mac_start_phy(hdev);
-       if (ret)
-               return ret;
+       hclge_mac_start_phy(hdev);
 
        return 0;
 }
@@ -5386,6 +5460,16 @@ static void hclge_get_mdix_mode(struct hnae3_handle *handle,
                *tp_mdix = ETH_TP_MDI;
 }
 
+static int hclge_init_instance_hw(struct hclge_dev *hdev)
+{
+       return hclge_mac_connect_phy(hdev);
+}
+
+static void hclge_uninit_instance_hw(struct hclge_dev *hdev)
+{
+       hclge_mac_disconnect_phy(hdev);
+}
+
 static int hclge_init_client_instance(struct hnae3_client *client,
                                      struct hnae3_ae_dev *ae_dev)
 {
@@ -5405,6 +5489,13 @@ static int hclge_init_client_instance(struct hnae3_client *client,
                        if (ret)
                                return ret;
 
+                       ret = hclge_init_instance_hw(hdev);
+                       if (ret) {
+                               client->ops->uninit_instance(&vport->nic,
+                                                            0);
+                               return ret;
+                       }
+
                        if (hdev->roce_client &&
                            hnae3_dev_roce_supported(hdev)) {
                                struct hnae3_client *rc = hdev->roce_client;
@@ -5467,6 +5558,7 @@ static void hclge_uninit_client_instance(struct hnae3_client *client,
                if (client->type == HNAE3_CLIENT_ROCE)
                        return;
                if (client->ops->uninit_instance) {
+                       hclge_uninit_instance_hw(hdev);
                        client->ops->uninit_instance(&vport->nic, 0);
                        hdev->nic_client = NULL;
                        vport->nic.client = NULL;
@@ -5889,7 +5981,7 @@ static int hclge_set_channels(struct hnae3_handle *handle, u32 new_tqps_num)
        /* Free old tqps, and reallocate with new tqp number when nic setup */
        hclge_release_tqp(vport);
 
-       ret = hclge_knic_setup(vport, new_tqps_num);
+       ret = hclge_knic_setup(vport, new_tqps_num, kinfo->num_desc);
        if (ret) {
                dev_err(&hdev->pdev->dev, "setup nic fail, ret =%d\n", ret);
                return ret;