Skip to content

Commit efdc810

Browse files
Mohamad Haj Yahiadavem330
authored andcommitted
net/mlx5: Flow steering, Add vport ACL support
Update the relevant flow steering device structs and commands to support vport. Update the flow steering core API to receive vport number. Add ingress and egress ACL flow table name spaces. Add ACL flow table support: * ACL (Access Control List) flow table is a table that contains only allow/drop steering rules. * We have two types of ACL flow tables - ingress and egress. * ACLs handle traffic sent from/to E-Switch FDB table, Ingress refers to traffic sent from Vport to E-Switch and Egress refers to traffic sent from E-Switch to vport. * Ingress ACL flow table allow/drop rules is checked against traffic sent from VF. * Egress ACL flow table allow/drop rules is checked against traffic sent to VF. Signed-off-by: Mohamad Haj Yahia <mohamad@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fbc4a69 commit efdc810

9 files changed

Lines changed: 142 additions & 9 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/eswitch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw)
845845
int mlx5_eswitch_init(struct mlx5_core_dev *dev)
846846
{
847847
int l2_table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table);
848-
int total_vports = 1 + pci_sriov_get_totalvfs(dev->pdev);
848+
int total_vports = MLX5_TOTAL_VPORTS(dev);
849849
struct mlx5_eswitch *esw;
850850
int vport_num;
851851
int err;

‎drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,18 @@ int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
5050
MLX5_CMD_OP_SET_FLOW_TABLE_ROOT);
5151
MLX5_SET(set_flow_table_root_in, in, table_type, ft->type);
5252
MLX5_SET(set_flow_table_root_in, in, table_id, ft->id);
53+
if (ft->vport) {
54+
MLX5_SET(set_flow_table_root_in, in, vport_number, ft->vport);
55+
MLX5_SET(set_flow_table_root_in, in, other_vport, 1);
56+
}
5357

5458
memset(out, 0, sizeof(out));
5559
return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
5660
sizeof(out));
5761
}
5862

5963
int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
64+
u16 vport,
6065
enum fs_flow_table_type type, unsigned int level,
6166
unsigned int log_size, struct mlx5_flow_table
6267
*next_ft, unsigned int *table_id)
@@ -77,6 +82,10 @@ int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
7782
MLX5_SET(create_flow_table_in, in, table_type, type);
7883
MLX5_SET(create_flow_table_in, in, level, level);
7984
MLX5_SET(create_flow_table_in, in, log_size, log_size);
85+
if (vport) {
86+
MLX5_SET(create_flow_table_in, in, vport_number, vport);
87+
MLX5_SET(create_flow_table_in, in, other_vport, 1);
88+
}
8089

8190
memset(out, 0, sizeof(out));
8291
err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
@@ -101,6 +110,10 @@ int mlx5_cmd_destroy_flow_table(struct mlx5_core_dev *dev,
101110
MLX5_CMD_OP_DESTROY_FLOW_TABLE);
102111
MLX5_SET(destroy_flow_table_in, in, table_type, ft->type);
103112
MLX5_SET(destroy_flow_table_in, in, table_id, ft->id);
113+
if (ft->vport) {
114+
MLX5_SET(destroy_flow_table_in, in, vport_number, ft->vport);
115+
MLX5_SET(destroy_flow_table_in, in, other_vport, 1);
116+
}
104117

