mlxsw: spectrum_acl: Ask device for rule stats only if counter was created
authorJiri Pirko <jiri@mellanox.com>
Sat, 7 Mar 2020 11:40:18 +0000 (12:40 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Mar 2020 04:07:48 +0000 (21:07 -0700)
Set a flag in case rule counter was created. Only query the device for
stats of a rule, which has the valid counter assigned.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c

index ff61cad74bb0eb0be9bbe6857d23c186b38523f3..81801c6fb941d53ca36f6d8dd632932b0121ce6a 100644 (file)
@@ -641,7 +641,8 @@ struct mlxsw_sp_acl_rule_info {
        struct mlxsw_afa_block *act_block;
        u8 action_created:1,
           ingress_bind_blocker:1,
-          egress_bind_blocker:1;
+          egress_bind_blocker:1,
+          counter_valid:1;
        unsigned int counter_index;
 };
 
index 36b264798f04ec50d96d472b09a42888a38bf4d5..6f8d5005ff3674a8c8e77a7976e94a0c06ff4d51 100644 (file)
@@ -642,8 +642,14 @@ int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
                                 struct mlxsw_sp_acl_rule_info *rulei,
                                 struct netlink_ext_ack *extack)
 {
-       return mlxsw_afa_block_append_counter(rulei->act_block,
-                                             &rulei->counter_index, extack);
+       int err;
+
+       err = mlxsw_afa_block_append_counter(rulei->act_block,
+                                            &rulei->counter_index, extack);
+       if (err)
+               return err;
+       rulei->counter_valid = true;
+       return 0;
 }
 
 int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
@@ -857,16 +863,18 @@ int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
 
 {
        struct mlxsw_sp_acl_rule_info *rulei;
-       u64 current_packets;
-       u64 current_bytes;
+       u64 current_packets = 0;
+       u64 current_bytes = 0;
        int err;
 
        rulei = mlxsw_sp_acl_rule_rulei(rule);
-       err = mlxsw_sp_flow_counter_get(mlxsw_sp, rulei->counter_index,
-                                       &current_packets, &current_bytes);
-       if (err)
-               return err;
-
+       if (rulei->counter_valid) {
+               err = mlxsw_sp_flow_counter_get(mlxsw_sp, rulei->counter_index,
+                                               &current_packets,
+                                               &current_bytes);
+               if (err)
+                       return err;
+       }
        *packets = current_packets - rule->last_packets;
        *bytes = current_bytes - rule->last_bytes;
        *last_use = rule->last_used;