4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_errno.h>
37 #include "rte_ethdev.h"
38 #include "rte_mtr_driver.h"
41 /* Get generic traffic metering & policing operations structure from a port. */
42 const struct rte_mtr_ops *
43 rte_mtr_ops_get(uint16_t port_id, struct rte_mtr_error *error)
45 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
46 const struct rte_mtr_ops *ops;
48 if (!rte_eth_dev_is_valid_port(port_id)) {
49 rte_mtr_error_set(error,
51 RTE_MTR_ERROR_TYPE_UNSPECIFIED,
53 rte_strerror(ENODEV));
57 if ((dev->dev_ops->mtr_ops_get == NULL) ||
58 (dev->dev_ops->mtr_ops_get(dev, &ops) != 0) ||
60 rte_mtr_error_set(error,
62 RTE_MTR_ERROR_TYPE_UNSPECIFIED,
64 rte_strerror(ENOSYS));
71 #define RTE_MTR_FUNC(port_id, func) \
73 const struct rte_mtr_ops *ops = \
74 rte_mtr_ops_get(port_id, error); \
78 if (ops->func == NULL) \
79 return -rte_mtr_error_set(error, \
81 RTE_MTR_ERROR_TYPE_UNSPECIFIED, \
83 rte_strerror(ENOSYS)); \
88 /* MTR capabilities get */
90 rte_mtr_capabilities_get(uint16_t port_id,
91 struct rte_mtr_capabilities *cap,
92 struct rte_mtr_error *error)
94 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
95 return RTE_MTR_FUNC(port_id, capabilities_get)(dev,
99 /* MTR meter profile add */
101 rte_mtr_meter_profile_add(uint16_t port_id,
102 uint32_t meter_profile_id,
103 struct rte_mtr_meter_profile *profile,
104 struct rte_mtr_error *error)
106 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
107 return RTE_MTR_FUNC(port_id, meter_profile_add)(dev,
108 meter_profile_id, profile, error);
111 /** MTR meter profile delete */
113 rte_mtr_meter_profile_delete(uint16_t port_id,
114 uint32_t meter_profile_id,
115 struct rte_mtr_error *error)
117 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
118 return RTE_MTR_FUNC(port_id, meter_profile_delete)(dev,
119 meter_profile_id, error);
122 /** MTR object create */
124 rte_mtr_create(uint16_t port_id,
126 struct rte_mtr_params *params,
128 struct rte_mtr_error *error)
130 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
131 return RTE_MTR_FUNC(port_id, create)(dev,
132 mtr_id, params, shared, error);
135 /** MTR object destroy */
137 rte_mtr_destroy(uint16_t port_id,
139 struct rte_mtr_error *error)
141 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
142 return RTE_MTR_FUNC(port_id, destroy)(dev,
146 /** MTR object meter enable */
148 rte_mtr_meter_enable(uint16_t port_id,
150 struct rte_mtr_error *error)
152 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
153 return RTE_MTR_FUNC(port_id, meter_enable)(dev,
157 /** MTR object meter disable */
159 rte_mtr_meter_disable(uint16_t port_id,
161 struct rte_mtr_error *error)
163 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
164 return RTE_MTR_FUNC(port_id, meter_disable)(dev,
168 /** MTR object meter profile update */
170 rte_mtr_meter_profile_update(uint16_t port_id,
172 uint32_t meter_profile_id,
173 struct rte_mtr_error *error)
175 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
176 return RTE_MTR_FUNC(port_id, meter_profile_update)(dev,
177 mtr_id, meter_profile_id, error);
180 /** MTR object meter DSCP table update */
182 rte_mtr_meter_dscp_table_update(uint16_t port_id,
184 enum rte_mtr_color *dscp_table,
185 struct rte_mtr_error *error)
187 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
188 return RTE_MTR_FUNC(port_id, meter_dscp_table_update)(dev,
189 mtr_id, dscp_table, error);
192 /** MTR object policer action update */
194 rte_mtr_policer_actions_update(uint16_t port_id,
196 uint32_t action_mask,
197 enum rte_mtr_policer_action *actions,
198 struct rte_mtr_error *error)
200 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
201 return RTE_MTR_FUNC(port_id, policer_actions_update)(dev,
202 mtr_id, action_mask, actions, error);
205 /** MTR object enabled stats update */
207 rte_mtr_stats_update(uint16_t port_id,
210 struct rte_mtr_error *error)
212 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
213 return RTE_MTR_FUNC(port_id, stats_update)(dev,
214 mtr_id, stats_mask, error);
217 /** MTR object stats read */
219 rte_mtr_stats_read(uint16_t port_id,
221 struct rte_mtr_stats *stats,
222 uint64_t *stats_mask,
224 struct rte_mtr_error *error)
226 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
227 return RTE_MTR_FUNC(port_id, stats_read)(dev,
228 mtr_id, stats, stats_mask, clear, error);