Commit c83da292 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

mlxsw: core: Allow to enable/disable rx_listener for trap

For source traps, the "thin policer" is going to be used in order
to reduce the amount of trapped packets to minimum. However, there
will be still small number of packets coming in that need to be dropped
in the driver. Allow to enable/disable rx_listener related to specific
trap in order to prevent unwanted packets to go up the stack.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3e6cacaf
...@@ -142,6 +142,7 @@ struct mlxsw_rx_listener_item { ...@@ -142,6 +142,7 @@ struct mlxsw_rx_listener_item {
struct list_head list; struct list_head list;
struct mlxsw_rx_listener rxl; struct mlxsw_rx_listener rxl;
void *priv; void *priv;
bool enabled;
}; };
struct mlxsw_event_listener_item { struct mlxsw_event_listener_item {
...@@ -1470,7 +1471,7 @@ __find_rx_listener_item(struct mlxsw_core *mlxsw_core, ...@@ -1470,7 +1471,7 @@ __find_rx_listener_item(struct mlxsw_core *mlxsw_core,
int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core, int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_rx_listener *rxl, const struct mlxsw_rx_listener *rxl,
void *priv) void *priv, bool enabled)
{ {
struct mlxsw_rx_listener_item *rxl_item; struct mlxsw_rx_listener_item *rxl_item;
...@@ -1482,6 +1483,7 @@ int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core, ...@@ -1482,6 +1483,7 @@ int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
return -ENOMEM; return -ENOMEM;
rxl_item->rxl = *rxl; rxl_item->rxl = *rxl;
rxl_item->priv = priv; rxl_item->priv = priv;
rxl_item->enabled = enabled;
list_add_rcu(&rxl_item->list, &mlxsw_core->rx_listener_list); list_add_rcu(&rxl_item->list, &mlxsw_core->rx_listener_list);
return 0; return 0;
...@@ -1502,6 +1504,19 @@ void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core, ...@@ -1502,6 +1504,19 @@ void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
} }
EXPORT_SYMBOL(mlxsw_core_rx_listener_unregister); EXPORT_SYMBOL(mlxsw_core_rx_listener_unregister);
static void
mlxsw_core_rx_listener_state_set(struct mlxsw_core *mlxsw_core,
const struct mlxsw_rx_listener *rxl,
bool enabled)
{
struct mlxsw_rx_listener_item *rxl_item;
rxl_item = __find_rx_listener_item(mlxsw_core, rxl);
if (WARN_ON(!rxl_item))
return;
rxl_item->enabled = enabled;
}
static void mlxsw_core_event_listener_func(struct sk_buff *skb, u8 local_port, static void mlxsw_core_event_listener_func(struct sk_buff *skb, u8 local_port,
void *priv) void *priv)
{ {
...@@ -1563,7 +1578,7 @@ int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core, ...@@ -1563,7 +1578,7 @@ int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core,
el_item->el = *el; el_item->el = *el;
el_item->priv = priv; el_item->priv = priv;
err = mlxsw_core_rx_listener_register(mlxsw_core, &rxl, el_item); err = mlxsw_core_rx_listener_register(mlxsw_core, &rxl, el_item, true);
if (err) if (err)
goto err_rx_listener_register; goto err_rx_listener_register;
...@@ -1601,16 +1616,18 @@ EXPORT_SYMBOL(mlxsw_core_event_listener_unregister); ...@@ -1601,16 +1616,18 @@ EXPORT_SYMBOL(mlxsw_core_event_listener_unregister);
static int mlxsw_core_listener_register(struct mlxsw_core *mlxsw_core, static int mlxsw_core_listener_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener, const struct mlxsw_listener *listener,
void *priv) void *priv, bool enabled)
{ {
if (listener->is_event) if (listener->is_event) {
WARN_ON(!enabled);
return mlxsw_core_event_listener_register(mlxsw_core, return mlxsw_core_event_listener_register(mlxsw_core,
&listener->event_listener, &listener->event_listener,
priv); priv);
else } else {
return mlxsw_core_rx_listener_register(mlxsw_core, return mlxsw_core_rx_listener_register(mlxsw_core,
&listener->rx_listener, &listener->rx_listener,
priv); priv, enabled);
}
} }
static void mlxsw_core_listener_unregister(struct mlxsw_core *mlxsw_core, static void mlxsw_core_listener_unregister(struct mlxsw_core *mlxsw_core,
...@@ -1632,7 +1649,8 @@ int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core, ...@@ -1632,7 +1649,8 @@ int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
char hpkt_pl[MLXSW_REG_HPKT_LEN]; char hpkt_pl[MLXSW_REG_HPKT_LEN];
int err; int err;
err = mlxsw_core_listener_register(mlxsw_core, listener, priv); err = mlxsw_core_listener_register(mlxsw_core, listener, priv,
listener->enabled_on_register);
if (err) if (err)
return err; return err;
...@@ -1675,11 +1693,22 @@ int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core, ...@@ -1675,11 +1693,22 @@ int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core,
{ {
enum mlxsw_reg_hpkt_action action; enum mlxsw_reg_hpkt_action action;
char hpkt_pl[MLXSW_REG_HPKT_LEN]; char hpkt_pl[MLXSW_REG_HPKT_LEN];
int err;
/* Not supported for event listener */
if (WARN_ON(listener->is_event))
return -EINVAL;
action = enabled ? listener->en_action : listener->dis_action; action = enabled ? listener->en_action : listener->dis_action;
mlxsw_reg_hpkt_pack(hpkt_pl, action, listener->trap_id, mlxsw_reg_hpkt_pack(hpkt_pl, action, listener->trap_id,
listener->trap_group, listener->is_ctrl); listener->trap_group, listener->is_ctrl);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl); err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
if (err)
return err;
mlxsw_core_rx_listener_state_set(mlxsw_core, &listener->rx_listener,
enabled);
return 0;
} }
EXPORT_SYMBOL(mlxsw_core_trap_state_set); EXPORT_SYMBOL(mlxsw_core_trap_state_set);
...@@ -1939,7 +1968,8 @@ void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb, ...@@ -1939,7 +1968,8 @@ void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
if ((rxl->local_port == MLXSW_PORT_DONT_CARE || if ((rxl->local_port == MLXSW_PORT_DONT_CARE ||
rxl->local_port == local_port) && rxl->local_port == local_port) &&
rxl->trap_id == rx_info->trap_id) { rxl->trap_id == rx_info->trap_id) {
found = true; if (rxl_item->enabled)
found = true;
break; break;
} }
} }
......
...@@ -129,7 +129,7 @@ struct mlxsw_listener { ...@@ -129,7 +129,7 @@ struct mlxsw_listener {
int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core, int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_rx_listener *rxl, const struct mlxsw_rx_listener *rxl,
void *priv); void *priv, bool enabled);
void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core, void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_rx_listener *rxl); const struct mlxsw_rx_listener *rxl);
......
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