drivers/net/ethernet/mellanox/mlx5/core/lib/port_tun.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/lib/port_tun.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/lib/port_tun.c- Extension
.c- Size
- 6096 bytes
- Lines
- 187
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mlx5/driver.hlinux/mlx5/port.hmlx5_core.hlib/port_tun.h
Detected Declarations
struct mlx5_port_tun_entropy_flagsfunction mlx5_query_port_tun_entropyfunction mlx5_set_port_tun_entropy_calcfunction mlx5_set_port_gre_tun_entropy_calcfunction mlx5_init_port_tun_entropyfunction mlx5_set_entropyfunction controlfunction mlx5_tun_entropy_refcount_incfunction mlx5_tun_entropy_refcount_dec
Annotated Snippet
struct mlx5_port_tun_entropy_flags {
bool force_supported, force_enabled;
bool calc_supported, calc_enabled;
bool gre_calc_supported, gre_calc_enabled;
};
static void mlx5_query_port_tun_entropy(struct mlx5_core_dev *mdev,
struct mlx5_port_tun_entropy_flags *entropy_flags)
{
u32 out[MLX5_ST_SZ_DW(pcmr_reg)];
/* Default values for FW which do not support MLX5_REG_PCMR */
entropy_flags->force_supported = false;
entropy_flags->calc_supported = false;
entropy_flags->gre_calc_supported = false;
entropy_flags->force_enabled = false;
entropy_flags->calc_enabled = true;
entropy_flags->gre_calc_enabled = true;
if (!MLX5_CAP_GEN(mdev, ports_check))
return;
if (mlx5_query_ports_check(mdev, out, sizeof(out)))
return;
entropy_flags->force_supported = !!(MLX5_GET(pcmr_reg, out, entropy_force_cap));
entropy_flags->calc_supported = !!(MLX5_GET(pcmr_reg, out, entropy_calc_cap));
entropy_flags->gre_calc_supported = !!(MLX5_GET(pcmr_reg, out, entropy_gre_calc_cap));
entropy_flags->force_enabled = !!(MLX5_GET(pcmr_reg, out, entropy_force));
entropy_flags->calc_enabled = !!(MLX5_GET(pcmr_reg, out, entropy_calc));
entropy_flags->gre_calc_enabled = !!(MLX5_GET(pcmr_reg, out, entropy_gre_calc));
}
static int mlx5_set_port_tun_entropy_calc(struct mlx5_core_dev *mdev, u8 enable,
u8 force)
{
u32 in[MLX5_ST_SZ_DW(pcmr_reg)] = {0};
int err;
err = mlx5_query_ports_check(mdev, in, sizeof(in));
if (err)
return err;
MLX5_SET(pcmr_reg, in, local_port, 1);
MLX5_SET(pcmr_reg, in, entropy_force, force);
MLX5_SET(pcmr_reg, in, entropy_calc, enable);
return mlx5_set_ports_check(mdev, in, sizeof(in));
}
static int mlx5_set_port_gre_tun_entropy_calc(struct mlx5_core_dev *mdev,
u8 enable, u8 force)
{
u32 in[MLX5_ST_SZ_DW(pcmr_reg)] = {0};
int err;
err = mlx5_query_ports_check(mdev, in, sizeof(in));
if (err)
return err;
MLX5_SET(pcmr_reg, in, local_port, 1);
MLX5_SET(pcmr_reg, in, entropy_force, force);
MLX5_SET(pcmr_reg, in, entropy_gre_calc, enable);
return mlx5_set_ports_check(mdev, in, sizeof(in));
}
void mlx5_init_port_tun_entropy(struct mlx5_tun_entropy *tun_entropy,
struct mlx5_core_dev *mdev)
{
struct mlx5_port_tun_entropy_flags entropy_flags;
tun_entropy->mdev = mdev;
mutex_init(&tun_entropy->lock);
mlx5_query_port_tun_entropy(mdev, &entropy_flags);
tun_entropy->num_enabling_entries = 0;
tun_entropy->num_disabling_entries = 0;
tun_entropy->enabled = entropy_flags.calc_supported ?
entropy_flags.calc_enabled : true;
}
static int mlx5_set_entropy(struct mlx5_tun_entropy *tun_entropy,
int reformat_type, bool enable)
{
struct mlx5_port_tun_entropy_flags entropy_flags;
int err;
mlx5_query_port_tun_entropy(tun_entropy->mdev, &entropy_flags);
/* Tunnel entropy calculation may be controlled either on port basis
* for all tunneling protocols or specifically for GRE protocol.
* Prioritize GRE protocol control (if capable) over global port
* configuration.
*/
if (entropy_flags.gre_calc_supported &&
reformat_type == MLX5_REFORMAT_TYPE_L2_TO_NVGRE) {
Annotation
- Immediate include surface: `linux/mlx5/driver.h`, `linux/mlx5/port.h`, `mlx5_core.h`, `lib/port_tun.h`.
- Detected declarations: `struct mlx5_port_tun_entropy_flags`, `function mlx5_query_port_tun_entropy`, `function mlx5_set_port_tun_entropy_calc`, `function mlx5_set_port_gre_tun_entropy_calc`, `function mlx5_init_port_tun_entropy`, `function mlx5_set_entropy`, `function control`, `function mlx5_tun_entropy_refcount_inc`, `function mlx5_tun_entropy_refcount_dec`.
- 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.