Skip to content

Commit 5024fa9

Browse files
author
Saeed Mahameed
committed
net/mlx5e: Remove mlx5e dependency from E-Switch sample
mlx5/esw/sample.c doesn't really need mlx5e_priv object, we can remove this redundant dependency by passing the eswitch object directly to the sample object constructor. Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Roi Dayan <[email protected]>
1 parent f444fea commit 5024fa9

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4976,7 +4976,7 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
49764976
MLX5_FLOW_NAMESPACE_FDB);
49774977

49784978
#if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE)
4979-
uplink_priv->esw_psample = mlx5_esw_sample_init(netdev_priv(priv->netdev));
4979+
uplink_priv->esw_psample = mlx5_esw_sample_init(esw);
49804980
#endif
49814981

49824982
mapping_id = mlx5_query_nic_system_image_guid(esw->dev);

drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const struct esw_vport_tbl_namespace mlx5_esw_vport_tbl_sample_ns = {
1818
};
1919

2020
struct mlx5_esw_psample {
21-
struct mlx5e_priv *priv;
21+
struct mlx5_eswitch *esw;
2222
struct mlx5_flow_table *termtbl;
2323
struct mlx5_flow_handle *termtbl_rule;
2424
DECLARE_HASHTABLE(hashtbl, 8);
@@ -55,10 +55,10 @@ struct mlx5_sample_restore {
5555
static int
5656
sampler_termtbl_create(struct mlx5_esw_psample *esw_psample)
5757
{
58-
struct mlx5_core_dev *dev = esw_psample->priv->mdev;
59-
struct mlx5_eswitch *esw = dev->priv.eswitch;
58+
struct mlx5_eswitch *esw = esw_psample->esw;
6059
struct mlx5_flow_table_attr ft_attr = {};
6160
struct mlx5_flow_destination dest = {};
61+
struct mlx5_core_dev *dev = esw->dev;
6262
struct mlx5_flow_namespace *root_ns;
6363
struct mlx5_flow_act act = {};
6464
int err;
@@ -187,7 +187,7 @@ sampler_get(struct mlx5_esw_psample *esw_psample, u32 sample_ratio, u32 default_
187187
sampler->default_table_id = default_table_id;
188188
sampler->sample_ratio = sample_ratio;
189189

190-
err = sampler_obj_create(esw_psample->priv->mdev, sampler);
190+
err = sampler_obj_create(esw_psample->esw->dev, sampler);
191191
if (err)
192192
goto err_create;
193193

@@ -211,7 +211,7 @@ sampler_put(struct mlx5_esw_psample *esw_psample, struct mlx5_sampler *sampler)
211211
mutex_lock(&esw_psample->ht_lock);
212212
if (--sampler->count == 0) {
213213
hash_del(&sampler->hlist);
214-
sampler_obj_destroy(esw_psample->priv->mdev, sampler->sampler_id);
214+
sampler_obj_destroy(esw_psample->esw->dev, sampler->sampler_id);
215215
kfree(sampler);
216216
}
217217
mutex_unlock(&esw_psample->ht_lock);
@@ -249,8 +249,8 @@ sample_metadata_rule_get(struct mlx5_core_dev *mdev, u32 obj_id)
249249
static struct mlx5_sample_restore *
250250
sample_restore_get(struct mlx5_esw_psample *esw_psample, u32 obj_id)
251251
{
252-
struct mlx5_core_dev *mdev = esw_psample->priv->mdev;
253-
struct mlx5_eswitch *esw = mdev->priv.eswitch;
252+
struct mlx5_eswitch *esw = esw_psample->esw;
253+
struct mlx5_core_dev *mdev = esw->dev;
254254
struct mlx5_sample_restore *restore;
255255
struct mlx5_modify_hdr *modify_hdr;
256256
int err;
@@ -305,7 +305,7 @@ sample_restore_put(struct mlx5_esw_psample *esw_psample, struct mlx5_sample_rest
305305

306306
if (!restore->count) {
307307
mlx5_del_flow_rules(restore->rule);
308-
mlx5_modify_header_dealloc(esw_psample->priv->mdev, restore->modify_hdr);
308+
mlx5_modify_header_dealloc(esw_psample->esw->dev, restore->modify_hdr);
309309
kfree(restore);
310310
}
311311
}
@@ -384,7 +384,7 @@ mlx5_esw_sample_offload(struct mlx5_esw_psample *esw_psample,
384384
/* If slow path flag is set, eg. when the neigh is invalid for encap,
385385
* don't offload sample action.
386386
*/
387-
esw = esw_psample->priv->mdev->priv.eswitch;
387+
esw = esw_psample->esw;
388388
if (attr->flags & MLX5_ESW_ATTR_FLAG_SLOW_PATH)
389389
return mlx5_eswitch_add_offloaded_rule(esw, spec, attr);
390390

@@ -522,7 +522,7 @@ mlx5_esw_sample_unoffload(struct mlx5_esw_psample *esw_psample,
522522
/* If slow path flag is set, sample action is not offloaded.
523523
* No need to delete sample rule.
524524
*/
525-
esw = esw_psample->priv->mdev->priv.eswitch;
525+
esw = esw_psample->esw;
526526
if (attr->flags & MLX5_ESW_ATTR_FLAG_SLOW_PATH) {
527527
mlx5_eswitch_del_offloaded_rule(esw, rule, attr);
528528
return;
@@ -531,7 +531,6 @@ mlx5_esw_sample_unoffload(struct mlx5_esw_psample *esw_psample,
531531
sample_flow = esw_attr->sample->sample_flow;
532532
pre_attr = sample_flow->pre_attr;
533533
memset(pre_attr, 0, sizeof(*pre_attr));
534-
esw = esw_psample->priv->mdev->priv.eswitch;
535534
mlx5_eswitch_del_offloaded_rule(esw, sample_flow->pre_rule, pre_attr);
536535
mlx5_eswitch_del_offloaded_rule(esw, sample_flow->rule, attr);
537536

@@ -550,15 +549,15 @@ mlx5_esw_sample_unoffload(struct mlx5_esw_psample *esw_psample,
550549
}
551550

552551
struct mlx5_esw_psample *
553-
mlx5_esw_sample_init(struct mlx5e_priv *priv)
552+
mlx5_esw_sample_init(struct mlx5_eswitch *esw)
554553
{
555554
struct mlx5_esw_psample *esw_psample;
556555
int err;
557556

558557
esw_psample = kzalloc(sizeof(*esw_psample), GFP_KERNEL);
559558
if (!esw_psample)
560559
return ERR_PTR(-ENOMEM);
561-
esw_psample->priv = priv;
560+
esw_psample->esw = esw;
562561
err = sampler_termtbl_create(esw_psample);
563562
if (err)
564563
goto err_termtbl;

drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
#ifndef __MLX5_EN_TC_SAMPLE_H__
55
#define __MLX5_EN_TC_SAMPLE_H__
66

7-
#include "en.h"
87
#include "eswitch.h"
98

10-
struct mlx5e_priv;
119
struct mlx5_flow_attr;
1210
struct mlx5_esw_psample;
1311

@@ -34,7 +32,7 @@ mlx5_esw_sample_unoffload(struct mlx5_esw_psample *sample_priv,
3432
struct mlx5_flow_attr *attr);
3533

3634
struct mlx5_esw_psample *
37-
mlx5_esw_sample_init(struct mlx5e_priv *priv);
35+
mlx5_esw_sample_init(struct mlx5_eswitch *esw);
3836

3937
void
4038
mlx5_esw_sample_cleanup(struct mlx5_esw_psample *esw_psample);

0 commit comments

Comments
 (0)