net/virtio: fix incorrect cast of void *
[dpdk.git] / ethdev / rte_mtr.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #include <stdint.h>
6
7 #include <rte_errno.h>
8 #include "rte_compat.h"
9 #include "rte_ethdev.h"
10 #include "rte_mtr_driver.h"
11 #include "rte_mtr.h"
12
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)
16 {
17         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
18         const struct rte_mtr_ops *ops;
19
20         if (!rte_eth_dev_is_valid_port(port_id)) {
21                 rte_mtr_error_set(error,
22                         ENODEV,
23                         RTE_MTR_ERROR_TYPE_UNSPECIFIED,
24                         NULL,
25                         rte_strerror(ENODEV));
26                 return NULL;
27         }
28
29         if ((dev->dev_ops->mtr_ops_get == NULL) ||
30                 (dev->dev_ops->mtr_ops_get(dev, &ops) != 0) ||
31                 (ops == NULL)) {
32                 rte_mtr_error_set(error,
33                         ENOSYS,
34                         RTE_MTR_ERROR_TYPE_UNSPECIFIED,
35                         NULL,
36                         rte_strerror(ENOSYS));
37                 return NULL;
38         }
39
40         return ops;
41 }
42
43 #define RTE_MTR_FUNC(port_id, func)                     \
44 ({                                                      \
45         const struct rte_mtr_ops *ops =                 \
46                 rte_mtr_ops_get(port_id, error);                \
47         if (ops == NULL)                                        \
48                 return -rte_errno;                      \
49                                                         \
50         if (ops->func == NULL)                          \
51                 return -rte_mtr_error_set(error,                \
52                         ENOSYS,                         \
53                         RTE_MTR_ERROR_TYPE_UNSPECIFIED, \
54                         NULL,                           \
55                         rte_strerror(ENOSYS));          \
56                                                         \
57         ops->func;                                      \
58 })
59
60 /* MTR capabilities get */
61 int
62 rte_mtr_capabilities_get(uint16_t port_id,
63         struct rte_mtr_capabilities *cap,
64         struct rte_mtr_error *error)
65 {
66         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
67         return RTE_MTR_FUNC(port_id, capabilities_get)(dev,
68                 cap, error);
69 }
70
71 /* MTR meter profile add */
72 int
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)
77 {
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);
81 }
82
83 /** MTR meter profile delete */
84 int
85 rte_mtr_meter_profile_delete(uint16_t port_id,
86         uint32_t meter_profile_id,
87         struct rte_mtr_error *error)
88 {
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);
92 }
93
94 /* MTR meter policy validate */
95 int
96 rte_mtr_meter_policy_validate(uint16_t port_id,
97         struct rte_mtr_meter_policy_params *policy,
98         struct rte_mtr_error *error)
99 {
100         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
101         return RTE_MTR_FUNC(port_id, meter_policy_validate)(dev,
102                 policy, error);
103 }
104
105 /* MTR meter policy add */
106 int
107 rte_mtr_meter_policy_add(uint16_t port_id,
108         uint32_t policy_id,
109         struct rte_mtr_meter_policy_params *policy,
110         struct rte_mtr_error *error)
111 {
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);
115 }
116
117 /** MTR meter policy delete */
118 int
119 rte_mtr_meter_policy_delete(uint16_t port_id,
120         uint32_t policy_id,
121         struct rte_mtr_error *error)
122 {
123         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
124         return RTE_MTR_FUNC(port_id, meter_policy_delete)(dev,
125                 policy_id, error);
126 }
127
128 /** MTR object create */
129 int
130 rte_mtr_create(uint16_t port_id,
131         uint32_t mtr_id,
132         struct rte_mtr_params *params,
133         int shared,
134         struct rte_mtr_error *error)
135 {
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);
139 }
140
141 /** MTR object destroy */
142 int
143 rte_mtr_destroy(uint16_t port_id,
144         uint32_t mtr_id,
145         struct rte_mtr_error *error)
146 {
147         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
148         return RTE_MTR_FUNC(port_id, destroy)(dev,
149                 mtr_id, error);
150 }
151
152 /** MTR object meter enable */
153 int
154 rte_mtr_meter_enable(uint16_t port_id,
155         uint32_t mtr_id,
156         struct rte_mtr_error *error)
157 {
158         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
159         return RTE_MTR_FUNC(port_id, meter_enable)(dev,
160                 mtr_id, error);
161 }
162
163 /** MTR object meter disable */
164 int
165 rte_mtr_meter_disable(uint16_t port_id,
166         uint32_t mtr_id,
167         struct rte_mtr_error *error)
168 {
169         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
170         return RTE_MTR_FUNC(port_id, meter_disable)(dev,
171                 mtr_id, error);
172 }
173
174 /** MTR object meter profile update */
175 int
176 rte_mtr_meter_profile_update(uint16_t port_id,
177         uint32_t mtr_id,
178         uint32_t meter_profile_id,
179         struct rte_mtr_error *error)
180 {
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);
184 }
185
186 /** MTR object meter policy update */
187 int
188 rte_mtr_meter_policy_update(uint16_t port_id,
189         uint32_t mtr_id,
190         uint32_t meter_policy_id,
191         struct rte_mtr_error *error)
192 {
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);
196 }
197
198 /** MTR object meter DSCP table update */
199 int
200 rte_mtr_meter_dscp_table_update(uint16_t port_id,
201         uint32_t mtr_id,
202         enum rte_color *dscp_table,
203         struct rte_mtr_error *error)
204 {
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);
208 }
209
210 /** MTR object enabled stats update */
211 int
212 rte_mtr_stats_update(uint16_t port_id,
213         uint32_t mtr_id,
214         uint64_t stats_mask,
215         struct rte_mtr_error *error)
216 {
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);
220 }
221
222 /** MTR object stats read */
223 int
224 rte_mtr_stats_read(uint16_t port_id,
225         uint32_t mtr_id,
226         struct rte_mtr_stats *stats,
227         uint64_t *stats_mask,
228         int clear,
229         struct rte_mtr_error *error)
230 {
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);
234 }