drivers/net/ethernet/mellanox/mlx5/core/alloc.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/alloc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/alloc.c- Extension
.c- Size
- 14522 bytes
- Lines
- 565
- 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.hlinux/nodemask.hlinux/debugfs.hlinux/seq_file.hlinux/mlx5/driver.hmlx5_core.h
Detected Declarations
struct mlx5_db_pgdirstruct mlx5_dma_poolstruct mlx5_dma_pool_pagestruct mlx5_frag_buf_node_poolsstruct mlx5_dma_pool_statsfunction mlx5_dma_pool_destroyfunction mlx5_dma_pool_page_allocfunction mlx5_dma_pool_page_freefunction mlx5_dma_pool_alloc_from_pagefunction mlx5_dma_pool_allocfunction mlx5_dma_pool_freefunction mlx5_dma_pool_debugfs_get_statsfunction mlx5_dma_pool_debugfs_stats_printfunction mlx5_dma_pools_debugfs_print_headerfunction mlx5_frag_buf_node_pools_destroyfunction mlx5_frag_buf_node_pools_createfunction mlx5_frag_buf_dma_pools_debugfs_showfunction for_each_node_statefunction mlx5_frag_buf_pools_cleanupfunction for_each_node_statefunction mlx5_frag_buf_pools_initfunction for_each_node_statefunction mlx5_frag_buf_alloc_nodefunction mlx5_frag_buf_freefunction mlx5_alloc_db_from_pgdirfunction mlx5_db_alloc_nodefunction mlx5_db_freefunction mlx5_fill_page_frag_array_permfunction mlx5_fill_page_frag_arrayexport mlx5_frag_buf_alloc_nodeexport mlx5_frag_buf_freeexport mlx5_db_alloc_nodeexport mlx5_db_freeexport mlx5_fill_page_frag_array_permexport mlx5_fill_page_frag_array
Annotated Snippet
struct mlx5_db_pgdir {
struct list_head list;
unsigned long *bitmap;
__be32 *db_page;
dma_addr_t db_dma;
};
struct mlx5_dma_pool {
/* Protects page_list and per-page allocation bitmaps. */
struct mutex lock;
struct list_head page_list;
struct mlx5_core_dev *dev;
int node;
u8 block_shift;
};
struct mlx5_dma_pool_page {
struct mlx5_dma_pool *pool;
struct list_head pool_link;
unsigned long *bitmap;
void *buf;
dma_addr_t dma;
};
struct mlx5_frag_buf_node_pools {
struct mlx5_dma_pool *pools[MLX5_FRAG_BUF_POOLS_NUM];
};
struct mlx5_dma_pool_stats {
int node;
size_t block_size;
size_t used_blocks;
size_t allocated_blocks;
};
/* Handling for queue buffers -- we allocate a bunch of memory and
* register it in a memory region at HCA virtual address 0.
*/
static void *mlx5_dma_zalloc_coherent_node(struct mlx5_core_dev *dev,
size_t size, dma_addr_t *dma_handle,
int node)
{
struct device *device = mlx5_core_dma_dev(dev);
struct mlx5_priv *priv = &dev->priv;
int original_node;
void *cpu_handle;
mutex_lock(&priv->alloc_mutex);
original_node = dev_to_node(device);
set_dev_node(device, node);
cpu_handle = dma_alloc_coherent(device, size, dma_handle,
GFP_KERNEL);
set_dev_node(device, original_node);
mutex_unlock(&priv->alloc_mutex);
return cpu_handle;
}
static void mlx5_dma_pool_destroy(struct mlx5_dma_pool *pool)
{
mutex_destroy(&pool->lock);
kfree(pool);
}
static struct mlx5_dma_pool *mlx5_dma_pool_create(struct mlx5_core_dev *dev,
int node, u8 block_shift)
{
struct mlx5_dma_pool *pool;
pool = kzalloc_obj(*pool);
if (!pool)
return NULL;
INIT_LIST_HEAD(&pool->page_list);
mutex_init(&pool->lock);
pool->dev = dev;
pool->node = node;
pool->block_shift = block_shift;
return pool;
}
static struct mlx5_dma_pool_page *
mlx5_dma_pool_page_alloc(struct mlx5_dma_pool *pool)
{
int blocks_per_page = BIT(PAGE_SHIFT - pool->block_shift);
struct mlx5_dma_pool_page *page;
page = kzalloc_obj(*page);
if (!page)
goto err_out;
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`, `linux/nodemask.h`.
- Detected declarations: `struct mlx5_db_pgdir`, `struct mlx5_dma_pool`, `struct mlx5_dma_pool_page`, `struct mlx5_frag_buf_node_pools`, `struct mlx5_dma_pool_stats`, `function mlx5_dma_pool_destroy`, `function mlx5_dma_pool_page_alloc`, `function mlx5_dma_pool_page_free`, `function mlx5_dma_pool_alloc_from_page`, `function mlx5_dma_pool_alloc`.
- 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.