Commit 90f53c53 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller

mlxsw: spectrum: Start using sampling triggers hash table

Start using the previously introduced sampling triggers hash table to
store sampling parameters instead of storing them as attributes of the
sampled port.

This makes it easier to introduce new sampling triggers.
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1b9fc42e
...@@ -253,14 +253,6 @@ struct mlxsw_sp_sample_params { ...@@ -253,14 +253,6 @@ struct mlxsw_sp_sample_params {
bool truncate; bool truncate;
}; };
struct mlxsw_sp_port_sample {
struct psample_group *psample_group;
u32 trunc_size;
u32 rate;
bool truncate;
int span_id; /* Relevant for Spectrum-2 onwards. */
};
struct mlxsw_sp_bridge_port; struct mlxsw_sp_bridge_port;
struct mlxsw_sp_fid; struct mlxsw_sp_fid;
...@@ -324,7 +316,6 @@ struct mlxsw_sp_port { ...@@ -324,7 +316,6 @@ struct mlxsw_sp_port {
struct mlxsw_sp_port_xstats xstats; struct mlxsw_sp_port_xstats xstats;
struct delayed_work update_dw; struct delayed_work update_dw;
} periodic_hw_stats; } periodic_hw_stats;
struct mlxsw_sp_port_sample __rcu *sample;
struct list_head vlans_list; struct list_head vlans_list;
struct mlxsw_sp_port_vlan *default_vlan; struct mlxsw_sp_port_vlan *default_vlan;
struct mlxsw_sp_qdisc_state *qdisc; struct mlxsw_sp_qdisc_state *qdisc;
...@@ -1092,6 +1083,11 @@ struct mlxsw_sp_mall_trap_entry { ...@@ -1092,6 +1083,11 @@ struct mlxsw_sp_mall_trap_entry {
int span_id; int span_id;
}; };
struct mlxsw_sp_mall_sample_entry {
struct mlxsw_sp_sample_params params;
int span_id; /* Relevant for Spectrum-2 onwards. */
};
struct mlxsw_sp_mall_entry { struct mlxsw_sp_mall_entry {
struct list_head list; struct list_head list;
unsigned long cookie; unsigned long cookie;
...@@ -1101,7 +1097,7 @@ struct mlxsw_sp_mall_entry { ...@@ -1101,7 +1097,7 @@ struct mlxsw_sp_mall_entry {
union { union {
struct mlxsw_sp_mall_mirror_entry mirror; struct mlxsw_sp_mall_mirror_entry mirror;
struct mlxsw_sp_mall_trap_entry trap; struct mlxsw_sp_mall_trap_entry trap;
struct mlxsw_sp_port_sample sample; struct mlxsw_sp_mall_sample_entry sample;
}; };
struct rcu_head rcu; struct rcu_head rcu;
}; };
......
...@@ -105,13 +105,19 @@ mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -105,13 +105,19 @@ mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
struct mlxsw_sp_sample_trigger trigger;
int err; int err;
if (rtnl_dereference(mlxsw_sp_port->sample)) { if (mall_entry->ingress)
NL_SET_ERR_MSG(extack, "Sampling already active on port"); trigger.type = MLXSW_SP_SAMPLE_TRIGGER_TYPE_INGRESS;
return -EEXIST; else
} trigger.type = MLXSW_SP_SAMPLE_TRIGGER_TYPE_EGRESS;
rcu_assign_pointer(mlxsw_sp_port->sample, &mall_entry->sample); trigger.local_port = mlxsw_sp_port->local_port;
err = mlxsw_sp_sample_trigger_params_set(mlxsw_sp, &trigger,
&mall_entry->sample.params,
extack);
if (err)
return err;
err = mlxsw_sp->mall_ops->sample_add(mlxsw_sp, mlxsw_sp_port, err = mlxsw_sp->mall_ops->sample_add(mlxsw_sp, mlxsw_sp_port,
mall_entry, extack); mall_entry, extack);
...@@ -120,7 +126,7 @@ mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -120,7 +126,7 @@ mlxsw_sp_mall_port_sample_add(struct mlxsw_sp_port *mlxsw_sp_port,
return 0; return 0;
err_port_sample_set: err_port_sample_set:
RCU_INIT_POINTER(mlxsw_sp_port->sample, NULL); mlxsw_sp_sample_trigger_params_unset(mlxsw_sp, &trigger);
return err; return err;
} }
...@@ -129,12 +135,16 @@ mlxsw_sp_mall_port_sample_del(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -129,12 +135,16 @@ mlxsw_sp_mall_port_sample_del(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp_mall_entry *mall_entry) struct mlxsw_sp_mall_entry *mall_entry)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
struct mlxsw_sp_sample_trigger trigger;
if (!mlxsw_sp_port->sample) if (mall_entry->ingress)
return; trigger.type = MLXSW_SP_SAMPLE_TRIGGER_TYPE_INGRESS;
else
trigger.type = MLXSW_SP_SAMPLE_TRIGGER_TYPE_EGRESS;
trigger.local_port = mlxsw_sp_port->local_port;
mlxsw_sp->mall_ops->sample_del(mlxsw_sp, mlxsw_sp_port, mall_entry); mlxsw_sp->mall_ops->sample_del(mlxsw_sp, mlxsw_sp_port, mall_entry);
RCU_INIT_POINTER(mlxsw_sp_port->sample, NULL); mlxsw_sp_sample_trigger_params_unset(mlxsw_sp, &trigger);
} }
static int static int
...@@ -261,10 +271,10 @@ int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp, ...@@ -261,10 +271,10 @@ int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
goto errout; goto errout;
} }
mall_entry->type = MLXSW_SP_MALL_ACTION_TYPE_SAMPLE; mall_entry->type = MLXSW_SP_MALL_ACTION_TYPE_SAMPLE;
mall_entry->sample.psample_group = act->sample.psample_group; mall_entry->sample.params.psample_group = act->sample.psample_group;
mall_entry->sample.truncate = act->sample.truncate; mall_entry->sample.params.truncate = act->sample.truncate;
mall_entry->sample.trunc_size = act->sample.trunc_size; mall_entry->sample.params.trunc_size = act->sample.trunc_size;
mall_entry->sample.rate = act->sample.rate; mall_entry->sample.params.rate = act->sample.rate;
} else { } else {
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto errout; goto errout;
...@@ -369,7 +379,7 @@ static int mlxsw_sp1_mall_sample_add(struct mlxsw_sp *mlxsw_sp, ...@@ -369,7 +379,7 @@ static int mlxsw_sp1_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mall_entry *mall_entry, struct mlxsw_sp_mall_entry *mall_entry,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
u32 rate = mall_entry->sample.rate; u32 rate = mall_entry->sample.params.rate;
if (!mall_entry->ingress) { if (!mall_entry->ingress) {
NL_SET_ERR_MSG(extack, "Sampling is not supported on egress"); NL_SET_ERR_MSG(extack, "Sampling is not supported on egress");
...@@ -406,8 +416,7 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp, ...@@ -406,8 +416,7 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
.to_dev = NULL, /* Mirror to CPU. */ .to_dev = NULL, /* Mirror to CPU. */
.session_id = MLXSW_SP_SPAN_SESSION_ID_SAMPLING, .session_id = MLXSW_SP_SPAN_SESSION_ID_SAMPLING,
}; };
struct mlxsw_sp_port_sample *sample; u32 rate = mall_entry->sample.params.rate;
u32 rate = mall_entry->sample.rate;
int err; int err;
if (!mall_entry->ingress) { if (!mall_entry->ingress) {
...@@ -415,9 +424,8 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp, ...@@ -415,9 +424,8 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
sample = rtnl_dereference(mlxsw_sp_port->sample); err = mlxsw_sp_span_agent_get(mlxsw_sp, &mall_entry->sample.span_id,
&agent_parms);
err = mlxsw_sp_span_agent_get(mlxsw_sp, &sample->span_id, &agent_parms);
if (err) { if (err) {
NL_SET_ERR_MSG(extack, "Failed to get SPAN agent"); NL_SET_ERR_MSG(extack, "Failed to get SPAN agent");
return err; return err;
...@@ -429,7 +437,7 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp, ...@@ -429,7 +437,7 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
goto err_analyzed_port_get; goto err_analyzed_port_get;
} }
trigger_parms.span_id = sample->span_id; trigger_parms.span_id = mall_entry->sample.span_id;
trigger_parms.probability_rate = rate; trigger_parms.probability_rate = rate;
err = mlxsw_sp_span_agent_bind(mlxsw_sp, MLXSW_SP_SPAN_TRIGGER_INGRESS, err = mlxsw_sp_span_agent_bind(mlxsw_sp, MLXSW_SP_SPAN_TRIGGER_INGRESS,
mlxsw_sp_port, &trigger_parms); mlxsw_sp_port, &trigger_parms);
...@@ -443,7 +451,7 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp, ...@@ -443,7 +451,7 @@ static int mlxsw_sp2_mall_sample_add(struct mlxsw_sp *mlxsw_sp,
err_agent_bind: err_agent_bind:
mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true); mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true);
err_analyzed_port_get: err_analyzed_port_get:
mlxsw_sp_span_agent_put(mlxsw_sp, sample->span_id); mlxsw_sp_span_agent_put(mlxsw_sp, mall_entry->sample.span_id);
return err; return err;
} }
...@@ -452,15 +460,12 @@ static void mlxsw_sp2_mall_sample_del(struct mlxsw_sp *mlxsw_sp, ...@@ -452,15 +460,12 @@ static void mlxsw_sp2_mall_sample_del(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mall_entry *mall_entry) struct mlxsw_sp_mall_entry *mall_entry)
{ {
struct mlxsw_sp_span_trigger_parms trigger_parms = {}; struct mlxsw_sp_span_trigger_parms trigger_parms = {};
struct mlxsw_sp_port_sample *sample;
sample = rtnl_dereference(mlxsw_sp_port->sample);
trigger_parms.span_id = sample->span_id; trigger_parms.span_id = mall_entry->sample.span_id;
mlxsw_sp_span_agent_unbind(mlxsw_sp, MLXSW_SP_SPAN_TRIGGER_INGRESS, mlxsw_sp_span_agent_unbind(mlxsw_sp, MLXSW_SP_SPAN_TRIGGER_INGRESS,
mlxsw_sp_port, &trigger_parms); mlxsw_sp_port, &trigger_parms);
mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true); mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true);
mlxsw_sp_span_agent_put(mlxsw_sp, sample->span_id); mlxsw_sp_span_agent_put(mlxsw_sp, mall_entry->sample.span_id);
} }
const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops = { const struct mlxsw_sp_mall_ops mlxsw_sp2_mall_ops = {
......
...@@ -257,8 +257,9 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port, ...@@ -257,8 +257,9 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port,
void *trap_ctx) void *trap_ctx)
{ {
struct mlxsw_sp *mlxsw_sp = devlink_trap_ctx_priv(trap_ctx); struct mlxsw_sp *mlxsw_sp = devlink_trap_ctx_priv(trap_ctx);
struct mlxsw_sp_sample_trigger trigger;
struct mlxsw_sp_sample_params *params;
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
struct mlxsw_sp_port_sample *sample;
struct psample_metadata md = {}; struct psample_metadata md = {};
int err; int err;
...@@ -270,8 +271,10 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port, ...@@ -270,8 +271,10 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port,
if (!mlxsw_sp_port) if (!mlxsw_sp_port)
goto out; goto out;
sample = rcu_dereference(mlxsw_sp_port->sample); trigger.type = MLXSW_SP_SAMPLE_TRIGGER_TYPE_INGRESS;
if (!sample) trigger.local_port = local_port;
params = mlxsw_sp_sample_trigger_params_lookup(mlxsw_sp, &trigger);
if (!params)
goto out; goto out;
/* The psample module expects skb->data to point to the start of the /* The psample module expects skb->data to point to the start of the
...@@ -279,9 +282,9 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port, ...@@ -279,9 +282,9 @@ static void mlxsw_sp_rx_sample_listener(struct sk_buff *skb, u8 local_port,
*/ */
skb_push(skb, ETH_HLEN); skb_push(skb, ETH_HLEN);
mlxsw_sp_psample_md_init(mlxsw_sp, &md, skb, mlxsw_sp_psample_md_init(mlxsw_sp, &md, skb,
mlxsw_sp_port->dev->ifindex, sample->truncate, mlxsw_sp_port->dev->ifindex, params->truncate,
sample->trunc_size); params->trunc_size);
psample_sample_packet(sample->psample_group, skb, sample->rate, &md); psample_sample_packet(params->psample_group, skb, params->rate, &md);
out: out:
consume_skb(skb); consume_skb(skb);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment