1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
8 #include "rte_compat.h"
9 #include "rte_ethdev.h"
10 #include "rte_mtr_driver.h"
13 /* Get generic traffic metering & policing operations structure from a port. */
14 const struct rte_mtr_ops *
15 rte_mtr_ops_get(uint16_t port_id, struct rte_mtr_error *error)
17 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
18 const struct rte_mtr_ops *ops;
20 if (!rte_eth_dev_is_valid_port(port_id)) {
21 rte_mtr_error_set(error,
23 RTE_MTR_ERROR_TYPE_UNSPECIFIED,
25 rte_strerror(ENODEV));
29 if ((dev->dev_ops->mtr_ops_get == NULL) ||
30 (dev->dev_ops->mtr_ops_get(dev, &ops) != 0) ||
32 rte_mtr_error_set(error,
34 RTE_MTR_ERROR_TYPE_UNSPECIFIED,
36 rte_strerror(ENOSYS));
43 #define RTE_MTR_FUNC(port_id, func) \
45 const struct rte_mtr_ops *ops = \
46 rte_mtr_ops_get(port_id, error); \
50 if (ops->func == NULL) \
51 return -rte_mtr_error_set(error, \
53 RTE_MTR_ERROR_TYPE_UNSPECIFIED, \
55 rte_strerror(ENOSYS)); \
60 /* MTR capabilities get */
62 rte_mtr_capabilities_get(uint16_t port_id,
63 struct rte_mtr_capabilities *cap,
64 struct rte_mtr_error *error)
66 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
67 return RTE_MTR_FUNC(port_id, capabilities_get)(dev,
71 /* MTR meter profile add */
73 rte_mtr_meter_profile_add(uint16_t port_id,
74 uint32_t meter_profile_id,
75 struct rte_mtr_meter_profile *profile,
76 struct rte_mtr_error *error)
78 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
79 return RTE_MTR_FUNC(port_id, meter_profile_add)(dev,
80 meter_profile_id, profile, error);
83 /** MTR meter profile delete */
85 rte_mtr_meter_profile_delete(uint16_t port_id,
86 uint32_t meter_profile_id,
87 struct rte_mtr_error *error)
89 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
90 return RTE_MTR_FUNC(port_id, meter_profile_delete)(dev,
91 meter_profile_id, error);
94 /* MTR meter policy validate */
96 rte_mtr_meter_policy_validate(uint16_t port_id,
97 struct rte_mtr_meter_policy_params *policy,
98 struct rte_mtr_error *error)
100 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
101 return RTE_MTR_FUNC(port_id, meter_policy_validate)(dev,
105 /* MTR meter policy add */
107 rte_mtr_meter_policy_add(uint16_t port_id,
109 struct rte_mtr_meter_policy_params *policy,
110 struct rte_mtr_error *error)
112 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
113 return RTE_MTR_FUNC(port_id, meter_policy_add)(dev,
114 policy_id, policy, error);
117 /** MTR meter policy delete */
119 rte_mtr_meter_policy_delete(uint16_t port_id,
121 struct rte_mtr_error *error)
123 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
124 return RTE_MTR_FUNC(port_id, meter_policy_delete)(dev,
128 /** MTR object create */
130 rte_mtr_create(uint16_t port_id,
132 struct rte_mtr_params *params,
134 struct rte_mtr_error *error)
136 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
137 return RTE_MTR_FUNC(port_id, create)(dev,
138 mtr_id, params, shared, error);
141 /** MTR object destroy */
143 rte_mtr_destroy(uint16_t port_id,
145 struct rte_mtr_error *error)
147 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
148 return RTE_MTR_FUNC(port_id, destroy)(dev,
152 /** MTR object meter enable */
154 rte_mtr_meter_enable(uint16_t port_id,
156 struct rte_mtr_error *error)
158 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
159 return RTE_MTR_FUNC(port_id, meter_enable)(dev,
163 /** MTR object meter disable */
165 rte_mtr_meter_disable(uint16_t port_id,
167 struct rte_mtr_error *error)
169 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
170 return RTE_MTR_FUNC(port_id, meter_disable)(dev,
174 /** MTR object meter profile update */
176 rte_mtr_meter_profile_update(uint16_t port_id,
178 uint32_t meter_profile_id,
179 struct rte_mtr_error *error)
181 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
182 return RTE_MTR_FUNC(port_id, meter_profile_update)(dev,
183 mtr_id, meter_profile_id, error);
186 /** MTR object meter policy update */
188 rte_mtr_meter_policy_update(uint16_t port_id,
190 uint32_t meter_policy_id,
191 struct rte_mtr_error *error)
193 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
194 return RTE_MTR_FUNC(port_id, meter_policy_update)(dev,
195 mtr_id, meter_policy_id, error);
198 /** MTR object meter DSCP table update */
200 rte_mtr_meter_dscp_table_update(uint16_t port_id,
202 enum rte_color *dscp_table,
203 struct rte_mtr_error *error)
205 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
206 return RTE_MTR_FUNC(port_id, meter_dscp_table_update)(dev,
207 mtr_id, dscp_table, error);
210 /** MTR object enabled stats update */
212 rte_mtr_stats_update(uint16_t port_id,
215 struct rte_mtr_error *error)
217 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
218 return RTE_MTR_FUNC(port_id, stats_update)(dev,
219 mtr_id, stats_mask, error);
222 /** MTR object stats read */
224 rte_mtr_stats_read(uint16_t port_id,
226 struct rte_mtr_stats *stats,
227 uint64_t *stats_mask,
229 struct rte_mtr_error *error)
231 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
232 return RTE_MTR_FUNC(port_id, stats_read)(dev,
233 mtr_id, stats, stats_mask, clear, error);