Commit d53b1162 authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-Reorganize-trap-data'

Ido Schimmel says:

====================
mlxsw: Reorganize trap data

This patch set does not include any functional changes. It merely
reworks the internal storage of traps, trap groups and trap policers in
mlxsw to each use a single array.

These changes allow us to get rid of the multiple arrays we currently
have for traps, which make the trap data easier to validate and extend
with more per-trap information in the future. It will also allow us to
more easily add per-ASIC traps in future submissions.

Last two patches include minor changes to devlink-trap selftests.

Tested with existing devlink-trap selftests.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 13f15b59 04cc99d9
......@@ -12,6 +12,25 @@
#include "spectrum.h"
#include "spectrum_trap.h"
struct mlxsw_sp_trap_policer_item {
struct devlink_trap_policer policer;
u16 hw_id;
};
struct mlxsw_sp_trap_group_item {
struct devlink_trap_group group;
u16 hw_group_id;
u8 priority;
u8 tc;
};
#define MLXSW_SP_TRAP_LISTENERS_MAX 3
struct mlxsw_sp_trap_item {
struct devlink_trap trap;
struct mlxsw_listener listeners_arr[MLXSW_SP_TRAP_LISTENERS_MAX];
};
/* All driver-specific traps must be documented in
* Documentation/networking/devlink/mlxsw.rst
*/
......@@ -176,136 +195,255 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port,
1 << MLXSW_REG_QPCR_LOWEST_CBS)
/* Ordered by policer identifier */
static const struct devlink_trap_policer mlxsw_sp_trap_policers_arr[] = {
MLXSW_SP_TRAP_POLICER(1, 10 * 1024, 128),
};
static const struct devlink_trap_group mlxsw_sp_trap_groups_arr[] = {
DEVLINK_TRAP_GROUP_GENERIC(L2_DROPS, 1),
DEVLINK_TRAP_GROUP_GENERIC(L3_DROPS, 1),
DEVLINK_TRAP_GROUP_GENERIC(TUNNEL_DROPS, 1),
DEVLINK_TRAP_GROUP_GENERIC(ACL_DROPS, 1),
static const struct mlxsw_sp_trap_policer_item
mlxsw_sp_trap_policer_items_arr[] = {
{
.policer = MLXSW_SP_TRAP_POLICER(1, 10 * 1024, 128),
},
};
static const struct devlink_trap mlxsw_sp_traps_arr[] = {
MLXSW_SP_TRAP_DROP(SMAC_MC, L2_DROPS),
MLXSW_SP_TRAP_DROP(VLAN_TAG_MISMATCH, L2_DROPS),
MLXSW_SP_TRAP_DROP(INGRESS_VLAN_FILTER, L2_DROPS),
MLXSW_SP_TRAP_DROP(INGRESS_STP_FILTER, L2_DROPS),
MLXSW_SP_TRAP_DROP(EMPTY_TX_LIST, L2_DROPS),
MLXSW_SP_TRAP_DROP(PORT_LOOPBACK_FILTER, L2_DROPS),
MLXSW_SP_TRAP_DROP(BLACKHOLE_ROUTE, L3_DROPS),
MLXSW_SP_TRAP_DROP(NON_IP_PACKET, L3_DROPS),
MLXSW_SP_TRAP_DROP(UC_DIP_MC_DMAC, L3_DROPS),
MLXSW_SP_TRAP_DROP(DIP_LB, L3_DROPS),
MLXSW_SP_TRAP_DROP(SIP_MC, L3_DROPS),
MLXSW_SP_TRAP_DROP(SIP_LB, L3_DROPS),
MLXSW_SP_TRAP_DROP(CORRUPTED_IP_HDR, L3_DROPS),
MLXSW_SP_TRAP_DROP(IPV4_SIP_BC, L3_DROPS),
MLXSW_SP_TRAP_DROP(IPV6_MC_DIP_RESERVED_SCOPE, L3_DROPS),
MLXSW_SP_TRAP_DROP(IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(MTU_ERROR, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(TTL_ERROR, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(RPF, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(REJECT_ROUTE, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(UNRESOLVED_NEIGH, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(IPV4_LPM_UNICAST_MISS, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(IPV6_LPM_UNICAST_MISS, L3_DROPS),
MLXSW_SP_TRAP_DRIVER_DROP(IRIF_DISABLED, L3_DROPS),
MLXSW_SP_TRAP_DRIVER_DROP(ERIF_DISABLED, L3_DROPS),
MLXSW_SP_TRAP_DROP(NON_ROUTABLE, L3_DROPS),
MLXSW_SP_TRAP_EXCEPTION(DECAP_ERROR, TUNNEL_DROPS),
MLXSW_SP_TRAP_DROP(OVERLAY_SMAC_MC, TUNNEL_DROPS),
MLXSW_SP_TRAP_DROP_EXT(INGRESS_FLOW_ACTION_DROP, ACL_DROPS,
DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE),
MLXSW_SP_TRAP_DROP_EXT(EGRESS_FLOW_ACTION_DROP, ACL_DROPS,
DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE),
static const struct mlxsw_sp_trap_group_item mlxsw_sp_trap_group_items_arr[] = {
{
.group = DEVLINK_TRAP_GROUP_GENERIC(L2_DROPS, 1),
.hw_group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_L2_DISCARDS,
.priority = 0,
.tc = 1,
},
{
.group = DEVLINK_TRAP_GROUP_GENERIC(L3_DROPS, 1),
.hw_group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_L3_DISCARDS,
.priority = 0,
.tc = 1,
},
{
.group = DEVLINK_TRAP_GROUP_GENERIC(TUNNEL_DROPS, 1),
.hw_group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_TUNNEL_DISCARDS,
.priority = 0,
.tc = 1,
},
{
.group = DEVLINK_TRAP_GROUP_GENERIC(ACL_DROPS, 1),
.hw_group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_ACL_DISCARDS,
.priority = 0,
.tc = 1,
},
};
static const struct mlxsw_listener mlxsw_sp_listeners_arr[] = {
MLXSW_SP_RXL_DISCARD(ING_PACKET_SMAC_MC, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_SWITCH_VTAG_ALLOW, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_SWITCH_VLAN, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_SWITCH_STP, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(LOOKUP_SWITCH_UC, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(LOOKUP_SWITCH_MC_NULL, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(LOOKUP_SWITCH_LB, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(ROUTER2, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_NON_IP_PACKET, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_UC_DIP_MC_DMAC, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_DIP_LB, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_SIP_MC, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_SIP_LB, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_CORRUPTED_IP_HDR, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ING_ROUTER_IPV4_SIP_BC, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(IPV6_MC_DIP_RESERVED_SCOPE, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE, L3_DISCARDS),
MLXSW_SP_RXL_EXCEPTION(MTUERROR, L3_DISCARDS, TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(TTLERROR, L3_DISCARDS, TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(RPF, L3_DISCARDS, TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(RTR_INGRESS1, L3_DISCARDS, TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(HOST_MISS_IPV4, L3_DISCARDS, TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(HOST_MISS_IPV6, L3_DISCARDS, TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(DISCARD_ROUTER3, L3_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(DISCARD_ROUTER_LPM4, L3_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(DISCARD_ROUTER_LPM6, L3_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_DISCARD(ROUTER_IRIF_EN, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(ROUTER_ERIF_EN, L3_DISCARDS),
MLXSW_SP_RXL_DISCARD(NON_ROUTABLE, L3_DISCARDS),
MLXSW_SP_RXL_EXCEPTION(DECAP_ECN0, TUNNEL_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(IPIP_DECAP_ERROR, TUNNEL_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(DISCARD_DEC_PKT, TUNNEL_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_DISCARD(OVERLAY_SMAC_MC, TUNNEL_DISCARDS),
MLXSW_SP_RXL_ACL_DISCARD(INGRESS_ACL, ACL_DISCARDS, DUMMY),
MLXSW_SP_RXL_ACL_DISCARD(EGRESS_ACL, ACL_DISCARDS, DUMMY),
};
/* Mapping between hardware trap and devlink trap. Multiple hardware traps can
* be mapped to the same devlink trap. Order is according to
* 'mlxsw_sp_listeners_arr'.
*/
static const u16 mlxsw_sp_listener_devlink_map[] = {
DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
DEVLINK_TRAP_GENERIC_ID_DIP_LB,
DEVLINK_TRAP_GENERIC_ID_SIP_MC,
DEVLINK_TRAP_GENERIC_ID_SIP_LB,
DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
DEVLINK_TRAP_GENERIC_ID_RPF,
DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
DEVLINK_MLXSW_TRAP_ID_IRIF_DISABLED,
DEVLINK_MLXSW_TRAP_ID_ERIF_DISABLED,
DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
static const struct mlxsw_sp_trap_item mlxsw_sp_trap_items_arr[] = {
{
.trap = MLXSW_SP_TRAP_DROP(SMAC_MC, L2_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_PACKET_SMAC_MC, L2_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(VLAN_TAG_MISMATCH, L2_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_SWITCH_VTAG_ALLOW,
L2_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(INGRESS_VLAN_FILTER, L2_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_SWITCH_VLAN, L2_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(INGRESS_STP_FILTER, L2_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_SWITCH_STP, L2_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(EMPTY_TX_LIST, L2_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(LOOKUP_SWITCH_UC, L2_DISCARDS),
MLXSW_SP_RXL_DISCARD(LOOKUP_SWITCH_MC_NULL, L2_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(PORT_LOOPBACK_FILTER, L2_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(LOOKUP_SWITCH_LB, L2_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(BLACKHOLE_ROUTE, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ROUTER2, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(NON_IP_PACKET, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_NON_IP_PACKET,
L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(UC_DIP_MC_DMAC, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_UC_DIP_MC_DMAC,
L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(DIP_LB, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_DIP_LB, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(SIP_MC, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_SIP_MC, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(SIP_LB, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_SIP_LB, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(CORRUPTED_IP_HDR, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_CORRUPTED_IP_HDR,
L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(IPV4_SIP_BC, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ING_ROUTER_IPV4_SIP_BC,
L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(IPV6_MC_DIP_RESERVED_SCOPE,
L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(IPV6_MC_DIP_RESERVED_SCOPE,
L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(MTU_ERROR, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(MTUERROR, L3_DISCARDS,
TRAP_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(TTL_ERROR, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(TTLERROR, L3_DISCARDS,
TRAP_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(RPF, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(RPF, L3_DISCARDS, TRAP_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(REJECT_ROUTE, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(RTR_INGRESS1, L3_DISCARDS,
TRAP_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(UNRESOLVED_NEIGH, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(HOST_MISS_IPV4, L3_DISCARDS,
TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(HOST_MISS_IPV6, L3_DISCARDS,
TRAP_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(DISCARD_ROUTER3, L3_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(IPV4_LPM_UNICAST_MISS,
L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(DISCARD_ROUTER_LPM4, L3_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(IPV6_LPM_UNICAST_MISS,
L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(DISCARD_ROUTER_LPM6, L3_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_DRIVER_DROP(IRIF_DISABLED, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ROUTER_IRIF_EN, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DRIVER_DROP(ERIF_DISABLED, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(ROUTER_ERIF_EN, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(NON_ROUTABLE, L3_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(NON_ROUTABLE, L3_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_EXCEPTION(DECAP_ERROR, TUNNEL_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_EXCEPTION(DECAP_ECN0, TUNNEL_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(IPIP_DECAP_ERROR,
TUNNEL_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
MLXSW_SP_RXL_EXCEPTION(DISCARD_DEC_PKT, TUNNEL_DISCARDS,
TRAP_EXCEPTION_TO_CPU),
},
},
{
.trap = MLXSW_SP_TRAP_DROP(OVERLAY_SMAC_MC, TUNNEL_DROPS),
.listeners_arr = {
MLXSW_SP_RXL_DISCARD(OVERLAY_SMAC_MC, TUNNEL_DISCARDS),
},
},
{
.trap = MLXSW_SP_TRAP_DROP_EXT(INGRESS_FLOW_ACTION_DROP,
ACL_DROPS,
DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE),
.listeners_arr = {
MLXSW_SP_RXL_ACL_DISCARD(INGRESS_ACL, ACL_DISCARDS,
DUMMY),
},
},
{
.trap = MLXSW_SP_TRAP_DROP_EXT(EGRESS_FLOW_ACTION_DROP,
ACL_DROPS,
DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE),
.listeners_arr = {
MLXSW_SP_RXL_ACL_DISCARD(EGRESS_ACL, ACL_DISCARDS,
DUMMY),
},
},
};
#define MLXSW_SP_THIN_POLICER_ID (MLXSW_REG_HTGT_TRAP_GROUP_MAX + 1)
......@@ -313,12 +451,40 @@ static const u16 mlxsw_sp_listener_devlink_map[] = {
static struct mlxsw_sp_trap_policer_item *
mlxsw_sp_trap_policer_item_lookup(struct mlxsw_sp *mlxsw_sp, u32 id)
{
struct mlxsw_sp_trap_policer_item *policer_item;
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int i;
list_for_each_entry(policer_item, &trap->policer_item_list, list) {
if (policer_item->id == id)
return policer_item;
for (i = 0; i < trap->policers_count; i++) {
if (trap->policer_items_arr[i].policer.id == id)
return &trap->policer_items_arr[i];
}
return NULL;
}
static struct mlxsw_sp_trap_group_item *
mlxsw_sp_trap_group_item_lookup(struct mlxsw_sp *mlxsw_sp, u16 id)
{
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int i;
for (i = 0; i < trap->groups_count; i++) {
if (trap->group_items_arr[i].group.id == id)
return &trap->group_items_arr[i];
}
return NULL;
}
static struct mlxsw_sp_trap_item *
mlxsw_sp_trap_item_lookup(struct mlxsw_sp *mlxsw_sp, u16 id)
{
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int i;
for (i = 0; i < trap->traps_count; i++) {
if (trap->trap_items_arr[i].trap.id == id)
return &trap->trap_items_arr[i];
}
return NULL;
......@@ -346,78 +512,210 @@ static int mlxsw_sp_trap_dummy_group_init(struct mlxsw_sp *mlxsw_sp)
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(htgt), htgt_pl);
}
static int mlxsw_sp_trap_policers_init(struct mlxsw_sp *mlxsw_sp)
static int mlxsw_sp_trap_policer_items_arr_init(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
size_t elem_size = sizeof(struct mlxsw_sp_trap_policer_item);
u64 arr_size = ARRAY_SIZE(mlxsw_sp_trap_policer_items_arr);
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
u64 free_policers = 0;
u32 last_id = 0;
int err, i;
u32 last_id;
int i;
for_each_clear_bit(i, trap->policers_usage, trap->max_policers)
free_policers++;
if (ARRAY_SIZE(mlxsw_sp_trap_policers_arr) > free_policers) {
if (arr_size > free_policers) {
dev_err(mlxsw_sp->bus_info->dev, "Exceeded number of supported packet trap policers\n");
return -ENOBUFS;
}
trap->policers_arr = kcalloc(free_policers,
sizeof(struct devlink_trap_policer),
GFP_KERNEL);
if (!trap->policers_arr)
trap->policer_items_arr = kcalloc(free_policers, elem_size, GFP_KERNEL);
if (!trap->policer_items_arr)
return -ENOMEM;
trap->policers_count = free_policers;
for (i = 0; i < free_policers; i++) {
const struct devlink_trap_policer *policer;
if (i < ARRAY_SIZE(mlxsw_sp_trap_policers_arr)) {
policer = &mlxsw_sp_trap_policers_arr[i];
trap->policers_arr[i] = *policer;
last_id = policer->id;
} else {
/* Use parameters set for first policer and override
* relevant ones.
*/
policer = &mlxsw_sp_trap_policers_arr[0];
trap->policers_arr[i] = *policer;
trap->policers_arr[i].id = ++last_id;
trap->policers_arr[i].init_rate = 1;
trap->policers_arr[i].init_burst = 16;
}
/* Initialize policer items array with pre-defined policers. */
memcpy(trap->policer_items_arr, mlxsw_sp_trap_policer_items_arr,
elem_size * arr_size);
/* Initialize policer items array with the rest of the available
* policers.
*/
last_id = mlxsw_sp_trap_policer_items_arr[arr_size - 1].policer.id;
for (i = arr_size; i < trap->policers_count; i++) {
const struct mlxsw_sp_trap_policer_item *policer_item;
/* Use parameters set for first policer and override
* relevant ones.
*/
policer_item = &mlxsw_sp_trap_policer_items_arr[0];
trap->policer_items_arr[i] = *policer_item;
trap->policer_items_arr[i].policer.id = ++last_id;
trap->policer_items_arr[i].policer.init_rate = 1;
trap->policer_items_arr[i].policer.init_burst = 16;
}
INIT_LIST_HEAD(&trap->policer_item_list);
return 0;
}
static void mlxsw_sp_trap_policer_items_arr_fini(struct mlxsw_sp *mlxsw_sp)
{
kfree(mlxsw_sp->trap->policer_items_arr);
}
err = devlink_trap_policers_register(devlink, trap->policers_arr,
trap->policers_count);
static int mlxsw_sp_trap_policers_init(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
const struct mlxsw_sp_trap_policer_item *policer_item;
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int err, i;
err = mlxsw_sp_trap_policer_items_arr_init(mlxsw_sp);
if (err)
goto err_trap_policers_register;
return err;
for (i = 0; i < trap->policers_count; i++) {
policer_item = &trap->policer_items_arr[i];
err = devlink_trap_policers_register(devlink,
&policer_item->policer, 1);
if (err)
goto err_trap_policer_register;
}
return 0;
err_trap_policers_register:
kfree(trap->policers_arr);
err_trap_policer_register:
for (i--; i >= 0; i--) {
policer_item = &trap->policer_items_arr[i];
devlink_trap_policers_unregister(devlink,
&policer_item->policer, 1);
}
mlxsw_sp_trap_policer_items_arr_fini(mlxsw_sp);
return err;
}
static void mlxsw_sp_trap_policers_fini(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
const struct mlxsw_sp_trap_policer_item *policer_item;
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int i;
devlink_trap_policers_unregister(devlink, trap->policers_arr,
trap->policers_count);
WARN_ON(!list_empty(&trap->policer_item_list));
kfree(trap->policers_arr);
for (i = trap->policers_count - 1; i >= 0; i--) {
policer_item = &trap->policer_items_arr[i];
devlink_trap_policers_unregister(devlink,
&policer_item->policer, 1);
}
mlxsw_sp_trap_policer_items_arr_fini(mlxsw_sp);
}
int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp)
static int mlxsw_sp_trap_groups_init(struct mlxsw_sp *mlxsw_sp)
{
size_t groups_count = ARRAY_SIZE(mlxsw_sp_trap_groups_arr);
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
const struct mlxsw_sp_trap_group_item *group_item;
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int err, i;
trap->group_items_arr = kmemdup(mlxsw_sp_trap_group_items_arr,
sizeof(mlxsw_sp_trap_group_items_arr),
GFP_KERNEL);
if (!trap->group_items_arr)
return -ENOMEM;
trap->groups_count = ARRAY_SIZE(mlxsw_sp_trap_group_items_arr);
for (i = 0; i < trap->groups_count; i++) {
group_item = &trap->group_items_arr[i];
err = devlink_trap_groups_register(devlink, &group_item->group,
1);
if (err)
goto err_trap_group_register;
}
return 0;
err_trap_group_register:
for (i--; i >= 0; i--) {
group_item = &trap->group_items_arr[i];
devlink_trap_groups_unregister(devlink, &group_item->group, 1);
}
kfree(trap->group_items_arr);
return err;
}
static void mlxsw_sp_trap_groups_fini(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int i;
for (i = trap->groups_count - 1; i >= 0; i--) {
const struct mlxsw_sp_trap_group_item *group_item;
group_item = &trap->group_items_arr[i];
devlink_trap_groups_unregister(devlink, &group_item->group, 1);
}
kfree(trap->group_items_arr);
}
static bool
mlxsw_sp_trap_listener_is_valid(const struct mlxsw_listener *listener)
{
return listener->trap_id != 0;
}
static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
const struct mlxsw_sp_trap_item *trap_item;
int err, i;
trap->trap_items_arr = kmemdup(mlxsw_sp_trap_items_arr,
sizeof(mlxsw_sp_trap_items_arr),
GFP_KERNEL);
if (!trap->trap_items_arr)
return -ENOMEM;
trap->traps_count = ARRAY_SIZE(mlxsw_sp_trap_items_arr);
for (i = 0; i < trap->traps_count; i++) {
trap_item = &trap->trap_items_arr[i];
err = devlink_traps_register(devlink, &trap_item->trap, 1,
mlxsw_sp);
if (err)
goto err_trap_register;
}
return 0;
err_trap_register:
for (i--; i >= 0; i--) {
trap_item = &trap->trap_items_arr[i];
devlink_traps_unregister(devlink, &trap_item->trap, 1);
}
kfree(trap->trap_items_arr);
return err;
}
static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int i;
for (i = trap->traps_count - 1; i >= 0; i--) {
const struct mlxsw_sp_trap_item *trap_item;
trap_item = &trap->trap_items_arr[i];
devlink_traps_unregister(devlink, &trap_item->trap, 1);
}
kfree(trap->trap_items_arr);
}
int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp)
{
int err;
err = mlxsw_sp_trap_cpu_policers_set(mlxsw_sp);
......@@ -428,59 +726,52 @@ int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp)
if (err)
return err;
if (WARN_ON(ARRAY_SIZE(mlxsw_sp_listener_devlink_map) !=
ARRAY_SIZE(mlxsw_sp_listeners_arr)))
return -EINVAL;
err = mlxsw_sp_trap_policers_init(mlxsw_sp);
if (err)
return err;
err = devlink_trap_groups_register(devlink, mlxsw_sp_trap_groups_arr,
groups_count);
err = mlxsw_sp_trap_groups_init(mlxsw_sp);
if (err)
goto err_trap_groups_register;
goto err_trap_groups_init;
err = devlink_traps_register(devlink, mlxsw_sp_traps_arr,
ARRAY_SIZE(mlxsw_sp_traps_arr), mlxsw_sp);
err = mlxsw_sp_traps_init(mlxsw_sp);
if (err)
goto err_traps_register;
goto err_traps_init;
return 0;
err_traps_register:
devlink_trap_groups_unregister(devlink, mlxsw_sp_trap_groups_arr,
groups_count);
err_trap_groups_register:
err_traps_init:
mlxsw_sp_trap_groups_fini(mlxsw_sp);
err_trap_groups_init:
mlxsw_sp_trap_policers_fini(mlxsw_sp);
return err;
}
void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp)
{
size_t groups_count = ARRAY_SIZE(mlxsw_sp_trap_groups_arr);
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
devlink_traps_unregister(devlink, mlxsw_sp_traps_arr,
ARRAY_SIZE(mlxsw_sp_traps_arr));
devlink_trap_groups_unregister(devlink, mlxsw_sp_trap_groups_arr,
groups_count);
mlxsw_sp_traps_fini(mlxsw_sp);
mlxsw_sp_trap_groups_fini(mlxsw_sp);
mlxsw_sp_trap_policers_fini(mlxsw_sp);
}
int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
const struct devlink_trap *trap, void *trap_ctx)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
const struct mlxsw_sp_trap_item *trap_item;
int i;
for (i = 0; i < ARRAY_SIZE(mlxsw_sp_listener_devlink_map); i++) {
trap_item = mlxsw_sp_trap_item_lookup(mlxsw_sp, trap->id);
if (WARN_ON(!trap_item))
return -EINVAL;
for (i = 0; i < MLXSW_SP_TRAP_LISTENERS_MAX; i++) {
const struct mlxsw_listener *listener;
int err;
if (mlxsw_sp_listener_devlink_map[i] != trap->id)
listener = &trap_item->listeners_arr[i];
if (!mlxsw_sp_trap_listener_is_valid(listener))
continue;
listener = &mlxsw_sp_listeners_arr[i];
err = mlxsw_core_trap_register(mlxsw_core, listener, trap_ctx);
if (err)
return err;
......@@ -492,15 +783,20 @@ int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
const struct devlink_trap *trap, void *trap_ctx)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
const struct mlxsw_sp_trap_item *trap_item;
int i;
for (i = 0; i < ARRAY_SIZE(mlxsw_sp_listener_devlink_map); i++) {
trap_item = mlxsw_sp_trap_item_lookup(mlxsw_sp, trap->id);
if (WARN_ON(!trap_item))
return;
for (i = MLXSW_SP_TRAP_LISTENERS_MAX - 1; i >= 0; i--) {
const struct mlxsw_listener *listener;
if (mlxsw_sp_listener_devlink_map[i] != trap->id)
listener = &trap_item->listeners_arr[i];
if (!mlxsw_sp_trap_listener_is_valid(listener))
continue;
listener = &mlxsw_sp_listeners_arr[i];
mlxsw_core_trap_unregister(mlxsw_core, listener, trap_ctx);
}
}
......@@ -509,16 +805,23 @@ int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
const struct devlink_trap *trap,
enum devlink_trap_action action)
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
const struct mlxsw_sp_trap_item *trap_item;
int i;
for (i = 0; i < ARRAY_SIZE(mlxsw_sp_listener_devlink_map); i++) {
trap_item = mlxsw_sp_trap_item_lookup(mlxsw_sp, trap->id);
if (WARN_ON(!trap_item))
return -EINVAL;
for (i = 0; i < MLXSW_SP_TRAP_LISTENERS_MAX; i++) {
const struct mlxsw_listener *listener;
bool enabled;
int err;
if (mlxsw_sp_listener_devlink_map[i] != trap->id)
listener = &trap_item->listeners_arr[i];
if (!mlxsw_sp_trap_listener_is_valid(listener))
continue;
listener = &mlxsw_sp_listeners_arr[i];
switch (action) {
case DEVLINK_TRAP_ACTION_DROP:
enabled = false;
......@@ -544,33 +847,12 @@ __mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
{
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
u16 hw_policer_id = MLXSW_REG_HTGT_INVALID_POLICER;
const struct mlxsw_sp_trap_group_item *group_item;
char htgt_pl[MLXSW_REG_HTGT_LEN];
u8 priority, tc, group_id;
switch (group->id) {
case DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS:
group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_L2_DISCARDS;
priority = 0;
tc = 1;
break;
case DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS:
group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_L3_DISCARDS;
priority = 0;
tc = 1;
break;
case DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS:
group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_TUNNEL_DISCARDS;
priority = 0;
tc = 1;
break;
case DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS:
group_id = MLXSW_REG_HTGT_TRAP_GROUP_SP_ACL_DISCARDS;
priority = 0;
tc = 1;
break;
default:
group_item = mlxsw_sp_trap_group_item_lookup(mlxsw_sp, group->id);
if (WARN_ON(!group_item))
return -EINVAL;
}
if (policer_id) {
struct mlxsw_sp_trap_policer_item *policer_item;
......@@ -582,7 +864,8 @@ __mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
hw_policer_id = policer_item->hw_id;
}
mlxsw_reg_htgt_pack(htgt_pl, group_id, hw_policer_id, priority, tc);
mlxsw_reg_htgt_pack(htgt_pl, group_item->hw_group_id, hw_policer_id,
group_item->priority, group_item->tc);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
}
......@@ -602,10 +885,10 @@ int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
return __mlxsw_sp_trap_group_init(mlxsw_core, group, policer_id);
}
static struct mlxsw_sp_trap_policer_item *
mlxsw_sp_trap_policer_item_init(struct mlxsw_sp *mlxsw_sp, u32 id)
static int
mlxsw_sp_trap_policer_item_init(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_trap_policer_item *policer_item)
{
struct mlxsw_sp_trap_policer_item *policer_item;
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
u16 hw_id;
......@@ -615,27 +898,19 @@ mlxsw_sp_trap_policer_item_init(struct mlxsw_sp *mlxsw_sp, u32 id)
*/
hw_id = find_first_zero_bit(trap->policers_usage, trap->max_policers);
if (WARN_ON(hw_id == trap->max_policers))
return ERR_PTR(-ENOBUFS);
policer_item = kzalloc(sizeof(*policer_item), GFP_KERNEL);
if (!policer_item)
return ERR_PTR(-ENOMEM);
return -ENOBUFS;
__set_bit(hw_id, trap->policers_usage);
policer_item->hw_id = hw_id;
policer_item->id = id;
list_add_tail(&policer_item->list, &trap->policer_item_list);
return policer_item;
return 0;
}
static void
mlxsw_sp_trap_policer_item_fini(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_trap_policer_item *policer_item)
{
list_del(&policer_item->list);
__clear_bit(policer_item->hw_id, mlxsw_sp->trap->policers_usage);
kfree(policer_item);
}
static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
......@@ -678,9 +953,13 @@ int mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
struct mlxsw_sp_trap_policer_item *policer_item;
int err;
policer_item = mlxsw_sp_trap_policer_item_init(mlxsw_sp, policer->id);
if (IS_ERR(policer_item))
return PTR_ERR(policer_item);
policer_item = mlxsw_sp_trap_policer_item_lookup(mlxsw_sp, policer->id);
if (WARN_ON(!policer_item))
return -EINVAL;
err = mlxsw_sp_trap_policer_item_init(mlxsw_sp, policer_item);
if (err)
return err;
err = __mlxsw_sp_trap_policer_set(mlxsw_sp, policer_item->hw_id,
policer->init_rate,
......
......@@ -8,17 +8,17 @@
#include <net/devlink.h>
struct mlxsw_sp_trap {
struct devlink_trap_policer *policers_arr; /* Registered policers */
struct mlxsw_sp_trap_policer_item *policer_items_arr;
u64 policers_count; /* Number of registered policers */
struct list_head policer_item_list;
struct mlxsw_sp_trap_group_item *group_items_arr;
u64 groups_count; /* Number of registered groups */
struct mlxsw_sp_trap_item *trap_items_arr;
u64 traps_count; /* Number of registered traps */
u64 max_policers;
unsigned long policers_usage[]; /* Usage bitmap */
};
struct mlxsw_sp_trap_policer_item {
u16 hw_id;
u32 id;
struct list_head list; /* Member of policer_item_list */
};
#endif
......@@ -107,7 +107,7 @@ ingress_flow_action_drop_test()
RET=0
devlink_trap_drop_test ingress_flow_action_drop acl_drops $swp2 101
devlink_trap_drop_test ingress_flow_action_drop $swp2 101
log_test "ingress_flow_action_drop"
......@@ -132,7 +132,7 @@ egress_flow_action_drop_test()
RET=0
devlink_trap_drop_test egress_flow_action_drop acl_drops $swp2 102
devlink_trap_drop_test egress_flow_action_drop $swp2 102
log_test "egress_flow_action_drop"
......
......@@ -96,7 +96,6 @@ source_mac_is_multicast_test()
{
local trap_name="source_mac_is_multicast"
local smac=01:02:03:04:05:06
local group_name="l2_drops"
local mz_pid
tc filter add dev $swp2 egress protocol ip pref 1 handle 101 \
......@@ -107,7 +106,7 @@ source_mac_is_multicast_test()
RET=0
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
log_test "Source MAC is multicast"
......@@ -118,7 +117,6 @@ __vlan_tag_mismatch_test()
{
local trap_name="vlan_tag_mismatch"
local dmac=de:ad:be:ef:13:37
local group_name="l2_drops"
local opt=$1; shift
local mz_pid
......@@ -132,7 +130,7 @@ __vlan_tag_mismatch_test()
$MZ $h1 "$opt" -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
# Add PVID and make sure packets are no longer dropped.
bridge vlan add vid 1 dev $swp1 pvid untagged master
......@@ -140,7 +138,7 @@ __vlan_tag_mismatch_test()
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle when packets should not be dropped"
devlink_trap_group_stats_idle_test $group_name
devlink_trap_group_stats_idle_test $(devlink_trap_group_get $trap_name)
check_err $? "Trap group stats not idle with when packets should not be dropped"
tc_check_packets "dev $swp2 egress" 101 0
......@@ -179,7 +177,6 @@ ingress_vlan_filter_test()
{
local trap_name="ingress_vlan_filter"
local dmac=de:ad:be:ef:13:37
local group_name="l2_drops"
local mz_pid
local vid=10
......@@ -193,7 +190,7 @@ ingress_vlan_filter_test()
$MZ $h1 -Q $vid -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
# Add the VLAN on the bridge port and make sure packets are no longer
# dropped.
......@@ -202,7 +199,7 @@ ingress_vlan_filter_test()
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle when packets should not be dropped"
devlink_trap_group_stats_idle_test $group_name
devlink_trap_group_stats_idle_test $(devlink_trap_group_get $trap_name)
check_err $? "Trap group stats not idle with when packets should not be dropped"
tc_check_packets "dev $swp2 egress" 101 0
......@@ -222,7 +219,6 @@ __ingress_stp_filter_test()
{
local trap_name="ingress_spanning_tree_filter"
local dmac=de:ad:be:ef:13:37
local group_name="l2_drops"
local state=$1; shift
local mz_pid
local vid=20
......@@ -237,7 +233,7 @@ __ingress_stp_filter_test()
$MZ $h1 -Q $vid -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
# Change STP state to forwarding and make sure packets are no longer
# dropped.
......@@ -246,7 +242,7 @@ __ingress_stp_filter_test()
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle when packets should not be dropped"
devlink_trap_group_stats_idle_test $group_name
devlink_trap_group_stats_idle_test $(devlink_trap_group_get $trap_name)
check_err $? "Trap group stats not idle with when packets should not be dropped"
tc_check_packets "dev $swp2 egress" 101 0
......@@ -292,7 +288,6 @@ port_list_is_empty_uc_test()
{
local trap_name="port_list_is_empty"
local dmac=de:ad:be:ef:13:37
local group_name="l2_drops"
local mz_pid
# Disable unicast flooding on both ports, so that packets cannot egress
......@@ -308,7 +303,7 @@ port_list_is_empty_uc_test()
$MZ $h1 -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
# Allow packets to be flooded to one port.
ip link set dev $swp2 type bridge_slave flood on
......@@ -316,7 +311,7 @@ port_list_is_empty_uc_test()
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle when packets should not be dropped"
devlink_trap_group_stats_idle_test $group_name
devlink_trap_group_stats_idle_test $(devlink_trap_group_get $trap_name)
check_err $? "Trap group stats not idle with when packets should not be dropped"
tc_check_packets "dev $swp2 egress" 101 0
......@@ -335,7 +330,6 @@ port_list_is_empty_mc_test()
{
local trap_name="port_list_is_empty"
local dmac=01:00:5e:00:00:01
local group_name="l2_drops"
local dip=239.0.0.1
local mz_pid
......@@ -354,7 +348,7 @@ port_list_is_empty_mc_test()
$MZ $h1 -c 0 -p 100 -a own -b $dmac -t ip -B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
# Allow packets to be flooded to one port.
ip link set dev $swp2 type bridge_slave mcast_flood on
......@@ -362,7 +356,7 @@ port_list_is_empty_mc_test()
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle when packets should not be dropped"
devlink_trap_group_stats_idle_test $group_name
devlink_trap_group_stats_idle_test $(devlink_trap_group_get $trap_name)
check_err $? "Trap group stats not idle with when packets should not be dropped"
tc_check_packets "dev $swp2 egress" 101 0
......@@ -387,7 +381,6 @@ port_loopback_filter_uc_test()
{
local trap_name="port_loopback_filter"
local dmac=de:ad:be:ef:13:37
local group_name="l2_drops"
local mz_pid
# Make sure packets can only egress the input port.
......@@ -401,7 +394,7 @@ port_loopback_filter_uc_test()
$MZ $h1 -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp2 101
devlink_trap_drop_test $trap_name $swp2 101
# Allow packets to be flooded.
ip link set dev $swp2 type bridge_slave flood on
......@@ -409,7 +402,7 @@ port_loopback_filter_uc_test()
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle when packets should not be dropped"
devlink_trap_group_stats_idle_test $group_name
devlink_trap_group_stats_idle_test $(devlink_trap_group_get $trap_name)
check_err $? "Trap group stats not idle with when packets should not be dropped"
tc_check_packets "dev $swp2 egress" 101 0
......
......@@ -161,7 +161,6 @@ ping_check()
non_ip_test()
{
local trap_name="non_ip"
local group_name="l3_drops"
local mz_pid
RET=0
......@@ -176,7 +175,7 @@ non_ip_test()
00:00 de:ad:be:ef" &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "Non IP"
......@@ -190,7 +189,6 @@ __uc_dip_over_mc_dmac_test()
local dip=$1; shift
local flags=${1:-""}; shift
local trap_name="uc_dip_over_mc_dmac"
local group_name="l3_drops"
local dmac=01:02:03:04:05:06
local mz_pid
......@@ -206,7 +204,7 @@ __uc_dip_over_mc_dmac_test()
-B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "Unicast destination IP over multicast destination MAC: $desc"
......@@ -227,7 +225,6 @@ __sip_is_loopback_test()
local dip=$1; shift
local flags=${1:-""}; shift
local trap_name="sip_is_loopback_address"
local group_name="l3_drops"
local mz_pid
RET=0
......@@ -242,7 +239,7 @@ __sip_is_loopback_test()
-b $rp1mac -B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "Source IP is loopback address: $desc"
......@@ -262,7 +259,6 @@ __dip_is_loopback_test()
local dip=$1; shift
local flags=${1:-""}; shift
local trap_name="dip_is_loopback_address"
local group_name="l3_drops"
local mz_pid
RET=0
......@@ -277,7 +273,7 @@ __dip_is_loopback_test()
-B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "Destination IP is loopback address: $desc"
......@@ -298,7 +294,6 @@ __sip_is_mc_test()
local dip=$1; shift
local flags=${1:-""}; shift
local trap_name="sip_is_mc"
local group_name="l3_drops"
local mz_pid
RET=0
......@@ -313,7 +308,7 @@ __sip_is_mc_test()
-b $rp1mac -B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "Source IP is multicast: $desc"
......@@ -329,7 +324,6 @@ sip_is_mc_test()
ipv4_sip_is_limited_bc_test()
{
local trap_name="ipv4_sip_is_limited_bc"
local group_name="l3_drops"
local sip=255.255.255.255
local mz_pid
......@@ -345,7 +339,7 @@ ipv4_sip_is_limited_bc_test()
-B $h2_ipv4 -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "IPv4 source IP is limited broadcast"
......@@ -382,7 +376,6 @@ __ipv4_header_corrupted_test()
local ihl=$1; shift
local checksum=$1; shift
local trap_name="ip_header_corrupted"
local group_name="l3_drops"
local payload
local mz_pid
......@@ -399,7 +392,7 @@ __ipv4_header_corrupted_test()
$MZ $h1 -c 0 -d 1msec -a $h1mac -b $rp1mac -q p=$payload &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "IP header corrupted: $desc: IPv4"
......@@ -429,7 +422,6 @@ __ipv6_header_corrupted_test()
local desc=$1; shift
local ipver=$1; shift
local trap_name="ip_header_corrupted"
local group_name="l3_drops"
local payload
local mz_pid
......@@ -446,7 +438,7 @@ __ipv6_header_corrupted_test()
$MZ $h1 -c 0 -d 1msec -a $h1mac -b $rp1mac -q p=$payload &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "IP header corrupted: $desc: IPv6"
......@@ -469,7 +461,6 @@ ip_header_corrupted_test()
ipv6_mc_dip_reserved_scope_test()
{
local trap_name="ipv6_mc_dip_reserved_scope"
local group_name="l3_drops"
local dip=FF00::
local mz_pid
......@@ -485,7 +476,7 @@ ipv6_mc_dip_reserved_scope_test()
"33:33:00:00:00:00" -B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "IPv6 multicast destination IP reserved scope"
......@@ -495,7 +486,6 @@ ipv6_mc_dip_reserved_scope_test()
ipv6_mc_dip_interface_local_scope_test()
{
local trap_name="ipv6_mc_dip_interface_local_scope"
local group_name="l3_drops"
local dip=FF01::
local mz_pid
......@@ -511,7 +501,7 @@ ipv6_mc_dip_interface_local_scope_test()
"33:33:00:00:00:00" -B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "IPv6 multicast destination IP interface-local scope"
......@@ -526,7 +516,6 @@ __blackhole_route_test()
local dip=$1; shift
local ip_proto=${1:-"icmp"}; shift
local trap_name="blackhole_route"
local group_name="l3_drops"
local mz_pid
RET=0
......@@ -542,7 +531,7 @@ __blackhole_route_test()
-B $dip -d 1msec -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $rp2 101
devlink_trap_drop_test $trap_name $rp2 101
log_test "Blackhole route: IPv$flags"
devlink_trap_drop_cleanup $mz_pid $rp2 $proto 1 101
......@@ -558,7 +547,6 @@ blackhole_route_test()
irif_disabled_test()
{
local trap_name="irif_disabled"
local group_name="l3_drops"
local t0_packets t0_bytes
local t1_packets t1_bytes
local mz_pid
......@@ -613,7 +601,6 @@ irif_disabled_test()
erif_disabled_test()
{
local trap_name="erif_disabled"
local group_name="l3_drops"
local t0_packets t0_bytes
local t1_packets t1_bytes
local mz_pid
......
......@@ -169,7 +169,6 @@ trap_action_check()
mtu_value_is_too_small_test()
{
local trap_name="mtu_value_is_too_small"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -191,7 +190,7 @@ mtu_value_is_too_small_test()
-B 198.51.100.1 -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets_hitting "dev $h1 ingress" 101
check_err $? "Packets were not received to h1"
......@@ -208,7 +207,6 @@ __ttl_value_is_too_small_test()
{
local ttl_val=$1; shift
local trap_name="ttl_value_is_too_small"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -227,7 +225,7 @@ __ttl_value_is_too_small_test()
-b $rp1mac -B 198.51.100.1 -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets_hitting "dev $h1 ingress" 101
check_err $? "Packets were not received to h1"
......@@ -271,7 +269,6 @@ __mc_reverse_path_forwarding_test()
local proto=$1; shift
local flags=${1:-""}; shift
local trap_name="mc_reverse_path_forwarding"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -292,7 +289,7 @@ __mc_reverse_path_forwarding_test()
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets "dev $rp2 egress" 101 0
check_err $? "Packets were not dropped"
......@@ -322,7 +319,6 @@ __reject_route_test()
local unreachable=$1; shift
local flags=${1:-""}; shift
local trap_name="reject_route"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -341,7 +337,7 @@ __reject_route_test()
-B $dst_ip -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets_hitting "dev $h1 ingress" 101
check_err $? "ICMP packet was not received to h1"
......@@ -370,7 +366,6 @@ __host_miss_test()
local desc=$1; shift
local dip=$1; shift
local trap_name="unresolved_neigh"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -405,7 +400,6 @@ __invalid_nexthop_test()
local subnet=$1; shift
local via_add=$1; shift
local trap_name="unresolved_neigh"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -494,7 +488,6 @@ vrf_without_routes_destroy()
ipv4_lpm_miss_test()
{
local trap_name="ipv4_lpm_miss"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -511,7 +504,7 @@ ipv4_lpm_miss_test()
-B 203.0.113.1 -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
log_test "LPM miss: IPv4"
......@@ -522,7 +515,6 @@ ipv4_lpm_miss_test()
ipv6_lpm_miss_test()
{
local trap_name="ipv6_lpm_miss"
local group_name="l3_drops"
local expected_action="trap"
local mz_pid
......@@ -539,7 +531,7 @@ ipv6_lpm_miss_test()
-B 2001:db8::1 -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
log_test "LPM miss: IPv6"
......
......@@ -140,7 +140,6 @@ ecn_payload_get()
ecn_decap_test()
{
local trap_name="decap_error"
local group_name="tunnel_drops"
local desc=$1; shift
local ecn_desc=$1; shift
local outer_tos=$1; shift
......@@ -161,7 +160,7 @@ ecn_decap_test()
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets "dev $swp1 egress" 101 0
check_err $? "Packets were not dropped"
......@@ -200,7 +199,6 @@ ipip_payload_get()
no_matching_tunnel_test()
{
local trap_name="decap_error"
local group_name="tunnel_drops"
local desc=$1; shift
local sip=$1; shift
local mz_pid
......@@ -218,7 +216,7 @@ no_matching_tunnel_test()
-A $sip -B 192.0.2.65 -t ip len=48,proto=47,p=$payload -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets "dev $swp1 egress" 101 0
check_err $? "Packets were not dropped"
......
......@@ -159,7 +159,6 @@ ecn_payload_get()
ecn_decap_test()
{
local trap_name="decap_error"
local group_name="tunnel_drops"
local desc=$1; shift
local ecn_desc=$1; shift
local outer_tos=$1; shift
......@@ -177,7 +176,7 @@ ecn_decap_test()
-t udp sp=12345,dp=$VXPORT,tos=$outer_tos,p=$payload -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets "dev $swp1 egress" 101 0
check_err $? "Packets were not dropped"
......@@ -228,7 +227,6 @@ short_payload_get()
corrupted_packet_test()
{
local trap_name="decap_error"
local group_name="tunnel_drops"
local desc=$1; shift
local payload_get=$1; shift
local mz_pid
......@@ -246,7 +244,7 @@ corrupted_packet_test()
-B 192.0.2.17 -t udp sp=12345,dp=$VXPORT,p=$payload -q &
mz_pid=$!
devlink_trap_exception_test $trap_name $group_name
devlink_trap_exception_test $trap_name
tc_check_packets "dev $swp1 egress" 101 0
check_err $? "Packets were not dropped"
......@@ -297,7 +295,6 @@ mc_smac_payload_get()
overlay_smac_is_mc_test()
{
local trap_name="overlay_smac_is_mc"
local group_name="tunnel_drops"
local mz_pid
RET=0
......@@ -314,7 +311,7 @@ overlay_smac_is_mc_test()
-B 192.0.2.17 -t udp sp=12345,dp=$VXPORT,p=$payload -q &
mz_pid=$!
devlink_trap_drop_test $trap_name $group_name $swp1 101
devlink_trap_drop_test $trap_name $swp1 101
log_test "Overlay source MAC is multicast"
......
......@@ -365,7 +365,9 @@ devlink_trap_group_stats_idle_test()
devlink_trap_exception_test()
{
local trap_name=$1; shift
local group_name=$1; shift
local group_name
group_name=$(devlink_trap_group_get $trap_name)
devlink_trap_stats_idle_test $trap_name
check_fail $? "Trap stats idle when packets should have been trapped"
......@@ -377,9 +379,11 @@ devlink_trap_exception_test()
devlink_trap_drop_test()
{
local trap_name=$1; shift
local group_name=$1; shift
local dev=$1; shift
local handle=$1; shift
local group_name
group_name=$(devlink_trap_group_get $trap_name)
# This is the common part of all the tests. It checks that stats are
# initially idle, then non-idle after changing the trap action and
......@@ -390,7 +394,6 @@ devlink_trap_drop_test()
devlink_trap_group_stats_idle_test $group_name
check_err $? "Trap group stats not idle with initial drop action"
devlink_trap_action_set $trap_name "trap"
devlink_trap_stats_idle_test $trap_name
check_fail $? "Trap stats idle after setting action to trap"
......
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