doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_ethdev / rte_tm_driver.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef __INCLUDE_RTE_TM_DRIVER_H__
6 #define __INCLUDE_RTE_TM_DRIVER_H__
7
8 /**
9  * @file
10  * RTE Generic Traffic Manager API (Driver Side)
11  *
12  * This file provides implementation helpers for internal use by PMDs, they
13  * are not intended to be exposed to applications and are not subject to ABI
14  * versioning.
15  */
16
17 #include <stdint.h>
18
19 #include <rte_errno.h>
20 #include "rte_ethdev.h"
21 #include "ethdev_driver.h"
22 #include "rte_tm.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /** @internal Traffic manager node ID validate and type get */
29 typedef int (*rte_tm_node_type_get_t)(struct rte_eth_dev *dev,
30         uint32_t node_id,
31         int *is_leaf,
32         struct rte_tm_error *error);
33
34 /** @internal Traffic manager capabilities get */
35 typedef int (*rte_tm_capabilities_get_t)(struct rte_eth_dev *dev,
36         struct rte_tm_capabilities *cap,
37         struct rte_tm_error *error);
38
39 /** @internal Traffic manager level capabilities get */
40 typedef int (*rte_tm_level_capabilities_get_t)(struct rte_eth_dev *dev,
41         uint32_t level_id,
42         struct rte_tm_level_capabilities *cap,
43         struct rte_tm_error *error);
44
45 /** @internal Traffic manager node capabilities get */
46 typedef int (*rte_tm_node_capabilities_get_t)(struct rte_eth_dev *dev,
47         uint32_t node_id,
48         struct rte_tm_node_capabilities *cap,
49         struct rte_tm_error *error);
50
51 /** @internal Traffic manager WRED profile add */
52 typedef int (*rte_tm_wred_profile_add_t)(struct rte_eth_dev *dev,
53         uint32_t wred_profile_id,
54         struct rte_tm_wred_params *profile,
55         struct rte_tm_error *error);
56
57 /** @internal Traffic manager WRED profile delete */
58 typedef int (*rte_tm_wred_profile_delete_t)(struct rte_eth_dev *dev,
59         uint32_t wred_profile_id,
60         struct rte_tm_error *error);
61
62 /** @internal Traffic manager shared WRED context add */
63 typedef int (*rte_tm_shared_wred_context_add_update_t)(
64         struct rte_eth_dev *dev,
65         uint32_t shared_wred_context_id,
66         uint32_t wred_profile_id,
67         struct rte_tm_error *error);
68
69 /** @internal Traffic manager shared WRED context delete */
70 typedef int (*rte_tm_shared_wred_context_delete_t)(
71         struct rte_eth_dev *dev,
72         uint32_t shared_wred_context_id,
73         struct rte_tm_error *error);
74
75 /** @internal Traffic manager shaper profile add */
76 typedef int (*rte_tm_shaper_profile_add_t)(struct rte_eth_dev *dev,
77         uint32_t shaper_profile_id,
78         struct rte_tm_shaper_params *profile,
79         struct rte_tm_error *error);
80
81 /** @internal Traffic manager shaper profile delete */
82 typedef int (*rte_tm_shaper_profile_delete_t)(struct rte_eth_dev *dev,
83         uint32_t shaper_profile_id,
84         struct rte_tm_error *error);
85
86 /** @internal Traffic manager shared shaper add/update */
87 typedef int (*rte_tm_shared_shaper_add_update_t)(struct rte_eth_dev *dev,
88         uint32_t shared_shaper_id,
89         uint32_t shaper_profile_id,
90         struct rte_tm_error *error);
91
92 /** @internal Traffic manager shared shaper delete */
93 typedef int (*rte_tm_shared_shaper_delete_t)(struct rte_eth_dev *dev,
94         uint32_t shared_shaper_id,
95         struct rte_tm_error *error);
96
97 /** @internal Traffic manager node add */
98 typedef int (*rte_tm_node_add_t)(struct rte_eth_dev *dev,
99         uint32_t node_id,
100         uint32_t parent_node_id,
101         uint32_t priority,
102         uint32_t weight,
103         uint32_t level_id,
104         struct rte_tm_node_params *params,
105         struct rte_tm_error *error);
106
107 /** @internal Traffic manager node delete */
108 typedef int (*rte_tm_node_delete_t)(struct rte_eth_dev *dev,
109         uint32_t node_id,
110         struct rte_tm_error *error);
111
112 /** @internal Traffic manager node suspend */
113 typedef int (*rte_tm_node_suspend_t)(struct rte_eth_dev *dev,
114         uint32_t node_id,
115         struct rte_tm_error *error);
116
117 /** @internal Traffic manager node resume */
118 typedef int (*rte_tm_node_resume_t)(struct rte_eth_dev *dev,
119         uint32_t node_id,
120         struct rte_tm_error *error);
121
122 /** @internal Traffic manager hierarchy commit */
123 typedef int (*rte_tm_hierarchy_commit_t)(struct rte_eth_dev *dev,
124         int clear_on_fail,
125         struct rte_tm_error *error);
126
127 /** @internal Traffic manager node parent update */
128 typedef int (*rte_tm_node_parent_update_t)(struct rte_eth_dev *dev,
129         uint32_t node_id,
130         uint32_t parent_node_id,
131         uint32_t priority,
132         uint32_t weight,
133         struct rte_tm_error *error);
134
135 /** @internal Traffic manager node shaper update */
136 typedef int (*rte_tm_node_shaper_update_t)(struct rte_eth_dev *dev,
137         uint32_t node_id,
138         uint32_t shaper_profile_id,
139         struct rte_tm_error *error);
140
141 /** @internal Traffic manager node shaper update */
142 typedef int (*rte_tm_node_shared_shaper_update_t)(struct rte_eth_dev *dev,
143         uint32_t node_id,
144         uint32_t shared_shaper_id,
145         int32_t add,
146         struct rte_tm_error *error);
147
148 /** @internal Traffic manager node stats update */
149 typedef int (*rte_tm_node_stats_update_t)(struct rte_eth_dev *dev,
150         uint32_t node_id,
151         uint64_t stats_mask,
152         struct rte_tm_error *error);
153
154 /** @internal Traffic manager node WFQ weight mode update */
155 typedef int (*rte_tm_node_wfq_weight_mode_update_t)(
156         struct rte_eth_dev *dev,
157         uint32_t node_id,
158         int *wfq_weight_mode,
159         uint32_t n_sp_priorities,
160         struct rte_tm_error *error);
161
162 /** @internal Traffic manager node congestion management mode update */
163 typedef int (*rte_tm_node_cman_update_t)(struct rte_eth_dev *dev,
164         uint32_t node_id,
165         enum rte_tm_cman_mode cman,
166         struct rte_tm_error *error);
167
168 /** @internal Traffic manager node WRED context update */
169 typedef int (*rte_tm_node_wred_context_update_t)(
170         struct rte_eth_dev *dev,
171         uint32_t node_id,
172         uint32_t wred_profile_id,
173         struct rte_tm_error *error);
174
175 /** @internal Traffic manager node WRED context update */
176 typedef int (*rte_tm_node_shared_wred_context_update_t)(
177         struct rte_eth_dev *dev,
178         uint32_t node_id,
179         uint32_t shared_wred_context_id,
180         int add,
181         struct rte_tm_error *error);
182
183 /** @internal Traffic manager read stats counters for specific node */
184 typedef int (*rte_tm_node_stats_read_t)(struct rte_eth_dev *dev,
185         uint32_t node_id,
186         struct rte_tm_node_stats *stats,
187         uint64_t *stats_mask,
188         int clear,
189         struct rte_tm_error *error);
190
191 /** @internal Traffic manager packet marking - VLAN DEI */
192 typedef int (*rte_tm_mark_vlan_dei_t)(struct rte_eth_dev *dev,
193         int mark_green,
194         int mark_yellow,
195         int mark_red,
196         struct rte_tm_error *error);
197
198 /** @internal Traffic manager packet marking - IPv4/IPv6 ECN */
199 typedef int (*rte_tm_mark_ip_ecn_t)(struct rte_eth_dev *dev,
200         int mark_green,
201         int mark_yellow,
202         int mark_red,
203         struct rte_tm_error *error);
204
205 /** @internal Traffic manager packet marking - IPv4/IPv6 DSCP */
206 typedef int (*rte_tm_mark_ip_dscp_t)(struct rte_eth_dev *dev,
207         int mark_green,
208         int mark_yellow,
209         int mark_red,
210         struct rte_tm_error *error);
211
212 struct rte_tm_ops {
213         /** Traffic manager node type get */
214         rte_tm_node_type_get_t node_type_get;
215
216         /** Traffic manager capabilities_get */
217         rte_tm_capabilities_get_t capabilities_get;
218         /** Traffic manager level capabilities_get */
219         rte_tm_level_capabilities_get_t level_capabilities_get;
220         /** Traffic manager node capabilities get */
221         rte_tm_node_capabilities_get_t node_capabilities_get;
222
223         /** Traffic manager WRED profile add */
224         rte_tm_wred_profile_add_t wred_profile_add;
225         /** Traffic manager WRED profile delete */
226         rte_tm_wred_profile_delete_t wred_profile_delete;
227         /** Traffic manager shared WRED context add/update */
228         rte_tm_shared_wred_context_add_update_t
229                 shared_wred_context_add_update;
230         /** Traffic manager shared WRED context delete */
231         rte_tm_shared_wred_context_delete_t
232                 shared_wred_context_delete;
233
234         /** Traffic manager shaper profile add */
235         rte_tm_shaper_profile_add_t shaper_profile_add;
236         /** Traffic manager shaper profile delete */
237         rte_tm_shaper_profile_delete_t shaper_profile_delete;
238         /** Traffic manager shared shaper add/update */
239         rte_tm_shared_shaper_add_update_t shared_shaper_add_update;
240         /** Traffic manager shared shaper delete */
241         rte_tm_shared_shaper_delete_t shared_shaper_delete;
242
243         /** Traffic manager node add */
244         rte_tm_node_add_t node_add;
245         /** Traffic manager node delete */
246         rte_tm_node_delete_t node_delete;
247         /** Traffic manager node suspend */
248         rte_tm_node_suspend_t node_suspend;
249         /** Traffic manager node resume */
250         rte_tm_node_resume_t node_resume;
251         /** Traffic manager hierarchy commit */
252         rte_tm_hierarchy_commit_t hierarchy_commit;
253
254         /** Traffic manager node parent update */
255         rte_tm_node_parent_update_t node_parent_update;
256         /** Traffic manager node shaper update */
257         rte_tm_node_shaper_update_t node_shaper_update;
258         /** Traffic manager node shared shaper update */
259         rte_tm_node_shared_shaper_update_t node_shared_shaper_update;
260         /** Traffic manager node stats update */
261         rte_tm_node_stats_update_t node_stats_update;
262         /** Traffic manager node WFQ weight mode update */
263         rte_tm_node_wfq_weight_mode_update_t node_wfq_weight_mode_update;
264         /** Traffic manager node congestion management mode update */
265         rte_tm_node_cman_update_t node_cman_update;
266         /** Traffic manager node WRED context update */
267         rte_tm_node_wred_context_update_t node_wred_context_update;
268         /** Traffic manager node shared WRED context update */
269         rte_tm_node_shared_wred_context_update_t
270                 node_shared_wred_context_update;
271         /** Traffic manager read statistics counters for current node */
272         rte_tm_node_stats_read_t node_stats_read;
273
274         /** Traffic manager packet marking - VLAN DEI */
275         rte_tm_mark_vlan_dei_t mark_vlan_dei;
276         /** Traffic manager packet marking - IPv4/IPv6 ECN */
277         rte_tm_mark_ip_ecn_t mark_ip_ecn;
278         /** Traffic manager packet marking - IPv4/IPv6 DSCP */
279         rte_tm_mark_ip_dscp_t mark_ip_dscp;
280 };
281
282 /**
283  * Initialize generic error structure.
284  *
285  * This function also sets rte_errno to a given value.
286  *
287  * @param[out] error
288  *   Pointer to error structure (may be NULL).
289  * @param[in] code
290  *   Related error code (rte_errno).
291  * @param[in] type
292  *   Cause field and error type.
293  * @param[in] cause
294  *   Object responsible for the error.
295  * @param[in] message
296  *   Human-readable error message.
297  *
298  * @return
299  *   Error code.
300  */
301 static inline int
302 rte_tm_error_set(struct rte_tm_error *error,
303                    int code,
304                    enum rte_tm_error_type type,
305                    const void *cause,
306                    const char *message)
307 {
308         if (error) {
309                 *error = (struct rte_tm_error){
310                         .type = type,
311                         .cause = cause,
312                         .message = message,
313                 };
314         }
315         rte_errno = code;
316         return code;
317 }
318
319 /**
320  * Get generic traffic manager operations structure from a port
321  *
322  * @param[in] port_id
323  *   The port identifier of the Ethernet device.
324  * @param[out] error
325  *   Error details
326  *
327  * @return
328  *   The traffic manager operations structure associated with port_id on
329  *   success, NULL otherwise.
330  */
331 const struct rte_tm_ops *
332 rte_tm_ops_get(uint16_t port_id, struct rte_tm_error *error);
333
334 #ifdef __cplusplus
335 }
336 #endif
337
338 #endif /* __INCLUDE_RTE_TM_DRIVER_H__ */