drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/police.c

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

File Facts

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

// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

#include "act.h"
#include "en/tc_priv.h"
#include "fs_core.h"

static bool police_act_validate_control(enum flow_action_id act_id,
					struct netlink_ext_ack *extack)
{
	if (act_id != FLOW_ACTION_PIPE &&
	    act_id != FLOW_ACTION_ACCEPT &&
	    act_id != FLOW_ACTION_JUMP &&
	    act_id != FLOW_ACTION_DROP) {
		NL_SET_ERR_MSG_MOD(extack,
				   "Offload not supported when conform-exceed action is not pipe, ok, jump or drop");
		return false;
	}

	return true;
}

static int police_act_validate(const struct flow_action_entry *act,
			       struct netlink_ext_ack *extack)
{
	if (!police_act_validate_control(act->police.exceed.act_id, extack) ||
	    !police_act_validate_control(act->police.notexceed.act_id, extack))
		return -EOPNOTSUPP;

	if (act->police.peakrate_bytes_ps ||
	    act->police.avrate || act->police.overhead) {
		NL_SET_ERR_MSG_MOD(extack,
				   "Offload not supported when peakrate/avrate/overhead is configured");
		return -EOPNOTSUPP;
	}

	return 0;
}

static bool
tc_act_can_offload_police(struct mlx5e_tc_act_parse_state *parse_state,
			  const struct flow_action_entry *act,
			  int act_index,
			  struct mlx5_flow_attr *attr)
{
	int err;

	err = police_act_validate(act, parse_state->extack);
	if (err)
		return false;

	return !!mlx5e_get_flow_meters(parse_state->flow->priv->mdev);
}

static int
fill_meter_params_from_act(const struct flow_action_entry *act,
			   struct mlx5e_flow_meter_params *params)
{
	params->index = act->hw_index;
	if (act->police.rate_bytes_ps) {
		params->mode = MLX5_RATE_LIMIT_BPS;
		/* change rate to bits per second */
		params->rate = act->police.rate_bytes_ps << 3;
		params->burst = act->police.burst;
	} else if (act->police.rate_pkt_ps) {
		params->mode = MLX5_RATE_LIMIT_PPS;
		params->rate = act->police.rate_pkt_ps;
		params->burst = act->police.burst_pkt;
	} else if (act->police.mtu) {
		params->mtu = act->police.mtu;
	} else {
		return -EOPNOTSUPP;
	}

	return 0;
}

static int
tc_act_parse_police(struct mlx5e_tc_act_parse_state *parse_state,
		    const struct flow_action_entry *act,
		    struct mlx5e_priv *priv,
		    struct mlx5_flow_attr *attr)
{
	enum mlx5_flow_namespace_type ns =  mlx5e_get_flow_namespace(parse_state->flow);
	struct mlx5e_flow_meter_params *params = &attr->meter_attr.params;
	int err;

	err = fill_meter_params_from_act(act, params);
	if (err)
		return err;

Annotation

Implementation Notes