xref: /f-stack/dpdk/lib/librte_ethdev/rte_mtr.h (revision 4418919f)
1*4418919fSjohnjiang /* SPDX-License-Identifier: BSD-3-Clause
2d30ea906Sjfb8856606  * Copyright 2017 Intel Corporation
3d30ea906Sjfb8856606  * Copyright 2017 NXP
4d30ea906Sjfb8856606  * Copyright 2017 Cavium
5d30ea906Sjfb8856606  */
6d30ea906Sjfb8856606 
7d30ea906Sjfb8856606 #ifndef __INCLUDE_RTE_MTR_H__
8d30ea906Sjfb8856606 #define __INCLUDE_RTE_MTR_H__
9d30ea906Sjfb8856606 
10d30ea906Sjfb8856606 /**
11d30ea906Sjfb8856606  * @file
12d30ea906Sjfb8856606  * RTE Generic Traffic Metering and Policing API
13d30ea906Sjfb8856606  *
14d30ea906Sjfb8856606  * This interface provides the ability to configure the traffic metering and
15d30ea906Sjfb8856606  * policing (MTR) in a generic way.
16d30ea906Sjfb8856606  *
17d30ea906Sjfb8856606  * The processing done for each input packet hitting a MTR object is:
18d30ea906Sjfb8856606  *    A) Traffic metering: The packet is assigned a color (the meter output
19d30ea906Sjfb8856606  *       color), based on the previous history of the flow reflected in the
20d30ea906Sjfb8856606  *       current state of the MTR object, according to the specific traffic
21d30ea906Sjfb8856606  *       metering algorithm. The traffic metering algorithm can typically work
22d30ea906Sjfb8856606  *       in color aware mode, in which case the input packet already has an
23d30ea906Sjfb8856606  *       initial color (the input color), or in color blind mode, which is
24d30ea906Sjfb8856606  *       equivalent to considering all input packets initially colored as green.
25d30ea906Sjfb8856606  *    B) Policing: There is a separate policer action configured for each meter
26d30ea906Sjfb8856606  *       output color, which can:
27d30ea906Sjfb8856606  *          a) Drop the packet.
28d30ea906Sjfb8856606  *          b) Keep the same packet color: the policer output color matches the
29d30ea906Sjfb8856606  *             meter output color (essentially a no-op action).
30d30ea906Sjfb8856606  *          c) Recolor the packet: the policer output color is different than
31d30ea906Sjfb8856606  *             the meter output color.
32d30ea906Sjfb8856606  *       The policer output color is the output color of the packet, which is
33d30ea906Sjfb8856606  *       set in the packet meta-data (i.e. struct rte_mbuf::sched::color).
34d30ea906Sjfb8856606  *    C) Statistics: The set of counters maintained for each MTR object is
35d30ea906Sjfb8856606  *       configurable and subject to the implementation support. This set
36d30ea906Sjfb8856606  *       includes the number of packets and bytes dropped or passed for each
37d30ea906Sjfb8856606  *       output color.
38d30ea906Sjfb8856606  *
39d30ea906Sjfb8856606  * Once successfully created, an MTR object is linked to one or several flows
40d30ea906Sjfb8856606  * through the meter action of the flow API.
41d30ea906Sjfb8856606  *    A) Whether an MTR object is private to a flow or potentially shared by
42d30ea906Sjfb8856606  *       several flows has to be specified at creation time.
43d30ea906Sjfb8856606  *    B) Several meter actions can be potentially registered for the same flow.
44d30ea906Sjfb8856606  *
45d30ea906Sjfb8856606  * @warning
46d30ea906Sjfb8856606  * @b EXPERIMENTAL: this API may change without prior notice
47d30ea906Sjfb8856606  */
48d30ea906Sjfb8856606 #include <stdint.h>
49d30ea906Sjfb8856606 #include <rte_compat.h>
50d30ea906Sjfb8856606 #include <rte_common.h>
51*4418919fSjohnjiang #include <rte_meter.h>
52d30ea906Sjfb8856606 
53d30ea906Sjfb8856606 #ifdef __cplusplus
54d30ea906Sjfb8856606 extern "C" {
55d30ea906Sjfb8856606 #endif
56d30ea906Sjfb8856606 
57d30ea906Sjfb8856606 /**
58d30ea906Sjfb8856606  * Statistics counter type
59d30ea906Sjfb8856606  */
60d30ea906Sjfb8856606 enum rte_mtr_stats_type {
61d30ea906Sjfb8856606 	/** Number of packets passed as green by the policer. */
62d30ea906Sjfb8856606 	RTE_MTR_STATS_N_PKTS_GREEN = 1 << 0,
63d30ea906Sjfb8856606 
64d30ea906Sjfb8856606 	/** Number of packets passed as yellow by the policer. */
65d30ea906Sjfb8856606 	RTE_MTR_STATS_N_PKTS_YELLOW = 1 << 1,
66d30ea906Sjfb8856606 
67d30ea906Sjfb8856606 	/** Number of packets passed as red by the policer. */
68d30ea906Sjfb8856606 	RTE_MTR_STATS_N_PKTS_RED = 1 << 2,
69d30ea906Sjfb8856606 
70d30ea906Sjfb8856606 	/** Number of packets dropped by the policer. */
71d30ea906Sjfb8856606 	RTE_MTR_STATS_N_PKTS_DROPPED = 1 << 3,
72d30ea906Sjfb8856606 
73d30ea906Sjfb8856606 	/** Number of bytes passed as green by the policer. */
74d30ea906Sjfb8856606 	RTE_MTR_STATS_N_BYTES_GREEN = 1 << 4,
75d30ea906Sjfb8856606 
76d30ea906Sjfb8856606 	/** Number of bytes passed as yellow by the policer. */
77d30ea906Sjfb8856606 	RTE_MTR_STATS_N_BYTES_YELLOW = 1 << 5,
78d30ea906Sjfb8856606 
79d30ea906Sjfb8856606 	/** Number of bytes passed as red by the policer. */
80d30ea906Sjfb8856606 	RTE_MTR_STATS_N_BYTES_RED = 1 << 6,
81d30ea906Sjfb8856606 
82d30ea906Sjfb8856606 	/** Number of bytes dropped by the policer. */
83d30ea906Sjfb8856606 	RTE_MTR_STATS_N_BYTES_DROPPED = 1 << 7,
84d30ea906Sjfb8856606 };
85d30ea906Sjfb8856606 
86d30ea906Sjfb8856606 /**
87d30ea906Sjfb8856606  * Statistics counters
88d30ea906Sjfb8856606  */
89d30ea906Sjfb8856606 struct rte_mtr_stats {
90d30ea906Sjfb8856606 	/** Number of packets passed by the policer (per color). */
91*4418919fSjohnjiang 	uint64_t n_pkts[RTE_COLORS];
92d30ea906Sjfb8856606 
93d30ea906Sjfb8856606 	/** Number of bytes passed by the policer (per color). */
94*4418919fSjohnjiang 	uint64_t n_bytes[RTE_COLORS];
95d30ea906Sjfb8856606 
96d30ea906Sjfb8856606 	/** Number of packets dropped by the policer. */
97d30ea906Sjfb8856606 	uint64_t n_pkts_dropped;
98d30ea906Sjfb8856606 
99d30ea906Sjfb8856606 	/** Number of bytes passed by the policer. */
100d30ea906Sjfb8856606 	uint64_t n_bytes_dropped;
101d30ea906Sjfb8856606 };
102d30ea906Sjfb8856606 
103d30ea906Sjfb8856606 /**
104d30ea906Sjfb8856606  * Traffic metering algorithms
105d30ea906Sjfb8856606  */
106d30ea906Sjfb8856606 enum rte_mtr_algorithm {
107d30ea906Sjfb8856606 	/** No traffic metering performed, the output color is the same as the
108d30ea906Sjfb8856606 	 * input color for every input packet. The meter of the MTR object is
109d30ea906Sjfb8856606 	 * working in pass-through mode, having same effect as meter disable.
110d30ea906Sjfb8856606 	 * @see rte_mtr_meter_disable()
111d30ea906Sjfb8856606 	 */
112d30ea906Sjfb8856606 	RTE_MTR_NONE = 0,
113d30ea906Sjfb8856606 
114d30ea906Sjfb8856606 	/** Single Rate Three Color Marker (srTCM) - IETF RFC 2697. */
115d30ea906Sjfb8856606 	RTE_MTR_SRTCM_RFC2697,
116d30ea906Sjfb8856606 
117d30ea906Sjfb8856606 	/** Two Rate Three Color Marker (trTCM) - IETF RFC 2698. */
118d30ea906Sjfb8856606 	RTE_MTR_TRTCM_RFC2698,
119d30ea906Sjfb8856606 
120d30ea906Sjfb8856606 	/** Two Rate Three Color Marker (trTCM) - IETF RFC 4115. */
121d30ea906Sjfb8856606 	RTE_MTR_TRTCM_RFC4115,
122d30ea906Sjfb8856606 };
123d30ea906Sjfb8856606 
124d30ea906Sjfb8856606 /**
125d30ea906Sjfb8856606  * Meter profile
126d30ea906Sjfb8856606  */
127d30ea906Sjfb8856606 struct rte_mtr_meter_profile {
128d30ea906Sjfb8856606 	/** Traffic metering algorithm. */
129d30ea906Sjfb8856606 	enum rte_mtr_algorithm alg;
130d30ea906Sjfb8856606 
131d30ea906Sjfb8856606 	RTE_STD_C11
132d30ea906Sjfb8856606 	union {
133d30ea906Sjfb8856606 		/** Items only valid when *alg* is set to srTCM - RFC 2697. */
134d30ea906Sjfb8856606 		struct {
135d30ea906Sjfb8856606 			/** Committed Information Rate (CIR) (bytes/second). */
136d30ea906Sjfb8856606 			uint64_t cir;
137d30ea906Sjfb8856606 
138d30ea906Sjfb8856606 			/** Committed Burst Size (CBS) (bytes). */
139d30ea906Sjfb8856606 			uint64_t cbs;
140d30ea906Sjfb8856606 
141d30ea906Sjfb8856606 			/** Excess Burst Size (EBS) (bytes). */
142d30ea906Sjfb8856606 			uint64_t ebs;
143d30ea906Sjfb8856606 		} srtcm_rfc2697;
144d30ea906Sjfb8856606 
145d30ea906Sjfb8856606 		/** Items only valid when *alg* is set to trTCM - RFC 2698. */
146d30ea906Sjfb8856606 		struct {
147d30ea906Sjfb8856606 			/** Committed Information Rate (CIR) (bytes/second). */
148d30ea906Sjfb8856606 			uint64_t cir;
149d30ea906Sjfb8856606 
150d30ea906Sjfb8856606 			/** Peak Information Rate (PIR) (bytes/second). */
151d30ea906Sjfb8856606 			uint64_t pir;
152d30ea906Sjfb8856606 
153d30ea906Sjfb8856606 			/** Committed Burst Size (CBS) (byes). */
154d30ea906Sjfb8856606 			uint64_t cbs;
155d30ea906Sjfb8856606 
156d30ea906Sjfb8856606 			/** Peak Burst Size (PBS) (bytes). */
157d30ea906Sjfb8856606 			uint64_t pbs;
158d30ea906Sjfb8856606 		} trtcm_rfc2698;
159d30ea906Sjfb8856606 
160d30ea906Sjfb8856606 		/** Items only valid when *alg* is set to trTCM - RFC 4115. */
161d30ea906Sjfb8856606 		struct {
162d30ea906Sjfb8856606 			/** Committed Information Rate (CIR) (bytes/second). */
163d30ea906Sjfb8856606 			uint64_t cir;
164d30ea906Sjfb8856606 
165d30ea906Sjfb8856606 			/** Excess Information Rate (EIR) (bytes/second). */
166d30ea906Sjfb8856606 			uint64_t eir;
167d30ea906Sjfb8856606 
168d30ea906Sjfb8856606 			/** Committed Burst Size (CBS) (byes). */
169d30ea906Sjfb8856606 			uint64_t cbs;
170d30ea906Sjfb8856606 
171d30ea906Sjfb8856606 			/** Excess Burst Size (EBS) (bytes). */
172d30ea906Sjfb8856606 			uint64_t ebs;
173d30ea906Sjfb8856606 		} trtcm_rfc4115;
174d30ea906Sjfb8856606 	};
175d30ea906Sjfb8856606 };
176d30ea906Sjfb8856606 
177d30ea906Sjfb8856606 /**
178d30ea906Sjfb8856606  * Policer actions
179d30ea906Sjfb8856606  */
180d30ea906Sjfb8856606 enum rte_mtr_policer_action {
181d30ea906Sjfb8856606 	/** Recolor the packet as green. */
182d30ea906Sjfb8856606 	MTR_POLICER_ACTION_COLOR_GREEN = 0,
183d30ea906Sjfb8856606 
184d30ea906Sjfb8856606 	/** Recolor the packet as yellow. */
185d30ea906Sjfb8856606 	MTR_POLICER_ACTION_COLOR_YELLOW,
186d30ea906Sjfb8856606 
187d30ea906Sjfb8856606 	/** Recolor the packet as red. */
188d30ea906Sjfb8856606 	MTR_POLICER_ACTION_COLOR_RED,
189d30ea906Sjfb8856606 
190d30ea906Sjfb8856606 	/** Drop the packet. */
191d30ea906Sjfb8856606 	MTR_POLICER_ACTION_DROP,
192d30ea906Sjfb8856606 };
193d30ea906Sjfb8856606 
194d30ea906Sjfb8856606 /**
195d30ea906Sjfb8856606  * Parameters for each traffic metering & policing object
196d30ea906Sjfb8856606  *
197d30ea906Sjfb8856606  * @see enum rte_mtr_stats_type
198d30ea906Sjfb8856606  */
199d30ea906Sjfb8856606 struct rte_mtr_params {
200d30ea906Sjfb8856606 	/** Meter profile ID. */
201d30ea906Sjfb8856606 	uint32_t meter_profile_id;
202d30ea906Sjfb8856606 
203d30ea906Sjfb8856606 	/** Meter input color in case of MTR object chaining. When non-zero: if
204d30ea906Sjfb8856606 	 * a previous MTR object is enabled in the same flow, then the color
205d30ea906Sjfb8856606 	 * determined by the latest MTR object in the same flow is used as the
206d30ea906Sjfb8856606 	 * input color by the current MTR object, otherwise the current MTR
207d30ea906Sjfb8856606 	 * object uses the *dscp_table* to determine the input color. When zero:
208d30ea906Sjfb8856606 	 * the color determined by any previous MTR object in same flow is
209d30ea906Sjfb8856606 	 * ignored by the current MTR object, which uses the *dscp_table* to
210d30ea906Sjfb8856606 	 * determine the input color.
211d30ea906Sjfb8856606 	 */
212d30ea906Sjfb8856606 	int use_prev_mtr_color;
213d30ea906Sjfb8856606 
214d30ea906Sjfb8856606 	/** Meter input color. When non-NULL: it points to a pre-allocated and
215d30ea906Sjfb8856606 	 * pre-populated table with exactly 64 elements providing the input
216d30ea906Sjfb8856606 	 * color for each value of the IPv4/IPv6 Differentiated Services Code
217d30ea906Sjfb8856606 	 * Point (DSCP) input packet field. When NULL: it is equivalent to
218d30ea906Sjfb8856606 	 * setting this parameter to an all-green populated table (i.e. table
219d30ea906Sjfb8856606 	 * with all the 64 elements set to green color). The color blind mode
220d30ea906Sjfb8856606 	 * is configured by setting *use_prev_mtr_color* to 0 and *dscp_table*
221d30ea906Sjfb8856606 	 * to either NULL or to an all-green populated table. When
222d30ea906Sjfb8856606 	 * *use_prev_mtr_color* is non-zero value or when *dscp_table* contains
223d30ea906Sjfb8856606 	 * at least one yellow or red color element, then the color aware mode
224d30ea906Sjfb8856606 	 * is configured.
225d30ea906Sjfb8856606 	 */
226*4418919fSjohnjiang 	enum rte_color *dscp_table;
227d30ea906Sjfb8856606 
228d30ea906Sjfb8856606 	/** Non-zero to enable the meter, zero to disable the meter at the time
229d30ea906Sjfb8856606 	 * of MTR object creation. Ignored when the meter profile indicated by
230d30ea906Sjfb8856606 	 * *meter_profile_id* is set to NONE.
231d30ea906Sjfb8856606 	 * @see rte_mtr_meter_disable()
232d30ea906Sjfb8856606 	 */
233d30ea906Sjfb8856606 	int meter_enable;
234d30ea906Sjfb8856606 
235d30ea906Sjfb8856606 	/** Policer actions (per meter output color). */
236*4418919fSjohnjiang 	enum rte_mtr_policer_action action[RTE_COLORS];
237d30ea906Sjfb8856606 
238d30ea906Sjfb8856606 	/** Set of stats counters to be enabled.
239d30ea906Sjfb8856606 	 * @see enum rte_mtr_stats_type
240d30ea906Sjfb8856606 	 */
241d30ea906Sjfb8856606 	uint64_t stats_mask;
242d30ea906Sjfb8856606 };
243d30ea906Sjfb8856606 
244d30ea906Sjfb8856606 /**
245d30ea906Sjfb8856606  * MTR capabilities
246d30ea906Sjfb8856606  */
247d30ea906Sjfb8856606 struct rte_mtr_capabilities {
248d30ea906Sjfb8856606 	/** Maximum number of MTR objects. */
249d30ea906Sjfb8856606 	uint32_t n_max;
250d30ea906Sjfb8856606 
251d30ea906Sjfb8856606 	/** Maximum number of MTR objects that can be shared by multiple flows.
252d30ea906Sjfb8856606 	 * The value of zero indicates that shared MTR objects are not
253d30ea906Sjfb8856606 	 * supported. The maximum value is *n_max*.
254d30ea906Sjfb8856606 	 */
255d30ea906Sjfb8856606 	uint32_t n_shared_max;
256d30ea906Sjfb8856606 
257d30ea906Sjfb8856606 	/** When non-zero, this flag indicates that all the MTR objects that
258d30ea906Sjfb8856606 	 * cannot be shared by multiple flows have identical capability set.
259d30ea906Sjfb8856606 	 */
260d30ea906Sjfb8856606 	int identical;
261d30ea906Sjfb8856606 
262d30ea906Sjfb8856606 	/** When non-zero, this flag indicates that all the MTR objects that
263d30ea906Sjfb8856606 	 * can be shared by multiple flows have identical capability set.
264d30ea906Sjfb8856606 	 */
265d30ea906Sjfb8856606 	int shared_identical;
266d30ea906Sjfb8856606 
267d30ea906Sjfb8856606 	/** Maximum number of flows that can share the same MTR object. The
268d30ea906Sjfb8856606 	 * value of zero is invalid. The value of 1 means that shared MTR
269d30ea906Sjfb8856606 	 * objects not supported.
270d30ea906Sjfb8856606 	 */
271d30ea906Sjfb8856606 	uint32_t shared_n_flows_per_mtr_max;
272d30ea906Sjfb8856606 
273d30ea906Sjfb8856606 	/** Maximum number of MTR objects that can be part of the same flow. The
274d30ea906Sjfb8856606 	 * value of zero is invalid. The value of 1 indicates that MTR object
275d30ea906Sjfb8856606 	 * chaining is not supported. The maximum value is *n_max*.
276d30ea906Sjfb8856606 	 */
277d30ea906Sjfb8856606 	uint32_t chaining_n_mtrs_per_flow_max;
278d30ea906Sjfb8856606 
279d30ea906Sjfb8856606 	/**
280d30ea906Sjfb8856606 	 * When non-zero, it indicates that the packet color identified by one
281d30ea906Sjfb8856606 	 * MTR object can be used as the packet input color by any subsequent
282d30ea906Sjfb8856606 	 * MTR object from the same flow. When zero, it indicates that the color
283d30ea906Sjfb8856606 	 * determined by one MTR object is always ignored by any subsequent MTR
284d30ea906Sjfb8856606 	 * object from the same flow. Only valid when MTR chaining is supported,
285d30ea906Sjfb8856606 	 * i.e. *chaining_n_mtrs_per_flow_max* is greater than 1. When non-zero,
286d30ea906Sjfb8856606 	 * it also means that the color aware mode is supported by at least one
287d30ea906Sjfb8856606 	 * metering algorithm.
288d30ea906Sjfb8856606 	 */
289d30ea906Sjfb8856606 	int chaining_use_prev_mtr_color_supported;
290d30ea906Sjfb8856606 
291d30ea906Sjfb8856606 	/**
292d30ea906Sjfb8856606 	 * When non-zero, it indicates that the packet color identified by one
293d30ea906Sjfb8856606 	 * MTR object is always used as the packet input color by any subsequent
294d30ea906Sjfb8856606 	 * MTR object that is part of the same flow. When zero, it indicates
295d30ea906Sjfb8856606 	 * that whether the color determined by one MTR object is either ignored
296d30ea906Sjfb8856606 	 * or used as the packet input color by any subsequent MTR object from
297d30ea906Sjfb8856606 	 * the same flow is individually configurable for each MTR object. Only
298d30ea906Sjfb8856606 	 * valid when *chaining_use_prev_mtr_color_supported* is non-zero.
299d30ea906Sjfb8856606 	 */
300d30ea906Sjfb8856606 	int chaining_use_prev_mtr_color_enforced;
301d30ea906Sjfb8856606 
302d30ea906Sjfb8856606 	/** Maximum number of MTR objects that can have their meter configured
303d30ea906Sjfb8856606 	 * to run the srTCM RFC 2697 algorithm. The value of 0 indicates this
304d30ea906Sjfb8856606 	 * metering algorithm is not supported. The maximum value is *n_max*.
305d30ea906Sjfb8856606 	 */
306d30ea906Sjfb8856606 	uint32_t meter_srtcm_rfc2697_n_max;
307d30ea906Sjfb8856606 
308d30ea906Sjfb8856606 	/** Maximum number of MTR objects that can have their meter configured
309d30ea906Sjfb8856606 	 * to run the trTCM RFC 2698 algorithm. The value of 0 indicates this
310d30ea906Sjfb8856606 	 * metering algorithm is not supported. The maximum value is *n_max*.
311d30ea906Sjfb8856606 	 */
312d30ea906Sjfb8856606 	uint32_t meter_trtcm_rfc2698_n_max;
313d30ea906Sjfb8856606 
314d30ea906Sjfb8856606 	/** Maximum number of MTR objects that can have their meter configured
315d30ea906Sjfb8856606 	 * to run the trTCM RFC 4115 algorithm. The value of 0 indicates this
316d30ea906Sjfb8856606 	 * metering algorithm is not supported. The maximum value is *n_max*.
317d30ea906Sjfb8856606 	 */
318d30ea906Sjfb8856606 	uint32_t meter_trtcm_rfc4115_n_max;
319d30ea906Sjfb8856606 
320d30ea906Sjfb8856606 	/** Maximum traffic rate that can be metered by a single MTR object. For
321d30ea906Sjfb8856606 	 * srTCM RFC 2697, this is the maximum CIR rate. For trTCM RFC 2698,
322d30ea906Sjfb8856606 	 * this is the maximum PIR rate. For trTCM RFC 4115, this is the maximum
323d30ea906Sjfb8856606 	 * value for the sum of PIR and EIR rates.
324d30ea906Sjfb8856606 	 */
325d30ea906Sjfb8856606 	uint64_t meter_rate_max;
326d30ea906Sjfb8856606 
327d30ea906Sjfb8856606 	/**
328d30ea906Sjfb8856606 	 * When non-zero, it indicates that color aware mode is supported for
329d30ea906Sjfb8856606 	 * the srTCM RFC 2697 metering algorithm.
330d30ea906Sjfb8856606 	 */
331d30ea906Sjfb8856606 	int color_aware_srtcm_rfc2697_supported;
332d30ea906Sjfb8856606 
333d30ea906Sjfb8856606 	/**
334d30ea906Sjfb8856606 	 * When non-zero, it indicates that color aware mode is supported for
335d30ea906Sjfb8856606 	 * the trTCM RFC 2698 metering algorithm.
336d30ea906Sjfb8856606 	 */
337d30ea906Sjfb8856606 	int color_aware_trtcm_rfc2698_supported;
338d30ea906Sjfb8856606 
339d30ea906Sjfb8856606 	/**
340d30ea906Sjfb8856606 	 * When non-zero, it indicates that color aware mode is supported for
341d30ea906Sjfb8856606 	 * the trTCM RFC 4115 metering algorithm.
342d30ea906Sjfb8856606 	 */
343d30ea906Sjfb8856606 	int color_aware_trtcm_rfc4115_supported;
344d30ea906Sjfb8856606 
345d30ea906Sjfb8856606 	/** When non-zero, it indicates that the policer packet recolor actions
346d30ea906Sjfb8856606 	 * are supported.
347d30ea906Sjfb8856606 	 * @see enum rte_mtr_policer_action
348d30ea906Sjfb8856606 	 */
349d30ea906Sjfb8856606 	int policer_action_recolor_supported;
350d30ea906Sjfb8856606 
351d30ea906Sjfb8856606 	/** When non-zero, it indicates that the policer packet drop action is
352d30ea906Sjfb8856606 	 * supported.
353d30ea906Sjfb8856606 	 * @see enum rte_mtr_policer_action
354d30ea906Sjfb8856606 	 */
355d30ea906Sjfb8856606 	int policer_action_drop_supported;
356d30ea906Sjfb8856606 
357d30ea906Sjfb8856606 	/** Set of supported statistics counter types.
358d30ea906Sjfb8856606 	 * @see enum rte_mtr_stats_type
359d30ea906Sjfb8856606 	 */
360d30ea906Sjfb8856606 	uint64_t stats_mask;
361d30ea906Sjfb8856606 };
362d30ea906Sjfb8856606 
363d30ea906Sjfb8856606 /**
364d30ea906Sjfb8856606  * Verbose error types.
365d30ea906Sjfb8856606  *
366d30ea906Sjfb8856606  * Most of them provide the type of the object referenced by struct
367d30ea906Sjfb8856606  * rte_mtr_error::cause.
368d30ea906Sjfb8856606  */
369d30ea906Sjfb8856606 enum rte_mtr_error_type {
370d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_NONE, /**< No error. */
371d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
372d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_METER_PROFILE_ID,
373d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_METER_PROFILE,
374d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_MTR_ID,
375d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_MTR_PARAMS,
376d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN,
377d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW,
378d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED,
379d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_STATS_MASK,
380d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_STATS,
381d30ea906Sjfb8856606 	RTE_MTR_ERROR_TYPE_SHARED,
382d30ea906Sjfb8856606 };
383d30ea906Sjfb8856606 
384d30ea906Sjfb8856606 /**
385d30ea906Sjfb8856606  * Verbose error structure definition.
386d30ea906Sjfb8856606  *
387d30ea906Sjfb8856606  * This object is normally allocated by applications and set by PMDs, the
388d30ea906Sjfb8856606  * message points to a constant string which does not need to be freed by
389d30ea906Sjfb8856606  * the application, however its pointer can be considered valid only as long
390d30ea906Sjfb8856606  * as its associated DPDK port remains configured. Closing the underlying
391d30ea906Sjfb8856606  * device or unloading the PMD invalidates it.
392d30ea906Sjfb8856606  *
393d30ea906Sjfb8856606  * Both cause and message may be NULL regardless of the error type.
394d30ea906Sjfb8856606  */
395d30ea906Sjfb8856606 struct rte_mtr_error {
396d30ea906Sjfb8856606 	enum rte_mtr_error_type type; /**< Cause field and error type. */
397d30ea906Sjfb8856606 	const void *cause; /**< Object responsible for the error. */
398d30ea906Sjfb8856606 	const char *message; /**< Human-readable error message. */
399d30ea906Sjfb8856606 };
400d30ea906Sjfb8856606 
401d30ea906Sjfb8856606 /**
402d30ea906Sjfb8856606  * MTR capabilities get
403d30ea906Sjfb8856606  *
404d30ea906Sjfb8856606  * @param[in] port_id
405d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
406d30ea906Sjfb8856606  * @param[out] cap
407d30ea906Sjfb8856606  *   MTR capabilities. Needs to be pre-allocated and valid.
408d30ea906Sjfb8856606  * @param[out] error
409d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
410d30ea906Sjfb8856606  * @return
411d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
412d30ea906Sjfb8856606  */
413*4418919fSjohnjiang __rte_experimental
414*4418919fSjohnjiang int
415d30ea906Sjfb8856606 rte_mtr_capabilities_get(uint16_t port_id,
416d30ea906Sjfb8856606 	struct rte_mtr_capabilities *cap,
417d30ea906Sjfb8856606 	struct rte_mtr_error *error);
418d30ea906Sjfb8856606 
419d30ea906Sjfb8856606 /**
420d30ea906Sjfb8856606  * Meter profile add
421d30ea906Sjfb8856606  *
422d30ea906Sjfb8856606  * Create a new meter profile with ID set to *meter_profile_id*. The new profile
423d30ea906Sjfb8856606  * is used to create one or several MTR objects.
424d30ea906Sjfb8856606  *
425d30ea906Sjfb8856606  * @param[in] port_id
426d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
427d30ea906Sjfb8856606  * @param[in] meter_profile_id
428d30ea906Sjfb8856606  *   ID for the new meter profile. Needs to be unused by any of the existing
429d30ea906Sjfb8856606  *   meter profiles added for the current port.
430d30ea906Sjfb8856606  * @param[in] profile
431d30ea906Sjfb8856606  *   Meter profile parameters. Needs to be pre-allocated and valid.
432d30ea906Sjfb8856606  * @param[out] error
433d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
434d30ea906Sjfb8856606  * @return
435d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
436d30ea906Sjfb8856606  */
437*4418919fSjohnjiang __rte_experimental
438*4418919fSjohnjiang int
439d30ea906Sjfb8856606 rte_mtr_meter_profile_add(uint16_t port_id,
440d30ea906Sjfb8856606 	uint32_t meter_profile_id,
441d30ea906Sjfb8856606 	struct rte_mtr_meter_profile *profile,
442d30ea906Sjfb8856606 	struct rte_mtr_error *error);
443d30ea906Sjfb8856606 
444d30ea906Sjfb8856606 /**
445d30ea906Sjfb8856606  * Meter profile delete
446d30ea906Sjfb8856606  *
447d30ea906Sjfb8856606  * Delete an existing meter profile. This operation fails when there is
448d30ea906Sjfb8856606  * currently at least one user (i.e. MTR object) of this profile.
449d30ea906Sjfb8856606  *
450d30ea906Sjfb8856606  * @param[in] port_id
451d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
452d30ea906Sjfb8856606  * @param[in] meter_profile_id
453d30ea906Sjfb8856606  *   Meter profile ID. Needs to be the valid.
454d30ea906Sjfb8856606  * @param[out] error
455d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
456d30ea906Sjfb8856606  * @return
457d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
458d30ea906Sjfb8856606  */
459*4418919fSjohnjiang __rte_experimental
460*4418919fSjohnjiang int
461d30ea906Sjfb8856606 rte_mtr_meter_profile_delete(uint16_t port_id,
462d30ea906Sjfb8856606 	uint32_t meter_profile_id,
463d30ea906Sjfb8856606 	struct rte_mtr_error *error);
464d30ea906Sjfb8856606 
465d30ea906Sjfb8856606 /**
466d30ea906Sjfb8856606  * MTR object create
467d30ea906Sjfb8856606  *
468d30ea906Sjfb8856606  * Create a new MTR object for the current port. This object is run as part of
469d30ea906Sjfb8856606  * associated flow action for traffic metering and policing.
470d30ea906Sjfb8856606  *
471d30ea906Sjfb8856606  * @param[in] port_id
472d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
473d30ea906Sjfb8856606  * @param[in] mtr_id
474d30ea906Sjfb8856606  *   MTR object ID. Needs to be unused by any of the existing MTR objects.
475d30ea906Sjfb8856606  *   created for the current port.
476d30ea906Sjfb8856606  * @param[in] params
477d30ea906Sjfb8856606  *   MTR object params. Needs to be pre-allocated and valid.
478d30ea906Sjfb8856606  * @param[in] shared
479d30ea906Sjfb8856606  *   Non-zero when this MTR object can be shared by multiple flows, zero when
480d30ea906Sjfb8856606  *   this MTR object can be used by a single flow.
481d30ea906Sjfb8856606  * @param[out] error
482d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
483d30ea906Sjfb8856606  * @return
484d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
485d30ea906Sjfb8856606  *
486d30ea906Sjfb8856606  * @see enum rte_flow_action_type::RTE_FLOW_ACTION_TYPE_METER
487d30ea906Sjfb8856606  */
488*4418919fSjohnjiang __rte_experimental
489*4418919fSjohnjiang int
490d30ea906Sjfb8856606 rte_mtr_create(uint16_t port_id,
491d30ea906Sjfb8856606 	uint32_t mtr_id,
492d30ea906Sjfb8856606 	struct rte_mtr_params *params,
493d30ea906Sjfb8856606 	int shared,
494d30ea906Sjfb8856606 	struct rte_mtr_error *error);
495d30ea906Sjfb8856606 
496d30ea906Sjfb8856606 /**
497d30ea906Sjfb8856606  * MTR object destroy
498d30ea906Sjfb8856606  *
499d30ea906Sjfb8856606  * Delete an existing MTR object. This operation fails when there is currently
500d30ea906Sjfb8856606  * at least one user (i.e. flow) of this MTR object.
501d30ea906Sjfb8856606  *
502d30ea906Sjfb8856606  * @param[in] port_id
503d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
504d30ea906Sjfb8856606  * @param[in] mtr_id
505d30ea906Sjfb8856606  *   MTR object ID. Needs to be valid.
506d30ea906Sjfb8856606  *   created for the current port.
507d30ea906Sjfb8856606  * @param[out] error
508d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
509d30ea906Sjfb8856606  * @return
510d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
511d30ea906Sjfb8856606  */
512*4418919fSjohnjiang __rte_experimental
513*4418919fSjohnjiang int
514d30ea906Sjfb8856606 rte_mtr_destroy(uint16_t port_id,
515d30ea906Sjfb8856606 	uint32_t mtr_id,
516d30ea906Sjfb8856606 	struct rte_mtr_error *error);
517d30ea906Sjfb8856606 
518d30ea906Sjfb8856606 /**
519d30ea906Sjfb8856606  * MTR object meter disable
520d30ea906Sjfb8856606  *
521d30ea906Sjfb8856606  * Disable the meter of an existing MTR object. In disabled state, the meter of
522d30ea906Sjfb8856606  * the current MTR object works in pass-through mode, meaning that for each
523d30ea906Sjfb8856606  * input packet the meter output color is always the same as the input color. In
524d30ea906Sjfb8856606  * particular, when the meter of the current MTR object is configured in color
525d30ea906Sjfb8856606  * blind mode, the input color is always green, so the meter output color is
526d30ea906Sjfb8856606  * also always green. Note that the policer and the statistics of the current
527d30ea906Sjfb8856606  * MTR object are working as usual while the meter is disabled. No action is
528d30ea906Sjfb8856606  * taken and this function returns successfully when the meter of the current
529d30ea906Sjfb8856606  * MTR object is already disabled.
530d30ea906Sjfb8856606  *
531d30ea906Sjfb8856606  * @param[in] port_id
532d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
533d30ea906Sjfb8856606  * @param[in] mtr_id
534d30ea906Sjfb8856606  *   MTR object ID.
535d30ea906Sjfb8856606  * @param[out] error
536d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
537d30ea906Sjfb8856606  * @return
538d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
539d30ea906Sjfb8856606  */
540*4418919fSjohnjiang __rte_experimental
541*4418919fSjohnjiang int
542d30ea906Sjfb8856606 rte_mtr_meter_disable(uint16_t port_id,
543d30ea906Sjfb8856606 	uint32_t mtr_id,
544d30ea906Sjfb8856606 	struct rte_mtr_error *error);
545d30ea906Sjfb8856606 
546d30ea906Sjfb8856606 /**
547d30ea906Sjfb8856606  * MTR object meter enable
548d30ea906Sjfb8856606  *
549d30ea906Sjfb8856606  * Enable the meter of an existing MTR object. If the MTR object has its meter
550d30ea906Sjfb8856606  * already enabled, then no action is taken and this function returns
551d30ea906Sjfb8856606  * successfully.
552d30ea906Sjfb8856606  *
553d30ea906Sjfb8856606  * @param[in] port_id
554d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
555d30ea906Sjfb8856606  * @param[in] mtr_id
556d30ea906Sjfb8856606  *   MTR object ID.
557d30ea906Sjfb8856606  * @param[out] error
558d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
559d30ea906Sjfb8856606  * @return
560d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
561d30ea906Sjfb8856606  */
562*4418919fSjohnjiang __rte_experimental
563*4418919fSjohnjiang int
564d30ea906Sjfb8856606 rte_mtr_meter_enable(uint16_t port_id,
565d30ea906Sjfb8856606 	uint32_t mtr_id,
566d30ea906Sjfb8856606 	struct rte_mtr_error *error);
567d30ea906Sjfb8856606 
568d30ea906Sjfb8856606 /**
569d30ea906Sjfb8856606  * MTR object meter profile update
570d30ea906Sjfb8856606  *
571d30ea906Sjfb8856606  * @param[in] port_id
572d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
573d30ea906Sjfb8856606  * @param[in] mtr_id
574d30ea906Sjfb8856606  *   MTR object ID. Needs to be valid.
575d30ea906Sjfb8856606  * @param[in] meter_profile_id
576d30ea906Sjfb8856606  *   Meter profile ID for the current MTR object. Needs to be valid.
577d30ea906Sjfb8856606  * @param[out] error
578d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
579d30ea906Sjfb8856606  * @return
580d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
581d30ea906Sjfb8856606  */
582*4418919fSjohnjiang __rte_experimental
583*4418919fSjohnjiang int
584d30ea906Sjfb8856606 rte_mtr_meter_profile_update(uint16_t port_id,
585d30ea906Sjfb8856606 	uint32_t mtr_id,
586d30ea906Sjfb8856606 	uint32_t meter_profile_id,
587d30ea906Sjfb8856606 	struct rte_mtr_error *error);
588d30ea906Sjfb8856606 
589d30ea906Sjfb8856606 /**
590d30ea906Sjfb8856606  * MTR object DSCP table update
591d30ea906Sjfb8856606  *
592d30ea906Sjfb8856606  * @param[in] port_id
593d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
594d30ea906Sjfb8856606  * @param[in] mtr_id
595d30ea906Sjfb8856606  *   MTR object ID. Needs to be valid.
596d30ea906Sjfb8856606  * @param[in] dscp_table
597d30ea906Sjfb8856606  *   When non-NULL: it points to a pre-allocated and pre-populated table with
598d30ea906Sjfb8856606  *   exactly 64 elements providing the input color for each value of the
599d30ea906Sjfb8856606  *   IPv4/IPv6 Differentiated Services Code Point (DSCP) input packet field.
600d30ea906Sjfb8856606  *   When NULL: it is equivalent to setting this parameter to an “all-green”
601d30ea906Sjfb8856606  *   populated table (i.e. table with all the 64 elements set to green color).
602d30ea906Sjfb8856606  * @param[out] error
603d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
604d30ea906Sjfb8856606  * @return
605d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
606d30ea906Sjfb8856606  */
607*4418919fSjohnjiang __rte_experimental
608*4418919fSjohnjiang int
609d30ea906Sjfb8856606 rte_mtr_meter_dscp_table_update(uint16_t port_id,
610d30ea906Sjfb8856606 	uint32_t mtr_id,
611*4418919fSjohnjiang 	enum rte_color *dscp_table,
612d30ea906Sjfb8856606 	struct rte_mtr_error *error);
613d30ea906Sjfb8856606 
614d30ea906Sjfb8856606 /**
615d30ea906Sjfb8856606  * MTR object policer actions update
616d30ea906Sjfb8856606  *
617d30ea906Sjfb8856606  * @param[in] port_id
618d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
619d30ea906Sjfb8856606  * @param[in] mtr_id
620d30ea906Sjfb8856606  *   MTR object ID. Needs to be valid.
621d30ea906Sjfb8856606  * @param[in] action_mask
622d30ea906Sjfb8856606  *   Bit mask indicating which policer actions need to be updated. One or more
623d30ea906Sjfb8856606  *   policer actions can be updated in a single function invocation. To update
624d30ea906Sjfb8856606  *   the policer action associated with color C, bit (1 << C) needs to be set in
625d30ea906Sjfb8856606  *   *action_mask* and element at position C in the *actions* array needs to be
626d30ea906Sjfb8856606  *   valid.
627d30ea906Sjfb8856606  * @param[in] actions
628d30ea906Sjfb8856606  *   Pre-allocated and pre-populated array of policer actions.
629d30ea906Sjfb8856606  * @param[out] error
630d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
631d30ea906Sjfb8856606  * @return
632d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
633d30ea906Sjfb8856606  */
634*4418919fSjohnjiang __rte_experimental
635*4418919fSjohnjiang int
636d30ea906Sjfb8856606 rte_mtr_policer_actions_update(uint16_t port_id,
637d30ea906Sjfb8856606 	uint32_t mtr_id,
638d30ea906Sjfb8856606 	uint32_t action_mask,
639d30ea906Sjfb8856606 	enum rte_mtr_policer_action *actions,
640d30ea906Sjfb8856606 	struct rte_mtr_error *error);
641d30ea906Sjfb8856606 
642d30ea906Sjfb8856606 /**
643d30ea906Sjfb8856606  * MTR object enabled statistics counters update
644d30ea906Sjfb8856606  *
645d30ea906Sjfb8856606  * @param[in] port_id
646d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
647d30ea906Sjfb8856606  * @param[in] mtr_id
648d30ea906Sjfb8856606  *   MTR object ID. Needs to be valid.
649d30ea906Sjfb8856606  * @param[in] stats_mask
650d30ea906Sjfb8856606  *   Mask of statistics counter types to be enabled for the current MTR object.
651d30ea906Sjfb8856606  *   Any statistics counter type not included in this set is to be disabled for
652d30ea906Sjfb8856606  *   the current MTR object.
653d30ea906Sjfb8856606  * @param[out] error
654d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
655d30ea906Sjfb8856606  * @return
656d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
657d30ea906Sjfb8856606  *
658d30ea906Sjfb8856606  * @see enum rte_mtr_stats_type
659d30ea906Sjfb8856606  */
660*4418919fSjohnjiang __rte_experimental
661*4418919fSjohnjiang int
662d30ea906Sjfb8856606 rte_mtr_stats_update(uint16_t port_id,
663d30ea906Sjfb8856606 	uint32_t mtr_id,
664d30ea906Sjfb8856606 	uint64_t stats_mask,
665d30ea906Sjfb8856606 	struct rte_mtr_error *error);
666d30ea906Sjfb8856606 
667d30ea906Sjfb8856606 /**
668d30ea906Sjfb8856606  * MTR object statistics counters read
669d30ea906Sjfb8856606  *
670d30ea906Sjfb8856606  * @param[in] port_id
671d30ea906Sjfb8856606  *   The port identifier of the Ethernet device.
672d30ea906Sjfb8856606  * @param[in] mtr_id
673d30ea906Sjfb8856606  *   MTR object ID. Needs to be valid.
674d30ea906Sjfb8856606  * @param[out] stats
675d30ea906Sjfb8856606  *   When non-NULL, it contains the current value for the statistics counters
676d30ea906Sjfb8856606  *   enabled for the current MTR object.
677d30ea906Sjfb8856606  * @param[out] stats_mask
678d30ea906Sjfb8856606  *   When non-NULL, it contains the mask of statistics counter types that are
679d30ea906Sjfb8856606  *   currently enabled for this MTR object, indicating which of the counters
680d30ea906Sjfb8856606  *   retrieved with the *stats* structure are valid.
681d30ea906Sjfb8856606  * @param[in] clear
682d30ea906Sjfb8856606  *   When this parameter has a non-zero value, the statistics counters are
683d30ea906Sjfb8856606  *   cleared (i.e. set to zero) immediately after they have been read,
684d30ea906Sjfb8856606  *   otherwise the statistics counters are left untouched.
685d30ea906Sjfb8856606  * @param[out] error
686d30ea906Sjfb8856606  *   Error details. Filled in only on error, when not NULL.
687d30ea906Sjfb8856606  * @return
688d30ea906Sjfb8856606  *   0 on success, non-zero error code otherwise.
689d30ea906Sjfb8856606  *
690d30ea906Sjfb8856606  * @see enum rte_mtr_stats_type
691d30ea906Sjfb8856606  */
692*4418919fSjohnjiang __rte_experimental
693*4418919fSjohnjiang int
694d30ea906Sjfb8856606 rte_mtr_stats_read(uint16_t port_id,
695d30ea906Sjfb8856606 	uint32_t mtr_id,
696d30ea906Sjfb8856606 	struct rte_mtr_stats *stats,
697d30ea906Sjfb8856606 	uint64_t *stats_mask,
698d30ea906Sjfb8856606 	int clear,
699d30ea906Sjfb8856606 	struct rte_mtr_error *error);
700d30ea906Sjfb8856606 
701d30ea906Sjfb8856606 #ifdef __cplusplus
702d30ea906Sjfb8856606 }
703d30ea906Sjfb8856606 #endif
704d30ea906Sjfb8856606 
705d30ea906Sjfb8856606 #endif /* __INCLUDE_RTE_MTR_H__ */
706