drivers/infiniband/hw/hns/hns_roce_hem.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hns/hns_roce_hem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hns/hns_roce_hem.c- Extension
.c- Size
- 37438 bytes
- Lines
- 1460
- 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.
- 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
hns_roce_device.hhns_roce_hem.hhns_roce_common.h
Detected Declarations
struct hns_roce_hem_indexstruct hns_roce_hem_itemstruct hns_roce_hem_headfunction hns_roce_check_whether_mhopfunction hns_roce_check_hem_nullfunction hns_roce_check_bt_nullfunction hns_roce_get_bt_numfunction get_hem_table_configfunction hns_roce_calc_hem_mhopfunction hns_roce_free_hemfunction calc_hem_configfunction free_mhop_hemfunction alloc_mhop_hemfunction check_whether_bt_num_2function set_mhop_hemfunction hns_roce_table_mhop_getfunction hns_roce_table_getfunction clear_mhop_hemfunction hns_roce_table_mhop_putfunction hns_roce_table_putfunction hns_roce_init_hem_tablefunction hns_roce_cleanup_mhop_hem_tablefunction hns_roce_cleanup_hem_tablefunction hns_roce_cleanup_hemfunction hem_list_alloc_itemfunction hem_list_free_itemfunction hem_list_free_allfunction list_for_each_entry_safefunction hem_list_link_btfunction hem_list_assign_btfunction hem_list_page_is_in_rangefunction list_for_each_entry_safefunction hem_list_is_bottom_btfunction hem_list_calc_ba_rangefunction hns_roce_hem_list_calc_root_bafunction hem_list_alloc_mid_btfunction alloc_root_hemfunction alloc_fake_root_btfunction setup_middle_btfunction setup_root_hemfunction hem_list_alloc_root_btfunction cal_best_bt_pg_szfunction hns_roce_hem_list_releasefunction hns_roce_hem_list_initfunction list_for_each_entry_safe
Annotated Snippet
struct hns_roce_hem_index {
u64 buf;
u64 l0;
u64 l1;
u32 inited; /* indicate which index is available */
};
bool hns_roce_check_whether_mhop(struct hns_roce_dev *hr_dev, u32 type)
{
int hop_num = 0;
switch (type) {
case HEM_TYPE_QPC:
hop_num = hr_dev->caps.qpc_hop_num;
break;
case HEM_TYPE_MTPT:
hop_num = hr_dev->caps.mpt_hop_num;
break;
case HEM_TYPE_CQC:
hop_num = hr_dev->caps.cqc_hop_num;
break;
case HEM_TYPE_SRQC:
hop_num = hr_dev->caps.srqc_hop_num;
break;
case HEM_TYPE_SCCC:
hop_num = hr_dev->caps.sccc_hop_num;
break;
case HEM_TYPE_QPC_TIMER:
hop_num = hr_dev->caps.qpc_timer_hop_num;
break;
case HEM_TYPE_CQC_TIMER:
hop_num = hr_dev->caps.cqc_timer_hop_num;
break;
case HEM_TYPE_GMV:
hop_num = hr_dev->caps.gmv_hop_num;
break;
default:
return false;
}
return hop_num;
}
static bool hns_roce_check_hem_null(struct hns_roce_hem **hem, u64 hem_idx,
u32 bt_chunk_num, u64 hem_max_num)
{
u64 start_idx = round_down(hem_idx, bt_chunk_num);
u64 check_max_num = start_idx + bt_chunk_num;
u64 i;
for (i = start_idx; (i < check_max_num) && (i < hem_max_num); i++)
if (i != hem_idx && hem[i])
return false;
return true;
}
static bool hns_roce_check_bt_null(u64 **bt, u64 ba_idx, u32 bt_chunk_num)
{
u64 start_idx = round_down(ba_idx, bt_chunk_num);
int i;
for (i = 0; i < bt_chunk_num; i++)
if (i != ba_idx && bt[start_idx + i])
return false;
return true;
}
static int hns_roce_get_bt_num(u32 table_type, u32 hop_num)
{
if (check_whether_bt_num_3(table_type, hop_num))
return 3;
else if (check_whether_bt_num_2(table_type, hop_num))
return 2;
else if (check_whether_bt_num_1(table_type, hop_num))
return 1;
else
return 0;
}
static int get_hem_table_config(struct hns_roce_dev *hr_dev,
struct hns_roce_hem_mhop *mhop,
u32 type)
{
struct device *dev = hr_dev->dev;
switch (type) {
case HEM_TYPE_QPC:
mhop->buf_chunk_size = 1 << (hr_dev->caps.qpc_buf_pg_sz
Annotation
- Immediate include surface: `hns_roce_device.h`, `hns_roce_hem.h`, `hns_roce_common.h`.
- Detected declarations: `struct hns_roce_hem_index`, `struct hns_roce_hem_item`, `struct hns_roce_hem_head`, `function hns_roce_check_whether_mhop`, `function hns_roce_check_hem_null`, `function hns_roce_check_bt_null`, `function hns_roce_get_bt_num`, `function get_hem_table_config`, `function hns_roce_calc_hem_mhop`, `function hns_roce_free_hem`.
- 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.
- 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.