drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c- Extension
.c- Size
- 82197 bytes
- Lines
- 3119
- 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/debugfs.hlinux/mlx5/driver.hlinux/mlx5/mlx5_ifc.hlinux/mlx5/vport.hlinux/mlx5/fs.hlinux/mlx5/mpfs.hesw/acl/lgcy.hesw/legacy.hesw/qos.hmlx5_core.hlib/eq.hlag/lag.heswitch.hfs_core.hdevlink.hecpf.hen/mod_hdr.hen_accel/ipsec.h
Detected Declarations
struct vport_addrfunction mlx5_eswitch_checkfunction mlx5_devlink_eswitch_getfunction mlx5_eswitch_get_vportfunction arm_vport_context_events_cmdfunction mlx5_eswitch_modify_esw_vport_contextfunction modify_esw_vport_cvlanfunction __esw_fdb_set_vport_rulefunction esw_fdb_set_vport_rulefunction esw_fdb_set_vport_allmulti_rulefunction esw_fdb_set_vport_promisc_rulefunction esw_add_uc_addrfunction esw_del_uc_addrfunction update_allmulti_vportsfunction mlx5_esw_for_each_vportfunction esw_add_mc_addrfunction esw_del_mc_addrfunction esw_apply_vport_addr_listfunction esw_update_vport_addr_listfunction for_each_l2hash_nodefunction esw_update_vport_mc_promiscfunction for_each_l2hash_nodefunction esw_apply_vport_rx_modefunction esw_update_vport_rx_modefunction esw_vport_change_handle_lockedfunction esw_vport_change_handlerfunction node_guid_gen_from_macfunction esw_vport_setup_aclfunction esw_vport_cleanup_aclfunction mlx5_esw_vport_caps_getfunction mlx5_esw_vport_vhca_idfunction esw_vport_to_func_typefunction mlx5_esw_vhca_id_to_func_typefunction esw_vport_setupfunction esw_vport_cleanupfunction mlx5_esw_vport_set_max_tx_speedfunction mlx5_esw_vport_enablefunction mlx5_esw_vport_disablefunction eswitch_vport_eventfunction mlx5_esw_query_functionsfunction mlx5_esw_host_pf_from_host_paramsfunction mlx5_esw_host_pf_from_net_func_paramsfunction mlx5_esw_get_host_pf_infofunction mlx5_esw_get_spf_disabledfunction mlx5_esw_host_functions_enabled_queryfunction mlx5_eswitch_event_handler_registerfunction mlx5_eswitch_invalidate_wqfunction mlx5_eswitch_event_handler_unregister
Annotated Snippet
struct vport_addr {
struct l2addr_node node;
u8 action;
u16 vport;
struct mlx5_flow_handle *flow_rule;
bool mpfs; /* UC MAC was added to MPFs */
/* A flag indicating that mac was added due to mc promiscuous vport */
bool mc_promisc;
};
static int mlx5_eswitch_check(const struct mlx5_core_dev *dev)
{
if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
return -EOPNOTSUPP;
if (!MLX5_ESWITCH_MANAGER(dev))
return -EOPNOTSUPP;
return 0;
}
static struct mlx5_eswitch *__mlx5_devlink_eswitch_get(struct devlink *devlink, bool check)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
int err;
if (check) {
err = mlx5_eswitch_check(dev);
if (err)
return ERR_PTR(err);
}
return dev->priv.eswitch;
}
struct mlx5_eswitch *__must_check
mlx5_devlink_eswitch_get(struct devlink *devlink)
{
return __mlx5_devlink_eswitch_get(devlink, true);
}
struct mlx5_eswitch *mlx5_devlink_eswitch_nocheck_get(struct devlink *devlink)
{
return __mlx5_devlink_eswitch_get(devlink, false);
}
struct mlx5_vport *__must_check
mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num)
{
struct mlx5_vport *vport;
if (!esw)
return ERR_PTR(-EPERM);
vport = xa_load(&esw->vports, vport_num);
if (!vport) {
esw_debug(esw->dev, "vport out of range: num(0x%x)\n", vport_num);
return ERR_PTR(-EINVAL);
}
return vport;
}
static int arm_vport_context_events_cmd(struct mlx5_core_dev *dev, u16 vport,
u32 events_mask)
{
u32 in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)] = {};
void *nic_vport_ctx;
MLX5_SET(modify_nic_vport_context_in, in,
opcode, MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
MLX5_SET(modify_nic_vport_context_in, in, field_select.change_event, 1);
MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
if (vport || mlx5_core_is_ecpf(dev))
MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
in, nic_vport_context);
MLX5_SET(nic_vport_context, nic_vport_ctx, arm_change_event, 1);
if (events_mask & MLX5_VPORT_UC_ADDR_CHANGE)
MLX5_SET(nic_vport_context, nic_vport_ctx,
event_on_uc_address_change, 1);
if (events_mask & MLX5_VPORT_MC_ADDR_CHANGE)
MLX5_SET(nic_vport_context, nic_vport_ctx,
event_on_mc_address_change, 1);
if (events_mask & MLX5_VPORT_PROMISC_CHANGE)
MLX5_SET(nic_vport_context, nic_vport_ctx,
event_on_promisc_change, 1);
return mlx5_cmd_exec_in(dev, modify_nic_vport_context, in);
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/debugfs.h`, `linux/mlx5/driver.h`, `linux/mlx5/mlx5_ifc.h`, `linux/mlx5/vport.h`, `linux/mlx5/fs.h`, `linux/mlx5/mpfs.h`, `esw/acl/lgcy.h`.
- Detected declarations: `struct vport_addr`, `function mlx5_eswitch_check`, `function mlx5_devlink_eswitch_get`, `function mlx5_eswitch_get_vport`, `function arm_vport_context_events_cmd`, `function mlx5_eswitch_modify_esw_vport_context`, `function modify_esw_vport_cvlan`, `function __esw_fdb_set_vport_rule`, `function esw_fdb_set_vport_rule`, `function esw_fdb_set_vport_allmulti_rule`.
- 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.