105118
return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
106119
sizeof(out));
@@ -120,6 +133,10 @@ int mlx5_cmd_modify_flow_table(struct mlx5_core_dev *dev,
120133
MLX5_CMD_OP_MODIFY_FLOW_TABLE);
121134
MLX5_SET(modify_flow_table_in, in, table_type, ft->type);
122135
MLX5_SET(modify_flow_table_in, in, table_id, ft->id);
136+
if (ft->vport) {
137+
MLX5_SET(modify_flow_table_in, in, vport_number, ft->vport);
138+
MLX5_SET(modify_flow_table_in, in, other_vport, 1);
139+
}
123140
MLX5_SET(modify_flow_table_in, in, modify_field_select,
124141
MLX5_MODIFY_FLOW_TABLE_MISS_TABLE_ID);
125142
if (next_ft) {
@@ -148,6 +165,10 @@ int mlx5_cmd_create_flow_group(struct mlx5_core_dev *dev,
148165
MLX5_CMD_OP_CREATE_FLOW_GROUP);
149166
MLX5_SET(create_flow_group_in, in, table_type, ft->type);
150167
MLX5_SET(create_flow_group_in, in, table_id, ft->id);
168+
if (ft->vport) {
169+
MLX5_SET(create_flow_group_in, in, vport_number, ft->vport);
170+
MLX5_SET(create_flow_group_in, in, other_vport, 1);
171+
}
151172

152173
err = mlx5_cmd_exec_check_status(dev, in,
153174
inlen, out,
@@ -174,6 +195,10 @@ int mlx5_cmd_destroy_flow_group(struct mlx5_core_dev *dev,
174195
MLX5_SET(destroy_flow_group_in, in, table_type, ft->type);
175196
MLX5_SET(destroy_flow_group_in, in, table_id, ft->id);
176197
MLX5_SET(destroy_flow_group_in, in, group_id, group_id);
198+
if (ft->vport) {
199+
MLX5_SET(destroy_flow_group_in, in, vport_number, ft->vport);
200+
MLX5_SET(destroy_flow_group_in, in, other_vport, 1);
201+
}
177202

178203
return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
179204
sizeof(out));
@@ -207,6 +232,10 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
207232
MLX5_SET(set_fte_in, in, table_type, ft->type);
208233
MLX5_SET(set_fte_in, in, table_id, ft->id);
209234
MLX5_SET(set_fte_in, in, flow_index, fte->index);
235+
if (ft->vport) {
236+
MLX5_SET(set_fte_in, in, vport_number, ft->vport);
237+
MLX5_SET(set_fte_in, in, other_vport, 1);
238+
}
210239

211240
in_flow_context = MLX5_ADDR_OF(set_fte_in, in, flow_context);
212241
MLX5_SET(flow_context, in_flow_context, group_id, group_id);
@@ -285,6 +314,10 @@ int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
285314
MLX5_SET(delete_fte_in, in, table_type, ft->type);
286315
MLX5_SET(delete_fte_in, in, table_id, ft->id);
287316
MLX5_SET(delete_fte_in, in, flow_index, index);
317+
if (ft->vport) {
318+
MLX5_SET(delete_fte_in, in, vport_number, ft->vport);
319+
MLX5_SET(delete_fte_in, in, other_vport, 1);
320+
}
288321

289322
err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
290323

‎drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define _MLX5_FS_CMD_
3535

3636
int mlx5_cmd_create_flow_table(struct mlx5_core_dev *dev,
37+
u16 vport,
3738
enum fs_flow_table_type type, unsigned int level,
3839
unsigned int log_size, struct mlx5_flow_table
3940
*next_ft, unsigned int *table_id);

‎drivers/net/ethernet/mellanox/mlx5/core/fs_core.c‎

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static struct mlx5_flow_group *alloc_flow_group(u32 *create_fg_in)
457457
return fg;
458458
}
459459

460-
static struct mlx5_flow_table *alloc_flow_table(int level, int max_fte,
460+
static struct mlx5_flow_table *alloc_flow_table(int level, u16 vport, int max_fte,
461461
enum fs_flow_table_type table_type)
462462
{
463463
struct mlx5_flow_table *ft;
@@ -469,6 +469,7 @@ static struct mlx5_flow_table *alloc_flow_table(int level, int max_fte,
469469
ft->level = level;
470470
ft->node.type = FS_TYPE_FLOW_TABLE;
471471
ft->type = table_type;
472+
ft->vport = vport;
472473
ft->max_fte = max_fte;
473474
INIT_LIST_HEAD(&ft->fwd_rules);
474475
mutex_init(&ft->lock);
@@ -700,9 +701,9 @@ static void list_add_flow_table(struct mlx5_flow_table *ft,
700701
list_add(&ft->node.list, prev);
701702
}
702703

703-
struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
704-
int prio, int max_fte,
705-
u32 level)
704+
static struct mlx5_flow_table *__mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
705+
u16 vport, int prio,
706+
int max_fte, u32 level)
706707
{
707708
struct mlx5_flow_table *next_ft = NULL;
708709
struct mlx5_flow_table *ft;
@@ -732,6 +733,7 @@ struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
732733
*/
733734
level += fs_prio->start_level;
734735
ft = alloc_flow_table(level,
736+
vport,
735737
roundup_pow_of_two(max_fte),
736738
root->table_type);
737739
if (!ft) {
@@ -742,7 +744,7 @@ struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
742744
tree_init_node(&ft->node, 1, del_flow_table);
743745
log_table_sz = ilog2(ft->max_fte);
744746
next_ft = find_next_chained_ft(fs_prio);
745-
err = mlx5_cmd_create_flow_table(root->dev, ft->type, ft->level,
747+
err = mlx5_cmd_create_flow_table(root->dev, ft->vport, ft->type, ft->level,
746748
log_table_sz, next_ft, &ft->id);
747749
if (err)
748750
goto free_ft;
@@ -766,6 +768,20 @@ struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
766768
return ERR_PTR(err);
767769
}
768770

771+
struct mlx5_flow_table *mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
772+
int prio, int max_fte,
773+
u32 level)
774+
{
775+
return __mlx5_create_flow_table(ns, 0, prio, max_fte, level);
776+
}
777+
778+
struct mlx5_flow_table *mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
779+
int prio, int max_fte,
780+
u32 level, u16 vport)
781+
{
782+
return __mlx5_create_flow_table(ns, vport, prio, max_fte, level);
783+
}
784+
769785
struct mlx5_flow_table *mlx5_create_auto_grouped_flow_table(struct mlx5_flow_namespace *ns,
770786
int prio,
771787
int num_flow_table_entries,
@@ -1319,6 +1335,16 @@ struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
13191335
return &dev->priv.fdb_root_ns->ns;
13201336
else
13211337
return NULL;
1338+
case MLX5_FLOW_NAMESPACE_ESW_EGRESS:
1339+
if (dev->priv.esw_egress_root_ns)
1340+
return &dev->priv.esw_egress_root_ns->ns;
1341+
else
1342+
return NULL;
1343+
case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
1344+
if (dev->priv.esw_ingress_root_ns)
1345+
return &dev->priv.esw_ingress_root_ns->ns;
1346+
else
1347+
return NULL;
13221348
default:
13231349
return NULL;
13241350
}
@@ -1699,6 +1725,8 @@ void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
16991725
{
17001726
cleanup_root_ns(dev);
17011727
cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1728+
cleanup_single_prio_root_ns(dev, dev->priv.esw_egress_root_ns);
1729+
cleanup_single_prio_root_ns(dev, dev->priv.esw_ingress_root_ns);
17021730
}
17031731

17041732
static int init_fdb_root_ns(struct mlx5_core_dev *dev)
@@ -1719,6 +1747,38 @@ static int init_fdb_root_ns(struct mlx5_core_dev *dev)
17191747
}
17201748
}
17211749

