9103b6de374b3d3769a7323a8cbf04507b40d93f
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_meter.c
1 // SPDX-License-Identifier: BSD-3-Clause
2 /*
3  * Copyright 2018 Mellanox Technologies, Ltd
4  */
5 #include <math.h>
6
7 #include <rte_mtr.h>
8 #include <rte_mtr_driver.h>
9
10 #include "mlx5.h"
11 #include "mlx5_flow.h"
12
13 /**
14  * Callback to get MTR capabilities.
15  *
16  * @param[in] dev
17  *   Pointer to Ethernet device.
18  * @param[out] cap
19  *   Pointer to save MTR capabilities.
20  * @param[out] error
21  *   Pointer to the error structure.
22  *
23  * @return
24  *   0 on success, a negative errno value otherwise and rte_errno is set.
25  */
26 static int
27 mlx5_flow_mtr_cap_get(struct rte_eth_dev *dev,
28                  struct rte_mtr_capabilities *cap,
29                  struct rte_mtr_error *error __rte_unused)
30 {
31         struct mlx5_priv *priv = dev->data->dev_private;
32         struct mlx5_hca_qos_attr *qattr = &priv->config.hca_attr.qos;
33
34         if (!priv->mtr_en)
35                 return -rte_mtr_error_set(error, ENOTSUP,
36                                           RTE_MTR_ERROR_TYPE_UNSPECIFIED, NULL,
37                                           "Meter is not support");
38         memset(cap, 0, sizeof(*cap));
39         cap->n_max = 1 << qattr->log_max_flow_meter;
40         cap->n_shared_max = cap->n_max;
41         cap->identical = 1;
42         cap->shared_identical = 1;
43         cap->shared_n_flows_per_mtr_max = 4 << 20;
44         /* 2M flows can share the same meter. */
45         cap->chaining_n_mtrs_per_flow_max = 1; /* Chaining is not supported. */
46         cap->meter_srtcm_rfc2697_n_max = qattr->srtcm_sup ? cap->n_max : 0;
47         cap->meter_rate_max = 1ULL << 40; /* 1 Tera tokens per sec. */
48         cap->policer_action_drop_supported = 1;
49         cap->stats_mask = RTE_MTR_STATS_N_BYTES_DROPPED |
50                           RTE_MTR_STATS_N_PKTS_DROPPED;
51         return 0;
52 }
53
54 static const struct rte_mtr_ops mlx5_flow_mtr_ops = {
55         .capabilities_get = mlx5_flow_mtr_cap_get,
56         .meter_profile_add = NULL,
57         .meter_profile_delete = NULL,
58         .create = NULL,
59         .destroy = NULL,
60         .meter_enable = NULL,
61         .meter_disable = NULL,
62         .meter_profile_update = NULL,
63         .meter_dscp_table_update = NULL,
64         .policer_actions_update = NULL,
65         .stats_update = NULL,
66         .stats_read = NULL,
67 };
68
69 /**
70  * Get meter operations.
71  *
72  * @param dev
73  *   Pointer to Ethernet device structure.
74  * @param arg
75  *   Pointer to set the mtr operations.
76  *
77  * @return
78  *   Always 0.
79  */
80 int
81 mlx5_flow_meter_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg)
82 {
83         *(const struct rte_mtr_ops **)arg = &mlx5_flow_mtr_ops;
84         return 0;
85 }