Skip to content

Commit 35d1901

Browse files
Maor Gottliebdledford
authored andcommitted
IB/mlx5: Add support for don't trap rules
Each bypass flow steering priority will be split into two priorities: 1. Priority for don't trap rules. 2. Priority for normal rules. When user creates a flow using IB_FLOW_ATTR_FLAGS_DONT_TRAP flag, the driver creates two flow rules, one used for receiving the traffic and the other one for forwarding the packet to continue matching in lower or equal priorities. Signed-off-by: Maor Gottlieb <[email protected]> Reviewed-by: Matan Barak <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent b3638e1 commit 35d1901

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,11 +1369,20 @@ static int mlx5_ib_destroy_flow(struct ib_flow *flow_id)
13691369
return 0;
13701370
}
13711371

1372+
static int ib_prio_to_core_prio(unsigned int priority, bool dont_trap)
1373+
{
1374+
priority *= 2;
1375+
if (!dont_trap)
1376+
priority++;
1377+
return priority;
1378+
}
1379+
13721380
#define MLX5_FS_MAX_TYPES 10
13731381
#define MLX5_FS_MAX_ENTRIES 32000UL
13741382
static struct mlx5_ib_flow_prio *get_flow_table(struct mlx5_ib_dev *dev,
13751383
struct ib_flow_attr *flow_attr)
13761384
{
1385+
bool dont_trap = flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP;
13771386
struct mlx5_flow_namespace *ns = NULL;
13781387
struct mlx5_ib_flow_prio *prio;
13791388
struct mlx5_flow_table *ft;
@@ -1383,10 +1392,12 @@ static struct mlx5_ib_flow_prio *get_flow_table(struct mlx5_ib_dev *dev,
13831392
int err = 0;
13841393

13851394
if (flow_attr->type == IB_FLOW_ATTR_NORMAL) {
1386-
if (flow_is_multicast_only(flow_attr))
1395+
if (flow_is_multicast_only(flow_attr) &&
1396+
!dont_trap)
13871397
priority = MLX5_IB_FLOW_MCAST_PRIO;
13881398
else
1389-
priority = flow_attr->priority;
1399+
priority = ib_prio_to_core_prio(flow_attr->priority,
1400+
dont_trap);
13901401
ns = mlx5_get_flow_namespace(dev->mdev,
13911402
MLX5_FLOW_NAMESPACE_BYPASS);
13921403
num_entries = MLX5_FS_MAX_ENTRIES;
@@ -1434,6 +1445,7 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev,
14341445
unsigned int spec_index;
14351446
u32 *match_c;
14361447
u32 *match_v;
1448+
u32 action;
14371449
int err = 0;
14381450

14391451
if (!is_valid_attr(flow_attr))
@@ -1459,9 +1471,11 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev,
14591471

14601472
/* Outer header support only */
14611473
match_criteria_enable = (!outer_header_zero(match_c)) << 0;
1474+
action = dst ? MLX5_FLOW_CONTEXT_ACTION_FWD_DEST :
1475+
MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO;
14621476
handler->rule = mlx5_add_flow_rule(ft, match_criteria_enable,
14631477
match_c, match_v,
1464-
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
1478+
action,
14651479
MLX5_FS_DEFAULT_FLOW_TAG,
14661480
dst);
14671481

@@ -1481,6 +1495,29 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev,
14811495
return err ? ERR_PTR(err) : handler;
14821496
}
14831497

1498+
static struct mlx5_ib_flow_handler *create_dont_trap_rule(struct mlx5_ib_dev *dev,
1499+
struct mlx5_ib_flow_prio *ft_prio,
1500+
struct ib_flow_attr *flow_attr,
1501+
struct mlx5_flow_destination *dst)
1502+
{
1503+
struct mlx5_ib_flow_handler *handler_dst = NULL;
1504+
struct mlx5_ib_flow_handler *handler = NULL;
1505+
1506+
handler = create_flow_rule(dev, ft_prio, flow_attr, NULL);
1507+
if (!IS_ERR(handler)) {
1508+
handler_dst = create_flow_rule(dev, ft_prio,
1509+
flow_attr, dst);
1510+
if (IS_ERR(handler_dst)) {
1511+
mlx5_del_flow_rule(handler->rule);
1512+
kfree(handler);
1513+
handler = handler_dst;
1514+
} else {
1515+
list_add(&handler_dst->list, &handler->list);
1516+
}
1517+
}
1518+
1519+
return handler;
1520+
}
14841521
enum {
14851522
LEFTOVERS_MC,
14861523
LEFTOVERS_UC,
@@ -1558,7 +1595,7 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp,
15581595

15591596
if (domain != IB_FLOW_DOMAIN_USER ||
15601597
flow_attr->port > MLX5_CAP_GEN(dev->mdev, num_ports) ||
1561-
flow_attr->flags)
1598+
(flow_attr->flags & ~IB_FLOW_ATTR_FLAGS_DONT_TRAP))
15621599
return ERR_PTR(-EINVAL);
15631600

15641601
dst = kzalloc(sizeof(*dst), GFP_KERNEL);
@@ -1577,8 +1614,13 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp,
15771614
dst->tir_num = to_mqp(qp)->raw_packet_qp.rq.tirn;
15781615

15791616
if (flow_attr->type == IB_FLOW_ATTR_NORMAL) {
1580-
handler = create_flow_rule(dev, ft_prio, flow_attr,
1581-
dst);
1617+
if (flow_attr->flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) {
1618+
handler = create_dont_trap_rule(dev, ft_prio,
1619+
flow_attr, dst);
1620+
} else {
1621+
handler = create_flow_rule(dev, ft_prio, flow_attr,
1622+
dst);
1623+
}
15821624
} else if (flow_attr->type == IB_FLOW_ATTR_ALL_DEFAULT ||
15831625
flow_attr->type == IB_FLOW_ATTR_MC_DEFAULT) {
15841626
handler = create_leftovers_rule(dev, ft_prio, flow_attr,

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct mlx5_ib_pd {
126126
};
127127

128128
#define MLX5_IB_FLOW_MCAST_PRIO (MLX5_BY_PASS_NUM_PRIOS - 1)
129-
#define MLX5_IB_FLOW_LAST_PRIO (MLX5_IB_FLOW_MCAST_PRIO - 1)
129+
#define MLX5_IB_FLOW_LAST_PRIO (MLX5_BY_PASS_NUM_REGULAR_PRIOS - 1)
130130
#if (MLX5_IB_FLOW_LAST_PRIO <= 0)
131131
#error "Invalid number of bypass priorities"
132132
#endif

include/linux/mlx5/device.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,11 @@ static inline u16 mlx5_to_sw_pkey_sz(int pkey_sz)
12941294
return MLX5_MIN_PKEY_TABLE_SIZE << pkey_sz;
12951295
}
12961296

1297-
#define MLX5_BY_PASS_NUM_PRIOS 9
1297+
#define MLX5_BY_PASS_NUM_REGULAR_PRIOS 8
1298+
#define MLX5_BY_PASS_NUM_DONT_TRAP_PRIOS 8
1299+
#define MLX5_BY_PASS_NUM_MULTICAST_PRIOS 1
1300+
#define MLX5_BY_PASS_NUM_PRIOS (MLX5_BY_PASS_NUM_REGULAR_PRIOS +\
1301+
MLX5_BY_PASS_NUM_DONT_TRAP_PRIOS +\
1302+
MLX5_BY_PASS_NUM_MULTICAST_PRIOS)
12981303

12991304
#endif /* MLX5_DEVICE_H */

0 commit comments

Comments
 (0)