drivers/infiniband/hw/mthca/mthca_mr.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mthca/mthca_mr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/mthca/mthca_mr.c- Extension
.c- Size
- 17301 bytes
- Lines
- 702
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- 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.
- 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.
- 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/slab.hlinux/errno.hmthca_dev.hmthca_cmd.hmthca_memfree.h
Detected Declarations
struct mthca_mttstruct mthca_mpt_entryfunction segmentsfunction mthca_buddy_freefunction mthca_buddy_initfunction mthca_buddy_cleanupfunction mthca_alloc_mtt_rangefunction mthca_free_mttfunction __mthca_write_mttfunction mthca_write_mtt_sizefunction mthca_tavor_write_mtt_segfunction mthca_arbel_write_mtt_segfunction mthca_write_mttfunction tavor_hw_index_to_keyfunction tavor_key_to_hw_indexfunction arbel_hw_index_to_keyfunction arbel_key_to_hw_indexfunction hw_index_to_keyfunction key_to_hw_indexfunction adjust_keyfunction mthca_mr_allocfunction mthca_mr_alloc_notransfunction mthca_mr_alloc_physfunction mthca_free_regionfunction mthca_free_mrfunction mthca_init_mr_tablefunction mthca_cleanup_mr_table
Annotated Snippet
struct mthca_mtt {
struct mthca_buddy *buddy;
int order;
u32 first_seg;
};
/*
* Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
*/
struct mthca_mpt_entry {
__be32 flags;
__be32 page_size;
__be32 key;
__be32 pd;
__be64 start;
__be64 length;
__be32 lkey;
__be32 window_count;
__be32 window_count_limit;
__be64 mtt_seg;
__be32 mtt_sz; /* Arbel only */
u32 reserved[2];
} __packed;
#define MTHCA_MPT_FLAG_SW_OWNS (0xfUL << 28)
#define MTHCA_MPT_FLAG_MIO (1 << 17)
#define MTHCA_MPT_FLAG_BIND_ENABLE (1 << 15)
#define MTHCA_MPT_FLAG_PHYSICAL (1 << 9)
#define MTHCA_MPT_FLAG_REGION (1 << 8)
#define MTHCA_MTT_FLAG_PRESENT 1
#define MTHCA_MPT_STATUS_SW 0xF0
#define MTHCA_MPT_STATUS_HW 0x00
#define SINAI_FMR_KEY_INC 0x1000000
/*
* Buddy allocator for MTT segments (currently not very efficient
* since it doesn't keep a free list and just searches linearly
* through the bitmaps)
*/
static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
{
int o;
int m;
u32 seg;
spin_lock(&buddy->lock);
for (o = order; o <= buddy->max_order; ++o)
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 mthca_buddy_free(struct mthca_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;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/errno.h`, `mthca_dev.h`, `mthca_cmd.h`, `mthca_memfree.h`.
- Detected declarations: `struct mthca_mtt`, `struct mthca_mpt_entry`, `function segments`, `function mthca_buddy_free`, `function mthca_buddy_init`, `function mthca_buddy_cleanup`, `function mthca_alloc_mtt_range`, `function mthca_free_mtt`, `function __mthca_write_mtt`, `function mthca_write_mtt_size`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source 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.