net/mlx5: clean meter resources
[dpdk.git] / drivers / net / mlx5 / mlx5.c
index 1adef85..9a2c711 100644 (file)
@@ -1016,6 +1016,7 @@ mlx5_dev_close(struct rte_eth_dev *dev)
        mlx5_dev_interrupt_handler_devx_uninstall(dev);
        mlx5_traffic_disable(dev);
        mlx5_flow_flush(dev, NULL);
+       mlx5_flow_meter_flush(dev, NULL);
        /* Prevent crashes when queues are still in use. */
        dev->rx_pkt_burst = removed_rx_burst;
        dev->tx_pkt_burst = removed_tx_burst;
@@ -2293,7 +2294,25 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER)
                if (config.hca_attr.qos.sup && config.hca_attr.qos.srtcm_sup &&
                    config.dv_flow_en) {
-                       priv->mtr_en = 1;
+                       uint8_t reg_c_mask =
+                               config.hca_attr.qos.flow_meter_reg_c_ids;
+                       /*
+                        * Meter needs two REG_C's for color match and pre-sfx
+                        * flow match. Here get the REG_C for color match.
+                        * REG_C_0 and REG_C_1 is reserved for metadata feature.
+                        */
+                       reg_c_mask &= 0xfc;
+                       if (__builtin_popcount(reg_c_mask) < 1) {
+                               priv->mtr_en = 0;
+                               DRV_LOG(WARNING, "No available register for"
+                                       " meter.");
+                       } else {
+                               priv->mtr_color_reg = ffs(reg_c_mask) - 1 +
+                                                     REG_C_0;
+                               priv->mtr_en = 1;
+                               DRV_LOG(DEBUG, "The REG_C meter uses is %d",
+                                       priv->mtr_color_reg);
+                       }
                }
 #endif
        }
@@ -2385,6 +2404,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                mlx5_nl_mac_addr_sync(eth_dev);
        TAILQ_INIT(&priv->flows);
        TAILQ_INIT(&priv->ctrl_flows);
+       TAILQ_INIT(&priv->flow_meters);
+       TAILQ_INIT(&priv->flow_meter_profiles);
        /* Hint libmlx5 to use PMD allocator for data plane resources */
        struct mlx5dv_ctx_allocators alctr = {
                .alloc = &mlx5_alloc_verbs_buf,