drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_meter.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_meter.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/tc/post_meter.c
Extension
.c
Size
12911 bytes
Lines
461
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mlx5e_post_meter_rate_table {
	struct mlx5_flow_table *ft;
	struct mlx5_flow_group *fg;
	struct mlx5_flow_handle *green_rule;
	struct mlx5_flow_attr *green_attr;
	struct mlx5_flow_handle *red_rule;
	struct mlx5_flow_attr *red_attr;
};

struct mlx5e_post_meter_mtu_table {
	struct mlx5_flow_table *ft;
	struct mlx5_flow_group *fg;
	struct mlx5_flow_handle *rule;
	struct mlx5_flow_attr *attr;
};

struct mlx5e_post_meter_mtu_tables {
	struct mlx5e_post_meter_mtu_table green_table;
	struct mlx5e_post_meter_mtu_table red_table;
};

struct mlx5e_post_meter_priv {
	enum mlx5e_post_meter_type type;
	union {
		struct mlx5e_post_meter_rate_table rate_steering_table;
		struct mlx5e_post_meter_mtu_tables  mtu_tables;
	};
};

struct mlx5_flow_table *
mlx5e_post_meter_get_ft(struct mlx5e_post_meter_priv *post_meter)
{
	return post_meter->rate_steering_table.ft;
}

struct mlx5_flow_table *
mlx5e_post_meter_get_mtu_true_ft(struct mlx5e_post_meter_priv *post_meter)
{
	return post_meter->mtu_tables.green_table.ft;
}

struct mlx5_flow_table *
mlx5e_post_meter_get_mtu_false_ft(struct mlx5e_post_meter_priv *post_meter)
{
	return post_meter->mtu_tables.red_table.ft;
}

static struct mlx5_flow_table *
mlx5e_post_meter_table_create(struct mlx5e_priv *priv,
			      enum mlx5_flow_namespace_type ns_type)
{
	struct mlx5_flow_table_attr ft_attr = {};
	struct mlx5_flow_namespace *root_ns;

	root_ns = mlx5_get_flow_namespace(priv->mdev, ns_type);
	if (!root_ns) {
		mlx5_core_warn(priv->mdev, "Failed to get namespace for flow meter\n");
		return ERR_PTR(-EOPNOTSUPP);
	}

	ft_attr.flags = MLX5_FLOW_TABLE_UNMANAGED;
	ft_attr.prio = FDB_SLOW_PATH;
	ft_attr.max_fte = 2;
	ft_attr.level = 1;

	return mlx5_create_flow_table(root_ns, &ft_attr);
}

static int
mlx5e_post_meter_rate_fg_create(struct mlx5e_priv *priv,
				struct mlx5e_post_meter_priv *post_meter)
{
	struct mlx5e_post_meter_rate_table *table = &post_meter->rate_steering_table;
	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
	void *misc2, *match_criteria;
	u32 *flow_group_in;
	int err = 0;

	flow_group_in = kvzalloc(inlen, GFP_KERNEL);
	if (!flow_group_in)
		return -ENOMEM;

	MLX5_SET(create_flow_group_in, flow_group_in, match_criteria_enable,
		 MLX5_MATCH_MISC_PARAMETERS_2);
	match_criteria = MLX5_ADDR_OF(create_flow_group_in, flow_group_in,
				      match_criteria);
	misc2 = MLX5_ADDR_OF(fte_match_param, match_criteria, misc_parameters_2);
	MLX5_SET(fte_match_set_misc2, misc2, metadata_reg_c_5, MLX5_PACKET_COLOR_MASK);
	MLX5_SET(create_flow_group_in, flow_group_in, start_flow_index, 0);
	MLX5_SET(create_flow_group_in, flow_group_in, end_flow_index, 1);

Annotation

Implementation Notes