Commit 98977089 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

mlxsw: span: Remove span_entry by span_id

Instead of removing span_entry by the port number, allow removing by
SPAN id. That simplifies some code right here, and for mirroring to soft
netdevices, avoids problems with netdevice pointer invalidation and
reuse.

Rename mlxsw_sp_span_entry_find() to mlxsw_sp_span_entry_find_by_port()
and keep it--follow-up patches will make use of it.
Signed-off-by: default avatarPetr Machata <petrm@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1da93eb4
/* /*
* drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c * drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
* Copyright (c) 2017 Mellanox Technologies. All rights reserved. * Copyright (c) 2017, 2018 Mellanox Technologies. All rights reserved.
* Copyright (c) 2017 Jiri Pirko <jiri@mellanox.com> * Copyright (c) 2017 Jiri Pirko <jiri@mellanox.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -838,7 +838,6 @@ struct mlxsw_afa_mirror { ...@@ -838,7 +838,6 @@ struct mlxsw_afa_mirror {
struct mlxsw_afa_resource resource; struct mlxsw_afa_resource resource;
int span_id; int span_id;
u8 local_in_port; u8 local_in_port;
u8 local_out_port;
bool ingress; bool ingress;
}; };
...@@ -848,7 +847,7 @@ mlxsw_afa_mirror_destroy(struct mlxsw_afa_block *block, ...@@ -848,7 +847,7 @@ mlxsw_afa_mirror_destroy(struct mlxsw_afa_block *block,
{ {
block->afa->ops->mirror_del(block->afa->ops_priv, block->afa->ops->mirror_del(block->afa->ops_priv,
mirror->local_in_port, mirror->local_in_port,
mirror->local_out_port, mirror->span_id,
mirror->ingress); mirror->ingress);
kfree(mirror); kfree(mirror);
} }
...@@ -882,7 +881,6 @@ mlxsw_afa_mirror_create(struct mlxsw_afa_block *block, ...@@ -882,7 +881,6 @@ mlxsw_afa_mirror_create(struct mlxsw_afa_block *block,
goto err_mirror_add; goto err_mirror_add;
mirror->ingress = ingress; mirror->ingress = ingress;
mirror->local_out_port = local_out_port;
mirror->local_in_port = local_in_port; mirror->local_in_port = local_in_port;
mirror->resource.destructor = mlxsw_afa_mirror_destructor; mirror->resource.destructor = mlxsw_afa_mirror_destructor;
mlxsw_afa_resource_add(block, &mirror->resource); mlxsw_afa_resource_add(block, &mirror->resource);
......
...@@ -50,7 +50,7 @@ struct mlxsw_afa_ops { ...@@ -50,7 +50,7 @@ struct mlxsw_afa_ops {
void (*counter_index_put)(void *priv, unsigned int counter_index); void (*counter_index_put)(void *priv, unsigned int counter_index);
int (*mirror_add)(void *priv, u8 locol_in_port, u8 local_out_port, int (*mirror_add)(void *priv, u8 locol_in_port, u8 local_out_port,
bool ingress, int *p_span_id); bool ingress, int *p_span_id);
void (*mirror_del)(void *priv, u8 locol_in_port, u8 local_out_port, void (*mirror_del)(void *priv, u8 local_in_port, int span_id,
bool ingress); bool ingress);
}; };
......
...@@ -1273,11 +1273,10 @@ mlxsw_sp_port_add_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1273,11 +1273,10 @@ mlxsw_sp_port_add_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port,
} }
to_port = netdev_priv(to_dev); to_port = netdev_priv(to_dev);
mirror->to_local_port = to_port->local_port;
mirror->ingress = ingress; mirror->ingress = ingress;
span_type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS; span_type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
return mlxsw_sp_span_mirror_add(mlxsw_sp_port, to_port, span_type, return mlxsw_sp_span_mirror_add(mlxsw_sp_port, to_port, span_type,
true); true, &mirror->span_id);
} }
static void static void
...@@ -1288,7 +1287,7 @@ mlxsw_sp_port_del_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1288,7 +1287,7 @@ mlxsw_sp_port_del_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port,
span_type = mirror->ingress ? span_type = mirror->ingress ?
MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS; MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
mlxsw_sp_span_mirror_del(mlxsw_sp_port, mirror->to_local_port, mlxsw_sp_span_mirror_del(mlxsw_sp_port, mirror->span_id,
span_type, true); span_type, true);
} }
......
...@@ -124,7 +124,7 @@ enum mlxsw_sp_port_mall_action_type { ...@@ -124,7 +124,7 @@ enum mlxsw_sp_port_mall_action_type {
}; };
struct mlxsw_sp_port_mall_mirror_tc_entry { struct mlxsw_sp_port_mall_mirror_tc_entry {
u8 to_local_port; int span_id;
bool ingress; bool ingress;
}; };
......
/* /*
* drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.c * drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_actions.c
* Copyright (c) 2017 Mellanox Technologies. All rights reserved. * Copyright (c) 2017, 2018 Mellanox Technologies. All rights reserved.
* Copyright (c) 2017 Jiri Pirko <jiri@mellanox.com> * Copyright (c) 2017 Jiri Pirko <jiri@mellanox.com>
* Copyright (c) 2017 Yotam Gigi <yotamg@mellanox.com> * Copyright (c) 2017 Yotam Gigi <yotamg@mellanox.com>
* *
...@@ -130,36 +130,19 @@ mlxsw_sp_act_mirror_add(void *priv, u8 local_in_port, u8 local_out_port, ...@@ -130,36 +130,19 @@ mlxsw_sp_act_mirror_add(void *priv, u8 local_in_port, u8 local_out_port,
bool ingress, int *p_span_id) bool ingress, int *p_span_id)
{ {
struct mlxsw_sp_port *in_port, *out_port; struct mlxsw_sp_port *in_port, *out_port;
struct mlxsw_sp_span_entry *span_entry;
struct mlxsw_sp *mlxsw_sp = priv; struct mlxsw_sp *mlxsw_sp = priv;
enum mlxsw_sp_span_type type; enum mlxsw_sp_span_type type;
int err;
type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS; type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
out_port = mlxsw_sp->ports[local_out_port]; out_port = mlxsw_sp->ports[local_out_port];
in_port = mlxsw_sp->ports[local_in_port]; in_port = mlxsw_sp->ports[local_in_port];
err = mlxsw_sp_span_mirror_add(in_port, out_port, type, false); return mlxsw_sp_span_mirror_add(in_port, out_port, type,
if (err) false, p_span_id);
return err;
span_entry = mlxsw_sp_span_entry_find(mlxsw_sp, local_out_port);
if (!span_entry) {
err = -ENOENT;
goto err_span_entry_find;
}
*p_span_id = span_entry->id;
return 0;
err_span_entry_find:
mlxsw_sp_span_mirror_del(in_port, local_out_port, type, false);
return err;
} }
static void static void
mlxsw_sp_act_mirror_del(void *priv, u8 local_in_port, u8 local_out_port, mlxsw_sp_act_mirror_del(void *priv, u8 local_in_port, int span_id, bool ingress)
bool ingress)
{ {
struct mlxsw_sp *mlxsw_sp = priv; struct mlxsw_sp *mlxsw_sp = priv;
struct mlxsw_sp_port *in_port; struct mlxsw_sp_port *in_port;
...@@ -168,7 +151,7 @@ mlxsw_sp_act_mirror_del(void *priv, u8 local_in_port, u8 local_out_port, ...@@ -168,7 +151,7 @@ mlxsw_sp_act_mirror_del(void *priv, u8 local_in_port, u8 local_out_port,
type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS; type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
in_port = mlxsw_sp->ports[local_in_port]; in_port = mlxsw_sp->ports[local_in_port];
mlxsw_sp_span_mirror_del(in_port, local_out_port, type, false); mlxsw_sp_span_mirror_del(in_port, span_id, type, false);
} }
static const struct mlxsw_afa_ops mlxsw_sp_act_afa_ops = { static const struct mlxsw_afa_ops mlxsw_sp_act_afa_ops = {
......
...@@ -118,7 +118,7 @@ static void mlxsw_sp_span_entry_destroy(struct mlxsw_sp *mlxsw_sp, ...@@ -118,7 +118,7 @@ static void mlxsw_sp_span_entry_destroy(struct mlxsw_sp *mlxsw_sp,
} }
struct mlxsw_sp_span_entry * struct mlxsw_sp_span_entry *
mlxsw_sp_span_entry_find(struct mlxsw_sp *mlxsw_sp, u8 local_port) mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp, u8 local_port)
{ {
int i; int i;
...@@ -131,13 +131,27 @@ mlxsw_sp_span_entry_find(struct mlxsw_sp *mlxsw_sp, u8 local_port) ...@@ -131,13 +131,27 @@ mlxsw_sp_span_entry_find(struct mlxsw_sp *mlxsw_sp, u8 local_port)
return NULL; return NULL;
} }
static struct mlxsw_sp_span_entry *
mlxsw_sp_span_entry_find_by_id(struct mlxsw_sp *mlxsw_sp, int span_id)
{
int i;
for (i = 0; i < mlxsw_sp->span.entries_count; i++) {
struct mlxsw_sp_span_entry *curr = &mlxsw_sp->span.entries[i];
if (curr->ref_count && curr->id == span_id)
return curr;
}
return NULL;
}
static struct mlxsw_sp_span_entry * static struct mlxsw_sp_span_entry *
mlxsw_sp_span_entry_get(struct mlxsw_sp_port *port) mlxsw_sp_span_entry_get(struct mlxsw_sp_port *port)
{ {
struct mlxsw_sp_span_entry *span_entry; struct mlxsw_sp_span_entry *span_entry;
span_entry = mlxsw_sp_span_entry_find(port->mlxsw_sp, span_entry = mlxsw_sp_span_entry_find_by_port(port->mlxsw_sp,
port->local_port); port->local_port);
if (span_entry) { if (span_entry) {
/* Already exists, just take a reference */ /* Already exists, just take a reference */
span_entry->ref_count++; span_entry->ref_count++;
...@@ -316,7 +330,8 @@ mlxsw_sp_span_inspected_port_del(struct mlxsw_sp_port *port, ...@@ -316,7 +330,8 @@ mlxsw_sp_span_inspected_port_del(struct mlxsw_sp_port *port,
int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from, int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
struct mlxsw_sp_port *to, struct mlxsw_sp_port *to,
enum mlxsw_sp_span_type type, bool bind) enum mlxsw_sp_span_type type, bool bind,
int *p_span_id)
{ {
struct mlxsw_sp *mlxsw_sp = from->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = from->mlxsw_sp;
struct mlxsw_sp_span_entry *span_entry; struct mlxsw_sp_span_entry *span_entry;
...@@ -333,6 +348,7 @@ int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from, ...@@ -333,6 +348,7 @@ int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
if (err) if (err)
goto err_port_bind; goto err_port_bind;
*p_span_id = span_entry->id;
return 0; return 0;
err_port_bind: err_port_bind:
...@@ -340,13 +356,12 @@ int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from, ...@@ -340,13 +356,12 @@ int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
return err; return err;
} }
void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, u8 destination_port, void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, int span_id,
enum mlxsw_sp_span_type type, bool bind) enum mlxsw_sp_span_type type, bool bind)
{ {
struct mlxsw_sp_span_entry *span_entry; struct mlxsw_sp_span_entry *span_entry;
span_entry = mlxsw_sp_span_entry_find(from->mlxsw_sp, span_entry = mlxsw_sp_span_entry_find_by_id(from->mlxsw_sp, span_id);
destination_port);
if (!span_entry) { if (!span_entry) {
netdev_err(from->dev, "no span entry found\n"); netdev_err(from->dev, "no span entry found\n");
return; return;
......
...@@ -62,11 +62,12 @@ void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp); ...@@ -62,11 +62,12 @@ void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from, int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
struct mlxsw_sp_port *to, struct mlxsw_sp_port *to,
enum mlxsw_sp_span_type type, bool bind); enum mlxsw_sp_span_type type,
void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, u8 destination_port, bool bind, int *p_span_id);
void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, int span_id,
enum mlxsw_sp_span_type type, bool bind); enum mlxsw_sp_span_type type, bool bind);
struct mlxsw_sp_span_entry * struct mlxsw_sp_span_entry *
mlxsw_sp_span_entry_find(struct mlxsw_sp *mlxsw_sp, u8 local_port); mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp, u8 local_port);
int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu); int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
......
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