net/mlx5: Refactor completion irq request/release code
authorEli Cohen <elic@nvidia.com>
Mon, 9 Jan 2023 10:08:53 +0000 (12:08 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Fri, 24 Mar 2023 23:04:29 +0000 (16:04 -0700)
Break the request and release functions into pci and sub-functions
devices handling for better readability, eventually making the code
symmetric in terms of request/release.

Signed-off-by: Eli Cohen <elic@nvidia.com>
Reviewed-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
drivers/net/ethernet/mellanox/mlx5/core/eq.c

index b43121f..ed75b52 100644 (file)
@@ -804,44 +804,28 @@ void mlx5_eq_update_ci(struct mlx5_eq *eq, u32 cc, bool arm)
 }
 EXPORT_SYMBOL(mlx5_eq_update_ci);
 
-static void comp_irqs_release(struct mlx5_core_dev *dev)
+static void comp_irqs_release_pci(struct mlx5_core_dev *dev)
 {
        struct mlx5_eq_table *table = dev->priv.eq_table;
 
-       if (mlx5_core_is_sf(dev))
-               mlx5_irq_affinity_irqs_release(dev, table->comp_irqs, table->num_comp_eqs);
-       else
-               mlx5_irqs_release_vectors(table->comp_irqs, table->num_comp_eqs);
-       kfree(table->comp_irqs);
+       mlx5_irqs_release_vectors(table->comp_irqs, table->num_comp_eqs);
 }
 
-static int comp_irqs_request(struct mlx5_core_dev *dev)
+static int comp_irqs_request_pci(struct mlx5_core_dev *dev)
 {
        struct mlx5_eq_table *table = dev->priv.eq_table;
        const struct cpumask *prev = cpu_none_mask;
        const struct cpumask *mask;
-       int ncomp_eqs = table->num_comp_eqs;
+       int ncomp_eqs;
        u16 *cpus;
        int ret;
        int cpu;
        int i;
 
        ncomp_eqs = table->num_comp_eqs;
-       table->comp_irqs = kcalloc(ncomp_eqs, sizeof(*table->comp_irqs), GFP_KERNEL);
-       if (!table->comp_irqs)
-               return -ENOMEM;
-       if (mlx5_core_is_sf(dev)) {
-               ret = mlx5_irq_affinity_irqs_request_auto(dev, ncomp_eqs, table->comp_irqs);
-               if (ret < 0)
-                       goto free_irqs;
-               return ret;
-       }
-
        cpus = kcalloc(ncomp_eqs, sizeof(*cpus), GFP_KERNEL);
-       if (!cpus) {
+       if (!cpus)
                ret = -ENOMEM;
-               goto free_irqs;
-       }
 
        i = 0;
        rcu_read_lock();
@@ -857,12 +841,50 @@ spread_done:
        rcu_read_unlock();
        ret = mlx5_irqs_request_vectors(dev, cpus, ncomp_eqs, table->comp_irqs);
        kfree(cpus);
-       if (ret < 0)
-               goto free_irqs;
        return ret;
+}
+
+static void comp_irqs_release_sf(struct mlx5_core_dev *dev)
+{
+       struct mlx5_eq_table *table = dev->priv.eq_table;
+
+       mlx5_irq_affinity_irqs_release(dev, table->comp_irqs, table->num_comp_eqs);
+}
+
+static int comp_irqs_request_sf(struct mlx5_core_dev *dev)
+{
+       struct mlx5_eq_table *table = dev->priv.eq_table;
+       int ncomp_eqs = table->num_comp_eqs;
+
+       return mlx5_irq_affinity_irqs_request_auto(dev, ncomp_eqs, table->comp_irqs);
+}
+
+static void comp_irqs_release(struct mlx5_core_dev *dev)
+{
+       struct mlx5_eq_table *table = dev->priv.eq_table;
+
+       mlx5_core_is_sf(dev) ? comp_irqs_release_sf(dev) :
+                              comp_irqs_release_pci(dev);
 
-free_irqs:
        kfree(table->comp_irqs);
+}
+
+static int comp_irqs_request(struct mlx5_core_dev *dev)
+{
+       struct mlx5_eq_table *table = dev->priv.eq_table;
+       int ncomp_eqs;
+       int ret;
+
+       ncomp_eqs = table->num_comp_eqs;
+       table->comp_irqs = kcalloc(ncomp_eqs, sizeof(*table->comp_irqs), GFP_KERNEL);
+       if (!table->comp_irqs)
+               return -ENOMEM;
+
+       ret = mlx5_core_is_sf(dev) ? comp_irqs_request_sf(dev) :
+                                    comp_irqs_request_pci(dev);
+       if (ret < 0)
+               kfree(table->comp_irqs);
+
        return ret;
 }