1750+
static int init_egress_acl_root_ns(struct mlx5_core_dev *dev)
1751+
{
1752+
struct fs_prio *prio;
1753+
1754+
dev->priv.esw_egress_root_ns = create_root_ns(dev, FS_FT_ESW_EGRESS_ACL);
1755+
if (!dev->priv.esw_egress_root_ns)
1756+
return -ENOMEM;
1757+
1758+
/* create 1 prio*/
1759+
prio = fs_create_prio(&dev->priv.esw_egress_root_ns->ns, 0, MLX5_TOTAL_VPORTS(dev));
1760+
if (IS_ERR(prio))
1761+
return PTR_ERR(prio);
1762+
else
1763+
return 0;
1764+
}
1765+
1766+
static int init_ingress_acl_root_ns(struct mlx5_core_dev *dev)
1767+
{
1768+
struct fs_prio *prio;
1769+
1770+
dev->priv.esw_ingress_root_ns = create_root_ns(dev, FS_FT_ESW_INGRESS_ACL);
1771+
if (!dev->priv.esw_ingress_root_ns)
1772+
return -ENOMEM;
1773+
1774+
/* create 1 prio*/
1775+
prio = fs_create_prio(&dev->priv.esw_ingress_root_ns->ns, 0, MLX5_TOTAL_VPORTS(dev));
1776+
if (IS_ERR(prio))
1777+
return PTR_ERR(prio);
1778+
else
1779+
return 0;
1780+
}
1781+
17221782
int mlx5_init_fs(struct mlx5_core_dev *dev)
17231783
{
17241784
int err = 0;
@@ -1731,8 +1791,21 @@ int mlx5_init_fs(struct mlx5_core_dev *dev)
17311791
if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
17321792
err = init_fdb_root_ns(dev);
17331793
if (err)
1734-
cleanup_root_ns(dev);
1794+
goto err;
1795+
}
1796+
if (MLX5_CAP_ESW_EGRESS_ACL(dev, ft_support)) {
1797+
err = init_egress_acl_root_ns(dev);
1798+
if (err)
1799+
goto err;
1800+
}
1801+
if (MLX5_CAP_ESW_INGRESS_ACL(dev, ft_support)) {
1802+
err = init_ingress_acl_root_ns(dev);
1803+
if (err)
1804+
goto err;
17351805
}
17361806

