drivers/net/ethernet/mellanox/mlxsw/spectrum1_kvdl.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/spectrum1_kvdl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/spectrum1_kvdl.c- Extension
.c- Size
- 12173 bytes
- Lines
- 427
- 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.
- 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/kernel.hlinux/bitops.hspectrum.h
Detected Declarations
struct mlxsw_sp1_kvdl_part_infostruct mlxsw_sp1_kvdl_partstruct mlxsw_sp1_kvdlenum mlxsw_sp1_kvdl_part_idfunction mlxsw_sp1_kvdl_alloc_size_partfunction mlxsw_sp1_kvdl_index_partfunction mlxsw_sp1_kvdl_to_kvdl_indexfunction mlxsw_sp1_kvdl_to_entry_indexfunction mlxsw_sp1_kvdl_part_allocfunction mlxsw_sp1_kvdl_part_freefunction mlxsw_sp1_kvdl_allocfunction mlxsw_sp1_kvdl_freefunction mlxsw_sp1_kvdl_alloc_size_queryfunction mlxsw_sp1_kvdl_part_updatefunction mlxsw_sp1_kvdl_part_initfunction mlxsw_sp1_kvdl_part_finifunction mlxsw_sp1_kvdl_parts_initfunction mlxsw_sp1_kvdl_parts_finifunction mlxsw_sp1_kvdl_part_occfunction mlxsw_sp1_kvdl_occ_getfunction mlxsw_sp1_kvdl_single_occ_getfunction mlxsw_sp1_kvdl_chunks_occ_getfunction mlxsw_sp1_kvdl_large_chunks_occ_getfunction mlxsw_sp1_kvdl_initfunction mlxsw_sp1_kvdl_finifunction mlxsw_sp1_kvdl_resources_register
Annotated Snippet
struct mlxsw_sp1_kvdl_part_info {
unsigned int part_index;
unsigned int start_index;
unsigned int end_index;
unsigned int alloc_size;
enum mlxsw_sp_resource_id resource_id;
};
enum mlxsw_sp1_kvdl_part_id {
MLXSW_SP1_KVDL_PART_ID_SINGLE,
MLXSW_SP1_KVDL_PART_ID_CHUNKS,
MLXSW_SP1_KVDL_PART_ID_LARGE_CHUNKS,
};
#define MLXSW_SP1_KVDL_PART_INFO(id) \
[MLXSW_SP1_KVDL_PART_ID_##id] = { \
.start_index = MLXSW_SP1_KVDL_##id##_BASE, \
.end_index = MLXSW_SP1_KVDL_##id##_END, \
.alloc_size = MLXSW_SP1_KVDL_##id##_ALLOC_SIZE, \
.resource_id = MLXSW_SP_RESOURCE_KVD_LINEAR_##id, \
}
static const struct mlxsw_sp1_kvdl_part_info mlxsw_sp1_kvdl_parts_info[] = {
MLXSW_SP1_KVDL_PART_INFO(SINGLE),
MLXSW_SP1_KVDL_PART_INFO(CHUNKS),
MLXSW_SP1_KVDL_PART_INFO(LARGE_CHUNKS),
};
#define MLXSW_SP1_KVDL_PARTS_INFO_LEN ARRAY_SIZE(mlxsw_sp1_kvdl_parts_info)
struct mlxsw_sp1_kvdl_part {
struct mlxsw_sp1_kvdl_part_info info;
unsigned long usage[]; /* Entries */
};
struct mlxsw_sp1_kvdl {
struct mlxsw_sp1_kvdl_part *parts[MLXSW_SP1_KVDL_PARTS_INFO_LEN];
};
static struct mlxsw_sp1_kvdl_part *
mlxsw_sp1_kvdl_alloc_size_part(struct mlxsw_sp1_kvdl *kvdl,
unsigned int alloc_size)
{
struct mlxsw_sp1_kvdl_part *part, *min_part = NULL;
int i;
for (i = 0; i < MLXSW_SP1_KVDL_PARTS_INFO_LEN; i++) {
part = kvdl->parts[i];
if (alloc_size <= part->info.alloc_size &&
(!min_part ||
part->info.alloc_size <= min_part->info.alloc_size))
min_part = part;
}
return min_part ?: ERR_PTR(-ENOBUFS);
}
static struct mlxsw_sp1_kvdl_part *
mlxsw_sp1_kvdl_index_part(struct mlxsw_sp1_kvdl *kvdl, u32 kvdl_index)
{
struct mlxsw_sp1_kvdl_part *part;
int i;
for (i = 0; i < MLXSW_SP1_KVDL_PARTS_INFO_LEN; i++) {
part = kvdl->parts[i];
if (kvdl_index >= part->info.start_index &&
kvdl_index <= part->info.end_index)
return part;
}
return ERR_PTR(-EINVAL);
}
static u32
mlxsw_sp1_kvdl_to_kvdl_index(const struct mlxsw_sp1_kvdl_part_info *info,
unsigned int entry_index)
{
return info->start_index + entry_index * info->alloc_size;
}
static unsigned int
mlxsw_sp1_kvdl_to_entry_index(const struct mlxsw_sp1_kvdl_part_info *info,
u32 kvdl_index)
{
return (kvdl_index - info->start_index) / info->alloc_size;
}
static int mlxsw_sp1_kvdl_part_alloc(struct mlxsw_sp1_kvdl_part *part,
u32 *p_kvdl_index)
{
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/bitops.h`, `spectrum.h`.
- Detected declarations: `struct mlxsw_sp1_kvdl_part_info`, `struct mlxsw_sp1_kvdl_part`, `struct mlxsw_sp1_kvdl`, `enum mlxsw_sp1_kvdl_part_id`, `function mlxsw_sp1_kvdl_alloc_size_part`, `function mlxsw_sp1_kvdl_index_part`, `function mlxsw_sp1_kvdl_to_kvdl_index`, `function mlxsw_sp1_kvdl_to_entry_index`, `function mlxsw_sp1_kvdl_part_alloc`, `function mlxsw_sp1_kvdl_part_free`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
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.