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