Skip to content

Commit fba53f7

Browse files
Maor Gottliebdavem330
authored andcommitted
net/mlx5: Introduce mlx5_flow_steering structure
Instead of having all steering private name spaces and steering module fields flat in mlx5_core_priv, we wrap them in mlx5_flow_steering for better modularity and API exposure. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c5bb173 commit fba53f7

File tree

3 files changed

+84
-64
lines changed

3 files changed

+84
-64
lines changed

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

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,12 +1363,13 @@ void mlx5_destroy_flow_group(struct mlx5_flow_group *fg)
13631363
struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
13641364
enum mlx5_flow_namespace_type type)
13651365
{
1366-
struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1366+
struct mlx5_flow_steering *steering = dev->priv.steering;
1367+
struct mlx5_flow_root_namespace *root_ns;
13671368
int prio;
13681369
struct fs_prio *fs_prio;
13691370
struct mlx5_flow_namespace *ns;
13701371

1371-
if (!root_ns)
1372+
if (!steering)
13721373
return NULL;
13731374

13741375
switch (type) {
@@ -1380,24 +1381,28 @@ struct mlx5_flow_namespace *mlx5_get_flow_namespace(struct mlx5_core_dev *dev,
13801381
prio = type;
13811382
break;
13821383
case MLX5_FLOW_NAMESPACE_FDB:
1383-
if (dev->priv.fdb_root_ns)
1384-
return &dev->priv.fdb_root_ns->ns;
1384+
if (steering->fdb_root_ns)
1385+
return &steering->fdb_root_ns->ns;
13851386
else
13861387
return NULL;
13871388
case MLX5_FLOW_NAMESPACE_ESW_EGRESS:
1388-
if (dev->priv.esw_egress_root_ns)
1389-
return &dev->priv.esw_egress_root_ns->ns;
1389+
if (steering->esw_egress_root_ns)
1390+
return &steering->esw_egress_root_ns->ns;
13901391
else
13911392
return NULL;
13921393
case MLX5_FLOW_NAMESPACE_ESW_INGRESS:
1393-
if (dev->priv.esw_ingress_root_ns)
1394-
return &dev->priv.esw_ingress_root_ns->ns;
1394+
if (steering->esw_ingress_root_ns)
1395+
return &steering->esw_ingress_root_ns->ns;
13951396
else
13961397
return NULL;
13971398
default:
13981399
return NULL;
13991400
}
14001401

1402+
root_ns = steering->root_ns;
1403+
if (!root_ns)
1404+
return NULL;
1405+
14011406
fs_prio = find_prio(&root_ns->ns, prio);
14021407
if (!fs_prio)
14031408
return NULL;
@@ -1483,13 +1488,13 @@ static bool has_required_caps(struct mlx5_core_dev *dev, struct node_caps *caps)
14831488
return true;
14841489
}
14851490

1486-
static int init_root_tree_recursive(struct mlx5_core_dev *dev,
1491+
static int init_root_tree_recursive(struct mlx5_flow_steering *steering,
14871492
struct init_tree_node *init_node,
14881493
struct fs_node *fs_parent_node,
14891494
struct init_tree_node *init_parent_node,
14901495
int prio)
14911496
{
1492-
int max_ft_level = MLX5_CAP_FLOWTABLE(dev,
1497+
int max_ft_level = MLX5_CAP_FLOWTABLE(steering->dev,
14931498
flow_table_properties_nic_receive.
14941499
max_ft_level);
14951500
struct mlx5_flow_namespace *fs_ns;
@@ -1500,7 +1505,7 @@ static int init_root_tree_recursive(struct mlx5_core_dev *dev,
15001505

15011506
if (init_node->type == FS_TYPE_PRIO) {
15021507
if ((init_node->min_ft_level > max_ft_level) ||
1503-
!has_required_caps(dev, &init_node->caps))
1508+
!has_required_caps(steering->dev, &init_node->caps))
15041509
return 0;
15051510

15061511
fs_get_obj(fs_ns, fs_parent_node);
@@ -1521,7 +1526,7 @@ static int init_root_tree_recursive(struct mlx5_core_dev *dev,
15211526
}
15221527
prio = 0;
15231528
for (i = 0; i < init_node->ar_size; i++) {
1524-
err = init_root_tree_recursive(dev, &init_node->children[i],
1529+
err = init_root_tree_recursive(steering, &init_node->children[i],
15251530
base, init_node, prio);
15261531
if (err)
15271532
return err;
@@ -1534,7 +1539,7 @@ static int init_root_tree_recursive(struct mlx5_core_dev *dev,
15341539
return 0;
15351540
}
15361541

1537-
static int init_root_tree(struct mlx5_core_dev *dev,
1542+
static int init_root_tree(struct mlx5_flow_steering *steering,
15381543
struct init_tree_node *init_node,
15391544
struct fs_node *fs_parent_node)
15401545
{
@@ -1544,7 +1549,7 @@ static int init_root_tree(struct mlx5_core_dev *dev,
15441549

15451550
fs_get_obj(fs_ns, fs_parent_node);
15461551
for (i = 0; i < init_node->ar_size; i++) {
1547-
err = init_root_tree_recursive(dev, &init_node->children[i],
1552+
err = init_root_tree_recursive(steering, &init_node->children[i],
15481553
&fs_ns->node,
15491554
init_node, i);
15501555
if (err)
@@ -1553,7 +1558,7 @@ static int init_root_tree(struct mlx5_core_dev *dev,
15531558
return 0;
15541559
}
15551560

1556-
static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_core_dev *dev,
1561+
static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_flow_steering *steering,
15571562
enum fs_flow_table_type
15581563
table_type)
15591564
{
@@ -1565,7 +1570,7 @@ static struct mlx5_flow_root_namespace *create_root_ns(struct mlx5_core_dev *dev
15651570
if (!root_ns)
15661571
return NULL;
15671572

1568-
root_ns->dev = dev;
1573+
root_ns->dev = steering->dev;
15691574
root_ns->table_type = table_type;
15701575

15711576
ns = &root_ns->ns;
@@ -1620,46 +1625,45 @@ static void set_prio_attrs(struct mlx5_flow_root_namespace *root_ns)
16201625
#define ANCHOR_PRIO 0
16211626
#define ANCHOR_SIZE 1
16221627
#define ANCHOR_LEVEL 0
1623-
static int create_anchor_flow_table(struct mlx5_core_dev
1624-
*dev)
1628+
static int create_anchor_flow_table(struct mlx5_flow_steering *steering)
16251629
{
16261630
struct mlx5_flow_namespace *ns = NULL;
16271631
struct mlx5_flow_table *ft;
16281632

1629-
ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ANCHOR);
1633+
ns = mlx5_get_flow_namespace(steering->dev, MLX5_FLOW_NAMESPACE_ANCHOR);
16301634
if (!ns)
16311635
return -EINVAL;
16321636
ft = mlx5_create_flow_table(ns, ANCHOR_PRIO, ANCHOR_SIZE, ANCHOR_LEVEL);
16331637
if (IS_ERR(ft)) {
1634-
mlx5_core_err(dev, "Failed to create last anchor flow table");
1638+
mlx5_core_err(steering->dev, "Failed to create last anchor flow table");
16351639
return PTR_ERR(ft);
16361640
}
16371641
return 0;
16381642
}
16391643

1640-
static int init_root_ns(struct mlx5_core_dev *dev)
1644+
static int init_root_ns(struct mlx5_flow_steering *steering)
16411645
{
16421646

1643-
dev->priv.root_ns = create_root_ns(dev, FS_FT_NIC_RX);
1644-
if (IS_ERR_OR_NULL(dev->priv.root_ns))
1647+
steering->root_ns = create_root_ns(steering, FS_FT_NIC_RX);
1648+
if (IS_ERR_OR_NULL(steering->root_ns))
16451649
goto cleanup;
16461650

1647-
if (init_root_tree(dev, &root_fs, &dev->priv.root_ns->ns.node))
1651+
if (init_root_tree(steering, &root_fs, &steering->root_ns->ns.node))
16481652
goto cleanup;
16491653

1650-
set_prio_attrs(dev->priv.root_ns);
1654+
set_prio_attrs(steering->root_ns);
16511655

1652-
if (create_anchor_flow_table(dev))
1656+
if (create_anchor_flow_table(steering))
16531657
goto cleanup;
16541658

16551659
return 0;
16561660

16571661
cleanup:
1658-
mlx5_cleanup_fs(dev);
1662+
mlx5_cleanup_fs(steering->dev);
16591663
return -ENOMEM;
16601664
}
16611665

1662-
static void cleanup_single_prio_root_ns(struct mlx5_core_dev *dev,
1666+
static void cleanup_single_prio_root_ns(struct mlx5_flow_steering *steering,
16631667
struct mlx5_flow_root_namespace *root_ns)
16641668
{
16651669
struct fs_node *prio;
@@ -1672,11 +1676,11 @@ static void cleanup_single_prio_root_ns(struct mlx5_core_dev *dev,
16721676
struct fs_node,
16731677
list);
16741678
if (tree_remove_node(prio))
1675-
mlx5_core_warn(dev,
1679+
mlx5_core_warn(steering->dev,
16761680
"Flow steering priority wasn't destroyed, refcount > 1\n");
16771681
}
16781682
if (tree_remove_node(&root_ns->ns.node))
1679-
mlx5_core_warn(dev,
1683+
mlx5_core_warn(steering->dev,
16801684
"Flow steering namespace wasn't destroyed, refcount > 1\n");
16811685
root_ns = NULL;
16821686
}
@@ -1690,12 +1694,12 @@ static void destroy_flow_tables(struct fs_prio *prio)
16901694
mlx5_destroy_flow_table(iter);
16911695
}
16921696

1693-
static void cleanup_root_ns(struct mlx5_core_dev *dev)
1697+
static void cleanup_root_ns(struct mlx5_flow_steering *steering)
16941698
{
1695-
struct mlx5_flow_root_namespace *root_ns = dev->priv.root_ns;
1699+
struct mlx5_flow_root_namespace *root_ns = steering->root_ns;
16961700
struct fs_prio *iter_prio;
16971701

1698-
if (!MLX5_CAP_GEN(dev, nic_flow_table))
1702+
if (!MLX5_CAP_GEN(steering->dev, nic_flow_table))
16991703
return;
17001704

17011705
if (!root_ns)
@@ -1720,7 +1724,7 @@ static void cleanup_root_ns(struct mlx5_core_dev *dev)
17201724
fs_get_obj(obj_iter_prio2, iter_prio2);
17211725
destroy_flow_tables(obj_iter_prio2);
17221726
if (tree_remove_node(iter_prio2)) {
1723-
mlx5_core_warn(dev,
1727+
mlx5_core_warn(steering->dev,
17241728
"Priority %d wasn't destroyed, refcount > 1\n",
17251729
obj_iter_prio2->prio);
17261730
return;
@@ -1737,7 +1741,7 @@ static void cleanup_root_ns(struct mlx5_core_dev *dev)
17371741
struct fs_node,
17381742
list);
17391743
if (tree_remove_node(iter_ns)) {
1740-
mlx5_core_warn(dev,
1744+
mlx5_core_warn(steering->dev,
17411745
"Namespace wasn't destroyed, refcount > 1\n");
17421746
return;
17431747
}
@@ -1754,78 +1758,83 @@ static void cleanup_root_ns(struct mlx5_core_dev *dev)
17541758

17551759
fs_get_obj(obj_prio_node, prio_node);
17561760
if (tree_remove_node(prio_node)) {
1757-
mlx5_core_warn(dev,
1761+
mlx5_core_warn(steering->dev,
17581762
"Priority %d wasn't destroyed, refcount > 1\n",
17591763
obj_prio_node->prio);
17601764
return;
17611765
}
17621766
}
17631767

17641768
if (tree_remove_node(&root_ns->ns.node)) {
1765-
mlx5_core_warn(dev,
1769+
mlx5_core_warn(steering->dev,
17661770
"root namespace wasn't destroyed, refcount > 1\n");
17671771
return;
17681772
}
17691773

1770-
dev->priv.root_ns = NULL;
1774+
steering->root_ns = NULL;
17711775
}
17721776

17731777
void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
17741778
{
1779+
struct mlx5_flow_steering *steering = dev->priv.steering;
1780+
17751781
if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
17761782
return;
17771783

1778-
cleanup_root_ns(dev);
1779-
cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1780-
cleanup_single_prio_root_ns(dev, dev->priv.esw_egress_root_ns);
1781-
cleanup_single_prio_root_ns(dev, dev->priv.esw_ingress_root_ns);
1784+
cleanup_root_ns(steering);
1785+
cleanup_single_prio_root_ns(steering, steering->esw_egress_root_ns);
1786+
cleanup_single_prio_root_ns(steering, steering->esw_ingress_root_ns);
1787+
cleanup_single_prio_root_ns(steering, steering->fdb_root_ns);
17821788
mlx5_cleanup_fc_stats(dev);
1789+
kfree(steering);
17831790
}
17841791

1785-
static int init_fdb_root_ns(struct mlx5_core_dev *dev)
1792+
static int init_fdb_root_ns(struct mlx5_flow_steering *steering)
17861793
{
17871794
struct fs_prio *prio;
17881795

1789-
dev->priv.fdb_root_ns = create_root_ns(dev, FS_FT_FDB);
1790-
if (!dev->priv.fdb_root_ns)
1796+
steering->fdb_root_ns = create_root_ns(steering, FS_FT_FDB);
1797+
if (!steering->fdb_root_ns)
17911798
return -ENOMEM;
17921799

17931800
/* Create single prio */
1794-
prio = fs_create_prio(&dev->priv.fdb_root_ns->ns, 0, 1);
1801+
prio = fs_create_prio(&steering->fdb_root_ns->ns, 0, 1);
17951802
if (IS_ERR(prio)) {
1796-
cleanup_single_prio_root_ns(dev, dev->priv.fdb_root_ns);
1803+
cleanup_single_prio_root_ns(steering, steering->fdb_root_ns);
17971804
return PTR_ERR(prio);
17981805
} else {
17991806
return 0;
18001807
}
18011808
}
18021809

1803-
static int init_egress_acl_root_ns(struct mlx5_core_dev *dev)
1810+
static int init_ingress_acl_root_ns(struct mlx5_flow_steering *steering)
18041811
{
18051812
struct fs_prio *prio;
18061813

1807-
dev->priv.esw_egress_root_ns = create_root_ns(dev, FS_FT_ESW_EGRESS_ACL);
1808-
if (!dev->priv.esw_egress_root_ns)
1814+
steering->esw_egress_root_ns = create_root_ns(steering, FS_FT_ESW_EGRESS_ACL);
1815+
if (!steering->esw_egress_root_ns)
18091816
return -ENOMEM;
18101817

18111818
/* create 1 prio*/
1812-
prio = fs_create_prio(&dev->priv.esw_egress_root_ns->ns, 0, MLX5_TOTAL_VPORTS(dev));
1819+
prio = fs_create_prio(&steering->esw_egress_root_ns->ns, 0,
1820+
MLX5_TOTAL_VPORTS(steering->dev));
18131821
if (IS_ERR(prio))
18141822
return PTR_ERR(prio);
18151823
else
18161824
return 0;
18171825
}
18181826

1819-
static int init_ingress_acl_root_ns(struct mlx5_core_dev *dev)
1827+
static int init_egress_acl_root_ns(struct mlx5_flow_steering *steering)
18201828
{
18211829
struct fs_prio *prio;
18221830

1823-
dev->priv.esw_ingress_root_ns = create_root_ns(dev, FS_FT_ESW_INGRESS_ACL);
1824-
if (!dev->priv.esw_ingress_root_ns)
1831+
steering->esw_ingress_root_ns = create_root_ns(steering, FS_FT_ESW_INGRESS_ACL);
1832+
if (!steering->esw_ingress_root_ns)
18251833
return -ENOMEM;
18261834

18271835
/* create 1 prio*/
1828-
prio = fs_create_prio(&dev->priv.esw_ingress_root_ns->ns, 0, MLX5_TOTAL_VPORTS(dev));
1836+
prio = fs_create_prio(&steering->esw_ingress_root_ns->ns, 0,
1837+
MLX5_TOTAL_VPORTS(steering->dev));
18291838
if (IS_ERR(prio))
18301839
return PTR_ERR(prio);
18311840
else
@@ -1834,6 +1843,7 @@ static int init_ingress_acl_root_ns(struct mlx5_core_dev *dev)
18341843

18351844
int mlx5_init_fs(struct mlx5_core_dev *dev)
18361845
{
1846+
struct mlx5_flow_steering *steering;
18371847
int err = 0;
18381848

18391849
if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
@@ -1843,26 +1853,32 @@ int mlx5_init_fs(struct mlx5_core_dev *dev)
18431853
if (err)
18441854
return err;
18451855

1856+
steering = kzalloc(sizeof(*steering), GFP_KERNEL);
1857+
if (!steering)
1858+
return -ENOMEM;
1859+
steering->dev = dev;
1860+
dev->priv.steering = steering;
1861+
18461862
if (MLX5_CAP_GEN(dev, nic_flow_table) &&
18471863
MLX5_CAP_FLOWTABLE_NIC_RX(dev, ft_support)) {
1848-
err = init_root_ns(dev);
1864+
err = init_root_ns(steering);
18491865
if (err)
18501866
goto err;
18511867
}
18521868

18531869
if (MLX5_CAP_GEN(dev, eswitch_flow_table)) {
18541870
if (MLX5_CAP_ESW_FLOWTABLE_FDB(dev, ft_support)) {
1855-
err = init_fdb_root_ns(dev);
1871+
err = init_fdb_root_ns(steering);
18561872
if (err)
18571873
goto err;
18581874
}
18591875
if (MLX5_CAP_ESW_EGRESS_ACL(dev, ft_support)) {
1860-
err = init_egress_acl_root_ns(dev);
1876+
err = init_egress_acl_root_ns(steering);
18611877
if (err)
18621878
goto err;
18631879
}
18641880
if (MLX5_CAP_ESW_INGRESS_ACL(dev, ft_support)) {
1865-
err = init_ingress_acl_root_ns(dev);
1881+
err = init_ingress_acl_root_ns(steering);
18661882
if (err)
18671883
goto err;
18681884
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ enum fs_fte_status {
5555
FS_FTE_STATUS_EXISTING = 1UL << 0,
5656
};
5757

58+
struct mlx5_flow_steering {
59+
struct mlx5_core_dev *dev;
60+
struct mlx5_flow_root_namespace *root_ns;
61+
struct mlx5_flow_root_namespace *fdb_root_ns;
62+
struct mlx5_flow_root_namespace *esw_egress_root_ns;
63+
struct mlx5_flow_root_namespace *esw_ingress_root_ns;
64+
};
65+
5866
struct fs_node {
5967
struct list_head list;
6068
struct list_head children;

0 commit comments

Comments
 (0)