drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c- Extension
.c- Size
- 25185 bytes
- Lines
- 958
- 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.
- 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.
- 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/highmem.hlinux/kernel.hlinux/delay.hlinux/mlx5/driver.hlinux/xarray.hmlx5_core.hlib/eq.hlib/tout.heswitch.h
Detected Declarations
struct mlx5_pages_reqstruct fw_pagefunction mlx5_page_mgt_mode_is_vhca_idfunction mlx5_page_mgt_mode_setfunction get_function_keyfunction func_id_to_typefunction func_vhca_id_to_typefunction mlx5_get_ec_functionfunction mlx5_get_func_vhca_idfunction insert_pagefunction mlx5_cmd_query_pagesfunction alloc_4kfunction list_for_each_entryfunction free_fwpfunction free_4kfunction alloc_system_pagefunction page_notify_failfunction give_pagesfunction release_all_pagesfunction fwp_fill_manage_pages_outfunction for_each_clear_bitfunction reclaim_pages_cmdfunction reclaim_pagesfunction pages_work_handlerfunction req_pages_handlerfunction set_hca_capfunction mlx5_satisfy_startup_pagesfunction set_hca_capfunction optimal_reclaimed_pagesfunction mlx5_reclaim_root_pagesfunction mlx5_reclaim_startup_pagesfunction xa_for_eachfunction mlx5_pagealloc_initfunction mlx5_pagealloc_cleanupfunction mlx5_pagealloc_startfunction mlx5_pagealloc_stopfunction mlx5_wait_for_pages
Annotated Snippet
struct mlx5_pages_req {
struct mlx5_core_dev *dev;
u16 func_id;
u8 ec_function;
s32 npages;
struct work_struct work;
u8 release_all;
};
struct fw_page {
struct rb_node rb_node;
u64 addr;
struct page *page;
u32 function;
u16 func_type;
unsigned long bitmask;
struct list_head list;
unsigned int free_count;
};
enum {
MLX5_MAX_RECLAIM_TIME_MILI = 5000,
MLX5_NUM_4K_IN_PAGE = PAGE_SIZE / MLX5_ADAPTER_PAGE_SIZE,
};
static bool mlx5_page_mgt_mode_is_vhca_id(const struct mlx5_core_dev *dev)
{
return dev->priv.page_mgt_mode == MLX5_PAGE_MGT_MODE_VHCA_ID;
}
static void mlx5_page_mgt_mode_set(struct mlx5_core_dev *dev,
enum mlx5_page_mgt_mode mode)
{
dev->priv.page_mgt_mode = mode;
}
static u32 get_function_key(struct mlx5_core_dev *dev, u16 func_vhca_id,
bool ec_function)
{
if (mlx5_page_mgt_mode_is_vhca_id(dev))
return (u32)func_vhca_id;
return (u32)func_vhca_id | (ec_function << 16);
}
static u16 func_id_to_type(struct mlx5_core_dev *dev, u16 func_id, bool ec_function)
{
if (!func_id)
return mlx5_core_is_ecpf(dev) && !ec_function ?
MLX5_HOST_PF : MLX5_SELF;
if (func_id <= max(mlx5_core_max_vfs(dev), mlx5_core_max_ec_vfs(dev))) {
if (ec_function)
return MLX5_EC_VF;
else
return MLX5_VF;
}
return MLX5_SF;
}
static u16 func_vhca_id_to_type(struct mlx5_core_dev *dev, u16 func_vhca_id,
bool ec_function)
{
if (mlx5_page_mgt_mode_is_vhca_id(dev))
return mlx5_esw_vhca_id_to_func_type(dev, func_vhca_id);
return func_id_to_type(dev, func_vhca_id, ec_function);
}
static u32 mlx5_get_ec_function(u32 function)
{
return function >> 16;
}
static u32 mlx5_get_func_vhca_id(u32 function)
{
return function & 0xffff;
}
static struct rb_root *page_root_per_function(struct mlx5_core_dev *dev, u32 function)
{
struct rb_root *root;
int err;
root = xa_load(&dev->priv.page_root_xa, function);
if (root)
return root;
root = kzalloc_obj(*root);
if (!root)
Annotation
- Immediate include surface: `linux/highmem.h`, `linux/kernel.h`, `linux/delay.h`, `linux/mlx5/driver.h`, `linux/xarray.h`, `mlx5_core.h`, `lib/eq.h`, `lib/tout.h`.
- Detected declarations: `struct mlx5_pages_req`, `struct fw_page`, `function mlx5_page_mgt_mode_is_vhca_id`, `function mlx5_page_mgt_mode_set`, `function get_function_key`, `function func_id_to_type`, `function func_vhca_id_to_type`, `function mlx5_get_ec_function`, `function mlx5_get_func_vhca_id`, `function insert_page`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- 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.