net/mlx5: support meter modification operations
authorSuanming Mou <suanmingm@mellanox.com>
Fri, 8 Nov 2019 03:49:16 +0000 (05:49 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 11 Nov 2019 13:23:02 +0000 (14:23 +0100)
This commit add meter enable and disable supoort.

New internal functions in rte_mtr_ops callback:
1. meter_enable()
2. meter_disable()

The meter_enable() enables the meter action and the meter_disable()
disables the meter action.

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
drivers/net/mlx5/mlx5_flow.h
drivers/net/mlx5/mlx5_flow_meter.c
drivers/net/mlx5/mlx5_prm.h

index aaeb5b3..672552b 100644 (file)
@@ -523,6 +523,10 @@ struct mlx5_flow {
        bool external; /**< true if the flow is created external to PMD. */
 };
 
+/* Flow meter state. */
+#define MLX5_FLOW_METER_DISABLE 0
+#define MLX5_FLOW_METER_ENABLE 1
+
 #define MLX5_MAN_WIDTH 8
 /* Modify this value if enum rte_mtr_color changes. */
 #define RTE_MTR_DROPPED RTE_COLORS
@@ -553,6 +557,12 @@ struct mlx5_meter_domains_infos {
        /**< FDB meter table. */
        void *drop_actn;
        /**< Drop action as not matched. */
+       uint32_t fmp[MLX5_ST_SZ_DW(flow_meter_parameters)];
+       /**< Flow meter parameter. */
+       size_t fmp_size;
+       /**< Flow meter parameter size. */
+       void *meter_action;
+       /**< Flow meter action. */
 };
 
 /* Meter parameter structure. */
index 76a3180..6966ffc 100644 (file)
@@ -442,6 +442,103 @@ mlx5_flow_meter_validate(struct mlx5_priv *priv, uint32_t meter_id,
        return 0;
 }
 
+/**
+ * Modify the flow meter action.
+ *
+ * @param[in] priv
+ *   Pointer to mlx5 private data structure.
+ * @param[in] fm
+ *   Pointer to flow meter to be modified.
+ * @param[in] srtcm
+ *   Pointer to meter srtcm description parameter.
+ * @param[in] modify_bits
+ *   The bit in srtcm to be updated.
+ * @param[in] active_state
+ *   The state to be updated.
+ * @return
+ *   0 on success, o negative value otherwise.
+ */
+static int
+mlx5_flow_meter_action_modify(struct mlx5_priv *priv,
+               struct mlx5_flow_meter *fm,
+               const struct mlx5_flow_meter_srtcm_rfc2697_prm *srtcm,
+               uint64_t modify_bits, uint32_t active_state)
+{
+#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER
+       uint32_t in[MLX5_ST_SZ_DW(flow_meter_parameters)] = { 0 };
+       uint32_t *attr;
+       struct mlx5dv_dr_flow_meter_attr mod_attr = { 0 };
+       int ret;
+
+       /* Fill command parameters. */
+       mod_attr.reg_c_index = priv->mtr_color_reg - REG_C_0;
+       mod_attr.flow_meter_parameter = in;
+       mod_attr.flow_meter_parameter_sz = fm->mfts->fmp_size;
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_ACTIVE)
+               mod_attr.active = !!active_state;
+       else
+               mod_attr.active = 0;
+       attr = in;
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CBS) {
+               MLX5_SET(flow_meter_parameters,
+                        attr, cbs_exponent, srtcm->cbs_exponent);
+               MLX5_SET(flow_meter_parameters,
+                        attr, cbs_mantissa, srtcm->cbs_mantissa);
+       }
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CIR) {
+               MLX5_SET(flow_meter_parameters,
+                        attr, cir_exponent, srtcm->cir_exponent);
+               MLX5_SET(flow_meter_parameters,
+                        attr, cir_mantissa, srtcm->cir_mantissa);
+       }
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_EBS) {
+               MLX5_SET(flow_meter_parameters,
+                        attr, ebs_exponent, srtcm->ebs_exponent);
+               MLX5_SET(flow_meter_parameters,
+                        attr, ebs_mantissa, srtcm->ebs_mantissa);
+       }
+       /* Apply modifications to meter only if it was created. */
+       if (fm->mfts->meter_action) {
+               ret = mlx5_glue->dv_modify_flow_action_meter
+                                       (fm->mfts->meter_action, &mod_attr,
+                                       rte_cpu_to_be_64(modify_bits));
+               if (ret)
+                       return ret;
+       }
+       /* Update succeedded modify meter parameters. */
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_ACTIVE)
+               fm->active_state = !!active_state;
+       attr = fm->mfts->fmp;
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CBS) {
+               MLX5_SET(flow_meter_parameters,
+                        attr, cbs_exponent, srtcm->cbs_exponent);
+               MLX5_SET(flow_meter_parameters,
+                        attr, cbs_mantissa, srtcm->cbs_mantissa);
+       }
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CIR) {
+               MLX5_SET(flow_meter_parameters,
+                        attr, cir_exponent, srtcm->cir_exponent);
+               MLX5_SET(flow_meter_parameters,
+                        attr, cir_mantissa, srtcm->cir_mantissa);
+       }
+       if (modify_bits & MLX5_FLOW_METER_OBJ_MODIFY_FIELD_EBS) {
+               MLX5_SET(flow_meter_parameters,
+                        attr, ebs_exponent, srtcm->ebs_exponent);
+               MLX5_SET(flow_meter_parameters,
+                        attr, ebs_mantissa, srtcm->ebs_mantissa);
+       }
+
+       return 0;
+#else
+       (void)priv;
+       (void)fm;
+       (void)srtcm;
+       (void)modify_bits;
+       (void)active_state;
+       return -ENOTSUP;
+#endif
+}
+
 /**
  * Create meter rules.
  *
@@ -577,14 +674,146 @@ mlx5_flow_meter_destroy(struct rte_eth_dev *dev, uint32_t meter_id,
        return 0;
 }
 
+/**
+ * Modify meter state.
+ *
+ * @param[in] priv
+ *   Pointer to mlx5 private data structure.
+ * @param[in] fm
+ *   Pointer to flow meter.
+ * @param[in] new_state
+ *   New state to update.
+ * @param[out] error
+ *   Pointer to rte meter error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+mlx5_flow_meter_modify_state(struct mlx5_priv *priv,
+                            struct mlx5_flow_meter *fm,
+                            uint32_t new_state,
+                            struct rte_mtr_error *error)
+{
+       static const struct mlx5_flow_meter_srtcm_rfc2697_prm srtcm = {
+               .cbs_exponent = 20,
+               .cbs_mantissa = 191,
+               .cir_exponent = 0,
+               .cir_mantissa = 200,
+               .ebs_exponent = 0,
+               .ebs_mantissa = 0,
+       };
+       uint64_t modify_bits = MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CBS |
+                              MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CIR;
+       int ret;
+
+       if (new_state == MLX5_FLOW_METER_DISABLE)
+               ret = mlx5_flow_meter_action_modify(priv, fm, &srtcm,
+                                                   modify_bits, 0);
+       else
+               ret = mlx5_flow_meter_action_modify(priv, fm,
+                                                  &fm->profile->srtcm_prm,
+                                                   modify_bits, 0);
+       if (ret)
+               return -rte_mtr_error_set(error, -ret,
+                                         RTE_MTR_ERROR_TYPE_MTR_PARAMS,
+                                         NULL,
+                                         new_state ?
+                                         "Failed to enable meter." :
+                                         "Failed to disable meter.");
+       return 0;
+}
+
+/**
+ * Callback to enable flow meter.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in] meter_id
+ *   Meter id.
+ * @param[out] error
+ *   Pointer to rte meter error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+mlx5_flow_meter_enable(struct rte_eth_dev *dev,
+                      uint32_t meter_id,
+                      struct rte_mtr_error *error)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_flow_meter *fm;
+       int ret;
+
+       if (!priv->mtr_en)
+               return -rte_mtr_error_set(error, ENOTSUP,
+                                         RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+                                         "Meter is not support");
+       /* Meter object must exist. */
+       fm = mlx5_flow_meter_find(priv, meter_id);
+       if (fm == NULL)
+               return -rte_mtr_error_set(error, ENOENT,
+                                         RTE_MTR_ERROR_TYPE_MTR_ID,
+                                         NULL, "Meter not found.");
+       if (fm->active_state == MLX5_FLOW_METER_ENABLE)
+               return 0;
+       ret = mlx5_flow_meter_modify_state(priv, fm, MLX5_FLOW_METER_ENABLE,
+                                          error);
+       if (!ret)
+               fm->active_state = MLX5_FLOW_METER_ENABLE;
+       return ret;
+}
+
+/**
+ * Callback to disable flow meter.
+ *
+ * @param[in] dev
+ *   Pointer to Ethernet device.
+ * @param[in] meter_id
+ *   Meter id.
+ * @param[out] error
+ *   Pointer to rte meter error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+mlx5_flow_meter_disable(struct rte_eth_dev *dev,
+                       uint32_t meter_id,
+                       struct rte_mtr_error *error)
+{
+       struct mlx5_priv *priv = dev->data->dev_private;
+       struct mlx5_flow_meter *fm;
+       int ret;
+
+       if (!priv->mtr_en)
+               return -rte_mtr_error_set(error, ENOTSUP,
+                                         RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
+                                         "Meter is not support");
+       /* Meter object must exist. */
+       fm = mlx5_flow_meter_find(priv, meter_id);
+       if (fm == NULL)
+               return -rte_mtr_error_set(error, ENOENT,
+                                         RTE_MTR_ERROR_TYPE_MTR_ID,
+                                         NULL, "Meter not found.");
+       if (fm->active_state == MLX5_FLOW_METER_DISABLE)
+               return 0;
+       ret = mlx5_flow_meter_modify_state(priv, fm, MLX5_FLOW_METER_DISABLE,
+                                          error);
+       if (!ret)
+               fm->active_state = MLX5_FLOW_METER_DISABLE;
+       return ret;
+}
+
 static const struct rte_mtr_ops mlx5_flow_mtr_ops = {
        .capabilities_get = mlx5_flow_mtr_cap_get,
        .meter_profile_add = mlx5_flow_meter_profile_add,
        .meter_profile_delete = mlx5_flow_meter_profile_delete,
        .create = mlx5_flow_meter_create,
        .destroy = mlx5_flow_meter_destroy,
-       .meter_enable = NULL,
-       .meter_disable = NULL,
+       .meter_enable = mlx5_flow_meter_enable,
+       .meter_disable = mlx5_flow_meter_disable,
        .meter_profile_update = NULL,
        .meter_dscp_table_update = NULL,
        .policer_actions_update = NULL,
index ebedc90..651006b 100644 (file)
@@ -1745,6 +1745,38 @@ struct mlx5_ifc_create_sq_in_bits {
        struct mlx5_ifc_sqc_bits ctx;
 };
 
+enum {
+       MLX5_FLOW_METER_OBJ_MODIFY_FIELD_ACTIVE = (1ULL << 0),
+       MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CBS = (1ULL << 1),
+       MLX5_FLOW_METER_OBJ_MODIFY_FIELD_CIR = (1ULL << 2),
+       MLX5_FLOW_METER_OBJ_MODIFY_FIELD_EBS = (1ULL << 3),
+       MLX5_FLOW_METER_OBJ_MODIFY_FIELD_EIR = (1ULL << 4),
+};
+
+struct mlx5_ifc_flow_meter_parameters_bits {
+       u8         valid[0x1];                  // 00h
+       u8         bucket_overflow[0x1];
+       u8         start_color[0x2];
+       u8         both_buckets_on_green[0x1];
+       u8         meter_mode[0x2];
+       u8         reserved_at_1[0x19];
+       u8         reserved_at_2[0x20]; //04h
+       u8         reserved_at_3[0x3];
+       u8         cbs_exponent[0x5];           // 08h
+       u8         cbs_mantissa[0x8];
+       u8         reserved_at_4[0x3];
+       u8         cir_exponent[0x5];
+       u8         cir_mantissa[0x8];
+       u8         reserved_at_5[0x20];         // 0Ch
+       u8         reserved_at_6[0x3];
+       u8         ebs_exponent[0x5];           // 10h
+       u8         ebs_mantissa[0x8];
+       u8         reserved_at_7[0x3];
+       u8         eir_exponent[0x5];
+       u8         eir_mantissa[0x8];
+       u8         reserved_at_8[0x60];         // 14h-1Ch
+};
+
 /* CQE format mask. */
 #define MLX5E_CQE_FORMAT_MASK 0xc