drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c- Extension
.c- Size
- 66152 bytes
- Lines
- 2775
- 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/netdevice.hnet/bonding.hlinux/mlx5/driver.hlinux/mlx5/eswitch.hlinux/mlx5/vport.hlinux/mlx5/lag.hlib/mlx5.hlib/devcom.hmlx5_core.heswitch.hesw/acl/ofld.hlag.hmp.hmpesw.h
Detected Declarations
function get_port_sel_modefunction lag_active_port_bitsfunction mlx5_cmd_create_lagfunction mlx5_cmd_modify_lagfunction mlx5_lag_dev_group_idfunction mlx5_lag_for_eachfunction mlx5_lag_is_sw_lagfunction mlx5_cmd_create_vport_lagfunction mlx5_cmd_destroy_vport_lagfunction mlx5_infer_tx_disabledfunction mlx5_infer_tx_enabledfunction mlx5_lag_print_mappingfunction mlx5_ldev_for_eachfunction mlx5_ldev_freefunction mlx5_lag_for_eachfunction mlx5_ldev_putfunction mlx5_ldev_getfunction mlx5_lag_dev_get_netdev_idxfunction mlx5_ldev_for_eachfunction mlx5_lag_get_master_idxfunction mlx5_lag_get_dev_index_by_seqfunction mlx5_ldev_for_eachfunction mlx5_lag_get_filterfunction mlx5_lag_get_dev_seqfunction mlx5_lag_for_eachfunction mlx5_lag_get_dev_index_by_seq_allfunction mlx5_lag_for_eachfunction mlx5_lag_get_dev_index_by_seq_groupfunction mlx5_lag_for_eachfunction mlx5_lag_for_eachfunction mlx5_lag_get_dev_index_by_seq_filterfunction mlx5_lag_mark_masterfunction mlx5_ldev_for_eachfunction mlx5_lag_clear_masterfunction mlx5_lag_devcom_eventfunction mlx5_lag_num_devsfunction mlx5_ldev_for_eachfunction mlx5_lag_num_netdevsfunction mlx5_ldev_for_eachfunction __mlx5_lag_is_rocefunction __mlx5_lag_is_sriovfunction __mlx5_lag_is_sd_activefunction mlx5_infer_tx_affinity_mappingfunction mlx5_ldev_for_eachfunction mlx5_lag_has_drop_rulefunction mlx5_ldev_for_eachfunction mlx5_lag_drop_rule_cleanupfunction mlx5_ldev_for_each
Annotated Snippet
mlx5_ldev_for_each(i, 0, ldev) {
for (j = 0; j < ldev->buckets; j++) {
idx = i * ldev->buckets + j;
err = scnprintf(buf + written, 10,
" port %d:%d", i + 1, ldev->v2p_map[idx]);
if (err != 9)
return;
written += err;
}
}
mlx5_core_info(dev, "lag map:%s\n", buf);
}
}
static int mlx5_lag_netdev_event(struct notifier_block *this,
unsigned long event, void *ptr);
static void mlx5_do_bond_work(struct work_struct *work);
static void mlx5_ldev_free(struct kref *ref)
{
struct mlx5_lag *ldev = container_of(ref, struct mlx5_lag, ref);
struct lag_func *pf;
struct net *net;
int i;
if (ldev->nb.notifier_call) {
net = read_pnet(&ldev->net);
unregister_netdevice_notifier_net(net, &ldev->nb);
}
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
pf = mlx5_lag_pf(ldev, i);
if (pf->port_change_nb.nb.notifier_call) {
struct mlx5_nb *nb = &pf->port_change_nb;
mlx5_eq_notifier_unregister(pf->dev, nb);
}
xa_erase(&ldev->pfs, i);
kfree(pf);
}
xa_destroy(&ldev->pfs);
mlx5_lag_mp_cleanup(ldev);
cancel_delayed_work_sync(&ldev->bond_work);
cancel_work_sync(&ldev->speed_update_work);
destroy_workqueue(ldev->wq);
mutex_destroy(&ldev->lock);
kfree(ldev);
}
static void mlx5_ldev_put(struct mlx5_lag *ldev)
{
kref_put(&ldev->ref, mlx5_ldev_free);
}
static void mlx5_ldev_get(struct mlx5_lag *ldev)
{
kref_get(&ldev->ref);
}
static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
{
struct mlx5_lag *ldev;
int err;
ldev = kzalloc_obj(*ldev);
if (!ldev)
return NULL;
ldev->wq = create_singlethread_workqueue("mlx5_lag");
if (!ldev->wq) {
kfree(ldev);
return NULL;
}
kref_init(&ldev->ref);
mutex_init(&ldev->lock);
xa_init_flags(&ldev->pfs, XA_FLAGS_ALLOC);
INIT_DELAYED_WORK(&ldev->bond_work, mlx5_do_bond_work);
INIT_WORK(&ldev->speed_update_work, mlx5_mpesw_speed_update_work);
if (!mlx5_sd_is_supported(dev)) {
ldev->nb.notifier_call = mlx5_lag_netdev_event;
write_pnet(&ldev->net, mlx5_core_net(dev));
if (register_netdevice_notifier_net(read_pnet(&ldev->net),
&ldev->nb)) {
ldev->nb.notifier_call = NULL;
mlx5_core_err(dev, "Failed to register LAG netdev notifier\n");
}
}
Annotation
- Immediate include surface: `linux/netdevice.h`, `net/bonding.h`, `linux/mlx5/driver.h`, `linux/mlx5/eswitch.h`, `linux/mlx5/vport.h`, `linux/mlx5/lag.h`, `lib/mlx5.h`, `lib/devcom.h`.
- Detected declarations: `function get_port_sel_mode`, `function lag_active_port_bits`, `function mlx5_cmd_create_lag`, `function mlx5_cmd_modify_lag`, `function mlx5_lag_dev_group_id`, `function mlx5_lag_for_each`, `function mlx5_lag_is_sw_lag`, `function mlx5_cmd_create_vport_lag`, `function mlx5_cmd_destroy_vport_lag`, `function mlx5_infer_tx_disabled`.
- 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.