build: use static deps for pkg-config libs.private
[dpdk.git] / lib / librte_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 __rte_experimental
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 __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)
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 __rte_experimental
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 object create */
95 int __rte_experimental
96 rte_mtr_create(uint16_t port_id,
97         uint32_t mtr_id,
98         struct rte_mtr_params *params,
99         int shared,
100         struct rte_mtr_error *error)
101 {
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);
105 }
106
107 /** MTR object destroy */
108 int __rte_experimental
109 rte_mtr_destroy(uint16_t port_id,
110         uint32_t mtr_id,
111         struct rte_mtr_error *error)
112 {
113         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
114         return RTE_MTR_FUNC(port_id, destroy)(dev,
115                 mtr_id, error);
116 }
117
118 /** MTR object meter enable */
119 int __rte_experimental
120 rte_mtr_meter_enable(uint16_t port_id,
121         uint32_t mtr_id,
122         struct rte_mtr_error *error)
123 {
124         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
125         return RTE_MTR_FUNC(port_id, meter_enable)(dev,
126                 mtr_id, error);
127 }
128
129 /** MTR object meter disable */
130 int __rte_experimental
131 rte_mtr_meter_disable(uint16_t port_id,
132         uint32_t mtr_id,
133         struct rte_mtr_error *error)
134 {
135         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
136         return RTE_MTR_FUNC(port_id, meter_disable)(dev,
137                 mtr_id, error);
138 }
139
140 /** MTR object meter profile update */
141 int __rte_experimental
142 rte_mtr_meter_profile_update(uint16_t port_id,
143         uint32_t mtr_id,
144         uint32_t meter_profile_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, meter_profile_update)(dev,
149                 mtr_id, meter_profile_id, error);
150 }
151
152 /** MTR object meter DSCP table update */
153 int __rte_experimental
154 rte_mtr_meter_dscp_table_update(uint16_t port_id,
155         uint32_t mtr_id,
156         enum rte_mtr_color *dscp_table,
157         struct rte_mtr_error *error)
158 {
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);
162 }
163
164 /** MTR object policer action update */
165 int __rte_experimental
166 rte_mtr_policer_actions_update(uint16_t port_id,
167         uint32_t mtr_id,
168         uint32_t action_mask,
169         enum rte_mtr_policer_action *actions,
170         struct rte_mtr_error *error)
171 {
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);
175 }
176
177 /** MTR object enabled stats update */
178 int __rte_experimental
179 rte_mtr_stats_update(uint16_t port_id,
180         uint32_t mtr_id,
181         uint64_t stats_mask,
182         struct rte_mtr_error *error)
183 {
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);
187 }
188
189 /** MTR object stats read */
190 int __rte_experimental
191 rte_mtr_stats_read(uint16_t port_id,
192         uint32_t mtr_id,
193         struct rte_mtr_stats *stats,
194         uint64_t *stats_mask,
195         int clear,
196         struct rte_mtr_error *error)
197 {
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);
201 }