net/mlx5: support integrity flow item
[dpdk.git] / drivers / net / mlx5 / mlx5.h
index b2eb851..79ae8fb 100644 (file)
@@ -55,6 +55,7 @@ enum mlx5_ipool_index {
        MLX5_IPOOL_RTE_FLOW, /* Pool for rte_flow. */
        MLX5_IPOOL_RSS_EXPANTION_FLOW_ID, /* Pool for Queue/RSS flow ID. */
        MLX5_IPOOL_RSS_SHARED_ACTIONS, /* Pool for RSS shared actions. */
+       MLX5_IPOOL_MTR_POLICY, /* Pool for meter policy resource. */
        MLX5_IPOOL_MAX,
 };
 
@@ -290,7 +291,7 @@ struct mlx5_drop {
 #define MLX5_MAX_PENDING_QUERIES 4
 #define MLX5_CNT_CONTAINER_RESIZE 64
 #define MLX5_CNT_SHARED_OFFSET 0x80000000
-#define IS_SHARED_CNT(cnt) (!!((cnt) & MLX5_CNT_SHARED_OFFSET))
+#define IS_LEGACY_SHARED_CNT(cnt) (!!((cnt) & MLX5_CNT_SHARED_OFFSET))
 #define IS_BATCH_CNT(cnt) (((cnt) & (MLX5_CNT_SHARED_OFFSET - 1)) >= \
                           MLX5_CNT_BATCH_OFFSET)
 #define MLX5_CNT_SIZE (sizeof(struct mlx5_flow_counter))
