]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
net: hns3: refactor the hclge_get/set_rss function
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / hisilicon / hns3 / hns3pf / hclge_main.c
index 32bc6f68e2974762d9eb6f2597d976a59f833322..131234dfb05ff565dd545d024a17589fe9c66e54 100644 (file)
@@ -55,6 +55,8 @@ static const struct pci_device_id ae_algo_pci_tbl[] = {
        {0, }
 };
 
+MODULE_DEVICE_TABLE(pci, ae_algo_pci_tbl);
+
 static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
        "Mac    Loopback test",
        "Serdes Loopback test",
@@ -2979,31 +2981,6 @@ static u32 hclge_get_rss_indir_size(struct hnae3_handle *handle)
        return HCLGE_RSS_IND_TBL_SIZE;
 }
 
-static int hclge_get_rss_algo(struct hclge_dev *hdev)
-{
-       struct hclge_rss_config_cmd *req;
-       struct hclge_desc desc;
-       int rss_hash_algo;
-       int ret;
-
-       hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_GENERIC_CONFIG, true);
-
-       ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-       if (ret) {
-               dev_err(&hdev->pdev->dev,
-                       "Get link status error, status =%d\n", ret);
-               return ret;
-       }
-
-       req = (struct hclge_rss_config_cmd *)desc.data;
-       rss_hash_algo = (req->hash_config & HCLGE_RSS_HASH_ALGO_MASK);
-
-       if (rss_hash_algo == HCLGE_RSS_HASH_ALGO_TOEPLITZ)
-               return ETH_RSS_HASH_TOP;
-
-       return -EINVAL;
-}
-
 static int hclge_set_rss_algo_key(struct hclge_dev *hdev,
                                  const u8 hfunc, const u8 *key)
 {
@@ -3042,7 +3019,7 @@ static int hclge_set_rss_algo_key(struct hclge_dev *hdev,
        return 0;
 }
 
-static int hclge_set_rss_indir_table(struct hclge_dev *hdev, const u32 *indir)
+static int hclge_set_rss_indir_table(struct hclge_dev *hdev, const u8 *indir)
 {
        struct hclge_rss_indirection_table_cmd *req;
        struct hclge_desc desc;
@@ -3138,12 +3115,11 @@ static int hclge_get_rss(struct hnae3_handle *handle, u32 *indir,
                         u8 *key, u8 *hfunc)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
-       struct hclge_dev *hdev = vport->back;
        int i;
 
        /* Get hash algorithm */
        if (hfunc)
-               *hfunc = hclge_get_rss_algo(hdev);
+               *hfunc = vport->rss_algo;
 
        /* Get the RSS Key required by the user */
        if (key)
@@ -3167,8 +3143,6 @@ static int hclge_set_rss(struct hnae3_handle *handle, const u32 *indir,
 
        /* Set the RSS Hash Key if specififed by the user */
        if (key) {
-               /* Update the shadow RSS key with user specified qids */
-               memcpy(vport->rss_hash_key, key, HCLGE_RSS_KEY_SIZE);
 
                if (hfunc == ETH_RSS_HASH_TOP ||
                    hfunc == ETH_RSS_HASH_NO_CHANGE)
@@ -3178,6 +3152,10 @@ static int hclge_set_rss(struct hnae3_handle *handle, const u32 *indir,
                ret = hclge_set_rss_algo_key(hdev, hash_algo, key);
                if (ret)
                        return ret;
+
+               /* Update the shadow RSS key with user specified qids */
+               memcpy(vport->rss_hash_key, key, HCLGE_RSS_KEY_SIZE);
+               vport->rss_algo = hash_algo;
        }
 
        /* Update the shadow RSS table with user specified qids */
@@ -3185,8 +3163,7 @@ static int hclge_set_rss(struct hnae3_handle *handle, const u32 *indir,
                vport->rss_indirection_tbl[i] = indir[i];
 
        /* Update the hardware */
-       ret = hclge_set_rss_indir_table(hdev, indir);
-       return ret;
+       return hclge_set_rss_indir_table(hdev, vport->rss_indirection_tbl);
 }
 
 static u8 hclge_get_rss_hash_bits(struct ethtool_rxnfc *nfc)
@@ -3717,20 +3694,11 @@ 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, queue_id, ret;
+       int i, ret;
 
-       for (i = 0; i < vport->alloc_tqps; i++) {
-               /* todo clear interrupt */
-               /* ring enable */
-               queue_id = hclge_get_queue_id(handle->kinfo.tqp[i]);
-               if (queue_id < 0) {
-                       dev_warn(&hdev->pdev->dev,
-                                "Get invalid queue id, ignore it\n");
-                       continue;
-               }
+       for (i = 0; i < vport->alloc_tqps; i++)
+               hclge_tqp_enable(hdev, i, 0, true);
 
-               hclge_tqp_enable(hdev, queue_id, 0, true);
-       }
        /* mac enable */
        hclge_cfg_mac_mode(hdev, true);
        clear_bit(HCLGE_STATE_DOWN, &hdev->state);
@@ -3750,19 +3718,11 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
        struct hclge_dev *hdev = vport->back;
-       int i, queue_id;
+       int i;
 
-       for (i = 0; i < vport->alloc_tqps; i++) {
-               /* Ring disable */
-               queue_id = hclge_get_queue_id(handle->kinfo.tqp[i]);
-               if (queue_id < 0) {
-                       dev_warn(&hdev->pdev->dev,
-                                "Get invalid queue id, ignore it\n");
-                       continue;
-               }
+       for (i = 0; i < vport->alloc_tqps; i++)
+               hclge_tqp_enable(hdev, i, 0, false);
 
-               hclge_tqp_enable(hdev, queue_id, 0, false);
-       }
        /* Mac disable */
        hclge_cfg_mac_mode(hdev, false);
 
@@ -4848,21 +4808,36 @@ static int hclge_get_reset_status(struct hclge_dev *hdev, u16 queue_id)
        return hnae_get_bit(req->ready_to_reset, HCLGE_TQP_RESET_B);
 }
 
+static u16 hclge_covert_handle_qid_global(struct hnae3_handle *handle,
+                                         u16 queue_id)
+{
+       struct hnae3_queue *queue;
+       struct hclge_tqp *tqp;
+
+       queue = handle->kinfo.tqp[queue_id];
+       tqp = container_of(queue, struct hclge_tqp, q);
+
+       return tqp->index;
+}
+
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id)
 {
        struct hclge_vport *vport = hclge_get_vport(handle);
        struct hclge_dev *hdev = vport->back;
        int reset_try_times = 0;
        int reset_status;
+       u16 queue_gid;
        int ret;
 
+       queue_gid = hclge_covert_handle_qid_global(handle, queue_id);
+
        ret = hclge_tqp_enable(hdev, queue_id, 0, false);
        if (ret) {
                dev_warn(&hdev->pdev->dev, "Disable tqp fail, ret = %d\n", ret);
                return;
        }
 
-       ret = hclge_send_reset_tqp_cmd(hdev, queue_id, true);
+       ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, true);
        if (ret) {
                dev_warn(&hdev->pdev->dev,
                         "Send reset tqp cmd fail, ret = %d\n", ret);
@@ -4873,7 +4848,7 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id)
        while (reset_try_times++ < HCLGE_TQP_RESET_TRY_TIMES) {
                /* Wait for tqp hw reset */
                msleep(20);
-               reset_status = hclge_get_reset_status(hdev, queue_id);
+               reset_status = hclge_get_reset_status(hdev, queue_gid);
                if (reset_status)
                        break;
        }
@@ -4883,7 +4858,7 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id)
                return;
        }
 
-       ret = hclge_send_reset_tqp_cmd(hdev, queue_id, false);
+       ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, false);
        if (ret) {
                dev_warn(&hdev->pdev->dev,
                         "Deassert the soft reset fail, ret = %d\n", ret);