Skip to content

Commit 23bde06

Browse files
Lama KayalSaeed Mahameed
authored andcommitted
net/mlx5e: Make mlx5e_tc_table private
Move mlx5e_tc_table struct to en_tc.c thus make it private. Introduce allocation and deallocation functions as part of the tc API to allow this switch smoothly. Convert mlx5e_nic_chain() macro to a function of en_tc.c. Signed-off-by: Lama Kayal <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 65f586c commit 23bde06

File tree

6 files changed

+59
-32
lines changed

6 files changed

+59
-32
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/fs.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,6 @@ enum {
1515
MLX5E_TC_MISS_LEVEL,
1616
};
1717

18-
struct mlx5e_tc_table {
19-
/* Protects the dynamic assignment of the t parameter
20-
* which is the nic tc root table.
21-
*/
22-
struct mutex t_lock;
23-
struct mlx5e_priv *priv;
24-
struct mlx5_flow_table *t;
25-
struct mlx5_flow_table *miss_t;
26-
struct mlx5_fs_chains *chains;
27-
struct mlx5e_post_act *post_act;
28-
29-
struct rhashtable ht;
30-
31-
struct mod_hdr_tbl mod_hdr;
32-
struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
33-
DECLARE_HASHTABLE(hairpin_tbl, 8);
34-
35-
struct notifier_block netdevice_nb;
36-
struct netdev_net_notifier netdevice_nn;
37-
38-
struct mlx5_tc_ct_priv *ct;
39-
struct mapping_ctx *mapping;
40-
};
41-
4218
struct mlx5e_flow_table {
4319
int num_groups;
4420
struct mlx5_flow_table *t;

drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/goto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ validate_goto_chain(struct mlx5e_priv *priv,
2121
u32 max_chain;
2222

2323
esw = priv->mdev->priv.eswitch;
24-
chains = is_esw ? esw_chains(esw) : mlx5e_nic_chains(priv);
24+
chains = is_esw ? esw_chains(esw) : mlx5e_nic_chains(priv->fs.tc);
2525
max_chain = mlx5_chains_get_chain_range(chains);
2626
reformat_and_fwd = is_esw ?
2727
MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, reformat_and_fwd_to_table) :

drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#define MLX5E_TC_MAX_SPLITS 1
1313

14-
#define mlx5e_nic_chains(priv) ((priv)->fs.tc->chains)
1514

1615
enum {
1716
MLX5E_TC_FLOW_FLAG_INGRESS = MLX5E_TC_FLAG_INGRESS_BIT,
@@ -44,6 +43,8 @@ struct mlx5e_tc_flow_parse_attr {
4443
struct mlx5e_tc_act_parse_state parse_state;
4544
};
4645

46+
struct mlx5_fs_chains *mlx5e_nic_chains(struct mlx5e_tc_table *tc);
47+
4748
/* Helper struct for accessing a struct containing list_head array.
4849
* Containing struct
4950
* |- Helper array

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/mlx5/mpfs.h>
3939
#include "en.h"
4040
#include "en_rep.h"
41+
#include "en_tc.h"
4142
#include "lib/mpfs.h"
4243
#include "en/ptp.h"
4344

@@ -1347,9 +1348,11 @@ int mlx5e_fs_init(struct mlx5e_priv *priv)
13471348
priv->fs.vlan = kvzalloc(sizeof(*priv->fs.vlan), GFP_KERNEL);
13481349
if (!priv->fs.vlan)
13491350
goto err;
1350-
priv->fs.tc = kvzalloc(sizeof(*priv->fs.tc), GFP_KERNEL);
1351-
if (!priv->fs.tc)
1351+
1352+
priv->fs.tc = mlx5e_tc_table_alloc();
1353+
if (IS_ERR(priv->fs.tc))
13521354
goto err_free_vlan;
1355+
13531356
return 0;
13541357
err_free_vlan:
13551358
kvfree(priv->fs.vlan);
@@ -1360,7 +1363,7 @@ int mlx5e_fs_init(struct mlx5e_priv *priv)
13601363

13611364
void mlx5e_fs_cleanup(struct mlx5e_priv *priv)
13621365
{
1363-
kvfree(priv->fs.tc);
1366+
mlx5e_tc_table_free(priv->fs.tc);
13641367
kvfree(priv->fs.vlan);
13651368
priv->fs.vlan = NULL;
13661369
}

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@
7171
#define MLX5E_TC_TABLE_NUM_GROUPS 4
7272
#define MLX5E_TC_TABLE_MAX_GROUP_SIZE BIT(18)
7373

74+
struct mlx5e_tc_table {
75+
/* Protects the dynamic assignment of the t parameter
76+
* which is the nic tc root table.
77+
*/
78+
struct mutex t_lock;
79+
struct mlx5e_priv *priv;
80+
struct mlx5_flow_table *t;
81+
struct mlx5_flow_table *miss_t;
82+
struct mlx5_fs_chains *chains;
83+
struct mlx5e_post_act *post_act;
84+
85+
struct rhashtable ht;
86+
87+
struct mod_hdr_tbl mod_hdr;
88+
struct mutex hairpin_tbl_lock; /* protects hairpin_tbl */
89+
DECLARE_HASHTABLE(hairpin_tbl, 8);
90+
91+
struct notifier_block netdevice_nb;
92+
struct netdev_net_notifier netdevice_nn;
93+
94+
struct mlx5_tc_ct_priv *ct;
95+
struct mapping_ctx *mapping;
96+
};
97+
7498
struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = {
7599
[CHAIN_TO_REG] = {
76100
.mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_0,
@@ -108,6 +132,24 @@ struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = {
108132
[PACKET_COLOR_TO_REG] = packet_color_to_reg,
109133
};
110134

135+
struct mlx5e_tc_table *mlx5e_tc_table_alloc(void)
136+
{
137+
struct mlx5e_tc_table *tc;
138+
139+
tc = kvzalloc(sizeof(*tc), GFP_KERNEL);
140+
return tc ? tc : ERR_PTR(-ENOMEM);
141+
}
142+
143+
void mlx5e_tc_table_free(struct mlx5e_tc_table *tc)
144+
{
145+
kvfree(tc);
146+
}
147+
148+
struct mlx5_fs_chains *mlx5e_nic_chains(struct mlx5e_tc_table *tc)
149+
{
150+
return tc->chains;
151+
}
152+
111153
/* To avoid false lock dependency warning set the tc_ht lock
112154
* class different than the lock class of the ht being used when deleting
113155
* last flow from a group and then deleting a group, we get into del_sw_flow_group()
@@ -1084,10 +1126,10 @@ mlx5e_add_offloaded_nic_rule(struct mlx5e_priv *priv,
10841126
struct mlx5_flow_attr *attr)
10851127
{
10861128
struct mlx5_flow_context *flow_context = &spec->flow_context;
1087-
struct mlx5_fs_chains *nic_chains = mlx5e_nic_chains(priv);
10881129
struct mlx5_nic_flow_attr *nic_attr = attr->nic_attr;
10891130
struct mlx5e_tc_table *tc = priv->fs.tc;
10901131
struct mlx5_flow_destination dest[2] = {};
1132+
struct mlx5_fs_chains *nic_chains;
10911133
struct mlx5_flow_act flow_act = {
10921134
.action = attr->action,
10931135
.flags = FLOW_ACT_NO_APPEND,
@@ -1096,6 +1138,7 @@ mlx5e_add_offloaded_nic_rule(struct mlx5e_priv *priv,
10961138
struct mlx5_flow_table *ft;
10971139
int dest_ix = 0;
10981140

1141+
nic_chains = mlx5e_nic_chains(tc);
10991142
flow_context->flags |= FLOW_CONTEXT_HAS_TAG;
11001143
flow_context->flow_tag = nic_attr->flow_tag;
11011144

@@ -1250,7 +1293,7 @@ void mlx5e_del_offloaded_nic_rule(struct mlx5e_priv *priv,
12501293
struct mlx5_flow_handle *rule,
12511294
struct mlx5_flow_attr *attr)
12521295
{
1253-
struct mlx5_fs_chains *nic_chains = mlx5e_nic_chains(priv);
1296+
struct mlx5_fs_chains *nic_chains = mlx5e_nic_chains(priv->fs.tc);
12541297

12551298
mlx5_del_flow_rules(rule);
12561299

@@ -1282,7 +1325,7 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
12821325
mutex_lock(&priv->fs.tc->t_lock);
12831326
if (!mlx5e_tc_num_filters(priv, MLX5_TC_FLAG(NIC_OFFLOAD)) &&
12841327
!IS_ERR_OR_NULL(tc->t)) {
1285-
mlx5_chains_put_table(mlx5e_nic_chains(priv), 0, 1, MLX5E_TC_FT_LEVEL);
1328+
mlx5_chains_put_table(mlx5e_nic_chains(tc), 0, 1, MLX5E_TC_FT_LEVEL);
12861329
priv->fs.tc->t = NULL;
12871330
}
12881331
mutex_unlock(&priv->fs.tc->t_lock);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ mlx5e_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
356356
#endif
357357

358358
#if IS_ENABLED(CONFIG_MLX5_CLS_ACT)
359+
struct mlx5e_tc_table *mlx5e_tc_table_alloc(void);
360+
void mlx5e_tc_table_free(struct mlx5e_tc_table *tc);
359361
static inline bool mlx5e_cqe_regb_chain(struct mlx5_cqe64 *cqe)
360362
{
361363
#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
@@ -376,6 +378,8 @@ static inline bool mlx5e_cqe_regb_chain(struct mlx5_cqe64 *cqe)
376378

377379
bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe, struct sk_buff *skb);
378380
#else /* CONFIG_MLX5_CLS_ACT */
381+
static inline struct mlx5e_tc_table *mlx5e_tc_table_alloc(void) { return NULL; }
382+
static inline void mlx5e_tc_table_free(struct mlx5e_tc_table *tc) {}
379383
static inline bool mlx5e_cqe_regb_chain(struct mlx5_cqe64 *cqe)
380384
{ return false; }
381385
static inline bool

0 commit comments

Comments
 (0)