]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
net: hns3: Refine the MSIX allocation for PF
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / hisilicon / hns3 / hns3pf / hclge_main.c
index 8caaca13f68f2f524dfdd052e3d1579c2e87d172..2c309dec01f3328376db019bee3c2c92b1c3e228 100644 (file)
@@ -787,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) +
@@ -932,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);
@@ -939,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),
@@ -2037,7 +2042,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);
@@ -2630,7 +2635,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;
@@ -2647,19 +2651,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)
@@ -2810,6 +2831,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);
 
@@ -2828,6 +2853,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)
@@ -3686,6 +3714,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)
 {
@@ -3697,6 +3774,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,