net/mlx5_core: Flow counters infrastructure
[cascardo/linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / fs_core.h
index 00245fd..aa41a73 100644 (file)
@@ -45,8 +45,10 @@ enum fs_node_type {
 };
 
 enum fs_flow_table_type {
-       FS_FT_NIC_RX     = 0x0,
-       FS_FT_FDB        = 0X4,
+       FS_FT_NIC_RX          = 0x0,
+       FS_FT_ESW_EGRESS_ACL  = 0x2,
+       FS_FT_ESW_INGRESS_ACL = 0x3,
+       FS_FT_FDB             = 0X4,
 };
 
 enum fs_fte_status {
@@ -68,12 +70,18 @@ struct fs_node {
 struct mlx5_flow_rule {
        struct fs_node                          node;
        struct mlx5_flow_destination            dest_attr;
+       /* next_ft should be accessed under chain_lock and only of
+        * destination type is FWD_NEXT_fT.
+        */
+       struct list_head                        next_ft;
+       u32                                     sw_action;
 };
 
 /* Type of children is mlx5_flow_group */
 struct mlx5_flow_table {
        struct fs_node                  node;
        u32                             id;
+       u16                             vport;
        unsigned int                    max_fte;
        unsigned int                    level;
        enum fs_flow_table_type         type;
@@ -82,6 +90,32 @@ struct mlx5_flow_table {
                unsigned int            required_groups;
                unsigned int            num_groups;
        } autogroup;
+       /* Protect fwd_rules */
+       struct mutex                    lock;
+       /* FWD rules that point on this flow table */
+       struct list_head                fwd_rules;
+};
+
+struct mlx5_fc_cache {
+       u64 packets;
+       u64 bytes;
+       u64 lastuse;
+};
+
+struct mlx5_fc {
+       struct list_head list;
+
+       /* last{packets,bytes} members are used when calculating the delta since
+        * last reading
+        */
+       u64 lastpackets;
+       u64 lastbytes;
+
+       u16 id;
+       bool deleted;
+       bool aging;
+
+       struct mlx5_fc_cache cache ____cacheline_aligned_in_smp;
 };
 
 /* Type of children is mlx5_flow_rule */
@@ -93,12 +127,13 @@ struct fs_fte {
        u32                             index;
        u32                             action;
        enum fs_fte_status              status;
+       struct mlx5_fc                  *counter;
 };
 
 /* Type of children is mlx5_flow_table/namespace */
 struct fs_prio {
        struct fs_node                  node;
-       unsigned int                    max_ft;
+       unsigned int                    num_levels;
        unsigned int                    start_level;
        unsigned int                    prio;
        unsigned int                    num_ft;
@@ -134,6 +169,9 @@ struct mlx5_flow_root_namespace {
        struct mutex                    chain_lock;
 };
 
+int mlx5_init_fc_stats(struct mlx5_core_dev *dev);
+void mlx5_cleanup_fc_stats(struct mlx5_core_dev *dev);
+
 int mlx5_init_fs(struct mlx5_core_dev *dev);
 void mlx5_cleanup_fs(struct mlx5_core_dev *dev);
 
@@ -142,6 +180,9 @@ void mlx5_cleanup_fs(struct mlx5_core_dev *dev);
 #define fs_list_for_each_entry(pos, root)              \
        list_for_each_entry(pos, root, node.list)
 
+#define fs_list_for_each_entry_safe(pos, tmp, root)            \
+       list_for_each_entry_safe(pos, tmp, root, node.list)
+
 #define fs_for_each_ns_or_ft_reverse(pos, prio)                                \
        list_for_each_entry_reverse(pos, &(prio)->node.children, list)
 
@@ -157,6 +198,9 @@ void mlx5_cleanup_fs(struct mlx5_core_dev *dev);
 #define fs_for_each_ft(pos, prio)                      \
        fs_list_for_each_entry(pos, &(prio)->node.children)
 
+#define fs_for_each_ft_safe(pos, tmp, prio)                    \
+       fs_list_for_each_entry_safe(pos, tmp, &(prio)->node.children)
+
 #define fs_for_each_fg(pos, ft)                        \
        fs_list_for_each_entry(pos, &(ft)->node.children)