drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c- Extension
.c- Size
- 27677 bytes
- Lines
- 999
- 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
net/flow.hnet/inet_dscp.hnet/vxlan.hnet/gre.hnet/geneve.hnet/bareudp.hen/tc_tun.hen/tc_priv.hen_tc.hrep/tc.hrep/neigh.hlag/lag.hlag/mp.h
Detected Declarations
struct mlx5e_tc_tun_route_attrfunction mlx5e_tc_tun_route_attr_cleanupfunction get_route_and_out_devsfunction mlx5e_route_lookup_ipv4_getfunction mlx5e_route_lookup_ipv4_putfunction mlx5e_gen_ip_tunnel_headerfunction mlx5e_tc_tun_create_header_ipv4function mlx5e_tc_tun_update_header_ipv4function mlx5e_route_lookup_ipv6_getfunction mlx5e_route_lookup_ipv6_putfunction mlx5e_tc_tun_create_header_ipv6function mlx5e_tc_tun_update_header_ipv6function mlx5e_tc_tun_route_lookupfunction mlx5e_tc_tun_device_to_offloadfunction mlx5e_tc_tun_init_encap_attrfunction mlx5e_tc_tun_parsefunction mlx5e_tc_tun_parse_udp_ports
Annotated Snippet
struct mlx5e_tc_tun_route_attr {
struct net_device *out_dev;
struct net_device *route_dev;
union {
struct flowi4 fl4;
struct flowi6 fl6;
} fl;
struct neighbour *n;
u8 ttl;
};
#define TC_TUN_ROUTE_ATTR_INIT(name) struct mlx5e_tc_tun_route_attr name = {}
static void mlx5e_tc_tun_route_attr_cleanup(struct mlx5e_tc_tun_route_attr *attr)
{
if (attr->n)
neigh_release(attr->n);
dev_put(attr->route_dev);
}
struct mlx5e_tc_tunnel *mlx5e_get_tc_tun(struct net_device *tunnel_dev)
{
if (netif_is_vxlan(tunnel_dev))
return &vxlan_tunnel;
else if (netif_is_geneve(tunnel_dev))
return &geneve_tunnel;
else if (netif_is_gretap(tunnel_dev) ||
netif_is_ip6gretap(tunnel_dev))
return &gre_tunnel;
else if (netif_is_bareudp(tunnel_dev))
return &mplsoudp_tunnel;
else
return NULL;
}
static int get_route_and_out_devs(struct mlx5e_priv *priv,
struct net_device *dev,
struct net_device **route_dev,
struct net_device **out_dev)
{
struct net_device *uplink_dev, *uplink_upper, *real_dev;
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
bool dst_is_lag_dev;
real_dev = is_vlan_dev(dev) ? vlan_dev_real_dev(dev) : dev;
uplink_dev = mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH);
rcu_read_lock();
uplink_upper = netdev_master_upper_dev_get_rcu(uplink_dev);
/* mlx5_lag_is_sriov() is a blocking function which can't be called
* while holding rcu read lock. Take the net_device for correctness
* sake.
*/
dev_hold(uplink_upper);
rcu_read_unlock();
dst_is_lag_dev = (uplink_upper &&
netif_is_lag_master(uplink_upper) &&
real_dev == uplink_upper &&
mlx5_lag_is_sriov(priv->mdev));
dev_put(uplink_upper);
/* if the egress device isn't on the same HW e-switch or
* it's a LAG device, use the uplink
*/
*route_dev = dev;
if (!netdev_port_same_parent_id(priv->netdev, real_dev) ||
dst_is_lag_dev || is_vlan_dev(*route_dev) ||
netif_is_ovs_master(*route_dev))
*out_dev = uplink_dev;
else if (mlx5e_eswitch_rep(dev) &&
mlx5e_is_valid_eswitch_fwd_dev(priv, dev))
*out_dev = *route_dev;
else
return -EOPNOTSUPP;
if (!mlx5e_eswitch_uplink_rep(*out_dev))
return -EOPNOTSUPP;
if (mlx5e_eswitch_uplink_rep(priv->netdev) && *out_dev != priv->netdev &&
!mlx5_lag_is_mpesw(priv->mdev))
return -EOPNOTSUPP;
return 0;
}
static int mlx5e_route_lookup_ipv4_get(struct mlx5e_priv *priv,
struct net_device *dev,
struct mlx5e_tc_tun_route_attr *attr)
{
Annotation
- Immediate include surface: `net/flow.h`, `net/inet_dscp.h`, `net/vxlan.h`, `net/gre.h`, `net/geneve.h`, `net/bareudp.h`, `en/tc_tun.h`, `en/tc_priv.h`.
- Detected declarations: `struct mlx5e_tc_tun_route_attr`, `function mlx5e_tc_tun_route_attr_cleanup`, `function get_route_and_out_devs`, `function mlx5e_route_lookup_ipv4_get`, `function mlx5e_route_lookup_ipv4_put`, `function mlx5e_gen_ip_tunnel_header`, `function mlx5e_tc_tun_create_header_ipv4`, `function mlx5e_tc_tun_update_header_ipv4`, `function mlx5e_route_lookup_ipv6_get`, `function mlx5e_route_lookup_ipv6_put`.
- 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.