drivers/net/ethernet/intel/ice/ice_irq.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/intel/ice/ice_irq.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/intel/ice/ice_irq.c
Extension
.c
Size
7514 bytes
Lines
277
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2023, Intel Corporation. */

#include "ice.h"
#include "ice_lib.h"
#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
 * @num_static: number of preallocated interrupts
 */
static void
ice_init_irq_tracker(struct ice_pf *pf, unsigned int max_vectors,
		     unsigned int num_static)
{
	pf->irq_tracker.num_entries = max_vectors;
	pf->irq_tracker.num_static = num_static;
	xa_init_flags(&pf->irq_tracker.entries, XA_FLAGS_ALLOC);
}

static int
ice_init_virt_irq_tracker(struct ice_pf *pf, u32 base, u32 num_entries)
{
	pf->virt_irq_tracker.bm = bitmap_zalloc(num_entries, GFP_KERNEL);
	if (!pf->virt_irq_tracker.bm)
		return -ENOMEM;

	pf->virt_irq_tracker.num_entries = num_entries;
	pf->virt_irq_tracker.base = base;

	return 0;
}

/**
 * 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);
}

static void ice_deinit_virt_irq_tracker(struct ice_pf *pf)
{
	bitmap_free(pf->virt_irq_tracker.bm);
}

/**
 * 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
 * @dyn_allowed: allow entry to be dynamically allocated
 *
 * 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,
					     bool dyn_allowed)
{
	struct xa_limit limit = { .max = pf->irq_tracker.num_entries - 1,
				  .min = 0 };
	unsigned int num_static = pf->irq_tracker.num_static - 1;
	struct ice_irq_entry *entry;
	unsigned int index;
	int ret;

	entry = kzalloc_obj(*entry);
	if (!entry)
		return NULL;

	/* only already allocated if the caller says so */
	if (!dyn_allowed)
		limit.max = num_static;

Annotation

Implementation Notes