drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c- Extension
.c- Size
- 7354 bytes
- Lines
- 294
- 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.
- 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/etherdevice.hlinux/mlx5/driver.hlinux/mlx5/mlx5_ifc.hlinux/mlx5/mpfs.hlinux/mlx5/eswitch.hmlx5_core.hlib/mpfs.h
Detected Declarations
struct l2table_nodestruct mlx5_mpfsfunction Copyrightfunction del_l2table_entry_cmdfunction alloc_l2table_indexfunction free_l2table_indexfunction mlx5_mpfs_initfunction mlx5_mpfs_cleanupfunction mlx5_mpfs_add_macfunction mlx5_mpfs_del_macfunction mlx5_mpfs_enablefunction mlx5_mpfs_foreachfunction mlx5_mpfs_disableexport mlx5_mpfs_add_macexport mlx5_mpfs_del_mac
Annotated Snippet
struct l2table_node {
struct l2addr_node node;
int index; /* index in HW l2 table */
int ref_count;
};
struct mlx5_mpfs {
struct hlist_head hash[MLX5_L2_ADDR_HASH_SIZE];
struct mutex lock; /* Synchronize l2 table access */
bool enabled;
u32 size;
unsigned long *bitmap;
};
static int alloc_l2table_index(struct mlx5_mpfs *l2table, u32 *ix)
{
int err = 0;
*ix = find_first_zero_bit(l2table->bitmap, l2table->size);
if (*ix >= l2table->size)
err = -ENOSPC;
else
__set_bit(*ix, l2table->bitmap);
return err;
}
static void free_l2table_index(struct mlx5_mpfs *l2table, u32 ix)
{
__clear_bit(ix, l2table->bitmap);
}
int mlx5_mpfs_init(struct mlx5_core_dev *dev)
{
int l2table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table);
struct mlx5_mpfs *mpfs;
if (!MLX5_ESWITCH_MANAGER(dev) || l2table_size == 1)
return 0;
mpfs = kzalloc_obj(*mpfs);
if (!mpfs)
return -ENOMEM;
mutex_init(&mpfs->lock);
mpfs->size = l2table_size;
mpfs->bitmap = bitmap_zalloc(l2table_size, GFP_KERNEL);
if (!mpfs->bitmap) {
kfree(mpfs);
return -ENOMEM;
}
mpfs->enabled = true;
dev->priv.mpfs = mpfs;
return 0;
}
void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev)
{
struct mlx5_mpfs *mpfs = dev->priv.mpfs;
if (!mpfs)
return;
WARN_ON(!hlist_empty(mpfs->hash));
bitmap_free(mpfs->bitmap);
kfree(mpfs);
}
int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
{
struct mlx5_mpfs *mpfs = dev->priv.mpfs;
struct l2table_node *l2addr;
int err = 0;
int index;
if (!mpfs)
return 0;
mutex_lock(&mpfs->lock);
l2addr = l2addr_hash_find(mpfs->hash, mac, struct l2table_node);
if (l2addr) {
l2addr->ref_count++;
goto out;
}
l2addr = l2addr_hash_add(mpfs->hash, mac, struct l2table_node, GFP_KERNEL);
if (!l2addr) {
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/mlx5/driver.h`, `linux/mlx5/mlx5_ifc.h`, `linux/mlx5/mpfs.h`, `linux/mlx5/eswitch.h`, `mlx5_core.h`, `lib/mpfs.h`.
- Detected declarations: `struct l2table_node`, `struct mlx5_mpfs`, `function Copyright`, `function del_l2table_entry_cmd`, `function alloc_l2table_index`, `function free_l2table_index`, `function mlx5_mpfs_init`, `function mlx5_mpfs_cleanup`, `function mlx5_mpfs_add_mac`, `function mlx5_mpfs_del_mac`.
- 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.
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.