aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/intel/ice/ice_irq.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/ethernet/intel/ice/ice_irq.c')
-rw-r--r--drivers/net/ethernet/intel/ice/ice_irq.c101
1 files changed, 77 insertions, 24 deletions
diff --git a/drivers/net/ethernet/intel/ice/ice_irq.c b/drivers/net/ethernet/intel/ice/ice_irq.c
index ca1a1de26766..1713347c577f 100644
--- a/drivers/net/ethernet/intel/ice/ice_irq.c
+++ b/drivers/net/ethernet/intel/ice/ice_irq.c
@@ -6,6 +6,75 @@
#include "ice_irq.h"
/**
+ * ice_init_irq_tracker - initialize interrupt tracker
+ * @pf: board private structure
+ * @max_vectors: maximum number of vectors that tracker can hold
+ */
+static void
+ice_init_irq_tracker(struct ice_pf *pf, unsigned int max_vectors)
+{
+ pf->irq_tracker.num_entries = max_vectors;
+ xa_init_flags(&pf->irq_tracker.entries, XA_FLAGS_ALLOC);
+}
+
+/**
+ * ice_deinit_irq_tracker - free xarray tracker
+ * @pf: board private structure
+ */
+static void ice_deinit_irq_tracker(struct ice_pf *pf)
+{
+ xa_destroy(&pf->irq_tracker.entries);
+}
+
+/**
+ * ice_free_irq_res - free a block of resources
+ * @pf: board private structure
+ * @index: starting index previously returned by ice_get_res
+ */
+static void ice_free_irq_res(struct ice_pf *pf, u16 index)
+{
+ struct ice_irq_entry *entry;
+
+ entry = xa_erase(&pf->irq_tracker.entries, index);
+ kfree(entry);
+}
+
+/**
+ * ice_get_irq_res - get an interrupt resource
+ * @pf: board private structure
+ *
+ * Allocate new irq entry in the free slot of the tracker. Since xarray
+ * is used, always allocate new entry at the lowest possible index. Set
+ * proper allocation limit for maximum tracker entries.
+ *
+ * Returns allocated irq entry or NULL on failure.
+ */
+static struct ice_irq_entry *ice_get_irq_res(struct ice_pf *pf)
+{
+ struct xa_limit limit = { .max = pf->irq_tracker.num_entries,
+ .min = 0 };
+ struct ice_irq_entry *entry;
+ unsigned int index;
+ int ret;
+
+ entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+ if (!entry)
+ return NULL;
+
+ ret = xa_alloc(&pf->irq_tracker.entries, &index, entry, limit,
+ GFP_KERNEL);
+
+ if (ret) {
+ kfree(entry);
+ entry = NULL;
+ } else {
+ entry->index = index;
+ }
+
+ return entry;
+}
+
+/**
* ice_reduce_msix_usage - Reduce usage of MSI-X vectors
* @pf: board private structure
* @v_remain: number of remaining MSI-X vectors to be distributed
@@ -163,11 +232,7 @@ exit_err:
void ice_clear_interrupt_scheme(struct ice_pf *pf)
{
pci_free_irq_vectors(pf->pdev);
-
- if (pf->irq_tracker) {
- devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
- pf->irq_tracker = NULL;
- }
+ ice_deinit_irq_tracker(pf);
}
/**
@@ -183,19 +248,7 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
if (vectors < 0)
return vectors;
- /* set up vector assignment tracking */
- pf->irq_tracker = devm_kzalloc(ice_pf_to_dev(pf),
- struct_size(pf->irq_tracker, list,
- vectors),
- GFP_KERNEL);
- if (!pf->irq_tracker) {
- pci_free_irq_vectors(pf->pdev);
- return -ENOMEM;
- }
-
- /* populate SW interrupts pool with number of OS granted IRQs. */
- pf->irq_tracker->num_entries = (u16)vectors;
- pf->irq_tracker->end = pf->irq_tracker->num_entries;
+ ice_init_irq_tracker(pf, vectors);
return 0;
}
@@ -221,13 +274,13 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
struct msi_map ice_alloc_irq(struct ice_pf *pf)
{
struct msi_map map = { .index = -ENOENT };
- int entry;
+ struct ice_irq_entry *entry;
- entry = ice_get_res(pf, pf->irq_tracker);
- if (entry < 0)
+ entry = ice_get_irq_res(pf);
+ if (!entry)
return map;
- map.index = entry;
+ map.index = entry->index;
map.virq = pci_irq_vector(pf->pdev, map.index);
return map;
@@ -238,9 +291,9 @@ struct msi_map ice_alloc_irq(struct ice_pf *pf)
* @pf: board private structure
* @map: map with interrupt details
*
- * Remove allocated interrupt from the interrupt tracker
+ * Remove allocated interrupt from the interrupt tracker.
*/
void ice_free_irq(struct ice_pf *pf, struct msi_map map)
{
- ice_free_res(pf->irq_tracker, map.index);
+ ice_free_irq_res(pf, map.index);
}