Skip to content

Commit f8deaea

Browse files
committed
Merge branch 'mlxsw-Add-support-for-buffer-drop-traps'
Ido Schimmel says: ==================== mlxsw: Add support for buffer drop traps Petr says: A recent patch set added the ability to mirror buffer related drops (e.g., early drops) through a netdev. This patch set adds the ability to trap such packets to the local CPU for analysis. The trapping towards the CPU is configured by using tc-trap action instead of tc-mirred as was done when the packets were mirrored through a netdev. A future patch set will also add the ability to sample the dropped packets using tc-sample action. The buffer related drop traps are added to devlink, which means that the dropped packets can be reported to user space via the kernel's drop_monitor module. Patch set overview: Patch #1 adds the early_drop trap to devlink Patch #2 adds extack to a few devlink operations to facilitate better error reporting to user space. This is necessary - among other things - because the action of buffer drop traps cannot be changed in mlxsw Patch #3 performs a small refactoring in mlxsw, patch #4 fixes a bug that this patchset would trigger. Patches #5-#6 add the infrastructure required to support different traps / trap groups in mlxsw per-ASIC. This is required because buffer drop traps are not supported by Spectrum-1 Patch #7 extends mlxsw to register the early_drop trap Patch #8 adds the offload logic for the "trap" action at a qevent block. Patch #9 adds a mlxsw-specific selftest. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 80fbbb1 + 8fb6ac4 commit f8deaea

File tree

15 files changed

+406
-66
lines changed

15 files changed

+406
-66
lines changed

Documentation/networking/devlink/devlink-trap.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ be added to the following table:
405405
- ``control``
406406
- Traps packets logged during processing of flow action trap (e.g., via
407407
tc's trap action)
408+
* - ``early_drop``
409+
- ``drop``
410+
- Traps packets dropped due to the RED (Random Early Detection) algorithm
411+
(i.e., early drops)
408412

409413
Driver-specific Packet Traps
410414
============================

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,14 +1177,15 @@ static void mlxsw_devlink_trap_fini(struct devlink *devlink,
11771177

11781178
static int mlxsw_devlink_trap_action_set(struct devlink *devlink,
11791179
const struct devlink_trap *trap,
1180-
enum devlink_trap_action action)
1180+
enum devlink_trap_action action,
1181+
struct netlink_ext_ack *extack)
11811182
{
11821183
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
11831184
struct mlxsw_driver *mlxsw_driver = mlxsw_core->driver;
11841185

11851186
if (!mlxsw_driver->trap_action_set)
11861187
return -EOPNOTSUPP;
1187-
return mlxsw_driver->trap_action_set(mlxsw_core, trap, action);
1188+
return mlxsw_driver->trap_action_set(mlxsw_core, trap, action, extack);
11881189
}
11891190

11901191
static int
@@ -1202,14 +1203,15 @@ mlxsw_devlink_trap_group_init(struct devlink *devlink,
12021203
static int
12031204
mlxsw_devlink_trap_group_set(struct devlink *devlink,
12041205
const struct devlink_trap_group *group,
1205-
const struct devlink_trap_policer *policer)
1206+
const struct devlink_trap_policer *policer,
1207+
struct netlink_ext_ack *extack)
12061208
{
12071209
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
12081210
struct mlxsw_driver *mlxsw_driver = mlxsw_core->driver;
12091211

12101212
if (!mlxsw_driver->trap_group_set)
12111213
return -EOPNOTSUPP;
1212-
return mlxsw_driver->trap_group_set(mlxsw_core, group, policer);
1214+
return mlxsw_driver->trap_group_set(mlxsw_core, group, policer, extack);
12131215
}
12141216

12151217
static int

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ struct mlxsw_listener {
8989
};
9090

9191
#define __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \
92-
_dis_action, _enabled_on_register, _dis_trap_group) \
92+
_dis_action, _enabled_on_register, _dis_trap_group, \
93+
_mirror_reason) \
9394
{ \
9495
.trap_id = MLXSW_TRAP_ID_##_trap_id, \
9596
.rx_listener = \
9697
{ \
9798
.func = _func, \
9899
.local_port = MLXSW_PORT_DONT_CARE, \
100+
.mirror_reason = _mirror_reason, \
99101
.trap_id = MLXSW_TRAP_ID_##_trap_id, \
100102
}, \
101103
.en_action = MLXSW_REG_HPKT_ACTION_##_en_action, \
@@ -109,12 +111,17 @@ struct mlxsw_listener {
109111
#define MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group, \
110112
_dis_action) \
111113
__MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group, \
112-
_dis_action, true, _trap_group)
114+
_dis_action, true, _trap_group, 0)
113115

