Skip to content

Commit 6de9fce

Browse files
jpirkodavem330
authored andcommitted
mlxsw: spectrum_trap: Lookup and pass cookie down to devlink_trap_report()
Use the cookie index received along with the packet to lookup original flow_offload cookie binary and pass it down to devlink_trap_report(). Add "fa_cookie" metadata to the ACL trap. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 78a7dcb commit 6de9fce

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,22 @@ static void mlxsw_afa_cookie_put(struct mlxsw_afa *mlxsw_afa,
769769
mlxsw_afa_cookie_destroy(mlxsw_afa, cookie);
770770
}
771771

772+
/* RCU read lock must be held */
773+
const struct flow_action_cookie *
774+
mlxsw_afa_cookie_lookup(struct mlxsw_afa *mlxsw_afa, u32 cookie_index)
775+
{
776+
struct mlxsw_afa_cookie *cookie;
777+
778+
/* 0 index means no cookie */
779+
if (!cookie_index)
780+
return NULL;
781+
cookie = idr_find(&mlxsw_afa->cookie_idr, cookie_index);
782+
if (!cookie)
783+
return NULL;
784+
return &cookie->fa_cookie;
785+
}
786+
EXPORT_SYMBOL(mlxsw_afa_cookie_lookup);
787+
772788
struct mlxsw_afa_cookie_ref {
773789
struct mlxsw_afa_resource resource;
774790
struct mlxsw_afa_cookie *cookie;

drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ int mlxsw_afa_block_activity_get(struct mlxsw_afa_block *block, bool *activity);
4343
int mlxsw_afa_block_continue(struct mlxsw_afa_block *block);
4444
int mlxsw_afa_block_jump(struct mlxsw_afa_block *block, u16 group_id);
4545
int mlxsw_afa_block_terminate(struct mlxsw_afa_block *block);
46+
const struct flow_action_cookie *
47+
mlxsw_afa_cookie_lookup(struct mlxsw_afa *mlxsw_afa, u32 cookie_index);
4648
int mlxsw_afa_block_append_drop(struct mlxsw_afa_block *block, bool ingress,
4749
const struct flow_action_cookie *fa_cookie,
4850
struct netlink_ext_ack *extack);

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
780780

781781
struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
782782

783+
static inline const struct flow_action_cookie *
784+
mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
785+
{
786+
return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
787+
}
788+
783789
int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
784790
void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
785791
u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);

drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,35 @@ static void mlxsw_sp_rx_drop_listener(struct sk_buff *skb, u8 local_port,
7575
consume_skb(skb);
7676
}
7777

78+
static void mlxsw_sp_rx_acl_drop_listener(struct sk_buff *skb, u8 local_port,
79+
void *trap_ctx)
80+
{
81+
u32 cookie_index = mlxsw_skb_cb(skb)->cookie_index;
82+
const struct flow_action_cookie *fa_cookie;
83+
struct devlink_port *in_devlink_port;
84+
struct mlxsw_sp_port *mlxsw_sp_port;
85+
struct mlxsw_sp *mlxsw_sp;
86+
struct devlink *devlink;
87+
int err;
88+
89+
mlxsw_sp = devlink_trap_ctx_priv(trap_ctx);
90+
mlxsw_sp_port = mlxsw_sp->ports[local_port];
91+
92+
err = mlxsw_sp_rx_listener(mlxsw_sp, skb, local_port, mlxsw_sp_port);
93+
if (err)
94+
return;
95+
96+
devlink = priv_to_devlink(mlxsw_sp->core);
97+
in_devlink_port = mlxsw_core_port_devlink_port_get(mlxsw_sp->core,
98+
local_port);
99+
skb_push(skb, ETH_HLEN);
100+
rcu_read_lock();
101+
fa_cookie = mlxsw_sp_acl_act_cookie_lookup(mlxsw_sp, cookie_index);
102+
devlink_trap_report(devlink, skb, trap_ctx, in_devlink_port, fa_cookie);
103+
rcu_read_unlock();
104+
consume_skb(skb);
105+
}
106+
78107
static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port,
79108
void *trap_ctx)
80109
{
@@ -106,6 +135,11 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port,
106135
DEVLINK_TRAP_GROUP_GENERIC(_group_id), \
107136
MLXSW_SP_TRAP_METADATA)
108137

138+
#define MLXSW_SP_TRAP_DROP_EXT(_id, _group_id, _metadata) \
139+
DEVLINK_TRAP_GENERIC(DROP, DROP, _id, \
140+
DEVLINK_TRAP_GROUP_GENERIC(_group_id), \
141+
MLXSW_SP_TRAP_METADATA | (_metadata))
142+
109143
#define MLXSW_SP_TRAP_DRIVER_DROP(_id, _group_id) \
110144
DEVLINK_TRAP_DRIVER(DROP, DROP, DEVLINK_MLXSW_TRAP_ID_##_id, \
111145
DEVLINK_MLXSW_TRAP_NAME_##_id, \
@@ -123,7 +157,7 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port,
123157
SET_FW_DEFAULT, SP_##_group_id)
124158

125159
#define MLXSW_SP_RXL_ACL_DISCARD(_id, _en_group_id, _dis_group_id) \
126-
MLXSW_RXL_DIS(mlxsw_sp_rx_drop_listener, DISCARD_##_id, \
160+
MLXSW_RXL_DIS(mlxsw_sp_rx_acl_drop_listener, DISCARD_##_id, \
127161
TRAP_EXCEPTION_TO_CPU, false, SP_##_en_group_id, \
128162
SET_FW_DEFAULT, SP_##_dis_group_id)
129163

@@ -160,8 +194,10 @@ static const struct devlink_trap mlxsw_sp_traps_arr[] = {
160194
MLXSW_SP_TRAP_DROP(NON_ROUTABLE, L3_DROPS),
161195
MLXSW_SP_TRAP_EXCEPTION(DECAP_ERROR, TUNNEL_DROPS),
162196
MLXSW_SP_TRAP_DROP(OVERLAY_SMAC_MC, TUNNEL_DROPS),
163-
MLXSW_SP_TRAP_DROP(INGRESS_FLOW_ACTION_DROP, ACL_DROPS),
164-
MLXSW_SP_TRAP_DROP(EGRESS_FLOW_ACTION_DROP, ACL_DROPS),
197+
MLXSW_SP_TRAP_DROP_EXT(INGRESS_FLOW_ACTION_DROP, ACL_DROPS,
198+
DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE),
199+
MLXSW_SP_TRAP_DROP_EXT(EGRESS_FLOW_ACTION_DROP, ACL_DROPS,
200+
DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE),
165201
};
166202

167203
static const struct mlxsw_listener mlxsw_sp_listeners_arr[] = {

0 commit comments

Comments
 (0)