]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net/mlx5: Move legacy drop counter and rule under legacy structure
authorParav Pandit <parav@mellanox.com>
Mon, 28 Oct 2019 23:35:11 +0000 (23:35 +0000)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 1 Nov 2019 21:40:26 +0000 (14:40 -0700)
To improve code readability, move legacy drop counters and droup rule
under legacy structure.

While at it,
(a) prefix drop flow counters helper with legacy_.
(b) nullify the rule pointers only if they were valid.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

index fa1228a8005f23244b6db15076ed4d245dbefd7d..0dd5e5d5ea35e459501d415b3d69a488a2a8e8cc 100644 (file)
@@ -1040,14 +1040,15 @@ int esw_vport_enable_egress_acl(struct mlx5_eswitch *esw,
 void esw_vport_cleanup_egress_rules(struct mlx5_eswitch *esw,
                                    struct mlx5_vport *vport)
 {
-       if (!IS_ERR_OR_NULL(vport->egress.allowed_vlan))
+       if (!IS_ERR_OR_NULL(vport->egress.allowed_vlan)) {
                mlx5_del_flow_rules(vport->egress.allowed_vlan);
+               vport->egress.allowed_vlan = NULL;
+       }
 
-       if (!IS_ERR_OR_NULL(vport->egress.drop_rule))
-               mlx5_del_flow_rules(vport->egress.drop_rule);
-
-       vport->egress.allowed_vlan = NULL;
-       vport->egress.drop_rule = NULL;
+       if (!IS_ERR_OR_NULL(vport->egress.legacy.drop_rule)) {
+               mlx5_del_flow_rules(vport->egress.legacy.drop_rule);
+               vport->egress.legacy.drop_rule = NULL;
+       }
 }
 
 void esw_vport_disable_egress_acl(struct mlx5_eswitch *esw,
@@ -1202,14 +1203,15 @@ int esw_vport_enable_ingress_acl(struct mlx5_eswitch *esw,
 void esw_vport_cleanup_ingress_rules(struct mlx5_eswitch *esw,
                                     struct mlx5_vport *vport)
 {
-       if (!IS_ERR_OR_NULL(vport->ingress.drop_rule))
-               mlx5_del_flow_rules(vport->ingress.drop_rule);
+       if (!IS_ERR_OR_NULL(vport->ingress.legacy.drop_rule)) {
+               mlx5_del_flow_rules(vport->ingress.legacy.drop_rule);
+               vport->ingress.legacy.drop_rule = NULL;
+       }
 
-       if (!IS_ERR_OR_NULL(vport->ingress.allow_rule))
+       if (!IS_ERR_OR_NULL(vport->ingress.allow_rule)) {
                mlx5_del_flow_rules(vport->ingress.allow_rule);
-
-       vport->ingress.drop_rule = NULL;
-       vport->ingress.allow_rule = NULL;
+               vport->ingress.allow_rule = NULL;
+       }
 
        esw_vport_del_ingress_acl_modify_metadata(esw, vport);
 }
@@ -1238,7 +1240,7 @@ void esw_vport_disable_ingress_acl(struct mlx5_eswitch *esw,
 static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
                                    struct mlx5_vport *vport)
 {
-       struct mlx5_fc *counter = vport->ingress.drop_counter;
+       struct mlx5_fc *counter = vport->ingress.legacy.drop_counter;
        struct mlx5_flow_destination drop_ctr_dst = {0};
        struct mlx5_flow_destination *dst = NULL;
        struct mlx5_flow_act flow_act = {0};
@@ -1309,15 +1311,15 @@ static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
                dst = &drop_ctr_dst;
                dest_num++;
        }
-       vport->ingress.drop_rule =
+       vport->ingress.legacy.drop_rule =
                mlx5_add_flow_rules(vport->ingress.acl, spec,
                                    &flow_act, dst, dest_num);
-       if (IS_ERR(vport->ingress.drop_rule)) {
-               err = PTR_ERR(vport->ingress.drop_rule);
+       if (IS_ERR(vport->ingress.legacy.drop_rule)) {
+               err = PTR_ERR(vport->ingress.legacy.drop_rule);
                esw_warn(esw->dev,
                         "vport[%d] configure ingress drop rule, err(%d)\n",
                         vport->vport, err);
-               vport->ingress.drop_rule = NULL;
+               vport->ingress.legacy.drop_rule = NULL;
                goto out;
        }
 
@@ -1368,7 +1370,7 @@ int mlx5_esw_create_vport_egress_acl_vlan(struct mlx5_eswitch *esw,
 static int esw_vport_egress_config(struct mlx5_eswitch *esw,
                                   struct mlx5_vport *vport)
 {
-       struct mlx5_fc *counter = vport->egress.drop_counter;
+       struct mlx5_fc *counter = vport->egress.legacy.drop_counter;
        struct mlx5_flow_destination drop_ctr_dst = {0};
        struct mlx5_flow_destination *dst = NULL;
        struct mlx5_flow_act flow_act = {0};
@@ -1416,15 +1418,15 @@ static int esw_vport_egress_config(struct mlx5_eswitch *esw,
                dst = &drop_ctr_dst;
                dest_num++;
        }
-       vport->egress.drop_rule =
+       vport->egress.legacy.drop_rule =
                mlx5_add_flow_rules(vport->egress.acl, spec,
                                    &flow_act, dst, dest_num);
-       if (IS_ERR(vport->egress.drop_rule)) {
-               err = PTR_ERR(vport->egress.drop_rule);
+       if (IS_ERR(vport->egress.legacy.drop_rule)) {
+               err = PTR_ERR(vport->egress.legacy.drop_rule);
                esw_warn(esw->dev,
                         "vport[%d] configure egress drop rule failed, err(%d)\n",
                         vport->vport, err);
-               vport->egress.drop_rule = NULL;
+               vport->egress.legacy.drop_rule = NULL;
        }
 out:
        kvfree(spec);
@@ -1667,39 +1669,39 @@ static void esw_apply_vport_conf(struct mlx5_eswitch *esw,
        }
 }
 
-static void esw_vport_create_drop_counters(struct mlx5_vport *vport)
+static void esw_legacy_vport_create_drop_counters(struct mlx5_vport *vport)
 {
        struct mlx5_core_dev *dev = vport->dev;
 
        if (MLX5_CAP_ESW_INGRESS_ACL(dev, flow_counter)) {
-               vport->ingress.drop_counter = mlx5_fc_create(dev, false);
-               if (IS_ERR(vport->ingress.drop_counter)) {
+               vport->ingress.legacy.drop_counter = mlx5_fc_create(dev, false);
+               if (IS_ERR(vport->ingress.legacy.drop_counter)) {
                        esw_warn(dev,
                                 "vport[%d] configure ingress drop rule counter failed\n",
                                 vport->vport);
-                       vport->ingress.drop_counter = NULL;
+                       vport->ingress.legacy.drop_counter = NULL;
                }
        }
 
        if (MLX5_CAP_ESW_EGRESS_ACL(dev, flow_counter)) {
-               vport->egress.drop_counter = mlx5_fc_create(dev, false);
-               if (IS_ERR(vport->egress.drop_counter)) {
+               vport->egress.legacy.drop_counter = mlx5_fc_create(dev, false);
+               if (IS_ERR(vport->egress.legacy.drop_counter)) {
                        esw_warn(dev,
                                 "vport[%d] configure egress drop rule counter failed\n",
                                 vport->vport);
-                       vport->egress.drop_counter = NULL;
+                       vport->egress.legacy.drop_counter = NULL;
                }
        }
 }
 
-static void esw_vport_destroy_drop_counters(struct mlx5_vport *vport)
+static void esw_legacy_vport_destroy_drop_counters(struct mlx5_vport *vport)
 {
        struct mlx5_core_dev *dev = vport->dev;
 
-       if (vport->ingress.drop_counter)
-               mlx5_fc_destroy(dev, vport->ingress.drop_counter);
-       if (vport->egress.drop_counter)
-               mlx5_fc_destroy(dev, vport->egress.drop_counter);
+       if (vport->ingress.legacy.drop_counter)
+               mlx5_fc_destroy(dev, vport->ingress.legacy.drop_counter);
+       if (vport->egress.legacy.drop_counter)
+               mlx5_fc_destroy(dev, vport->egress.legacy.drop_counter);
 }
 
 static void esw_enable_vport(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
@@ -1715,7 +1717,7 @@ static void esw_enable_vport(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
        /* Create steering drop counters for ingress and egress ACLs */
        if (!mlx5_esw_is_manager_vport(esw, vport_num) &&
            esw->mode == MLX5_ESWITCH_LEGACY)
-               esw_vport_create_drop_counters(vport);
+               esw_legacy_vport_create_drop_counters(vport);
 
        /* Restore old vport configuration */
        esw_apply_vport_conf(esw, vport);
@@ -1775,7 +1777,7 @@ static void esw_disable_vport(struct mlx5_eswitch *esw,
                                              MLX5_VPORT_ADMIN_STATE_DOWN);
                esw_vport_disable_egress_acl(esw, vport);
                esw_vport_disable_ingress_acl(esw, vport);
-               esw_vport_destroy_drop_counters(vport);
+               esw_legacy_vport_destroy_drop_counters(vport);
        }
        esw->enabled_vports--;
        mutex_unlock(&esw->state_lock);
@@ -2495,12 +2497,12 @@ static int mlx5_eswitch_query_vport_drop_stats(struct mlx5_core_dev *dev,
        if (!vport->enabled || esw->mode != MLX5_ESWITCH_LEGACY)
                return 0;
 
-       if (vport->egress.drop_counter)
-               mlx5_fc_query(dev, vport->egress.drop_counter,
+       if (vport->egress.legacy.drop_counter)
+               mlx5_fc_query(dev, vport->egress.legacy.drop_counter,
                              &stats->rx_dropped, &bytes);
 
-       if (vport->ingress.drop_counter)
-               mlx5_fc_query(dev, vport->ingress.drop_counter,
+       if (vport->ingress.legacy.drop_counter)
+               mlx5_fc_query(dev, vport->ingress.legacy.drop_counter,
                              &stats->tx_dropped, &bytes);
 
        if (!MLX5_CAP_GEN(dev, receive_discard_vport_down) &&
index 5f862992b9c862b3dcad73820f1bb5bb74759479..ec0ef7c5d5396cfd3a78f9713afaccff9c1271e9 100644 (file)
@@ -70,8 +70,10 @@ struct vport_ingress {
        struct mlx5_flow_group *allow_untagged_only_grp;
        struct mlx5_flow_group *drop_grp;
        struct mlx5_flow_handle  *allow_rule;
-       struct mlx5_flow_handle  *drop_rule;
-       struct mlx5_fc           *drop_counter;
+       struct {
+               struct mlx5_flow_handle *drop_rule;
+               struct mlx5_fc *drop_counter;
+       } legacy;
        struct {
                struct mlx5_modify_hdr *modify_metadata;
                struct mlx5_flow_handle *modify_metadata_rule;
@@ -83,8 +85,10 @@ struct vport_egress {
        struct mlx5_flow_group *allowed_vlans_grp;
        struct mlx5_flow_group *drop_grp;
        struct mlx5_flow_handle  *allowed_vlan;
-       struct mlx5_flow_handle  *drop_rule;
-       struct mlx5_fc           *drop_counter;
+       struct {
+               struct mlx5_flow_handle *drop_rule;
+               struct mlx5_fc *drop_counter;
+       } legacy;
 };
 
 struct mlx5_vport_drop_stats {