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
283c2ca0a9SAndrew 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
333c2ca0a9SAndrew 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
393c2ca0a9SAndrew 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
44ece19ccaSAlexander Kozyrev /** @internal MTR meter profile get. */
45ece19ccaSAlexander Kozyrev typedef struct rte_flow_meter_profile *
46ece19ccaSAlexander Kozyrev (*rte_mtr_meter_profile_get_t)(struct rte_eth_dev *dev,
47ece19ccaSAlexander Kozyrev uint32_t meter_profile_id,
48ece19ccaSAlexander Kozyrev struct rte_mtr_error *error);
49ece19ccaSAlexander Kozyrev
503c2ca0a9SAndrew Rybchenko /** @internal MTR meter policy validate. */
515f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_validate_t)(struct rte_eth_dev *dev,
525f0d54f3SLi Zhang struct rte_mtr_meter_policy_params *policy,
535f0d54f3SLi Zhang struct rte_mtr_error *error);
545f0d54f3SLi Zhang
553c2ca0a9SAndrew Rybchenko /** @internal MTR meter policy add. */
565f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_add_t)(struct rte_eth_dev *dev,
575f0d54f3SLi Zhang uint32_t policy_id,
585f0d54f3SLi Zhang struct rte_mtr_meter_policy_params *policy,
595f0d54f3SLi Zhang struct rte_mtr_error *error);
605f0d54f3SLi Zhang
613c2ca0a9SAndrew Rybchenko /** @internal MTR meter policy delete. */
625f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_delete_t)(struct rte_eth_dev *dev,
635f0d54f3SLi Zhang uint32_t policy_id,
645f0d54f3SLi Zhang struct rte_mtr_error *error);
655f0d54f3SLi Zhang
66ece19ccaSAlexander Kozyrev /** @internal MTR meter policy get. */
67ece19ccaSAlexander Kozyrev typedef struct rte_flow_meter_policy *
68ece19ccaSAlexander Kozyrev (*rte_mtr_meter_policy_get_t)(struct rte_eth_dev *dev,
69ece19ccaSAlexander Kozyrev uint32_t policy_id,
70ece19ccaSAlexander Kozyrev struct rte_mtr_error *error);
71ece19ccaSAlexander Kozyrev
72ece19ccaSAlexander Kozyrev
733c2ca0a9SAndrew Rybchenko /** @internal MTR object create. */
7499a2dd95SBruce Richardson typedef int (*rte_mtr_create_t)(struct rte_eth_dev *dev,
7599a2dd95SBruce Richardson uint32_t mtr_id,
7699a2dd95SBruce Richardson struct rte_mtr_params *params,
7799a2dd95SBruce Richardson int shared,
7899a2dd95SBruce Richardson struct rte_mtr_error *error);
7999a2dd95SBruce Richardson
803c2ca0a9SAndrew Rybchenko /** @internal MTR object destroy. */
8199a2dd95SBruce Richardson typedef int (*rte_mtr_destroy_t)(struct rte_eth_dev *dev,
8299a2dd95SBruce Richardson uint32_t mtr_id,
8399a2dd95SBruce Richardson struct rte_mtr_error *error);
8499a2dd95SBruce Richardson
853c2ca0a9SAndrew Rybchenko /** @internal MTR object meter enable. */
8699a2dd95SBruce Richardson typedef int (*rte_mtr_meter_enable_t)(struct rte_eth_dev *dev,
8799a2dd95SBruce Richardson uint32_t mtr_id,
8899a2dd95SBruce Richardson struct rte_mtr_error *error);
8999a2dd95SBruce Richardson
903c2ca0a9SAndrew Rybchenko /** @internal MTR object meter disable. */
9199a2dd95SBruce Richardson typedef int (*rte_mtr_meter_disable_t)(struct rte_eth_dev *dev,
9299a2dd95SBruce Richardson uint32_t mtr_id,
9399a2dd95SBruce Richardson struct rte_mtr_error *error);
9499a2dd95SBruce Richardson
953c2ca0a9SAndrew Rybchenko /** @internal MTR object meter profile update. */
9699a2dd95SBruce Richardson typedef int (*rte_mtr_meter_profile_update_t)(struct rte_eth_dev *dev,
9799a2dd95SBruce Richardson uint32_t mtr_id,
9899a2dd95SBruce Richardson uint32_t meter_profile_id,
9999a2dd95SBruce Richardson struct rte_mtr_error *error);
10099a2dd95SBruce Richardson
1013c2ca0a9SAndrew Rybchenko /** @internal MTR object meter policy update. */
1025f0d54f3SLi Zhang typedef int (*rte_mtr_meter_policy_update_t)(struct rte_eth_dev *dev,
1035f0d54f3SLi Zhang uint32_t mtr_id,
1045f0d54f3SLi Zhang uint32_t meter_policy_id,
1055f0d54f3SLi Zhang struct rte_mtr_error *error);
1065f0d54f3SLi Zhang
1073c2ca0a9SAndrew Rybchenko /** @internal MTR object meter DSCP table update. */
10899a2dd95SBruce Richardson typedef int (*rte_mtr_meter_dscp_table_update_t)(struct rte_eth_dev *dev,
109*204daeeaSSunil Kumar Kori uint32_t mtr_id, enum rte_mtr_color_in_protocol proto,
11099a2dd95SBruce Richardson enum rte_color *dscp_table,
11199a2dd95SBruce Richardson struct rte_mtr_error *error);
11299a2dd95SBruce Richardson
113d04fb3b5SJerin Jacob /** @internal mtr object meter vlan table update. */
114d04fb3b5SJerin Jacob typedef int (*rte_mtr_meter_vlan_table_update_t)(struct rte_eth_dev *dev,
115*204daeeaSSunil Kumar Kori uint32_t mtr_id, enum rte_mtr_color_in_protocol proto,
116d04fb3b5SJerin Jacob enum rte_color *vlan_table,
117d04fb3b5SJerin Jacob struct rte_mtr_error *error);
118d04fb3b5SJerin Jacob
119d04fb3b5SJerin Jacob /** @internal Set the input color protocol on MTR object. */
120d04fb3b5SJerin Jacob typedef int (*rte_mtr_meter_color_in_proto_set_t)(struct rte_eth_dev *dev,
121d04fb3b5SJerin Jacob uint32_t mtr_id,
122d04fb3b5SJerin Jacob enum rte_mtr_color_in_protocol proto,
123d04fb3b5SJerin Jacob uint32_t priority,
124d04fb3b5SJerin Jacob struct rte_mtr_error *error);
125d04fb3b5SJerin Jacob
126d04fb3b5SJerin Jacob /** @internal Get the input color protocols of MTR object. */
127d04fb3b5SJerin Jacob typedef int (*rte_mtr_meter_color_in_proto_get_t)(struct rte_eth_dev *dev,
128d04fb3b5SJerin Jacob uint32_t mtr_id,
129d04fb3b5SJerin Jacob uint64_t *proto_mask,
130d04fb3b5SJerin Jacob struct rte_mtr_error *error);
131d04fb3b5SJerin Jacob
132d04fb3b5SJerin Jacob /** @internal Get the input color protocol priority of MTR object. */
133d04fb3b5SJerin Jacob typedef int (*rte_mtr_meter_color_in_proto_prio_get_t)(struct rte_eth_dev *dev,
134d04fb3b5SJerin Jacob uint32_t mtr_id,
135d04fb3b5SJerin Jacob enum rte_mtr_color_in_protocol proto,
136d04fb3b5SJerin Jacob uint32_t *priority,
137d04fb3b5SJerin Jacob struct rte_mtr_error *error);
138d04fb3b5SJerin Jacob
1393c2ca0a9SAndrew Rybchenko /** @internal MTR object enabled stats update. */
14099a2dd95SBruce Richardson typedef int (*rte_mtr_stats_update_t)(struct rte_eth_dev *dev,
14199a2dd95SBruce Richardson uint32_t mtr_id,
14299a2dd95SBruce Richardson uint64_t stats_mask,
14399a2dd95SBruce Richardson struct rte_mtr_error *error);
14499a2dd95SBruce Richardson
1453c2ca0a9SAndrew Rybchenko /** @internal MTR object stats read. */
14699a2dd95SBruce Richardson typedef int (*rte_mtr_stats_read_t)(struct rte_eth_dev *dev,
14799a2dd95SBruce Richardson uint32_t mtr_id,
14899a2dd95SBruce Richardson struct rte_mtr_stats *stats,
14999a2dd95SBruce Richardson uint64_t *stats_mask,
15099a2dd95SBruce Richardson int clear,
15199a2dd95SBruce Richardson struct rte_mtr_error *error);
15299a2dd95SBruce Richardson
15399a2dd95SBruce Richardson struct rte_mtr_ops {
15499a2dd95SBruce Richardson /** MTR capabilities get */
15599a2dd95SBruce Richardson rte_mtr_capabilities_get_t capabilities_get;
15699a2dd95SBruce Richardson
15799a2dd95SBruce Richardson /** MTR meter profile add */
15899a2dd95SBruce Richardson rte_mtr_meter_profile_add_t meter_profile_add;
15999a2dd95SBruce Richardson
16099a2dd95SBruce Richardson /** MTR meter profile delete */
16199a2dd95SBruce Richardson rte_mtr_meter_profile_delete_t meter_profile_delete;
16299a2dd95SBruce Richardson
16399a2dd95SBruce Richardson /** MTR object create */
16499a2dd95SBruce Richardson rte_mtr_create_t create;
16599a2dd95SBruce Richardson
16699a2dd95SBruce Richardson /** MTR object destroy */
16799a2dd95SBruce Richardson rte_mtr_destroy_t destroy;
16899a2dd95SBruce Richardson
16999a2dd95SBruce Richardson /** MTR object meter enable */
17099a2dd95SBruce Richardson rte_mtr_meter_enable_t meter_enable;
17199a2dd95SBruce Richardson
17299a2dd95SBruce Richardson /** MTR object meter disable */
17399a2dd95SBruce Richardson rte_mtr_meter_disable_t meter_disable;
17499a2dd95SBruce Richardson
17599a2dd95SBruce Richardson /** MTR object meter profile update */
17699a2dd95SBruce Richardson rte_mtr_meter_profile_update_t meter_profile_update;
17799a2dd95SBruce Richardson
17899a2dd95SBruce Richardson /** MTR object meter DSCP table update */
17999a2dd95SBruce Richardson rte_mtr_meter_dscp_table_update_t meter_dscp_table_update;
18099a2dd95SBruce Richardson
181d04fb3b5SJerin Jacob /** MTR object meter VLAN table update */
182d04fb3b5SJerin Jacob rte_mtr_meter_vlan_table_update_t meter_vlan_table_update;
183d04fb3b5SJerin Jacob
184d04fb3b5SJerin Jacob /** Set the input color protocol on MTR object. */
185d04fb3b5SJerin Jacob rte_mtr_meter_color_in_proto_set_t in_proto_set;
186d04fb3b5SJerin Jacob
187d04fb3b5SJerin Jacob /** Get the input color protocol of MTR object. */
188d04fb3b5SJerin Jacob rte_mtr_meter_color_in_proto_get_t in_proto_get;
189d04fb3b5SJerin Jacob
190d04fb3b5SJerin Jacob /** Get the input color protocol priority of MTR object. */
191d04fb3b5SJerin Jacob rte_mtr_meter_color_in_proto_prio_get_t in_proto_prio_get;
192d04fb3b5SJerin Jacob
19399a2dd95SBruce Richardson /** MTR object enabled stats update */
19499a2dd95SBruce Richardson rte_mtr_stats_update_t stats_update;
19599a2dd95SBruce Richardson
19699a2dd95SBruce Richardson /** MTR object stats read */
19799a2dd95SBruce Richardson rte_mtr_stats_read_t stats_read;
1985f0d54f3SLi Zhang
1995f0d54f3SLi Zhang /** MTR meter policy validate */
2005f0d54f3SLi Zhang rte_mtr_meter_policy_validate_t meter_policy_validate;
2015f0d54f3SLi Zhang
2025f0d54f3SLi Zhang /** MTR meter policy add */
2035f0d54f3SLi Zhang rte_mtr_meter_policy_add_t meter_policy_add;
2045f0d54f3SLi Zhang
2055f0d54f3SLi Zhang /** MTR meter policy delete */
2065f0d54f3SLi Zhang rte_mtr_meter_policy_delete_t meter_policy_delete;
2075f0d54f3SLi Zhang
2085f0d54f3SLi Zhang /** MTR object meter policy update */
2095f0d54f3SLi Zhang rte_mtr_meter_policy_update_t meter_policy_update;
210ece19ccaSAlexander Kozyrev
211ece19ccaSAlexander Kozyrev /** MTR meter profile get */
212ece19ccaSAlexander Kozyrev rte_mtr_meter_profile_get_t meter_profile_get;
213ece19ccaSAlexander Kozyrev
214ece19ccaSAlexander Kozyrev /** MTR meter policy get */
215ece19ccaSAlexander Kozyrev rte_mtr_meter_policy_get_t meter_policy_get;
21699a2dd95SBruce Richardson };
21799a2dd95SBruce Richardson
21899a2dd95SBruce Richardson /**
21999a2dd95SBruce Richardson * Initialize generic error structure.
22099a2dd95SBruce Richardson *
22199a2dd95SBruce Richardson * This function also sets rte_errno to a given value.
22299a2dd95SBruce Richardson *
22399a2dd95SBruce Richardson * @param[out] error
22499a2dd95SBruce Richardson * Pointer to error structure (may be NULL).
22599a2dd95SBruce Richardson * @param[in] code
22699a2dd95SBruce Richardson * Related error code (rte_errno).
22799a2dd95SBruce Richardson * @param[in] type
22899a2dd95SBruce Richardson * Cause field and error type.
22999a2dd95SBruce Richardson * @param[in] cause
23099a2dd95SBruce Richardson * Object responsible for the error.
23199a2dd95SBruce Richardson * @param[in] message
23299a2dd95SBruce Richardson * Human-readable error message.
23399a2dd95SBruce Richardson *
23499a2dd95SBruce Richardson * @return
23599a2dd95SBruce Richardson * Error code.
23699a2dd95SBruce Richardson */
23799a2dd95SBruce 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)23899a2dd95SBruce Richardson rte_mtr_error_set(struct rte_mtr_error *error,
23999a2dd95SBruce Richardson int code,
24099a2dd95SBruce Richardson enum rte_mtr_error_type type,
24199a2dd95SBruce Richardson const void *cause,
24299a2dd95SBruce Richardson const char *message)
24399a2dd95SBruce Richardson {
24499a2dd95SBruce Richardson if (error) {
24599a2dd95SBruce Richardson *error = (struct rte_mtr_error){
24699a2dd95SBruce Richardson .type = type,
24799a2dd95SBruce Richardson .cause = cause,
24899a2dd95SBruce Richardson .message = message,
24999a2dd95SBruce Richardson };
25099a2dd95SBruce Richardson }
25199a2dd95SBruce Richardson rte_errno = code;
25299a2dd95SBruce Richardson return code;
25399a2dd95SBruce Richardson }
25499a2dd95SBruce Richardson
25599a2dd95SBruce Richardson /**
25699a2dd95SBruce Richardson * Get generic traffic metering and policing operations structure from a port
25799a2dd95SBruce Richardson *
25899a2dd95SBruce Richardson * @param[in] port_id
25999a2dd95SBruce Richardson * The port identifier of the Ethernet device.
26099a2dd95SBruce Richardson * @param[out] error
26199a2dd95SBruce Richardson * Error details
26299a2dd95SBruce Richardson *
26399a2dd95SBruce Richardson * @return
26499a2dd95SBruce Richardson * The traffic metering and policing operations structure associated with
26599a2dd95SBruce Richardson * port_id on success, NULL otherwise.
26699a2dd95SBruce Richardson */
26799a2dd95SBruce Richardson const struct rte_mtr_ops *
26899a2dd95SBruce Richardson rte_mtr_ops_get(uint16_t port_id, struct rte_mtr_error *error);
26999a2dd95SBruce Richardson
27099a2dd95SBruce Richardson #ifdef __cplusplus
27199a2dd95SBruce Richardson }
27299a2dd95SBruce Richardson #endif
27399a2dd95SBruce Richardson
27499a2dd95SBruce Richardson #endif /* __INCLUDE_RTE_MTR_DRIVER_H__ */
275