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 */
61 int __rte_experimental
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 */
72 int __rte_experimental
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 */
84 int __rte_experimental
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 object create */
95 int __rte_experimental
96 rte_mtr_create(uint16_t port_id,
98 struct rte_mtr_params *params,
100 struct rte_mtr_error *error)
102 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
103 return RTE_MTR_FUNC(port_id, create)(dev,
104 mtr_id, params, shared, error);
107 /** MTR object destroy */
108 int __rte_experimental
109 rte_mtr_destroy(uint16_t port_id,
111 struct rte_mtr_error *error)
113 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
114 return RTE_MTR_FUNC(port_id, destroy)(dev,
118 /** MTR object meter enable */
119 int __rte_experimental
120 rte_mtr_meter_enable(uint16_t port_id,
122 struct rte_mtr_error *error)
124 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
125 return RTE_MTR_FUNC(port_id, meter_enable)(dev,
129 /** MTR object meter disable */
130 int __rte_experimental
131 rte_mtr_meter_disable(uint16_t port_id,
133 struct rte_mtr_error *error)
135 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
136 return RTE_MTR_FUNC(port_id, meter_disable)(dev,
140 /** MTR object meter profile update */
141 int __rte_experimental
142 rte_mtr_meter_profile_update(uint16_t port_id,
144 uint32_t meter_profile_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, meter_profile_update)(dev,
149 mtr_id, meter_profile_id, error);
152 /** MTR object meter DSCP table update */
153 int __rte_experimental
154 rte_mtr_meter_dscp_table_update(uint16_t port_id,
156 enum rte_mtr_color *dscp_table,
157 struct rte_mtr_error *error)
159 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
160 return RTE_MTR_FUNC(port_id, meter_dscp_table_update)(dev,
161 mtr_id, dscp_table, error);
164 /** MTR object policer action update */
165 int __rte_experimental
166 rte_mtr_policer_actions_update(uint16_t port_id,
168 uint32_t action_mask,
169 enum rte_mtr_policer_action *actions,
170 struct rte_mtr_error *error)
172 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
173 return RTE_MTR_FUNC(port_id, policer_actions_update)(dev,
174 mtr_id, action_mask, actions, error);
177 /** MTR object enabled stats update */
178 int __rte_experimental
179 rte_mtr_stats_update(uint16_t port_id,
182 struct rte_mtr_error *error)
184 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
185 return RTE_MTR_FUNC(port_id, stats_update)(dev,
186 mtr_id, stats_mask, error);
189 /** MTR object stats read */
190 int __rte_experimental
191 rte_mtr_stats_read(uint16_t port_id,
193 struct rte_mtr_stats *stats,
194 uint64_t *stats_mask,
196 struct rte_mtr_error *error)
198 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
199 return RTE_MTR_FUNC(port_id, stats_read)(dev,
200 mtr_id, stats, stats_mask, clear, error);