114116
#define MLXSW_RXL_DIS(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \
115117
_dis_action, _dis_trap_group) \
116118
__MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \
117-
_dis_action, false, _dis_trap_group)
119+
_dis_action, false, _dis_trap_group, 0)
120+
121+
#define MLXSW_RXL_MIRROR(_func, _session_id, _trap_group, _mirror_reason) \
122+
__MLXSW_RXL(_func, MIRROR_SESSION##_session_id, TRAP_TO_CPU, false, \
123+
_trap_group, TRAP_TO_CPU, true, _trap_group, \
124+
_mirror_reason)
118125

119126
#define MLXSW_EVENTL(_func, _trap_id, _trap_group) \
120127
{ \
@@ -326,12 +333,14 @@ struct mlxsw_driver {
326333
const struct devlink_trap *trap, void *trap_ctx);
327334
int (*trap_action_set)(struct mlxsw_core *mlxsw_core,
328335
const struct devlink_trap *trap,
329-
enum devlink_trap_action action);
336+
enum devlink_trap_action action,
337+
struct netlink_ext_ack *extack);
330338
int (*trap_group_init)(struct mlxsw_core *mlxsw_core,
331339
const struct devlink_trap_group *group);
332340
int (*trap_group_set)(struct mlxsw_core *mlxsw_core,
333341
const struct devlink_trap_group *group,
334-
const struct devlink_trap_policer *policer);
342+
const struct devlink_trap_policer *policer,
343+
struct netlink_ext_ack *extack);
335344
int (*trap_policer_init)(struct mlxsw_core *mlxsw_core,
336345
const struct devlink_trap_policer *policer);
337346
void (*trap_policer_fini)(struct mlxsw_core *mlxsw_core,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5614,6 +5614,7 @@ enum mlxsw_reg_htgt_trap_group {
56145614
MLXSW_REG_HTGT_TRAP_GROUP_SP_L3_EXCEPTIONS,
56155615
MLXSW_REG_HTGT_TRAP_GROUP_SP_TUNNEL_DISCARDS,
56165616
MLXSW_REG_HTGT_TRAP_GROUP_SP_ACL_DISCARDS,
5617+
MLXSW_REG_HTGT_TRAP_GROUP_SP_BUFFER_DISCARDS,
56175618

56185619
__MLXSW_REG_HTGT_TRAP_GROUP_MAX,
56195620
MLXSW_REG_HTGT_TRAP_GROUP_MAX = __MLXSW_REG_HTGT_TRAP_GROUP_MAX - 1

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,7 @@ static int mlxsw_sp1_init(struct mlxsw_core *mlxsw_core,
30553055
mlxsw_sp->ptp_ops = &mlxsw_sp1_ptp_ops;
30563056
mlxsw_sp->span_ops = &mlxsw_sp1_span_ops;
30573057
mlxsw_sp->policer_core_ops = &mlxsw_sp1_policer_core_ops;
3058+
mlxsw_sp->trap_ops = &mlxsw_sp1_trap_ops;
30583059
mlxsw_sp->listeners = mlxsw_sp1_listener;
30593060
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
30603061
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP1;
@@ -3084,6 +3085,7 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
30843085
mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
30853086
mlxsw_sp->span_ops = &mlxsw_sp2_span_ops;
30863087
mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
3088+
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
30873089
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2;
30883090

30893091
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
@@ -3111,6 +3113,7 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core,
31113113
mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
31123114
mlxsw_sp->span_ops = &mlxsw_sp3_span_ops;
31133115
mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
3116+
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
31143117
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3;
31153118

31163119
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct mlxsw_sp {
177177
const struct mlxsw_sp_ptp_ops *ptp_ops;
178178
const struct mlxsw_sp_span_ops *span_ops;
179179
const struct mlxsw_sp_policer_core_ops *policer_core_ops;
180+
const struct mlxsw_sp_trap_ops *trap_ops;
180181
const struct mlxsw_listener *listeners;
181182
size_t listeners_count;
182183
u32 lowest_shaper_bs;
@@ -983,6 +984,10 @@ struct mlxsw_sp_mall_mirror_entry {
983984
int span_id;
984985
};
985986

987+
struct mlxsw_sp_mall_trap_entry {
988+
int span_id;
989+
};
990+
986991
struct mlxsw_sp_mall_entry {
987992
struct list_head list;
988993
unsigned long cookie;
@@ -991,6 +996,7 @@ struct mlxsw_sp_mall_entry {
991996
bool ingress;
992997
union {
993998
struct mlxsw_sp_mall_mirror_entry mirror;
999+
struct mlxsw_sp_mall_trap_entry trap;
9941000
struct mlxsw_sp_port_sample sample;
9951001
};
9961002
struct rcu_head rcu;
@@ -1177,12 +1183,14 @@ void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
11771183
const struct devlink_trap *trap, void *trap_ctx);
11781184
int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
11791185
const struct devlink_trap *trap,
1180-
enum devlink_trap_action action);
1186+
enum devlink_trap_action action,
1187+
struct netlink_ext_ack *extack);
11811188
int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
11821189
const struct devlink_trap_group *group);
11831190
int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
11841191
const struct devlink_trap_group *group,
1185-
const struct devlink_trap_policer *policer);
1192+
const struct devlink_trap_policer *policer,
1193+
struct netlink_ext_ack *extack);
11861194
int
11871195
mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
11881196
const struct devlink_trap_policer *policer);
@@ -1196,6 +1204,8 @@ int
11961204
mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
11971205
const struct devlink_trap_policer *policer,
11981206
u64 *p_drops);
1207+
int mlxsw_sp_trap_group_policer_hw_id_get(struct mlxsw_sp *mlxsw_sp, u16 id,
1208+
bool *p_enabled, u16 *p_hw_id);
11991209

