drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/spectrum_kvdl.c- Extension
.c- Size
- 2170 bytes
- Lines
- 88
- 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.
- 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/kernel.hlinux/mutex.hlinux/slab.hspectrum.h
Detected Declarations
struct mlxsw_sp_kvdlfunction mlxsw_sp_kvdl_initfunction mlxsw_sp_kvdl_finifunction mlxsw_sp_kvdl_allocfunction mlxsw_sp_kvdl_freefunction mlxsw_sp_kvdl_alloc_count_query
Annotated Snippet
struct mlxsw_sp_kvdl {
const struct mlxsw_sp_kvdl_ops *kvdl_ops;
struct mutex kvdl_lock; /* Protects kvdl allocations */
unsigned long priv[];
/* priv has to be always the last item */
};
int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp)
{
const struct mlxsw_sp_kvdl_ops *kvdl_ops = mlxsw_sp->kvdl_ops;
struct mlxsw_sp_kvdl *kvdl;
int err;
kvdl = kzalloc(sizeof(*mlxsw_sp->kvdl) + kvdl_ops->priv_size,
GFP_KERNEL);
if (!kvdl)
return -ENOMEM;
mutex_init(&kvdl->kvdl_lock);
kvdl->kvdl_ops = kvdl_ops;
mlxsw_sp->kvdl = kvdl;
err = kvdl_ops->init(mlxsw_sp, kvdl->priv);
if (err)
goto err_init;
return 0;
err_init:
mutex_destroy(&kvdl->kvdl_lock);
kfree(kvdl);
return err;
}
void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp)
{
struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
kvdl->kvdl_ops->fini(mlxsw_sp, kvdl->priv);
mutex_destroy(&kvdl->kvdl_lock);
kfree(kvdl);
}
int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
enum mlxsw_sp_kvdl_entry_type type,
unsigned int entry_count, u32 *p_entry_index)
{
struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
int err;
mutex_lock(&kvdl->kvdl_lock);
err = kvdl->kvdl_ops->alloc(mlxsw_sp, kvdl->priv, type,
entry_count, p_entry_index);
mutex_unlock(&kvdl->kvdl_lock);
return err;
}
void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
enum mlxsw_sp_kvdl_entry_type type,
unsigned int entry_count, int entry_index)
{
struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
mutex_lock(&kvdl->kvdl_lock);
kvdl->kvdl_ops->free(mlxsw_sp, kvdl->priv, type,
entry_count, entry_index);
mutex_unlock(&kvdl->kvdl_lock);
}
int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
enum mlxsw_sp_kvdl_entry_type type,
unsigned int entry_count,
unsigned int *p_alloc_count)
{
struct mlxsw_sp_kvdl *kvdl = mlxsw_sp->kvdl;
return kvdl->kvdl_ops->alloc_size_query(mlxsw_sp, kvdl->priv, type,
entry_count, p_alloc_count);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mutex.h`, `linux/slab.h`, `spectrum.h`.
- Detected declarations: `struct mlxsw_sp_kvdl`, `function mlxsw_sp_kvdl_init`, `function mlxsw_sp_kvdl_fini`, `function mlxsw_sp_kvdl_alloc`, `function mlxsw_sp_kvdl_free`, `function mlxsw_sp_kvdl_alloc_count_query`.
- Atlas domain: Driver Families / drivers/net.
- 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.