xref: /dpdk/lib/ethdev/rte_tm_driver.h (revision 25a2a0dc3de31ca0a6fbc9371cf3dd85dfd74b07)
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 	const 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 	const 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 	const 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 node query */
123 typedef int (*rte_tm_node_query_t)(const struct rte_eth_dev *dev,
124 	uint32_t node_id,
125 	uint32_t *parent_node_id,
126 	uint32_t *priority,
127 	uint32_t *weight,
128 	uint32_t *level_id,
129 	struct rte_tm_node_params *params,
130 	struct rte_tm_error *error);
131 
132 /** @internal Traffic manager hierarchy commit */
133 typedef int (*rte_tm_hierarchy_commit_t)(struct rte_eth_dev *dev,
134 	int clear_on_fail,
135 	struct rte_tm_error *error);
136 
137 /** @internal Traffic manager node parent update */
138 typedef int (*rte_tm_node_parent_update_t)(struct rte_eth_dev *dev,
139 	uint32_t node_id,
140 	uint32_t parent_node_id,
141 	uint32_t priority,
142 	uint32_t weight,
143 	struct rte_tm_error *error);
144 
145 /** @internal Traffic manager node shaper update */
146 typedef int (*rte_tm_node_shaper_update_t)(struct rte_eth_dev *dev,
147 	uint32_t node_id,
148 	uint32_t shaper_profile_id,
149 	struct rte_tm_error *error);
150 
151 /** @internal Traffic manager node shaper update */
152 typedef int (*rte_tm_node_shared_shaper_update_t)(struct rte_eth_dev *dev,
153 	uint32_t node_id,
154 	uint32_t shared_shaper_id,
155 	int32_t add,
156 	struct rte_tm_error *error);
157 
158 /** @internal Traffic manager node stats update */
159 typedef int (*rte_tm_node_stats_update_t)(struct rte_eth_dev *dev,
160 	uint32_t node_id,
161 	uint64_t stats_mask,
162 	struct rte_tm_error *error);
163 
164 /** @internal Traffic manager node WFQ weight mode update */
165 typedef int (*rte_tm_node_wfq_weight_mode_update_t)(
166 	struct rte_eth_dev *dev,
167 	uint32_t node_id,
168 	int *wfq_weight_mode,
169 	uint32_t n_sp_priorities,
170 	struct rte_tm_error *error);
171 
172 /** @internal Traffic manager node congestion management mode update */
173 typedef int (*rte_tm_node_cman_update_t)(struct rte_eth_dev *dev,
174 	uint32_t node_id,
175 	enum rte_tm_cman_mode cman,
176 	struct rte_tm_error *error);
177 
178 /** @internal Traffic manager node WRED context update */
179 typedef int (*rte_tm_node_wred_context_update_t)(
180 	struct rte_eth_dev *dev,
181 	uint32_t node_id,
182 	uint32_t wred_profile_id,
183 	struct rte_tm_error *error);
184 
185 /** @internal Traffic manager node WRED context update */
186 typedef int (*rte_tm_node_shared_wred_context_update_t)(
187 	struct rte_eth_dev *dev,
188 	uint32_t node_id,
189 	uint32_t shared_wred_context_id,
190 	int add,
191 	struct rte_tm_error *error);
192 
193 /** @internal Traffic manager read stats counters for specific node */
194 typedef int (*rte_tm_node_stats_read_t)(struct rte_eth_dev *dev,
195 	uint32_t node_id,
196 	struct rte_tm_node_stats *stats,
197 	uint64_t *stats_mask,
198 	int clear,
199 	struct rte_tm_error *error);
200 
201 /** @internal Traffic manager packet marking - VLAN DEI */
202 typedef int (*rte_tm_mark_vlan_dei_t)(struct rte_eth_dev *dev,
203 	int mark_green,
204 	int mark_yellow,
205 	int mark_red,
206 	struct rte_tm_error *error);
207 
208 /** @internal Traffic manager packet marking - IPv4/IPv6 ECN */
209 typedef int (*rte_tm_mark_ip_ecn_t)(struct rte_eth_dev *dev,
210 	int mark_green,
211 	int mark_yellow,
212 	int mark_red,
213 	struct rte_tm_error *error);
214 
215 /** @internal Traffic manager packet marking - IPv4/IPv6 DSCP */
216 typedef int (*rte_tm_mark_ip_dscp_t)(struct rte_eth_dev *dev,
217 	int mark_green,
218 	int mark_yellow,
219 	int mark_red,
220 	struct rte_tm_error *error);
221 
222 struct rte_tm_ops {
223 	/** Traffic manager node type get */
224 	rte_tm_node_type_get_t node_type_get;
225 
226 	/** Traffic manager capabilities_get */
227 	rte_tm_capabilities_get_t capabilities_get;
228 	/** Traffic manager level capabilities_get */
229 	rte_tm_level_capabilities_get_t level_capabilities_get;
230 	/** Traffic manager node capabilities get */
231 	rte_tm_node_capabilities_get_t node_capabilities_get;
232 
233 	/** Traffic manager WRED profile add */
234 	rte_tm_wred_profile_add_t wred_profile_add;
235 	/** Traffic manager WRED profile delete */
236 	rte_tm_wred_profile_delete_t wred_profile_delete;
237 	/** Traffic manager shared WRED context add/update */
238 	rte_tm_shared_wred_context_add_update_t
239 		shared_wred_context_add_update;
240 	/** Traffic manager shared WRED context delete */
241 	rte_tm_shared_wred_context_delete_t
242 		shared_wred_context_delete;
243 
244 	/** Traffic manager shaper profile add */
245 	rte_tm_shaper_profile_add_t shaper_profile_add;
246 	/** Traffic manager shaper profile delete */
247 	rte_tm_shaper_profile_delete_t shaper_profile_delete;
248 	/** Traffic manager shared shaper add/update */
249 	rte_tm_shared_shaper_add_update_t shared_shaper_add_update;
250 	/** Traffic manager shared shaper delete */
251 	rte_tm_shared_shaper_delete_t shared_shaper_delete;
252 
253 	/** Traffic manager node add */
254 	rte_tm_node_add_t node_add;
255 	/** Traffic manager node delete */
256 	rte_tm_node_delete_t node_delete;
257 	/** Traffic manager node suspend */
258 	rte_tm_node_suspend_t node_suspend;
259 	/** Traffic manager node resume */
260 	rte_tm_node_resume_t node_resume;
261 	/** Traffic manager node query */
262 	rte_tm_node_query_t node_query;
263 	/** Traffic manager hierarchy commit */
264 	rte_tm_hierarchy_commit_t hierarchy_commit;
265 
266 	/** Traffic manager node parent update */
267 	rte_tm_node_parent_update_t node_parent_update;
268 	/** Traffic manager node shaper update */
269 	rte_tm_node_shaper_update_t node_shaper_update;
270 	/** Traffic manager node shared shaper update */
271 	rte_tm_node_shared_shaper_update_t node_shared_shaper_update;
272 	/** Traffic manager node stats update */
273 	rte_tm_node_stats_update_t node_stats_update;
274 	/** Traffic manager node WFQ weight mode update */
275 	rte_tm_node_wfq_weight_mode_update_t node_wfq_weight_mode_update;
276 	/** Traffic manager node congestion management mode update */
277 	rte_tm_node_cman_update_t node_cman_update;
278 	/** Traffic manager node WRED context update */
279 	rte_tm_node_wred_context_update_t node_wred_context_update;
280 	/** Traffic manager node shared WRED context update */
281 	rte_tm_node_shared_wred_context_update_t
282 		node_shared_wred_context_update;
283 	/** Traffic manager read statistics counters for current node */
284 	rte_tm_node_stats_read_t node_stats_read;
285 
286 	/** Traffic manager packet marking - VLAN DEI */
287 	rte_tm_mark_vlan_dei_t mark_vlan_dei;
288 	/** Traffic manager packet marking - IPv4/IPv6 ECN */
289 	rte_tm_mark_ip_ecn_t mark_ip_ecn;
290 	/** Traffic manager packet marking - IPv4/IPv6 DSCP */
291 	rte_tm_mark_ip_dscp_t mark_ip_dscp;
292 };
293 
294 /**
295  * Initialize generic error structure.
296  *
297  * This function also sets rte_errno to a given value.
298  *
299  * @param[out] error
300  *   Pointer to error structure (may be NULL).
301  * @param[in] code
302  *   Related error code (rte_errno).
303  * @param[in] type
304  *   Cause field and error type.
305  * @param[in] cause
306  *   Object responsible for the error.
307  * @param[in] message
308  *   Human-readable error message.
309  *
310  * @return
311  *   Error code.
312  */
313 static inline int
314 rte_tm_error_set(struct rte_tm_error *error,
315 		   int code,
316 		   enum rte_tm_error_type type,
317 		   const void *cause,
318 		   const char *message)
319 {
320 	if (error) {
321 		*error = (struct rte_tm_error){
322 			.type = type,
323 			.cause = cause,
324 			.message = message,
325 		};
326 	}
327 	rte_errno = code;
328 	return code;
329 }
330 
331 /**
332  * Get generic traffic manager operations structure from a port
333  *
334  * @param[in] port_id
335  *   The port identifier of the Ethernet device.
336  * @param[out] error
337  *   Error details
338  *
339  * @return
340  *   The traffic manager operations structure associated with port_id on
341  *   success, NULL otherwise.
342  */
343 const struct rte_tm_ops *
344 rte_tm_ops_get(uint16_t port_id, struct rte_tm_error *error);
345 
346 #ifdef __cplusplus
347 }
348 #endif
349 
350 #endif /* __INCLUDE_RTE_TM_DRIVER_H__ */
351