Commit 147747ec authored by Baowen Zheng's avatar Baowen Zheng Committed by Jakub Kicinski
Browse files

nfp: add support to offload police action from flower table



Offload flow table if the action is already offloaded to hardware when
flow table uses this action.

Change meter id to type of u32 to support all the action index.

Signed-off-by: default avatarBaowen Zheng <baowen.zheng@corigine.com>
Signed-off-by: default avatarLouis Peens <louis.peens@corigine.com>
Signed-off-by: default avatarSimon Horman <simon.horman@corigine.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 776178a5
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
@@ -922,6 +922,51 @@ nfp_fl_pedit(const struct flow_action_entry *act,
	}
}

static struct nfp_fl_meter *nfp_fl_meter(char *act_data)
{
	size_t act_size = sizeof(struct nfp_fl_meter);
	struct nfp_fl_meter *meter_act;

	meter_act = (struct nfp_fl_meter *)act_data;

	memset(meter_act, 0, act_size);

	meter_act->head.jump_id = NFP_FL_ACTION_OPCODE_METER;
	meter_act->head.len_lw = act_size >> NFP_FL_LW_SIZ;

	return meter_act;
}

static int
nfp_flower_meter_action(struct nfp_app *app,
			const struct flow_action_entry *action,
			struct nfp_fl_payload *nfp_fl, int *a_len,
			struct net_device *netdev,
			struct netlink_ext_ack *extack)
{
	struct nfp_fl_meter *fl_meter;
	u32 meter_id;

	if (*a_len + sizeof(struct nfp_fl_meter) > NFP_FL_MAX_A_SIZ) {
		NL_SET_ERR_MSG_MOD(extack,
				   "unsupported offload:meter action size beyond the allowed maximum");
		return -EOPNOTSUPP;
	}

	meter_id = action->hw_index;
	if (!nfp_flower_search_meter_entry(app, meter_id)) {
		NL_SET_ERR_MSG_MOD(extack,
				   "can not offload flow table with unsupported police action.\n");
		return -EOPNOTSUPP;
	}

	fl_meter = nfp_fl_meter(&nfp_fl->action_data[*a_len]);
	*a_len += sizeof(struct nfp_fl_meter);
	fl_meter->meter_id = cpu_to_be32(meter_id);

	return 0;
}

static int
nfp_flower_output_action(struct nfp_app *app,
			 const struct flow_action_entry *act,
@@ -985,6 +1030,7 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
		       struct nfp_flower_pedit_acts *set_act, bool *pkt_host,
		       struct netlink_ext_ack *extack, int act_idx)
{
	struct nfp_flower_priv *fl_priv = app->priv;
	struct nfp_fl_pre_tunnel *pre_tun;
	struct nfp_fl_set_tun *set_tun;
	struct nfp_fl_push_vlan *psh_v;
@@ -1149,6 +1195,18 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,

		*pkt_host = true;
		break;
	case FLOW_ACTION_POLICE:
		if (!(fl_priv->flower_ext_feats & NFP_FL_FEATS_QOS_METER)) {
			NL_SET_ERR_MSG_MOD(extack,
					   "unsupported offload: unsupported police action in action list");
			return -EOPNOTSUPP;
		}

		err = nfp_flower_meter_action(app, act, nfp_fl, a_len, netdev,
					      extack);
		if (err)
			return err;
		break;
	default:
		/* Currently we do not handle any other actions. */
		NL_SET_ERR_MSG_MOD(extack, "unsupported offload: unsupported action in action list");
+7 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@
#define NFP_FL_ACTION_OPCODE_SET_TCP		15
#define NFP_FL_ACTION_OPCODE_PRE_LAG		16
#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL		17
#define NFP_FL_ACTION_OPCODE_METER		24
#define NFP_FL_ACTION_OPCODE_PUSH_GENEVE	26
#define NFP_FL_ACTION_OPCODE_NUM		32

@@ -260,6 +261,12 @@ struct nfp_fl_set_mpls {
	__be32 lse;
};

struct nfp_fl_meter {
	struct nfp_fl_act_head head;
	__be16 reserved;
	__be32 meter_id;
};

/* Metadata with L2 (1W/4B)
 * ----------------------------------------------------------------
 *    3                   2                   1
+2 −0
Original line number Diff line number Diff line
@@ -613,4 +613,6 @@ int nfp_flower_setup_meter_entry(struct nfp_app *app,
				 const struct flow_action_entry *action,
				 enum nfp_meter_op op,
				 u32 meter_id);
struct nfp_meter_entry *
nfp_flower_search_meter_entry(struct nfp_app *app, u32 meter_id);
#endif
+1 −1
Original line number Diff line number Diff line
@@ -502,7 +502,7 @@ static const struct rhashtable_params stats_meter_table_params = {
	.key_len	= sizeof(u32),
};

static struct nfp_meter_entry *
struct nfp_meter_entry *
nfp_flower_search_meter_entry(struct nfp_app *app, u32 meter_id)
{
	struct nfp_flower_priv *priv = app->priv;