@@ -352,7 +353,10 @@ struct flow_counter_stats {
 
 /* Shared counters information for counters. */
 struct mlx5_flow_counter_shared {
-       uint32_t id; /**< User counter ID. */
+       union {
+               uint32_t refcnt; /* Only for shared action management. */
+               uint32_t id; /* User counter ID for legacy sharing. */
+       };
 };
 
 /* Shared counter configuration. */
@@ -559,6 +563,8 @@ struct mlx5_geneve_tlv_option_resource {
 #define MLX5_AGE_TRIGGER               2
 #define MLX5_AGE_SET(age_info, BIT) \
        ((age_info)->flags |= (1 << (BIT)))
+#define MLX5_AGE_UNSET(age_info, BIT) \
+       ((age_info)->flags &= ~(1 << (BIT)))
 #define MLX5_AGE_GET(age_info, BIT) \
        ((age_info)->flags & (1 << (BIT)))
 #define GET_PORT_AGE_INFO(priv) \
@@ -589,74 +595,139 @@ struct mlx5_dev_shared_port {
        /* Aging information for per port. */
 };
 
+/*
+ * Max number of actions per DV flow.
+ * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
+ * in rdma-core file providers/mlx5/verbs.c.
+ */
+#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
+
 /*ASO flow meter structures*/
 /* Modify this value if enum rte_mtr_color changes. */
 #define RTE_MTR_DROPPED RTE_COLORS
+/* Yellow is not supported. */
+#define MLX5_MTR_RTE_COLORS (RTE_COLOR_GREEN + 1)
+/* table_id 22 bits in mlx5_flow_tbl_key so limit policy number. */
+#define MLX5_MAX_SUB_POLICY_TBL_NUM 0x3FFFFF
+#define MLX5_INVALID_POLICY_ID UINT32_MAX
+/* Suffix table_id on MLX5_FLOW_TABLE_LEVEL_METER. */
+#define MLX5_MTR_TABLE_ID_SUFFIX 1
+/* Drop table_id on MLX5_FLOW_TABLE_LEVEL_METER. */
+#define MLX5_MTR_TABLE_ID_DROP 2
+
+enum mlx5_meter_domain {
+       MLX5_MTR_DOMAIN_INGRESS,
+       MLX5_MTR_DOMAIN_EGRESS,
+       MLX5_MTR_DOMAIN_TRANSFER,
+       MLX5_MTR_DOMAIN_MAX,
+};
+#define MLX5_MTR_DOMAIN_INGRESS_BIT  (1 << MLX5_MTR_DOMAIN_INGRESS)
+#define MLX5_MTR_DOMAIN_EGRESS_BIT   (1 << MLX5_MTR_DOMAIN_EGRESS)
+#define MLX5_MTR_DOMAIN_TRANSFER_BIT (1 << MLX5_MTR_DOMAIN_TRANSFER)
+#define MLX5_MTR_ALL_DOMAIN_BIT      (MLX5_MTR_DOMAIN_INGRESS_BIT | \
+                                       MLX5_MTR_DOMAIN_EGRESS_BIT | \
+                                       MLX5_MTR_DOMAIN_TRANSFER_BIT)
 
-/* Meter policer statistics */
-struct mlx5_flow_policer_stats {
-       uint32_t pass_cnt;
-       /**< Color counter for pass. */
-       uint32_t drop_cnt;
-       /**< Color counter for drop. */
+/*
+ * Meter sub-policy structure.
+ * Each RSS TIR in meter policy need its own sub-policy resource.
+ */
+struct mlx5_flow_meter_sub_policy {
+       uint32_t main_policy_id:1;
+       /* Main policy id is same as this sub_policy id. */
+       uint32_t idx:31;
+       /* Index to sub_policy ipool entity. */
+       void *main_policy;
+       /* Point to struct mlx5_flow_meter_policy. */
+       struct mlx5_flow_tbl_resource *tbl_rsc;
+       /* The sub-policy table resource. */
+       uint32_t rix_hrxq[MLX5_MTR_RTE_COLORS];
+       /* Index to TIR resource. */
+       struct mlx5_flow_tbl_resource *jump_tbl[MLX5_MTR_RTE_COLORS];
+       /* Meter jump/drop table. */
+       struct mlx5_flow_dv_matcher *color_matcher[RTE_COLORS];
+       /* Matcher for Color. */
+       void *color_rule[RTE_COLORS];
+       /* Meter green/yellow/drop rule. */
+};
+
+struct mlx5_meter_policy_acts {
+       uint8_t actions_n;
+       /* Number of actions. */
+       void *dv_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS];
+       /* Action list. */
+};
+
+struct mlx5_meter_policy_action_container {
+       uint32_t rix_mark;
+       /* Index to the mark action. */
+       struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
+       /* Pointer to modify header resource in cache. */
+       uint8_t fate_action;
+       /* Fate action type. */
+       union {
+               struct rte_flow_action *rss;
+               /* Rss action configuration. */
+               uint32_t rix_port_id_action;
+               /* Index to port ID action resource. */
+               void *dr_jump_action[MLX5_MTR_DOMAIN_MAX];
+               /* Jump/drop action per color. */
+       };
 };
 
-/* Meter table structure. */
-struct mlx5_meter_domain_info {
-       struct mlx5_flow_tbl_resource *tbl;
-       /**< Meter table. */
-       struct mlx5_flow_tbl_resource *sfx_tbl;
-       /**< Meter suffix table. */
-       struct mlx5_flow_dv_matcher *drop_matcher;
-       /**< Matcher for Drop. */
-       struct mlx5_flow_dv_matcher *color_matcher;
-       /**< Matcher for Color. */
-       void *jump_actn;
-       /**< Meter match action. */
-       void *green_rule;
-       /**< Meter green rule. */
-       void *drop_rule;
-       /**< Meter drop rule. */
-};
-
-/* Meter table set for TX RX FDB. */
-struct mlx5_meter_domains_infos {
+/* Flow meter policy parameter structure. */
+struct mlx5_flow_meter_policy {
+       uint32_t is_rss:1;
+       /* Is RSS policy table. */
+       uint32_t ingress:1;
+       /* Rule applies to ingress domain. */
+       uint32_t egress:1;
+       /* Rule applies to egress domain. */
+       uint32_t transfer:1;
+       /* Rule applies to transfer domain. */
+       rte_spinlock_t sl;
        uint32_t ref_cnt;
-       /**< Table user count. */
-       struct mlx5_meter_domain_info egress;
-       /**< TX meter table. */
-       struct mlx5_meter_domain_info ingress;
-       /**< RX meter table. */
-       struct mlx5_meter_domain_info transfer;
-       /**< FDB meter table. */
-       void *drop_actn;
-       /**< Drop action as not matched. */
-       void *green_count;
-       /**< Counters for green rule. */
-       void *drop_count;
-       /**< Counters for green rule. */
+       /* Use count. */
+       struct mlx5_meter_policy_action_container act_cnt[MLX5_MTR_RTE_COLORS];
+       /* Policy actions container. */
+       void *dr_drop_action[MLX5_MTR_DOMAIN_MAX];
+       /* drop action for red color. */
+       uint16_t sub_policy_num;
+       /* Count sub policy tables, 3 bits per domain. */
+       struct mlx5_flow_meter_sub_policy **sub_policys[MLX5_MTR_DOMAIN_MAX];
+       /* Sub policy table array must be the end of struct. */
+};
+
+/* The maximum sub policy is relate to struct mlx5_rss_hash_fields[]. */
+#define MLX5_MTR_RSS_MAX_SUB_POLICY 7
+#define MLX5_MTR_SUB_POLICY_NUM_SHIFT  3
+#define MLX5_MTR_SUB_POLICY_NUM_MASK  0x7
+#define MLX5_MTRS_DEFAULT_RULE_PRIORITY 0xFFFF
+
+/* Flow meter default policy parameter structure.
+ * Policy index 0 is reserved by default policy table.
+ * Action per color as below:
+ * green - do nothing, yellow - do nothing, red - drop
+ */
+struct mlx5_flow_meter_def_policy {
+       struct mlx5_flow_meter_sub_policy sub_policy;
+       /* Policy rules jump to other tables. */
+       void *dr_jump_action[RTE_COLORS];
+       /* Jump action per color. */
 };
 
 /* Meter parameter structure. */
 struct mlx5_flow_meter_info {
        uint32_t meter_id;
        /**< Meter id. */
+       uint32_t policy_id;
+       /* Policy id, the first sub_policy idx. */
        struct mlx5_flow_meter_profile *profile;
        /**< Meter profile parameters. */
        rte_spinlock_t sl; /**< Meter action spinlock. */
-       /** Policer actions (per meter output color). */
-       enum rte_mtr_policer_action action[RTE_COLORS];
        /** Set of stats counters to be enabled.
         * @see enum rte_mtr_stats_type
         */
-       uint32_t green_bytes:1;
-       /** Set green bytes stats to be enabled. */
-       uint32_t green_pkts:1;
-       /** Set green packets stats to be enabled. */
-       uint32_t red_bytes:1;
-       /** Set red bytes stats to be enabled. */
-       uint32_t red_pkts:1;
-       /** Set red packets stats to be enabled. */
        uint32_t bytes_dropped:1;
        /** Set bytes dropped stats to be enabled. */
        uint32_t pkts_dropped:1;
@@ -689,10 +760,12 @@ struct mlx5_flow_meter_info {
         * received by the application.
         */
        uint32_t transfer:1;
-       struct mlx5_meter_domains_infos *mfts;
-       /**< Flow table created for this meter. */
-       struct mlx5_flow_policer_stats policer_stats;
-       /**< Meter policer statistics. */
+       uint32_t def_policy:1;
+       /* Meter points to default policy. */
+       void *drop_rule[MLX5_MTR_DOMAIN_MAX];
+       /* Meter drop rule in drop table. */
+       uint32_t drop_cnt;
+       /**< Color counter for drop. */
        uint32_t ref_cnt;
        /**< Use count. */
        struct mlx5_indexed_pool *flow_ipool;
@@ -701,6 +774,11 @@ struct mlx5_flow_meter_info {
        /**< Flow meter action. */
 };
 
+/* PPS(packets per second) map to BPS(Bytes per second).
+ * HW treat packet as 128bytes in PPS mode
+ */
+#define MLX5_MTRS_PPS_MAP_BPS_SHIFT 7
+
 /* RFC2697 parameter structure. */
 struct mlx5_flow_meter_srtcm_rfc2697_prm {
        rte_be32_t cbs_cir;
@@ -775,14 +853,43 @@ struct mlx5_aso_mtr_pools_mng {
        struct mlx5_aso_mtr_pool **pools; /* ASO flow meter pool array. */
 };
 
+/* Meter management structure for global flow meter resource. */
+struct mlx5_flow_mtr_mng {
+       struct mlx5_aso_mtr_pools_mng pools_mng;
+       /* Pools management structure for ASO flow meter pools. */
+       struct mlx5_flow_meter_def_policy *def_policy[MLX5_MTR_DOMAIN_MAX];
+       /* Default policy table. */
+       uint32_t def_policy_id;
+       /* Default policy id. */
+       uint32_t def_policy_ref_cnt;
+       /** def_policy meter use count. */
+       struct mlx5_l3t_tbl *policy_idx_tbl;
+       /* Policy index lookup table. */
+       struct mlx5_flow_tbl_resource *drop_tbl[MLX5_MTR_DOMAIN_MAX];
+       /* Meter drop table. */
+       struct mlx5_flow_dv_matcher *
+                       drop_matcher[MLX5_MTR_DOMAIN_MAX][MLX5_REG_BITS];
+       /* Matcher meter in drop table. */
+       struct mlx5_flow_dv_matcher *def_matcher[MLX5_MTR_DOMAIN_MAX];
+       /* Default matcher in drop table. */
+       void *def_rule[MLX5_MTR_DOMAIN_MAX];
+       /* Default rule in drop table. */
+       uint8_t max_mtr_bits;
+       /* Indicate how many bits are used by meter id at the most. */
+       uint8_t max_mtr_flow_bits;
+       /* Indicate how many bits are used by meter flow id at the most. */
+};
+
 /* Table key of the hash organization. */
 union mlx5_flow_tbl_key {
        struct {
                /* Table ID should be at the lowest address. */
-               uint32_t table_id;      /**< ID of the table. */
-               uint16_t dummy;         /**< Dummy table for DV API. */
-               uint8_t domain;         /**< 1 - FDB, 0 - NIC TX/RX. */
-               uint8_t direction;      /**< 1 - egress, 0 - ingress. */
+               uint32_t level; /**< Level of the table. */
+               uint32_t id:22; /**< ID of the table. */
+               uint32_t dummy:1;       /**< Dummy table for DV API. */
+               uint32_t is_fdb:1;      /**< 1 - FDB, 0 - NIC TX/RX. */
+               uint32_t is_egress:1;   /**< 1 - egress, 0 - ingress. */
+               uint32_t reserved:7;    /**< must be zero for comparison. */
        };
        uint64_t v64;                   /**< full 64bits value of key */
 };
@@ -799,9 +906,9 @@ struct mlx5_flow_tbl_resource {
 #define MLX5_FLOW_MREG_ACT_TABLE_GROUP (MLX5_MAX_TABLES - 1)
 #define MLX5_FLOW_MREG_CP_TABLE_GROUP (MLX5_MAX_TABLES - 2)
 /* Tables for metering splits should be added here. */
-#define MLX5_FLOW_TABLE_LEVEL_SUFFIX (MLX5_MAX_TABLES - 3)
-#define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 4)
-#define MLX5_MAX_TABLES_EXTERNAL MLX5_FLOW_TABLE_LEVEL_METER
+#define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 3)
+#define MLX5_FLOW_TABLE_LEVEL_POLICY (MLX5_MAX_TABLES - 4)
+#define MLX5_MAX_TABLES_EXTERNAL MLX5_FLOW_TABLE_LEVEL_POLICY
 #define MLX5_MAX_TABLES_FDB UINT16_MAX
 #define MLX5_FLOW_TABLE_FACTOR 10
 
@@ -962,8 +1069,8 @@ struct mlx5_dev_ctx_shared {
        struct mlx5_geneve_tlv_option_resource *geneve_tlv_option_resource;
        /* Management structure for geneve tlv option */
        rte_spinlock_t geneve_tlv_opt_sl; /* Lock for geneve tlv resource */
-       struct mlx5_aso_mtr_pools_mng *mtrmng;
-       /* Meter pools management structure. */
+       struct mlx5_flow_mtr_mng *mtrmng;
+       /* Meter management structure. */
        struct mlx5_dev_shared_port port[]; /* per device port data array. */
 };
 
@@ -1209,10 +1316,6 @@ struct mlx5_priv {
        uint32_t rss_shared_actions; /* RSS shared actions. */
        struct mlx5_devx_obj *q_counters; /* DevX queue counter object. */
        uint32_t counter_set_id; /* Queue counter ID to set in DevX objects. */
-       uint8_t max_mtr_bits;
-       /* Indicate how many bits are used by meter id at the most. */
-       uint8_t max_mtr_flow_bits;
-       /* Indicate how many bits are used by meter flow id at the most. */
 };
 
 #define PORT_ID(priv) ((priv)->dev_data->port_id)
@@ -1264,7 +1367,7 @@ int mlx5_hairpin_cap_get(struct rte_eth_dev *dev,
 bool mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev);
 int mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev);
 int mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh);
-int mlx5_aso_flow_mtrs_mng_init(struct mlx5_priv *priv);
+int mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh);
 
 /* mlx5_ethdev.c */
 
@@ -1446,8 +1549,6 @@ int mlx5_ctrl_flow(struct rte_eth_dev *dev,
                   struct rte_flow_item_eth *eth_mask);
 int mlx5_flow_lacp_miss(struct rte_eth_dev *dev);
 struct rte_flow *mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev);
-int mlx5_flow_create_drop_queue(struct rte_eth_dev *dev);
-void mlx5_flow_delete_drop_queue(struct rte_eth_dev *dev);
 void mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
                                       uint64_t async_id, int status);
 void mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh);
@@ -1490,6 +1591,12 @@ int mlx5_flow_meter_attach(struct mlx5_priv *priv,
                           struct rte_flow_error *error);
 void mlx5_flow_meter_detach(struct mlx5_priv *priv,
                            struct mlx5_flow_meter_info *fm);
+struct mlx5_flow_meter_policy *mlx5_flow_meter_policy_find
+               (struct rte_eth_dev *dev,
+               uint32_t policy_id,
+               uint32_t *policy_idx);
+int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
+                         struct rte_mtr_error *error);
 
 /* mlx5_os.c */
 struct rte_pci_driver;