drivers/net/ethernet/mellanox/mlx4/alloc.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx4/alloc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx4/alloc.c- Extension
.c- Size
- 18345 bytes
- Lines
- 796
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/slab.hlinux/mm.hlinux/export.hlinux/bitmap.hlinux/dma-mapping.hlinux/vmalloc.hmlx4.h
Detected Declarations
struct mlx4_zone_allocatorstruct mlx4_zone_entryfunction Copyrightfunction mlx4_bitmap_freefunction find_aligned_rangefunction mlx4_bitmap_alloc_rangefunction mlx4_bitmap_availfunction mlx4_bitmap_masked_valuefunction mlx4_bitmap_free_rangefunction mlx4_bitmap_initfunction mlx4_bitmap_cleanupfunction mlx4_zone_add_onefunction __mlx4_zone_remove_one_entryfunction list_for_each_entryfunction mlx4_zone_allocator_destroyfunction list_for_each_entry_safefunction __mlx4_alloc_from_zonefunction list_for_each_entryfunction list_for_each_entry_continue_reversefunction list_for_each_entry_fromfunction list_for_each_entry_fromfunction __mlx4_free_from_zonefunction list_for_each_entryfunction mlx4_zone_remove_onefunction bitmapsfunction mlx4_zone_alloc_entriesfunction mlx4_zone_free_entries_uniquefunction mlx4_buf_direct_allocfunction mlx4_buf_allocfunction mlx4_buf_freefunction mlx4_alloc_db_from_pgdirfunction mlx4_db_allocfunction mlx4_db_freefunction mlx4_alloc_hwq_resfunction mlx4_free_hwq_resexport mlx4_buf_allocexport mlx4_buf_freeexport mlx4_db_allocexport mlx4_db_freeexport mlx4_alloc_hwq_resexport mlx4_free_hwq_res
Annotated Snippet
struct mlx4_zone_allocator {
struct list_head entries;
struct list_head prios;
u32 last_uid;
u32 mask;
/* protect the zone_allocator from concurrent accesses */
spinlock_t lock;
enum mlx4_zone_alloc_flags flags;
};
struct mlx4_zone_entry {
struct list_head list;
struct list_head prio_list;
u32 uid;
struct mlx4_zone_allocator *allocator;
struct mlx4_bitmap *bitmap;
int use_rr;
int priority;
int offset;
enum mlx4_zone_flags flags;
};
struct mlx4_zone_allocator *mlx4_zone_allocator_create(enum mlx4_zone_alloc_flags flags)
{
struct mlx4_zone_allocator *zones = kmalloc_obj(*zones);
if (NULL == zones)
return NULL;
INIT_LIST_HEAD(&zones->entries);
INIT_LIST_HEAD(&zones->prios);
spin_lock_init(&zones->lock);
zones->last_uid = 0;
zones->mask = 0;
zones->flags = flags;
return zones;
}
int mlx4_zone_add_one(struct mlx4_zone_allocator *zone_alloc,
struct mlx4_bitmap *bitmap,
u32 flags,
int priority,
int offset,
u32 *puid)
{
u32 mask = mlx4_bitmap_masked_value(bitmap, (u32)-1);
struct mlx4_zone_entry *it;
struct mlx4_zone_entry *zone = kmalloc_obj(*zone);
if (NULL == zone)
return -ENOMEM;
zone->flags = flags;
zone->bitmap = bitmap;
zone->use_rr = (flags & MLX4_ZONE_USE_RR) ? MLX4_USE_RR : 0;
zone->priority = priority;
zone->offset = offset;
spin_lock(&zone_alloc->lock);
zone->uid = zone_alloc->last_uid++;
zone->allocator = zone_alloc;
if (zone_alloc->mask < mask)
zone_alloc->mask = mask;
list_for_each_entry(it, &zone_alloc->prios, prio_list)
if (it->priority >= priority)
break;
if (&it->prio_list == &zone_alloc->prios || it->priority > priority)
list_add_tail(&zone->prio_list, &it->prio_list);
list_add_tail(&zone->list, &it->list);
spin_unlock(&zone_alloc->lock);
*puid = zone->uid;
return 0;
}
/* Should be called under a lock */
static void __mlx4_zone_remove_one_entry(struct mlx4_zone_entry *entry)
{
struct mlx4_zone_allocator *zone_alloc = entry->allocator;
if (!list_empty(&entry->prio_list)) {
/* Check if we need to add an alternative node to the prio list */
if (!list_is_last(&entry->list, &zone_alloc->entries)) {
Annotation
- Immediate include surface: `linux/errno.h`, `linux/slab.h`, `linux/mm.h`, `linux/export.h`, `linux/bitmap.h`, `linux/dma-mapping.h`, `linux/vmalloc.h`, `mlx4.h`.
- Detected declarations: `struct mlx4_zone_allocator`, `struct mlx4_zone_entry`, `function Copyright`, `function mlx4_bitmap_free`, `function find_aligned_range`, `function mlx4_bitmap_alloc_range`, `function mlx4_bitmap_avail`, `function mlx4_bitmap_masked_value`, `function mlx4_bitmap_free_range`, `function mlx4_bitmap_init`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.