drivers/net/ethernet/mellanox/mlx4/mr.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx4/mr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx4/mr.c- Extension
.c- Size
- 24196 bytes
- Lines
- 975
- 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.
- 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/export.hlinux/slab.hlinux/kernel.hlinux/vmalloc.hlinux/mlx4/cmd.hmlx4.hicm.h
Detected Declarations
function Copyrightfunction mlx4_buddy_freefunction mlx4_buddy_initfunction mlx4_buddy_cleanupfunction __mlx4_alloc_mtt_rangefunction mlx4_alloc_mtt_rangefunction mlx4_mtt_initfunction __mlx4_free_mtt_rangefunction mlx4_free_mtt_rangefunction mlx4_mtt_cleanupfunction mlx4_mtt_addrfunction hw_index_to_keyfunction key_to_hw_indexfunction mlx4_SW2HW_MPTfunction mlx4_HW2SW_MPTfunction mlx4_mr_hw_get_mptfunction mlx4_mr_hw_write_mptfunction mlx4_mr_hw_put_mptfunction mlx4_mr_hw_change_pdfunction mlx4_mr_hw_change_accessfunction mlx4_mr_alloc_reservedfunction mlx4_WRITE_MTTfunction __mlx4_mpt_reservefunction mlx4_mpt_reservefunction __mlx4_mpt_releasefunction mlx4_mpt_releasefunction __mlx4_mpt_alloc_icmfunction mlx4_mpt_alloc_icmfunction __mlx4_mpt_free_icmfunction mlx4_mpt_free_icmfunction mlx4_mr_allocfunction mlx4_mr_free_reservedfunction mlx4_mr_freefunction mlx4_mr_rereg_mem_cleanupfunction mlx4_mr_rereg_mem_writefunction mlx4_mr_enablefunction mlx4_write_mtt_chunkfunction __mlx4_write_mttfunction mlx4_write_mttfunction mlx4_buf_write_mttfunction mlx4_mw_allocfunction mlx4_mw_enablefunction mlx4_mw_freefunction mlx4_init_mr_tablefunction mlx4_cleanup_mr_tablefunction mlx4_SYNC_TPTexport mlx4_mtt_initexport mlx4_mtt_cleanup
Annotated Snippet
if (buddy->num_free[o]) {
m = 1 << (buddy->max_order - o);
seg = find_first_bit(buddy->bits[o], m);
if (seg < m)
goto found;
}
spin_unlock(&buddy->lock);
return -1;
found:
clear_bit(seg, buddy->bits[o]);
--buddy->num_free[o];
while (o > order) {
--o;
seg <<= 1;
set_bit(seg ^ 1, buddy->bits[o]);
++buddy->num_free[o];
}
spin_unlock(&buddy->lock);
seg <<= order;
return seg;
}
static void mlx4_buddy_free(struct mlx4_buddy *buddy, u32 seg, int order)
{
seg >>= order;
spin_lock(&buddy->lock);
while (test_bit(seg ^ 1, buddy->bits[order])) {
clear_bit(seg ^ 1, buddy->bits[order]);
--buddy->num_free[order];
seg >>= 1;
++order;
}
set_bit(seg, buddy->bits[order]);
++buddy->num_free[order];
spin_unlock(&buddy->lock);
}
static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
{
int i, s;
buddy->max_order = max_order;
spin_lock_init(&buddy->lock);
buddy->bits = kcalloc(buddy->max_order + 1, sizeof(*buddy->bits),
GFP_KERNEL);
buddy->num_free = kcalloc(buddy->max_order + 1, sizeof(*buddy->num_free),
GFP_KERNEL);
if (!buddy->bits || !buddy->num_free)
goto err_out;
for (i = 0; i <= buddy->max_order; ++i) {
s = BITS_TO_LONGS(1UL << (buddy->max_order - i));
buddy->bits[i] = kvmalloc_array(s, sizeof(long), GFP_KERNEL | __GFP_ZERO);
if (!buddy->bits[i])
goto err_out_free;
}
set_bit(0, buddy->bits[buddy->max_order]);
buddy->num_free[buddy->max_order] = 1;
return 0;
err_out_free:
for (i = 0; i <= buddy->max_order; ++i)
kvfree(buddy->bits[i]);
err_out:
kfree(buddy->bits);
kfree(buddy->num_free);
return -ENOMEM;
}
static void mlx4_buddy_cleanup(struct mlx4_buddy *buddy)
{
int i;
for (i = 0; i <= buddy->max_order; ++i)
kvfree(buddy->bits[i]);
Annotation
- Immediate include surface: `linux/errno.h`, `linux/export.h`, `linux/slab.h`, `linux/kernel.h`, `linux/vmalloc.h`, `linux/mlx4/cmd.h`, `mlx4.h`, `icm.h`.
- Detected declarations: `function Copyright`, `function mlx4_buddy_free`, `function mlx4_buddy_init`, `function mlx4_buddy_cleanup`, `function __mlx4_alloc_mtt_range`, `function mlx4_alloc_mtt_range`, `function mlx4_mtt_init`, `function __mlx4_free_mtt_range`, `function mlx4_free_mtt_range`, `function mlx4_mtt_cleanup`.
- 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.
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.