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