xref: /dpdk/lib/ethdev/rte_mtr_driver.h (revision 3c2ca0a9)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2017 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef __INCLUDE_RTE_MTR_DRIVER_H__
699a2dd95SBruce Richardson #define __INCLUDE_RTE_MTR_DRIVER_H__
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * RTE Generic Traffic Metering and Policing API (Driver Side)
1199a2dd95SBruce Richardson  *
1299a2dd95SBruce Richardson  * This file provides implementation helpers for internal use by PMDs, they
1399a2dd95SBruce Richardson  * are not intended to be exposed to applications and are not subject to ABI
1499a2dd95SBruce Richardson  * versioning.
1599a2dd95SBruce Richardson  */
1699a2dd95SBruce Richardson 
1799a2dd95SBruce Richardson #include <stdint.h>
1899a2dd95SBruce Richardson 
1999a2dd95SBruce Richardson #include <rte_errno.h>
2099a2dd95SBruce Richardson #include "rte_ethdev.h"
2199a2dd95SBruce Richardson #include "ethdev_driver.h"
2299a2dd95SBruce Richardson #include "rte_mtr.h"
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson #ifdef __cplusplus
2599a2dd95SBruce Richardson extern "C" {
2699a2dd95SBruce Richardson #endif
2799a2dd95SBruce Richardson 
28*3c2ca0a9SAndrew Rybchenko /** @internal MTR capabilities get. */
2999a2dd95SBruce Richardson typedef int (*rte_mtr_capabilities_get_t)(struct rte_eth_dev *dev,
3099a2dd95SBruce Richardson 	struct rte_mtr_capabilities *cap,
3199a2dd95SBruce Richardson 	struct rte_mtr_error *error);
3299a2dd95SBruce Richardson 
33*3c2ca0a9SAndrew Rybchenko /** @internal MTR meter profile add. */
3499a2dd95SBruce Richardson typedef int (*rte_mtr_meter_profile_add_t)(struct rte_eth_dev *dev,
3599a2dd95SBruce Richardson 	uint32_t meter_profile_id,
3699a2dd95SBruce Richardson 	struct rte_mtr_meter_profile *profile,
3799a2dd95SBruce Richardson 	struct rte_mtr_error *error);
3899a2dd95SBruce Richardson 
39*3c2ca0a9SAndrew Rybchenko /** @internal MTR meter profile delete. */
4099a2dd95SBruce Richardson typedef int (*rte_mtr_meter_profile_delete_t)(struct rte_eth_dev *dev,
4199a2dd95SBruce Richardson 	uint32_t meter_profile_id,
4299a2dd95SBruce Richardson 	struct rte_mtr_error *error);
4399a2dd95SBruce Richardson 
44*3c2ca0a9SAndrew Rybchenko /** @internal MTR meter policy validate. */
455f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_validate_t)(struct rte_eth_dev *dev,
465f0d54f3SLi Zhang 	struct rte_mtr_meter_policy_params *policy,
475f0d54f3SLi Zhang 	struct rte_mtr_error *error);
485f0d54f3SLi Zhang 
49*3c2ca0a9SAndrew Rybchenko /** @internal MTR meter policy add. */
505f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_add_t)(struct rte_eth_dev *dev,
515f0d54f3SLi Zhang 	uint32_t policy_id,
525f0d54f3SLi Zhang 	struct rte_mtr_meter_policy_params *policy,
535f0d54f3SLi Zhang 	struct rte_mtr_error *error);
545f0d54f3SLi Zhang 
55*3c2ca0a9SAndrew Rybchenko /** @internal MTR meter policy delete. */
565f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_delete_t)(struct rte_eth_dev *dev,
575f0d54f3SLi Zhang 	uint32_t policy_id,
585f0d54f3SLi Zhang 	struct rte_mtr_error *error);
595f0d54f3SLi Zhang 
60*3c2ca0a9SAndrew Rybchenko /** @internal MTR object create. */
6199a2dd95SBruce Richardson typedef int (*rte_mtr_create_t)(struct rte_eth_dev *dev,
6299a2dd95SBruce Richardson 	uint32_t mtr_id,
6399a2dd95SBruce Richardson 	struct rte_mtr_params *params,
6499a2dd95SBruce Richardson 	int shared,
6599a2dd95SBruce Richardson 	struct rte_mtr_error *error);
6699a2dd95SBruce Richardson 
67*3c2ca0a9SAndrew Rybchenko /** @internal MTR object destroy. */
6899a2dd95SBruce Richardson typedef int (*rte_mtr_destroy_t)(struct rte_eth_dev *dev,
6999a2dd95SBruce Richardson 	uint32_t mtr_id,
7099a2dd95SBruce Richardson 	struct rte_mtr_error *error);
7199a2dd95SBruce Richardson 
72*3c2ca0a9SAndrew Rybchenko /** @internal MTR object meter enable. */
7399a2dd95SBruce Richardson typedef int (*rte_mtr_meter_enable_t)(struct rte_eth_dev *dev,
7499a2dd95SBruce Richardson 	uint32_t mtr_id,
7599a2dd95SBruce Richardson 	struct rte_mtr_error *error);
7699a2dd95SBruce Richardson 
77*3c2ca0a9SAndrew Rybchenko /** @internal MTR object meter disable. */
7899a2dd95SBruce Richardson typedef int (*rte_mtr_meter_disable_t)(struct rte_eth_dev *dev,
7999a2dd95SBruce Richardson 	uint32_t mtr_id,
8099a2dd95SBruce Richardson 	struct rte_mtr_error *error);
8199a2dd95SBruce Richardson 
82*3c2ca0a9SAndrew Rybchenko /** @internal MTR object meter profile update. */
8399a2dd95SBruce Richardson typedef int (*rte_mtr_meter_profile_update_t)(struct rte_eth_dev *dev,
8499a2dd95SBruce Richardson 	uint32_t mtr_id,
8599a2dd95SBruce Richardson 	uint32_t meter_profile_id,
8699a2dd95SBruce Richardson 	struct rte_mtr_error *error);
8799a2dd95SBruce Richardson 
88*3c2ca0a9SAndrew Rybchenko /** @internal MTR object meter policy update. */
895f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_update_t)(struct rte_eth_dev *dev,
905f0d54f3SLi Zhang 	uint32_t mtr_id,
915f0d54f3SLi Zhang 	uint32_t meter_policy_id,
925f0d54f3SLi Zhang 	struct rte_mtr_error *error);
935f0d54f3SLi Zhang 
94*3c2ca0a9SAndrew Rybchenko /** @internal MTR object meter DSCP table update. */
9599a2dd95SBruce Richardson typedef int (*rte_mtr_meter_dscp_table_update_t)(struct rte_eth_dev *dev,
9699a2dd95SBruce Richardson 	uint32_t mtr_id,
9799a2dd95SBruce Richardson 	enum rte_color *dscp_table,
9899a2dd95SBruce Richardson 	struct rte_mtr_error *error);
9999a2dd95SBruce Richardson 
100*3c2ca0a9SAndrew Rybchenko /** @internal MTR object enabled stats update. */
10199a2dd95SBruce Richardson typedef int (*rte_mtr_stats_update_t)(struct rte_eth_dev *dev,
10299a2dd95SBruce Richardson 	uint32_t mtr_id,
10399a2dd95SBruce Richardson 	uint64_t stats_mask,
10499a2dd95SBruce Richardson 	struct rte_mtr_error *error);
10599a2dd95SBruce Richardson 
106*3c2ca0a9SAndrew Rybchenko /** @internal MTR object stats read. */
10799a2dd95SBruce Richardson typedef int (*rte_mtr_stats_read_t)(struct rte_eth_dev *dev,
10899a2dd95SBruce Richardson 	uint32_t mtr_id,
10999a2dd95SBruce Richardson 	struct rte_mtr_stats *stats,
11099a2dd95SBruce Richardson 	uint64_t *stats_mask,
11199a2dd95SBruce Richardson 	int clear,
11299a2dd95SBruce Richardson 	struct rte_mtr_error *error);
11399a2dd95SBruce Richardson 
11499a2dd95SBruce Richardson struct rte_mtr_ops {
11599a2dd95SBruce Richardson 	/** MTR capabilities get */
11699a2dd95SBruce Richardson 	rte_mtr_capabilities_get_t capabilities_get;
11799a2dd95SBruce Richardson 
11899a2dd95SBruce Richardson 	/** MTR meter profile add */
11999a2dd95SBruce Richardson 	rte_mtr_meter_profile_add_t meter_profile_add;
12099a2dd95SBruce Richardson 
12199a2dd95SBruce Richardson 	/** MTR meter profile delete */
12299a2dd95SBruce Richardson 	rte_mtr_meter_profile_delete_t meter_profile_delete;
12399a2dd95SBruce Richardson 
12499a2dd95SBruce Richardson 	/** MTR object create */
12599a2dd95SBruce Richardson 	rte_mtr_create_t create;
12699a2dd95SBruce Richardson 
12799a2dd95SBruce Richardson 	/** MTR object destroy */
12899a2dd95SBruce Richardson 	rte_mtr_destroy_t destroy;
12999a2dd95SBruce Richardson 
13099a2dd95SBruce Richardson 	/** MTR object meter enable */
13199a2dd95SBruce Richardson 	rte_mtr_meter_enable_t meter_enable;
13299a2dd95SBruce Richardson 
13399a2dd95SBruce Richardson 	/** MTR object meter disable */
13499a2dd95SBruce Richardson 	rte_mtr_meter_disable_t meter_disable;
13599a2dd95SBruce Richardson 
13699a2dd95SBruce Richardson 	/** MTR object meter profile update */
13799a2dd95SBruce Richardson 	rte_mtr_meter_profile_update_t meter_profile_update;
13899a2dd95SBruce Richardson 
13999a2dd95SBruce Richardson 	/** MTR object meter DSCP table update */
14099a2dd95SBruce Richardson 	rte_mtr_meter_dscp_table_update_t meter_dscp_table_update;
14199a2dd95SBruce Richardson 
14299a2dd95SBruce Richardson 	/** MTR object enabled stats update */
14399a2dd95SBruce Richardson 	rte_mtr_stats_update_t stats_update;
14499a2dd95SBruce Richardson 
14599a2dd95SBruce Richardson 	/** MTR object stats read */
14699a2dd95SBruce Richardson 	rte_mtr_stats_read_t stats_read;
1475f0d54f3SLi Zhang 
1485f0d54f3SLi Zhang 	/** MTR meter policy validate */
1495f0d54f3SLi Zhang 	rte_mtr_meter_policy_validate_t meter_policy_validate;
1505f0d54f3SLi Zhang 
1515f0d54f3SLi Zhang 	/** MTR meter policy add */
1525f0d54f3SLi Zhang 	rte_mtr_meter_policy_add_t meter_policy_add;
1535f0d54f3SLi Zhang 
1545f0d54f3SLi Zhang 	/** MTR meter policy delete */
1555f0d54f3SLi Zhang 	rte_mtr_meter_policy_delete_t meter_policy_delete;
1565f0d54f3SLi Zhang 
1575f0d54f3SLi Zhang 	/** MTR object meter policy update */
1585f0d54f3SLi Zhang 	rte_mtr_meter_policy_update_t meter_policy_update;
15999a2dd95SBruce Richardson };
16099a2dd95SBruce Richardson 
16199a2dd95SBruce Richardson /**
16299a2dd95SBruce Richardson  * Initialize generic error structure.
16399a2dd95SBruce Richardson  *
16499a2dd95SBruce Richardson  * This function also sets rte_errno to a given value.
16599a2dd95SBruce Richardson  *
16699a2dd95SBruce Richardson  * @param[out] error
16799a2dd95SBruce Richardson  *   Pointer to error structure (may be NULL).
16899a2dd95SBruce Richardson  * @param[in] code
16999a2dd95SBruce Richardson  *   Related error code (rte_errno).
17099a2dd95SBruce Richardson  * @param[in] type
17199a2dd95SBruce Richardson  *   Cause field and error type.
17299a2dd95SBruce Richardson  * @param[in] cause
17399a2dd95SBruce Richardson  *   Object responsible for the error.
17499a2dd95SBruce Richardson  * @param[in] message
17599a2dd95SBruce Richardson  *   Human-readable error message.
17699a2dd95SBruce Richardson  *
17799a2dd95SBruce Richardson  * @return
17899a2dd95SBruce Richardson  *   Error code.
17999a2dd95SBruce Richardson  */
18099a2dd95SBruce Richardson static inline int
rte_mtr_error_set(struct rte_mtr_error * error,int code,enum rte_mtr_error_type type,const void * cause,const char * message)18199a2dd95SBruce Richardson rte_mtr_error_set(struct rte_mtr_error *error,
18299a2dd95SBruce Richardson 		   int code,
18399a2dd95SBruce Richardson 		   enum rte_mtr_error_type type,
18499a2dd95SBruce Richardson 		   const void *cause,
18599a2dd95SBruce Richardson 		   const char *message)
18699a2dd95SBruce Richardson {
18799a2dd95SBruce Richardson 	if (error) {
18899a2dd95SBruce Richardson 		*error = (struct rte_mtr_error){
18999a2dd95SBruce Richardson 			.type = type,
19099a2dd95SBruce Richardson 			.cause = cause,
19199a2dd95SBruce Richardson 			.message = message,
19299a2dd95SBruce Richardson 		};
19399a2dd95SBruce Richardson 	}
19499a2dd95SBruce Richardson 	rte_errno = code;
19599a2dd95SBruce Richardson 	return code;
19699a2dd95SBruce Richardson }
19799a2dd95SBruce Richardson 
19899a2dd95SBruce Richardson /**
19999a2dd95SBruce Richardson  * Get generic traffic metering and policing operations structure from a port
20099a2dd95SBruce Richardson  *
20199a2dd95SBruce Richardson  * @param[in] port_id
20299a2dd95SBruce Richardson  *   The port identifier of the Ethernet device.
20399a2dd95SBruce Richardson  * @param[out] error
20499a2dd95SBruce Richardson  *   Error details
20599a2dd95SBruce Richardson  *
20699a2dd95SBruce Richardson  * @return
20799a2dd95SBruce Richardson  *   The traffic metering and policing operations structure associated with
20899a2dd95SBruce Richardson  *   port_id on success, NULL otherwise.
20999a2dd95SBruce Richardson  */
21099a2dd95SBruce Richardson const struct rte_mtr_ops *
21199a2dd95SBruce Richardson rte_mtr_ops_get(uint16_t port_id, struct rte_mtr_error *error);
21299a2dd95SBruce Richardson 
21399a2dd95SBruce Richardson #ifdef __cplusplus
21499a2dd95SBruce Richardson }
21599a2dd95SBruce Richardson #endif
21699a2dd95SBruce Richardson 
21799a2dd95SBruce Richardson #endif /* __INCLUDE_RTE_MTR_DRIVER_H__ */
218