Allow the rmap users to pass a notifier callback function that can be
called instead of irq_cpu_rmap_notify().

Two modifications are made:
   * make struct irg_glue visible in cpu_rmap.h
   * pass a new "void* data" parameter that can be used by the cb
     function.

Signed-off-by: Ahmed Zaki <[email protected]>
---
 drivers/net/ethernet/cisco/enic/enic_main.c   |  3 ++-
 .../net/ethernet/hisilicon/hns3/hns3_enet.c   |  2 +-
 drivers/net/ethernet/mellanox/mlx4/eq.c       |  2 +-
 .../net/ethernet/mellanox/mlx5/core/pci_irq.c |  2 +-
 drivers/net/ethernet/sfc/nic.c                |  2 +-
 include/linux/cpu_rmap.h                      | 13 +++++++++++-
 lib/cpu_rmap.c                                | 20 +++++++++----------
 7 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c 
b/drivers/net/ethernet/cisco/enic/enic_main.c
index 9913952ccb42..e384b975b8af 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -1657,7 +1657,8 @@ static void enic_set_rx_cpu_rmap(struct enic *enic)
                        return;
                for (i = 0; i < enic->rq_count; i++) {
                        res = irq_cpu_rmap_add(enic->netdev->rx_cpu_rmap,
-                                              enic->msix_entry[i].vector);
+                                              enic->msix_entry[i].vector,
+                                              NULL, NULL);
                        if (unlikely(res)) {
                                enic_free_rx_cpu_rmap(enic);
                                return;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 43377a7b2426..3f732516c8ee 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -697,7 +697,7 @@ static int hns3_set_rx_cpu_rmap(struct net_device *netdev)
        for (i = 0; i < priv->vector_num; i++) {
                tqp_vector = &priv->tqp_vector[i];
                ret = irq_cpu_rmap_add(netdev->rx_cpu_rmap,
-                                      tqp_vector->vector_irq);
+                                      tqp_vector->vector_irq, NULL, NULL);
                if (ret) {
                        hns3_free_rx_cpu_rmap(netdev);
                        return ret;
diff --git a/drivers/net/ethernet/mellanox/mlx4/eq.c 
b/drivers/net/ethernet/mellanox/mlx4/eq.c
index 9572a45f6143..d768a6a828c4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/eq.c
@@ -1243,7 +1243,7 @@ int mlx4_init_eq_table(struct mlx4_dev *dev)
                                }
 
                                err = irq_cpu_rmap_add(
-                                       info->rmap, eq->irq);
+                                       info->rmap, eq->irq, NULL, NULL);
                                if (err)
                                        mlx4_warn(dev, "Failed adding irq 
rmap\n");
                        }
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c 
b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
index 7db9cab9bedf..4f2c4631aecb 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c
@@ -285,7 +285,7 @@ struct mlx5_irq *mlx5_irq_alloc(struct mlx5_irq_pool *pool, 
int i,
 
        if (i && rmap && *rmap) {
 #ifdef CONFIG_RFS_ACCEL
-               err = irq_cpu_rmap_add(*rmap, irq->map.virq);
+               err = irq_cpu_rmap_add(*rmap, irq->map.virq, NULL, NULL);
                if (err)
                        goto err_irq_rmap;
 #endif
diff --git a/drivers/net/ethernet/sfc/nic.c b/drivers/net/ethernet/sfc/nic.c
index 80aa5e9c732a..e7c6c3002826 100644
--- a/drivers/net/ethernet/sfc/nic.c
+++ b/drivers/net/ethernet/sfc/nic.c
@@ -122,7 +122,7 @@ int efx_nic_init_interrupt(struct efx_nic *efx)
                if (efx->interrupt_mode == EFX_INT_MODE_MSIX &&
                    channel->channel < efx->n_rx_channels) {
                        rc = irq_cpu_rmap_add(efx->net_dev->rx_cpu_rmap,
-                                             channel->irq);
+                                             channel->irq, NULL, NULL);
                        if (rc)
                                goto fail2;
                }
diff --git a/include/linux/cpu_rmap.h b/include/linux/cpu_rmap.h
index 20b5729903d7..48f89d19bdb9 100644
--- a/include/linux/cpu_rmap.h
+++ b/include/linux/cpu_rmap.h
@@ -11,6 +11,15 @@
 #include <linux/gfp.h>
 #include <linux/slab.h>
 #include <linux/kref.h>
+#include <linux/interrupt.h>
+
+/* Glue between IRQ affinity notifiers and CPU rmaps */
+struct irq_glue {
+       struct irq_affinity_notify notify;
+       struct cpu_rmap *rmap;
+       void *data;
+       u16 index;
+};
 
 /**
  * struct cpu_rmap - CPU affinity reverse-map
@@ -61,6 +70,8 @@ static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned 
int size)
 extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
 
 int irq_cpu_rmap_remove(struct cpu_rmap *rmap, int irq);
-extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
+extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq, void *data,
+                           void (*notify)(struct irq_affinity_notify *notify,
+                                          const cpumask_t *mask));
 
 #endif /* __LINUX_CPU_RMAP_H */
diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
index 4c348670da31..0c9c1078143d 100644
--- a/lib/cpu_rmap.c
+++ b/lib/cpu_rmap.c
@@ -220,14 +220,6 @@ int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
 }
 EXPORT_SYMBOL(cpu_rmap_update);
 
-/* Glue between IRQ affinity notifiers and CPU rmaps */
-
-struct irq_glue {
-       struct irq_affinity_notify notify;
-       struct cpu_rmap *rmap;
-       u16 index;
-};
-
 /**
  * free_irq_cpu_rmap - free a CPU affinity reverse-map used for IRQs
  * @rmap: Reverse-map allocated with alloc_irq_cpu_map(), or %NULL
@@ -300,6 +292,8 @@ EXPORT_SYMBOL(irq_cpu_rmap_remove);
  * irq_cpu_rmap_add - add an IRQ to a CPU affinity reverse-map
  * @rmap: The reverse-map
  * @irq: The IRQ number
+ * @data: Generic data
+ * @notify: Callback function to update the CPU-IRQ rmap
  *
  * This adds an IRQ affinity notifier that will update the reverse-map
  * automatically.
@@ -307,16 +301,22 @@ EXPORT_SYMBOL(irq_cpu_rmap_remove);
  * Must be called in process context, after the IRQ is allocated but
  * before it is bound with request_irq().
  */
-int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq)
+int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq, void *data,
+                    void (*notify)(struct irq_affinity_notify *notify,
+                                   const cpumask_t *mask))
 {
        struct irq_glue *glue = kzalloc(sizeof(*glue), GFP_KERNEL);
        int rc;
 
        if (!glue)
                return -ENOMEM;
-       glue->notify.notify = irq_cpu_rmap_notify;
+
+       if (!notify)
+               notify = irq_cpu_rmap_notify;
+       glue->notify.notify = notify;
        glue->notify.release = irq_cpu_rmap_release;
        glue->rmap = rmap;
+       glue->data = data;
        cpu_rmap_get(rmap);
        rc = cpu_rmap_add(rmap, glue);
        if (rc < 0)
-- 
2.43.0

Reply via email to