drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c- Extension
.c- Size
- 155046 bytes
- Lines
- 5634
- 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/idr.hlinux/mlx5/driver.hlinux/mlx5/mlx5_ifc.hlinux/mlx5/vport.hlinux/mlx5/fs.hlinux/lockdep.hmlx5_core.heswitch.hesw/indir_table.hesw/acl/ofld.hrdma.hen.hfs_core.hlib/mlx5.hlib/devcom.hlib/sd.hlib/eq.hlib/fs_chains.hen_tc.hen/mapping.hdevlink.hlag/lag.hen/tc/post_meter.hfw_reset.h
Detected Declarations
function mlx5_eswitch_set_rule_flow_sourcefunction mlx5_eswitch_clear_rule_source_portfunction mlx5_eswitch_set_rule_source_portfunction esw_setup_decap_indirfunction esw_cleanup_decap_indirfunction esw_setup_mtu_destfunction esw_setup_sampler_destfunction esw_setup_ft_destfunction esw_setup_accept_destfunction esw_setup_slow_path_destfunction esw_setup_chain_destfunction esw_put_dest_tables_loopfunction esw_is_chain_src_port_rewritefunction esw_setup_chain_src_port_rewritefunction esw_cleanup_chain_src_port_rewritefunction esw_is_indir_tablefunction esw_setup_indir_tablefunction esw_cleanup_indir_tablefunction esw_cleanup_chain_destfunction esw_same_vhca_idfunction esw_setup_uplink_fwd_ipsec_neededfunction esw_flow_dests_fwd_ipsec_checkfunction esw_setup_dest_fwd_vportfunction esw_setup_dest_fwd_ipsecfunction esw_setup_vport_destfunction esw_setup_vport_destsfunction esw_src_port_rewrite_supportedfunction esw_dests_to_int_externalfunction esw_setup_destsfunction esw_cleanup_destsfunction esw_setup_meterfunction mlx5_eswitch_add_offloaded_rulefunction mlx5_eswitch_add_fwd_rulefunction __mlx5_eswitch_del_rulefunction mlx5_eswitch_del_offloaded_rulefunction mlx5_eswitch_del_fwd_rulefunction mlx5_eswitch_add_send_to_vport_rulefunction mlx5_eswitch_del_send_to_vport_rulefunction mlx5_eswitch_del_send_to_vport_meta_rulefunction mlx5_eswitch_add_send_to_vport_meta_rulefunction mlx5_eswitch_reg_c1_loopback_supportedfunction esw_set_passing_vport_metadatafunction peer_miss_rules_setupfunction esw_set_peer_miss_rule_source_portfunction esw_add_fdb_peer_miss_rulesfunction mlx5_esw_for_each_spf_vportfunction mlx5_esw_for_each_vf_vportfunction mlx5_core_max_ec_vfs
Annotated Snippet
if (IS_ERR(dest[*i].ft)) {
err = PTR_ERR(dest[*i].ft);
goto err_indir_tbl_get;
}
}
if (mlx5_esw_indir_table_decap_vport(attr)) {
err = esw_setup_decap_indir(esw, attr);
if (err)
goto err_indir_tbl_get;
}
return 0;
err_indir_tbl_get:
esw_put_dest_tables_loop(esw, attr, esw_attr->split_count, j);
return err;
}
static void esw_cleanup_indir_table(struct mlx5_eswitch *esw, struct mlx5_flow_attr *attr)
{
struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr;
esw_put_dest_tables_loop(esw, attr, esw_attr->split_count, esw_attr->out_count);
esw_cleanup_decap_indir(esw, attr);
}
static void
esw_cleanup_chain_dest(struct mlx5_fs_chains *chains, u32 chain, u32 prio, u32 level)
{
mlx5_chains_put_table(chains, chain, prio, level);
}
static bool esw_same_vhca_id(struct mlx5_core_dev *mdev1, struct mlx5_core_dev *mdev2)
{
return MLX5_CAP_GEN(mdev1, vhca_id) == MLX5_CAP_GEN(mdev2, vhca_id);
}
static bool esw_setup_uplink_fwd_ipsec_needed(struct mlx5_eswitch *esw,
struct mlx5_esw_flow_attr *esw_attr,
int attr_idx)
{
if (esw->offloads.ft_ipsec_tx_pol &&
esw_attr->dests[attr_idx].vport_valid &&
esw_attr->dests[attr_idx].vport == MLX5_VPORT_UPLINK &&
/* To be aligned with software, encryption is needed only for tunnel device */
(esw_attr->dests[attr_idx].flags & MLX5_ESW_DEST_ENCAP_VALID) &&
esw_attr->dests[attr_idx].vport != esw_attr->in_rep->vport &&
esw_same_vhca_id(esw_attr->dests[attr_idx].mdev, esw->dev))
return true;
return false;
}
static bool esw_flow_dests_fwd_ipsec_check(struct mlx5_eswitch *esw,
struct mlx5_esw_flow_attr *esw_attr)
{
int i;
if (!esw->offloads.ft_ipsec_tx_pol)
return true;
for (i = 0; i < esw_attr->split_count; i++)
if (esw_setup_uplink_fwd_ipsec_needed(esw, esw_attr, i))
return false;
for (i = esw_attr->split_count; i < esw_attr->out_count; i++)
if (esw_setup_uplink_fwd_ipsec_needed(esw, esw_attr, i) &&
(esw_attr->out_count - esw_attr->split_count > 1))
return false;
return true;
}
static void
esw_setup_dest_fwd_vport(struct mlx5_flow_destination *dest, struct mlx5_flow_act *flow_act,
struct mlx5_eswitch *esw, struct mlx5_esw_flow_attr *esw_attr,
int attr_idx, int dest_idx, bool pkt_reformat)
{
dest[dest_idx].type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
dest[dest_idx].vport.num = esw_attr->dests[attr_idx].vport;
if (MLX5_CAP_ESW(esw->dev, merged_eswitch)) {
dest[dest_idx].vport.vhca_id =
MLX5_CAP_GEN(esw_attr->dests[attr_idx].mdev, vhca_id);
dest[dest_idx].vport.flags |= MLX5_FLOW_DEST_VPORT_VHCA_ID;
if (dest[dest_idx].vport.num == MLX5_VPORT_UPLINK &&
mlx5_lag_is_mpesw(esw->dev))
dest[dest_idx].type = MLX5_FLOW_DESTINATION_TYPE_UPLINK;
}
if (esw_attr->dests[attr_idx].flags & MLX5_ESW_DEST_ENCAP_VALID) {
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/idr.h`, `linux/mlx5/driver.h`, `linux/mlx5/mlx5_ifc.h`, `linux/mlx5/vport.h`, `linux/mlx5/fs.h`, `linux/lockdep.h`, `mlx5_core.h`.
- Detected declarations: `function mlx5_eswitch_set_rule_flow_source`, `function mlx5_eswitch_clear_rule_source_port`, `function mlx5_eswitch_set_rule_source_port`, `function esw_setup_decap_indir`, `function esw_cleanup_decap_indir`, `function esw_setup_mtu_dest`, `function esw_setup_sampler_dest`, `function esw_setup_ft_dest`, `function esw_setup_accept_dest`, `function esw_setup_slow_path_dest`.
- 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.