12001210
static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
12011211
{

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

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,19 +1289,18 @@ struct mlxsw_sp_qevent_binding {
12891289

12901290
static LIST_HEAD(mlxsw_sp_qevent_block_cb_list);
12911291

1292-
static int mlxsw_sp_qevent_mirror_configure(struct mlxsw_sp *mlxsw_sp,
1293-
struct mlxsw_sp_mall_entry *mall_entry,
1294-
struct mlxsw_sp_qevent_binding *qevent_binding)
1292+
static int mlxsw_sp_qevent_span_configure(struct mlxsw_sp *mlxsw_sp,
1293+
struct mlxsw_sp_mall_entry *mall_entry,
1294+
struct mlxsw_sp_qevent_binding *qevent_binding,
1295+
const struct mlxsw_sp_span_agent_parms *agent_parms,
1296+
int *p_span_id)
12951297
{
12961298
struct mlxsw_sp_port *mlxsw_sp_port = qevent_binding->mlxsw_sp_port;
12971299
struct mlxsw_sp_span_trigger_parms trigger_parms = {};
1298-
struct mlxsw_sp_span_agent_parms agent_parms = {
1299-
.to_dev = mall_entry->mirror.to_dev,
1300-
};
13011300
int span_id;
13021301
int err;
13031302

1304-
err = mlxsw_sp_span_agent_get(mlxsw_sp, &span_id, &agent_parms);
1303+
err = mlxsw_sp_span_agent_get(mlxsw_sp, &span_id, agent_parms);
13051304
if (err)
13061305
return err;
13071306

@@ -1320,7 +1319,7 @@ static int mlxsw_sp_qevent_mirror_configure(struct mlxsw_sp *mlxsw_sp,
13201319
if (err)
13211320
goto err_trigger_enable;
13221321

1323-
mall_entry->mirror.span_id = span_id;
1322+
*p_span_id = span_id;
13241323
return 0;
13251324

13261325
err_trigger_enable:
@@ -1333,21 +1332,65 @@ static int mlxsw_sp_qevent_mirror_configure(struct mlxsw_sp *mlxsw_sp,
13331332
return err;
13341333
}
13351334

1336-
static void mlxsw_sp_qevent_mirror_deconfigure(struct mlxsw_sp *mlxsw_sp,
1337-
struct mlxsw_sp_mall_entry *mall_entry,
1338-
struct mlxsw_sp_qevent_binding *qevent_binding)
1335+
static void mlxsw_sp_qevent_span_deconfigure(struct mlxsw_sp *mlxsw_sp,
1336+
struct mlxsw_sp_qevent_binding *qevent_binding,
1337+
int span_id)
13391338
{
13401339
struct mlxsw_sp_port *mlxsw_sp_port = qevent_binding->mlxsw_sp_port;
13411340
struct mlxsw_sp_span_trigger_parms trigger_parms = {
1342-
.span_id = mall_entry->mirror.span_id,
1341+
.span_id = span_id,
13431342
};
13441343

13451344
mlxsw_sp_span_trigger_disable(mlxsw_sp_port, qevent_binding->span_trigger,
13461345
qevent_binding->tclass_num);
13471346
mlxsw_sp_span_agent_unbind(mlxsw_sp, qevent_binding->span_trigger, mlxsw_sp_port,
13481347
&trigger_parms);
13491348
mlxsw_sp_span_analyzed_port_put(mlxsw_sp_port, true);
1350-
mlxsw_sp_span_agent_put(mlxsw_sp, mall_entry->mirror.span_id);
1349+
mlxsw_sp_span_agent_put(mlxsw_sp, span_id);
1350+
}
1351+
1352+
static int mlxsw_sp_qevent_mirror_configure(struct mlxsw_sp *mlxsw_sp,
1353+
struct mlxsw_sp_mall_entry *mall_entry,
1354+
struct mlxsw_sp_qevent_binding *qevent_binding)
1355+
{
1356+
struct mlxsw_sp_span_agent_parms agent_parms = {
1357+
.to_dev = mall_entry->mirror.to_dev,
1358+
};
1359+
1360+
return mlxsw_sp_qevent_span_configure(mlxsw_sp, mall_entry, qevent_binding,
1361+
&agent_parms, &mall_entry->mirror.span_id);
1362+
}
1363+
1364+
static void mlxsw_sp_qevent_mirror_deconfigure(struct mlxsw_sp *mlxsw_sp,
1365+
struct mlxsw_sp_mall_entry *mall_entry,
1366+
struct mlxsw_sp_qevent_binding *qevent_binding)
1367+
{
1368+
mlxsw_sp_qevent_span_deconfigure(mlxsw_sp, qevent_binding, mall_entry->mirror.span_id);
1369+
}
1370+
1371+
static int mlxsw_sp_qevent_trap_configure(struct mlxsw_sp *mlxsw_sp,
1372+
struct mlxsw_sp_mall_entry *mall_entry,
1373+
struct mlxsw_sp_qevent_binding *qevent_binding)
1374+
{
1375+
struct mlxsw_sp_span_agent_parms agent_parms = {};
1376+
int err;
1377+
1378+
err = mlxsw_sp_trap_group_policer_hw_id_get(mlxsw_sp,
1379+
DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
1380+
&agent_parms.policer_enable,
1381+
&agent_parms.policer_id);
1382+
if (err)
1383+
return err;
1384+
1385+
return mlxsw_sp_qevent_span_configure(mlxsw_sp, mall_entry, qevent_binding,
1386+
&agent_parms, &mall_entry->trap.span_id);
1387+
}
1388+
1389+
static void mlxsw_sp_qevent_trap_deconfigure(struct mlxsw_sp *mlxsw_sp,
1390+
struct mlxsw_sp_mall_entry *mall_entry,
1391+
struct mlxsw_sp_qevent_binding *qevent_binding)
1392+
{
1393+
mlxsw_sp_qevent_span_deconfigure(mlxsw_sp, qevent_binding, mall_entry->trap.span_id);
13511394
}
13521395

13531396
static int mlxsw_sp_qevent_entry_configure(struct mlxsw_sp *mlxsw_sp,
@@ -1357,6 +1400,8 @@ static int mlxsw_sp_qevent_entry_configure(struct mlxsw_sp *mlxsw_sp,
13571400
switch (mall_entry->type) {
13581401
case MLXSW_SP_MALL_ACTION_TYPE_MIRROR:
13591402
return mlxsw_sp_qevent_mirror_configure(mlxsw_sp, mall_entry, qevent_binding);
1403+
case MLXSW_SP_MALL_ACTION_TYPE_TRAP:
1404+
return mlxsw_sp_qevent_trap_configure(mlxsw_sp, mall_entry, qevent_binding);
13601405
default:
13611406
/* This should have been validated away. */
13621407
WARN_ON(1);
@@ -1371,6 +1416,8 @@ static void mlxsw_sp_qevent_entry_deconfigure(struct mlxsw_sp *mlxsw_sp,
13711416
switch (mall_entry->type) {
13721417
case MLXSW_SP_MALL_ACTION_TYPE_MIRROR:
13731418
return mlxsw_sp_qevent_mirror_deconfigure(mlxsw_sp, mall_entry, qevent_binding);
1419+
case MLXSW_SP_MALL_ACTION_TYPE_TRAP:
1420+
return mlxsw_sp_qevent_trap_deconfigure(mlxsw_sp, mall_entry, qevent_binding);
13741421
default:
13751422
WARN_ON(1);
13761423
return;
@@ -1490,6 +1537,8 @@ static int mlxsw_sp_qevent_mall_replace(struct mlxsw_sp *mlxsw_sp,
14901537
if (act->id == FLOW_ACTION_MIRRED) {
14911538
mall_entry->type = MLXSW_SP_MALL_ACTION_TYPE_MIRROR;
14921539
mall_entry->mirror.to_dev = act->dev;
1540+
} else if (act->id == FLOW_ACTION_TRAP) {
1541+
mall_entry->type = MLXSW_SP_MALL_ACTION_TYPE_TRAP;
14931542
} else {
14941543
NL_SET_ERR_MSG(f->common.extack, "Unsupported action");
14951544
err = -EOPNOTSUPP;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ static int mlxsw_sp_span_policer_id_base_set(struct mlxsw_sp_span *span,
837837

838838
static void mlxsw_sp_span_policer_id_base_unset(struct mlxsw_sp_span *span)
839839
{
840-
refcount_dec(&span->policer_id_base_ref_count);
840+
if (refcount_dec_and_test(&span->policer_id_base_ref_count))
841+
span->policer_id_base = 0;
841842
}
842843

843844
static struct mlxsw_sp_span_entry *

0 commit comments

Comments
 (0)