]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
UBUNTU: SAUCE: {topost} net: hns3: separate roce from nic when resetting
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / hisilicon / hns3 / hns3pf / hclge_main.c
index ae1f6dcdcf4648113ea77f3cce869dbe070b1c48..12eb41e065ee1f3c88f16faecd72c2e7008ca572 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) +
@@ -2349,7 +2344,7 @@ static int hclge_get_mac_link_status(struct hclge_dev *hdev)
        }
 
        req = (struct hclge_link_status_cmd *)desc.data;
-       link_status = req->status & HCLGE_LINK_STATUS;
+       link_status = req->status & HCLGE_LINK_STATUS_UP_M;
 
        return !!link_status;
 }
@@ -2636,7 +2631,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 +2647,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 +2827,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 +2849,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 +3710,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 +3770,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,
@@ -4308,7 +4378,7 @@ static int hclge_add_mc_addr(struct hnae3_handle *handle,
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
 
-       return  hclge_add_mc_addr_common(vport, addr);
+       return hclge_add_mc_addr_common(vport, addr);
 }
 
 int hclge_add_mc_addr_common(struct hclge_vport *vport,
@@ -5886,6 +5956,7 @@ static int hclge_set_channels(struct hnae3_handle *handle, u32 new_tqps_num)
        u32 *rss_indir;
        int ret, i;
 
+       /* Free old tqps, and reallocate with new tqp number when nic setup */
        hclge_release_tqp(vport);
 
        ret = hclge_knic_setup(vport, new_tqps_num);