1807+
return 0;
1808+
err:
1809+
mlx5_cleanup_fs(dev);
17371810
return err;
17381811
}

‎drivers/net/ethernet/mellanox/mlx5/core/fs_core.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ enum fs_node_type {
4545
};
4646

4747
enum fs_flow_table_type {
48-
FS_FT_NIC_RX = 0x0,
49-
FS_FT_FDB = 0X4,
48+
FS_FT_NIC_RX = 0x0,
49+
FS_FT_ESW_EGRESS_ACL = 0x2,
50+
FS_FT_ESW_INGRESS_ACL = 0x3,
51+
FS_FT_FDB = 0X4,
5052
};
5153

5254
enum fs_fte_status {
@@ -79,6 +81,7 @@ struct mlx5_flow_rule {
7981
struct mlx5_flow_table {
8082
struct fs_node node;
8183
u32 id;
84+
u16 vport;
8285
unsigned int max_fte;
8386
unsigned int level;
8487
enum fs_flow_table_type type;

‎drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define DRIVER_VERSION "3.0-1"
4343
#define DRIVER_RELDATE "January 2015"
4444

45+
#define MLX5_TOTAL_VPORTS(mdev) (1 + pci_sriov_get_totalvfs(mdev->pdev))
46+
4547
extern int mlx5_core_debug_mask;
4648

4749
#define mlx5_core_dbg(__dev, format, ...) \

‎include/linux/mlx5/device.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,18 @@ enum mlx5_cap_type {
13491349
#define MLX5_CAP_ESW_FLOWTABLE_FDB_MAX(mdev, cap) \
13501350
MLX5_CAP_ESW_FLOWTABLE_MAX(mdev, flow_table_properties_nic_esw_fdb.cap)
13511351

1352+
#define MLX5_CAP_ESW_EGRESS_ACL(mdev, cap) \
1353+
MLX5_CAP_ESW_FLOWTABLE(mdev, flow_table_properties_esw_acl_egress.cap)
1354+
1355+
#define MLX5_CAP_ESW_EGRESS_ACL_MAX(mdev, cap) \
1356+
MLX5_CAP_ESW_FLOWTABLE_MAX(mdev, flow_table_properties_esw_acl_egress.cap)
1357+
1358+
#define MLX5_CAP_ESW_INGRESS_ACL(mdev, cap) \
1359+
MLX5_CAP_ESW_FLOWTABLE(mdev, flow_table_properties_esw_acl_ingress.cap)
1360+
1361+
#define MLX5_CAP_ESW_INGRESS_ACL_MAX(mdev, cap) \
1362+
MLX5_CAP_ESW_FLOWTABLE_MAX(mdev, flow_table_properties_esw_acl_ingress.cap)
1363+
13521364
#define MLX5_CAP_ESW(mdev, cap) \
13531365
MLX5_GET(e_switch_cap, \
13541366
mdev->hca_caps_cur[MLX5_CAP_ESWITCH], cap)

‎include/linux/mlx5/driver.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ struct mlx5_priv {
518518
unsigned long pci_dev_data;
519519
struct mlx5_flow_root_namespace *root_ns;
520520
struct mlx5_flow_root_namespace *fdb_root_ns;
521+
struct mlx5_flow_root_namespace *esw_egress_root_ns;
522+
struct mlx5_flow_root_namespace *esw_ingress_root_ns;
521523
};
522524

523525
enum mlx5_device_state {

‎include/linux/mlx5/fs.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ enum mlx5_flow_namespace_type {
5858
MLX5_FLOW_NAMESPACE_LEFTOVERS,
5959
MLX5_FLOW_NAMESPACE_ANCHOR,
6060
MLX5_FLOW_NAMESPACE_FDB,
61+
MLX5_FLOW_NAMESPACE_ESW_EGRESS,
62+
MLX5_FLOW_NAMESPACE_ESW_INGRESS,
6163
};
6264

6365
struct mlx5_flow_table;
@@ -90,6 +92,11 @@ mlx5_create_flow_table(struct mlx5_flow_namespace *ns,
9092
int prio,
9193
int num_flow_table_entries,
9294
u32 level);
95+
struct mlx5_flow_table *
96+
mlx5_create_vport_flow_table(struct mlx5_flow_namespace *ns,
97+
int prio,
98+
int num_flow_table_entries,
99+
u32 level, u16 vport);
93100
int mlx5_destroy_flow_table(struct mlx5_flow_table *ft);
94101

95102
/* inbox should be set with the following values:

0 commit comments

Comments
 (0)