net/mlx5: Use flow counter IDs and not the wrapping cache object
authorMark Bloch <markb@mellanox.com>
Wed, 3 Oct 2018 00:03:35 +0000 (00:03 +0000)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 17 Oct 2018 21:15:48 +0000 (14:15 -0700)
Currently, when a flow rule is created using the FS core layer, the caller
has to pass the entire flow counter object and not just the counter HW
handle (ID). This requires both the FS core and the caller to have
knowledge about the inner implementation of the FS layer flow counters
cache and limits the possible users.

Move to use the counter ID across the place when dealing with flows.

Doing this decoupling, now can we privatize the inner implementation
of the flow counters.

Signed-off-by: Mark Bloch <markb@mellanox.com>
Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/infiniband/hw/mlx5/main.c
drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.h
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
include/linux/mlx5/fs.h

index 5d9b7f62a0ba0abcb2665cd665e1db27e316ce8e..5ced0cc46ba15a0cec72a57ad6fabbb7ad106fab 100644 (file)
@@ -3320,15 +3320,18 @@ static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev,
        }
 
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
+               struct mlx5_ib_mcounters *mcounters;
+
                err = flow_counters_set_data(flow_act.counters, ucmd);
                if (err)
                        goto free;
 
+               mcounters = to_mcounters(flow_act.counters);
                handler->ibcounters = flow_act.counters;
                dest_arr[dest_num].type =
                        MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-               dest_arr[dest_num].counter =
-                       to_mcounters(flow_act.counters)->hw_cntrs_hndl;
+               dest_arr[dest_num].counter_id =
+                       mlx5_fc_id(mcounters->hw_cntrs_hndl);
                dest_num++;
        }
 
index e83dda441a818e01e7aa7a859e489bbe6e74d65a..d027ce00c8ce4f7044b5b8ba7724c822366783e9 100644 (file)
@@ -252,10 +252,10 @@ TRACE_EVENT(mlx5_fs_add_rule,
                           memcpy(__entry->destination,
                                  &rule->dest_attr,
                                  sizeof(__entry->destination));
-                          if (rule->dest_attr.type & MLX5_FLOW_DESTINATION_TYPE_COUNTER &&
-                              rule->dest_attr.counter)
+                          if (rule->dest_attr.type &
+                              MLX5_FLOW_DESTINATION_TYPE_COUNTER)
                                __entry->counter_id =
-                               rule->dest_attr.counter->id;
+                                       rule->dest_attr.counter_id;
            ),
            TP_printk("rule=%p fte=%p index=%u sw_action=<%s> [dst] %s\n",
                      __entry->rule, __entry->fte, __entry->index,
index 8a27c0813a18b1e2bc4313f13ba9222aed94862c..5ce87f54852d74598da75b6e4f7dca2552e26a65 100644 (file)
@@ -720,7 +720,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
                        goto err_fc_create;
                }
                dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-               dest[dest_ix].counter = counter;
+               dest[dest_ix].counter_id = mlx5_fc_id(counter);
                dest_ix++;
                attr->counter = counter;
        }
index e1d47fa5ab837770a5961c4fb483a1ef66e5e01a..9c893d7d273e185c01b81076a1979def05191634 100644 (file)
@@ -1198,7 +1198,7 @@ static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
        if (counter) {
                flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
                drop_ctr_dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-               drop_ctr_dst.counter = counter;
+               drop_ctr_dst.counter_id = mlx5_fc_id(counter);
                dst = &drop_ctr_dst;
                dest_num++;
        }
@@ -1285,7 +1285,7 @@ static int esw_vport_egress_config(struct mlx5_eswitch *esw,
        if (counter) {
                flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
                drop_ctr_dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-               drop_ctr_dst.counter = counter;
+               drop_ctr_dst.counter_id = mlx5_fc_id(counter);
                dst = &drop_ctr_dst;
                dest_num++;
        }
index a2f2d726c99b30c76671f6766b3a0a57ab1d33fc..39932dce15cbab4c93e7b9656c9a2ebd1ddc478f 100644 (file)
@@ -91,7 +91,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
        }
        if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
                dest[i].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-               dest[i].counter = attr->counter;
+               dest[i].counter_id = mlx5_fc_id(attr->counter);
                i++;
        }
 
index dc8d7f6b52c2f8061253a71f358cfd0f67a251d4..08a891f9aadea2af6abbd61a8ca328e43d4d8c1b 100644 (file)
@@ -419,7 +419,7 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
                                continue;
 
                        MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
-                                dst->dest_attr.counter->id);
+                                dst->dest_attr.counter_id);
                        in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
                        list_size++;
                }
index 9e18e6c0a8b3267554f6f076c45e53c073746d5d..cdcbf9d0ae6cf08e76be1d45d65842d9bf3095cd 100644 (file)
@@ -1474,14 +1474,8 @@ static struct mlx5_flow_handle *add_rule_fg(struct mlx5_flow_group *fg,
        return handle;
 }
 
-static bool counter_is_valid(struct mlx5_fc *counter, u32 action)
+static bool counter_is_valid(u32 action)
 {
-       if (!(action & MLX5_FLOW_CONTEXT_ACTION_COUNT))
-               return !counter;
-
-       if (!counter)
-               return false;
-
        return (action & (MLX5_FLOW_CONTEXT_ACTION_DROP |
                          MLX5_FLOW_CONTEXT_ACTION_FWD_DEST));
 }
@@ -1491,7 +1485,7 @@ static bool dest_is_valid(struct mlx5_flow_destination *dest,
                          struct mlx5_flow_table *ft)
 {
        if (dest && (dest->type == MLX5_FLOW_DESTINATION_TYPE_COUNTER))
-               return counter_is_valid(dest->counter, action);
+               return counter_is_valid(action);
 
        if (!(action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
                return true;
index 09206c4acd9a890d384b156d74f729910e4a43aa..1329bc5b7969b3a3ab296f451cb38bfd33da53fc 100644 (file)
@@ -258,6 +258,12 @@ err_out:
 }
 EXPORT_SYMBOL(mlx5_fc_create);
 
+u32 mlx5_fc_id(struct mlx5_fc *counter)
+{
+       return counter->id;
+}
+EXPORT_SYMBOL(mlx5_fc_id);
+
 void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
 {
        struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
index 74d0ea146c9aff75ef7f1b21bd23b2f88b418e11..a5fc62184195149644142f849034671e81b2aa18 100644 (file)
@@ -92,7 +92,7 @@ struct mlx5_flow_destination {
                u32                     tir_num;
                u32                     ft_num;
                struct mlx5_flow_table  *ft;
-               struct mlx5_fc          *counter;
+               u32                     counter_id;
                struct {
                        u16             num;
                        u16             vhca_id;
@@ -192,6 +192,7 @@ void mlx5_fc_query_cached(struct mlx5_fc *counter,
                          u64 *bytes, u64 *packets, u64 *lastuse);
 int mlx5_fc_query(struct mlx5_core_dev *dev, struct mlx5_fc *counter,
                  u64 *packets, u64 *bytes);
+u32 mlx5_fc_id(struct mlx5_fc *counter);
 
 int mlx5_fs_add_rx_underlay_qpn(struct mlx5_core_dev *dev, u32 underlay_qpn);
 int mlx5_fs_remove_rx_underlay_qpn(struct mlx5_core_dev *dev, u32 underlay_qpn);