From patchwork Thu Mar 18 08:58:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Zhang X-Patchwork-Id: 89459 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5E2BAA0561; Thu, 18 Mar 2021 09:58:23 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D86F4140EBF; Thu, 18 Mar 2021 09:58:22 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id DF692140EBF for ; Thu, 18 Mar 2021 09:58:21 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from lizh@nvidia.com) with SMTP; 18 Mar 2021 10:58:18 +0200 Received: from nvidia.com (c-235-17-1-009.mtl.labs.mlnx [10.235.17.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 12I8wH3J031633; Thu, 18 Mar 2021 10:58:17 +0200 From: Li Zhang To: dekelp@nvidia.com, orika@nvidia.com, viacheslavo@nvidia.com, matan@nvidia.com, shahafs@nvidia.com, lironh@marvell.com, jasvinder.singh@intel.com, Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Cristian Dumitrescu Cc: dev@dpdk.org, rasland@nvidia.com, roniba@nvidia.com Date: Thu, 18 Mar 2021 10:58:14 +0200 Message-Id: <20210318085815.804896-1-lizh@nvidia.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/2] [RFC]: ethdev: add pre-defined meter policy API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently, the flow meter policy does not support multiple actions per color; also the allowed action types per color are very limited. In addition, the policy cannot be pre-defined. Due to the growing in flow actions offload abilities there is a potential for the user to use variety of actions per color differently. This new meter policy API comes to allow this potential in the most ethdev common way using rte_flow action definition. A list of rte_flow actions will be provided by the user per color in order to create a meter policy. In addition, the API forces to pre-define the policy before the meters creation in order to allow sharing of single policy with multiple meters efficiently. meter_policy_id is added into struct rte_mtr_params. So that it can get the policy during the meters creation. Policy id 0 is default policy. Action per color as below: green - no action, yellow - no action, red - drop Allow coloring the packet using a new rte_flow_action_color as could be done by the old policy API, The next API function were added: - rte_mtr_meter_policy_add - rte_mtr_meter_policy_delete - rte_mtr_meter_policy_update - rte_mtr_meter_policy_validate The next struct was changed: - rte_mtr_params - rte_mtr_capabilities The next API was deleted: - rte_mtr_policer_actions_update Signed-off-by: Li Zhang --- lib/librte_ethdev/rte_flow.h | 18 ++++ lib/librte_ethdev/rte_mtr.c | 55 ++++++++-- lib/librte_ethdev/rte_mtr.h | 166 ++++++++++++++++++++--------- lib/librte_ethdev/rte_mtr_driver.h | 45 ++++++-- 4 files changed, 210 insertions(+), 74 deletions(-) diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index 669e677e91..5f38aa7fa4 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -2236,6 +2237,13 @@ enum rte_flow_action_type { * See struct rte_flow_action_modify_field. */ RTE_FLOW_ACTION_TYPE_MODIFY_FIELD, + + /** + * Color the packet to reflect the meter color result. + * + * See struct rte_flow_action_color. + */ + RTE_FLOW_ACTION_TYPE_COlOR, }; /** @@ -2828,6 +2836,16 @@ struct rte_flow_action_set_dscp { */ struct rte_flow_shared_action; +/** + * RTE_FLOW_ACTION_TYPE_COLOR + * + * The meter color should be set in the packet meta-data + * (i.e. struct rte_mbuf::sched::color). + */ +struct rte_flow_action_color { + enum rte_color color; /**< Green/Yellow/Red. */ +}; + /** * Field IDs for MODIFY_FIELD action. */ diff --git a/lib/librte_ethdev/rte_mtr.c b/lib/librte_ethdev/rte_mtr.c index 3073ac03f2..fccec3760b 100644 --- a/lib/librte_ethdev/rte_mtr.c +++ b/lib/librte_ethdev/rte_mtr.c @@ -91,6 +91,40 @@ rte_mtr_meter_profile_delete(uint16_t port_id, meter_profile_id, error); } +/* MTR meter policy validate */ +int +rte_mtr_meter_policy_validate(uint16_t port_id, + const struct rte_flow_action *actions[RTE_COLORS], + struct rte_mtr_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + return RTE_MTR_FUNC(port_id, meter_policy_validate)(dev, + actions, error); +} + +/* MTR meter policy add */ +int +rte_mtr_meter_policy_add(uint16_t port_id, + uint32_t policy_id, + const struct rte_flow_action *actions[RTE_COLORS], + struct rte_mtr_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + return RTE_MTR_FUNC(port_id, meter_policy_add)(dev, + policy_id, actions, error); +} + +/** MTR meter policy delete */ +int +rte_mtr_meter_policy_delete(uint16_t port_id, + uint32_t policy_id, + struct rte_mtr_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + return RTE_MTR_FUNC(port_id, meter_policy_delete)(dev, + policy_id, error); +} + /** MTR object create */ int rte_mtr_create(uint16_t port_id, @@ -149,29 +183,28 @@ rte_mtr_meter_profile_update(uint16_t port_id, mtr_id, meter_profile_id, error); } -/** MTR object meter DSCP table update */ +/** MTR object meter policy update */ int -rte_mtr_meter_dscp_table_update(uint16_t port_id, +rte_mtr_meter_policy_update(uint16_t port_id, uint32_t mtr_id, - enum rte_color *dscp_table, + uint32_t meter_policy_id, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - return RTE_MTR_FUNC(port_id, meter_dscp_table_update)(dev, - mtr_id, dscp_table, error); + return RTE_MTR_FUNC(port_id, meter_policy_update)(dev, + mtr_id, meter_policy_id, error); } -/** MTR object policer action update */ +/** MTR object meter DSCP table update */ int -rte_mtr_policer_actions_update(uint16_t port_id, +rte_mtr_meter_dscp_table_update(uint16_t port_id, uint32_t mtr_id, - uint32_t action_mask, - enum rte_mtr_policer_action *actions, + enum rte_color *dscp_table, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - return RTE_MTR_FUNC(port_id, policer_actions_update)(dev, - mtr_id, action_mask, actions, error); + return RTE_MTR_FUNC(port_id, meter_dscp_table_update)(dev, + mtr_id, dscp_table, error); } /** MTR object enabled stats update */ diff --git a/lib/librte_ethdev/rte_mtr.h b/lib/librte_ethdev/rte_mtr.h index 916a09c5c3..07961f2777 100644 --- a/lib/librte_ethdev/rte_mtr.h +++ b/lib/librte_ethdev/rte_mtr.h @@ -49,6 +49,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -174,23 +175,6 @@ struct rte_mtr_meter_profile { }; }; -/** - * Policer actions - */ -enum rte_mtr_policer_action { - /** Recolor the packet as green. */ - MTR_POLICER_ACTION_COLOR_GREEN = 0, - - /** Recolor the packet as yellow. */ - MTR_POLICER_ACTION_COLOR_YELLOW, - - /** Recolor the packet as red. */ - MTR_POLICER_ACTION_COLOR_RED, - - /** Drop the packet. */ - MTR_POLICER_ACTION_DROP, -}; - /** * Parameters for each traffic metering & policing object * @@ -232,13 +216,13 @@ struct rte_mtr_params { */ int meter_enable; - /** Policer actions (per meter output color). */ - enum rte_mtr_policer_action action[RTE_COLORS]; - /** Set of stats counters to be enabled. * @see enum rte_mtr_stats_type */ uint64_t stats_mask; + + /** Meter policy ID. */ + uint32_t meter_policy_id; }; /** @@ -324,6 +308,13 @@ struct rte_mtr_capabilities { */ uint64_t meter_rate_max; + /** + * Maximum number of policy objects that can have. + * The value of 0 is invalid. Policy must be supported for meter. + * The maximum value is *n_max*. + */ + uint64_t meter_policy_n_max; + /** * When non-zero, it indicates that color aware mode is supported for * the srTCM RFC 2697 metering algorithm. @@ -342,18 +333,6 @@ struct rte_mtr_capabilities { */ int color_aware_trtcm_rfc4115_supported; - /** When non-zero, it indicates that the policer packet recolor actions - * are supported. - * @see enum rte_mtr_policer_action - */ - int policer_action_recolor_supported; - - /** When non-zero, it indicates that the policer packet drop action is - * supported. - * @see enum rte_mtr_policer_action - */ - int policer_action_drop_supported; - /** Set of supported statistics counter types. * @see enum rte_mtr_stats_type */ @@ -462,6 +441,94 @@ rte_mtr_meter_profile_delete(uint16_t port_id, uint32_t meter_profile_id, struct rte_mtr_error *error); +/** + * Policy id 0 is default policy. + * Action per color as below: + * green - no action, yellow - no action, red - drop + * It can be used without creating it by the rte_mtr_meter_policy_add function. + */ +#define RTE_MTR_DEFAULT_POLICY_ID 0 + +/** + * Check whether a meter policy can be created on a given port. + * + * The meter policy is validated for correctness and + * whether it could be accepted by the device given sufficient resources. + * The policy is checked against the current capability information + * meter_policy_n_max configuration. + * The policy may also optionally be validated against existing + * device policy resources. + * This function has no effect on the target device. + * + * @param[in] port_id + * The port identifier of the Ethernet device. + * @param[in] policy_id + * Policy identifier for the new meter policy. + * @param[in] actions + * Associated action list per color. + * list NULL is legal and means no special action. + * (list terminated by the END action). + * @param[out] error + * Error details. Filled in only on error, when not NULL. + * + * @return + * 0 on success, non-zero error code otherwise. + * + */ +__rte_experimental +int +rte_mtr_meter_policy_validate(uint16_t port_id, + uint32_t policy_id, + const struct rte_flow_action *actions[RTE_COLORS], + struct rte_mtr_error *error); + +/** + * Meter policy add + * + * Create a new meter policy. The new policy + * is used to create single or multiple MTR objects. + * + * @param[in] port_id + * The port identifier of the Ethernet device. + * @param[in] policy_id + * Policy identifier for the new meter policy. + * @param[in] actions + * Associated actions per color. + * list NULL is legal and means no special action. + * (list terminated by the END action). + * @param[out] error + * Error details. Filled in only on error, when not NULL. + * @return + * 0 on success, non-zero error code otherwise. + */ +__rte_experimental +int +rte_mtr_meter_policy_add(uint16_t port_id, + uint32_t policy_id, + const struct rte_flow_action *actions[RTE_COLORS], + struct rte_mtr_error *error); + +/** + * Meter policy delete + * + * Delete an existing meter policy. This operation fails when there is + * currently at least one user (i.e. MTR object) of this policy. + * + * @param[in] port_id + * The port identifier of the Ethernet device. + * @param[in] policy_id + * Policy identifier. + * @param[out] error + * Error details. Filled in only on error, when not NULL. + * @return + * 0 on success, non-zero error code otherwise. + */ +__rte_experimental +int +rte_mtr_meter_policy_delete(uint16_t port_id, + uint32_t policy_id, + struct rte_mtr_error *error); + /** * MTR object create * @@ -587,18 +654,14 @@ rte_mtr_meter_profile_update(uint16_t port_id, struct rte_mtr_error *error); /** - * MTR object DSCP table update + * MTR object meter policy update * * @param[in] port_id * The port identifier of the Ethernet device. * @param[in] mtr_id * MTR object ID. Needs to be valid. - * @param[in] dscp_table - * When non-NULL: it points to a pre-allocated and pre-populated table with - * exactly 64 elements providing the input color for each value of the - * IPv4/IPv6 Differentiated Services Code Point (DSCP) input packet field. - * When NULL: it is equivalent to setting this parameter to an “all-green” - * populated table (i.e. table with all the 64 elements set to green color). + * @param[in] meter_policy_id + * Meter policy ID for the current MTR object. Needs to be valid. * @param[out] error * Error details. Filled in only on error, when not NULL. * @return @@ -606,26 +669,24 @@ rte_mtr_meter_profile_update(uint16_t port_id, */ __rte_experimental int -rte_mtr_meter_dscp_table_update(uint16_t port_id, +rte_mtr_meter_policy_update(uint16_t port_id, uint32_t mtr_id, - enum rte_color *dscp_table, + uint32_t meter_policy_id, struct rte_mtr_error *error); /** - * MTR object policer actions update + * MTR object DSCP table update * * @param[in] port_id * The port identifier of the Ethernet device. * @param[in] mtr_id * MTR object ID. Needs to be valid. - * @param[in] action_mask - * Bit mask indicating which policer actions need to be updated. One or more - * policer actions can be updated in a single function invocation. To update - * the policer action associated with color C, bit (1 << C) needs to be set in - * *action_mask* and element at position C in the *actions* array needs to be - * valid. - * @param[in] actions - * Pre-allocated and pre-populated array of policer actions. + * @param[in] dscp_table + * When non-NULL: it points to a pre-allocated and pre-populated table with + * exactly 64 elements providing the input color for each value of the + * IPv4/IPv6 Differentiated Services Code Point (DSCP) input packet field. + * When NULL: it is equivalent to setting this parameter to an “all-green” + * populated table (i.e. table with all the 64 elements set to green color). * @param[out] error * Error details. Filled in only on error, when not NULL. * @return @@ -633,10 +694,9 @@ rte_mtr_meter_dscp_table_update(uint16_t port_id, */ __rte_experimental int -rte_mtr_policer_actions_update(uint16_t port_id, +rte_mtr_meter_dscp_table_update(uint16_t port_id, uint32_t mtr_id, - uint32_t action_mask, - enum rte_mtr_policer_action *actions, + enum rte_color *dscp_table, struct rte_mtr_error *error); /** diff --git a/lib/librte_ethdev/rte_mtr_driver.h b/lib/librte_ethdev/rte_mtr_driver.h index a0ddc2b5f4..1ad8fb4c40 100644 --- a/lib/librte_ethdev/rte_mtr_driver.h +++ b/lib/librte_ethdev/rte_mtr_driver.h @@ -41,6 +41,23 @@ typedef int (*rte_mtr_meter_profile_delete_t)(struct rte_eth_dev *dev, struct rte_mtr_error *error); /**< @internal MTR meter profile delete */ +typedef int (*rte_mtr_meter_policy_validate_t)(struct rte_eth_dev *dev, + uint32_t policy_id, + const struct rte_flow_action *actions[RTE_COLORS], + struct rte_mtr_error *error); +/**< @internal MTR meter policy validate */ + +typedef int (*rte_mtr_meter_policy_add_t)(struct rte_eth_dev *dev, + uint32_t policy_id, + const struct rte_flow_action *actions[RTE_COLORS], + struct rte_mtr_error *error); +/**< @internal MTR meter policy add */ + +typedef int (*rte_mtr_meter_policy_delete_t)(struct rte_eth_dev *dev, + uint32_t policy_id, + struct rte_mtr_error *error); +/**< @internal MTR meter policy delete */ + typedef int (*rte_mtr_create_t)(struct rte_eth_dev *dev, uint32_t mtr_id, struct rte_mtr_params *params, @@ -69,18 +86,17 @@ typedef int (*rte_mtr_meter_profile_update_t)(struct rte_eth_dev *dev, struct rte_mtr_error *error); /**< @internal MTR object meter profile update */ -typedef int (*rte_mtr_meter_dscp_table_update_t)(struct rte_eth_dev *dev, +typedef int (*rte_mtr_meter_policy_update_t)(struct rte_eth_dev *dev, uint32_t mtr_id, - enum rte_color *dscp_table, + uint32_t meter_policy_id, struct rte_mtr_error *error); -/**< @internal MTR object meter DSCP table update */ +/**< @internal MTR object meter policy update */ -typedef int (*rte_mtr_policer_actions_update_t)(struct rte_eth_dev *dev, +typedef int (*rte_mtr_meter_dscp_table_update_t)(struct rte_eth_dev *dev, uint32_t mtr_id, - uint32_t action_mask, - enum rte_mtr_policer_action *actions, + enum rte_color *dscp_table, struct rte_mtr_error *error); -/**< @internal MTR object policer action update*/ +/**< @internal MTR object meter DSCP table update */ typedef int (*rte_mtr_stats_update_t)(struct rte_eth_dev *dev, uint32_t mtr_id, @@ -124,14 +140,23 @@ struct rte_mtr_ops { /** MTR object meter DSCP table update */ rte_mtr_meter_dscp_table_update_t meter_dscp_table_update; - /** MTR object policer action update */ - rte_mtr_policer_actions_update_t policer_actions_update; - /** MTR object enabled stats update */ rte_mtr_stats_update_t stats_update; /** MTR object stats read */ rte_mtr_stats_read_t stats_read; + + /** MTR meter policy validate */ + rte_mtr_meter_policy_validate_t meter_policy_validate; + + /** MTR meter policy add */ + rte_mtr_meter_policy_add_t meter_policy_add; + + /** MTR meter policy delete */ + rte_mtr_meter_policy_delete_t meter_policy_delete; + + /** MTR object meter policy update */ + rte_mtr_meter_policy_update_t meter_policy_update; }; /** From patchwork Thu Mar 18 08:58:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zhang X-Patchwork-Id: 89460 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1C731A0561; Thu, 18 Mar 2021 09:58:28 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20790140ED9; Thu, 18 Mar 2021 09:58:24 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id DF651140EB7 for ; Thu, 18 Mar 2021 09:58:21 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from lizh@nvidia.com) with SMTP; 18 Mar 2021 10:58:20 +0200 Received: from nvidia.com (c-235-17-1-009.mtl.labs.mlnx [10.235.17.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 12I8wH3K031633; Thu, 18 Mar 2021 10:58:20 +0200 From: Li Zhang To: dekelp@nvidia.com, orika@nvidia.com, viacheslavo@nvidia.com, matan@nvidia.com, shahafs@nvidia.com, lironh@marvell.com, jasvinder.singh@intel.com, Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Cristian Dumitrescu Cc: dev@dpdk.org, rasland@nvidia.com, roniba@nvidia.com Date: Thu, 18 Mar 2021 10:58:15 +0200 Message-Id: <20210318085815.804896-2-lizh@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210318085815.804896-1-lizh@nvidia.com> References: <20210318085815.804896-1-lizh@nvidia.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/2] [RFC]: ethdev: manage meter API object handles by the drivers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently, all the meter objects are managed by the user IDs: meter, profile and policy. Hence, each PMD should manage data-structure in order to map each API ID to the private PMD management structure. From the application side, it has all the picture how meter is going to be assigned to flows and can easily use direct mapping even when the meter handler is provided by the PMDs. Also, this is the approach of the rte_flow API handles: the flow handle and the shared action handle is provided by the PMDs. Use drivers handlers in order to manage all the meter API objects. The following API will be changed: - rte_mtr_meter_profile_add - rte_mtr_meter_profile_delete - rte_mtr_meter_policy_validate - rte_mtr_meter_policy_add - rte_mtr_meter_policy_delete - rte_mtr_create - rte_mtr_destroy - rte_mtr_meter_disable - rte_mtr_meter_enable - rte_mtr_meter_profile_update - rte_mtr_meter_policy_update - rte_mtr_meter_dscp_table_update - rte_mtr_stats_update - rte_mtr_stats_read The next struct will be changed: - rte_flow_action_meter - rte_mtr_params Signed-off-by: Li Zhang --- lib/librte_ethdev/rte_flow.h | 9 ++- lib/librte_ethdev/rte_mtr.c | 77 ++++++++++++---------- lib/librte_ethdev/rte_mtr.h | 102 +++++++++++++++-------------- lib/librte_ethdev/rte_mtr_driver.h | 36 +++++----- 4 files changed, 122 insertions(+), 102 deletions(-) diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index 5f38aa7fa4..6d2b86592d 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -2480,6 +2480,13 @@ struct rte_flow_action_port_id { uint32_t id; /**< DPDK port ID. */ }; +/** + * Opaque type returned after successfully creating a meter. + * + * This handle can be used to manage the related meter (e.g. to destroy it). + */ +struct rte_mtr; + /** * RTE_FLOW_ACTION_TYPE_METER * @@ -2489,7 +2496,7 @@ struct rte_flow_action_port_id { * next item with their color set by the MTR object. */ struct rte_flow_action_meter { - uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */ + struct rte_mtr *mtr; /**< MTR object created with rte_mtr_create(). */ }; /** diff --git a/lib/librte_ethdev/rte_mtr.c b/lib/librte_ethdev/rte_mtr.c index fccec3760b..e407c6f956 100644 --- a/lib/librte_ethdev/rte_mtr.c +++ b/lib/librte_ethdev/rte_mtr.c @@ -57,6 +57,19 @@ rte_mtr_ops_get(uint16_t port_id, struct rte_mtr_error *error) ops->func; \ }) +#define RTE_MTR_FUNC_PTR(port_id, func) \ +({ \ + const struct rte_mtr_ops *ops = \ + rte_mtr_ops_get(port_id, error); \ + if (ops == NULL) \ + return NULL; \ + \ + if (ops->func == NULL) \ + return NULL; \ + \ + ops->func; \ +}) + /* MTR capabilities get */ int rte_mtr_capabilities_get(uint16_t port_id, @@ -69,26 +82,25 @@ rte_mtr_capabilities_get(uint16_t port_id, } /* MTR meter profile add */ -int +struct rte_mtr_profile * rte_mtr_meter_profile_add(uint16_t port_id, - uint32_t meter_profile_id, struct rte_mtr_meter_profile *profile, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - return RTE_MTR_FUNC(port_id, meter_profile_add)(dev, - meter_profile_id, profile, error); + return RTE_MTR_FUNC_PTR(port_id, meter_profile_add)(dev, + profile, error); } /** MTR meter profile delete */ int rte_mtr_meter_profile_delete(uint16_t port_id, - uint32_t meter_profile_id, + struct rte_mtr_profile *profile, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_profile_delete)(dev, - meter_profile_id, error); + profile, error); } /* MTR meter policy validate */ @@ -103,126 +115,123 @@ rte_mtr_meter_policy_validate(uint16_t port_id, } /* MTR meter policy add */ -int +struct rte_mtr_policy * rte_mtr_meter_policy_add(uint16_t port_id, - uint32_t policy_id, const struct rte_flow_action *actions[RTE_COLORS], struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - return RTE_MTR_FUNC(port_id, meter_policy_add)(dev, - policy_id, actions, error); + return RTE_MTR_FUNC_PTR(port_id, meter_policy_add)(dev, + actions, error); } /** MTR meter policy delete */ int rte_mtr_meter_policy_delete(uint16_t port_id, - uint32_t policy_id, + struct rte_mtr_policy *policy, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_policy_delete)(dev, - policy_id, error); + policy, error); } /** MTR object create */ -int +struct rte_mtr * rte_mtr_create(uint16_t port_id, - uint32_t mtr_id, struct rte_mtr_params *params, int shared, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - return RTE_MTR_FUNC(port_id, create)(dev, - mtr_id, params, shared, error); + return RTE_MTR_FUNC_PTR(port_id, create)(dev, params, shared, error); } /** MTR object destroy */ int rte_mtr_destroy(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, destroy)(dev, - mtr_id, error); + mtr, error); } /** MTR object meter enable */ int rte_mtr_meter_enable(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_enable)(dev, - mtr_id, error); + mtr, error); } /** MTR object meter disable */ int rte_mtr_meter_disable(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_disable)(dev, - mtr_id, error); + mtr, error); } /** MTR object meter profile update */ int rte_mtr_meter_profile_update(uint16_t port_id, - uint32_t mtr_id, - uint32_t meter_profile_id, + struct rte_mtr *mtr, + struct rte_mtr_profile *profile, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_profile_update)(dev, - mtr_id, meter_profile_id, error); + mtr, profile, error); } /** MTR object meter policy update */ int rte_mtr_meter_policy_update(uint16_t port_id, - uint32_t mtr_id, - uint32_t meter_policy_id, + struct rte_mtr *mtr, + struct rte_mtr_policy *policy, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_policy_update)(dev, - mtr_id, meter_policy_id, error); + mtr, policy, error); } /** MTR object meter DSCP table update */ int rte_mtr_meter_dscp_table_update(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, enum rte_color *dscp_table, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, meter_dscp_table_update)(dev, - mtr_id, dscp_table, error); + mtr, dscp_table, error); } /** MTR object enabled stats update */ int rte_mtr_stats_update(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, uint64_t stats_mask, struct rte_mtr_error *error) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, stats_update)(dev, - mtr_id, stats_mask, error); + mtr, stats_mask, error); } /** MTR object stats read */ int rte_mtr_stats_read(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_stats *stats, uint64_t *stats_mask, int clear, @@ -230,5 +239,5 @@ rte_mtr_stats_read(uint16_t port_id, { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; return RTE_MTR_FUNC(port_id, stats_read)(dev, - mtr_id, stats, stats_mask, clear, error); + mtr, stats, stats_mask, clear, error); } diff --git a/lib/librte_ethdev/rte_mtr.h b/lib/librte_ethdev/rte_mtr.h index 07961f2777..2b20e55079 100644 --- a/lib/librte_ethdev/rte_mtr.h +++ b/lib/librte_ethdev/rte_mtr.h @@ -181,8 +181,8 @@ struct rte_mtr_meter_profile { * @see enum rte_mtr_stats_type */ struct rte_mtr_params { - /** Meter profile ID. */ - uint32_t meter_profile_id; + /** Meter profile. */ + struct rte_mtr_profile *profile; /** Meter input color in case of MTR object chaining. When non-zero: if * a previous MTR object is enabled in the same flow, then the color @@ -221,8 +221,8 @@ struct rte_mtr_params { */ uint64_t stats_mask; - /** Meter policy ID. */ - uint32_t meter_policy_id; + /** Meter policy. */ + struct rte_mtr_policy *policy; }; /** @@ -395,28 +395,32 @@ rte_mtr_capabilities_get(uint16_t port_id, struct rte_mtr_capabilities *cap, struct rte_mtr_error *error); +/** + * Opaque type returned after successfully creating a profile. + * + * This handle can be used to manage the related profile (e.g. to destroy it). + */ +struct rte_mtr_profile; + /** * Meter profile add * - * Create a new meter profile with ID set to *meter_profile_id*. The new profile + * Create a new meter profile. The new profile * is used to create one or several MTR objects. * * @param[in] port_id * The port identifier of the Ethernet device. - * @param[in] meter_profile_id - * ID for the new meter profile. Needs to be unused by any of the existing - * meter profiles added for the current port. * @param[in] profile * Meter profile parameters. Needs to be pre-allocated and valid. * @param[out] error * Error details. Filled in only on error, when not NULL. * @return - * 0 on success, non-zero error code otherwise. + * A valid handle in case of success, NULL otherwise and rte_errno is set + * to the positive version of one of the error codes. */ __rte_experimental -int +struct rte_mtr_profile * rte_mtr_meter_profile_add(uint16_t port_id, - uint32_t meter_profile_id, struct rte_mtr_meter_profile *profile, struct rte_mtr_error *error); @@ -428,8 +432,8 @@ rte_mtr_meter_profile_add(uint16_t port_id, * * @param[in] port_id * The port identifier of the Ethernet device. - * @param[in] meter_profile_id - * Meter profile ID. Needs to be the valid. + * @param[in] profile + * Meter profile pointer. Needs to be the valid. * @param[out] error * Error details. Filled in only on error, when not NULL. * @return @@ -438,16 +442,15 @@ rte_mtr_meter_profile_add(uint16_t port_id, __rte_experimental int rte_mtr_meter_profile_delete(uint16_t port_id, - uint32_t meter_profile_id, + struct rte_mtr_profile *profile, struct rte_mtr_error *error); /** - * Policy id 0 is default policy. - * Action per color as below: - * green - no action, yellow - no action, red - drop - * It can be used without creating it by the rte_mtr_meter_policy_add function. + * Opaque type returned after successfully creating a policy. + * + * This handle can be used to manage the related policy (e.g. to destroy it). */ -#define RTE_MTR_DEFAULT_POLICY_ID 0 +struct rte_mtr_policy; /** * Check whether a meter policy can be created on a given port. @@ -478,7 +481,6 @@ rte_mtr_meter_profile_delete(uint16_t port_id, __rte_experimental int rte_mtr_meter_policy_validate(uint16_t port_id, - uint32_t policy_id, const struct rte_flow_action *actions[RTE_COLORS], struct rte_mtr_error *error); @@ -490,8 +492,6 @@ rte_mtr_meter_policy_validate(uint16_t port_id, * * @param[in] port_id * The port identifier of the Ethernet device. - * @param[in] policy_id - * Policy identifier for the new meter policy. * @param[in] actions * Associated actions per color. * list NULL is legal and means no special action. @@ -499,12 +499,12 @@ rte_mtr_meter_policy_validate(uint16_t port_id, * @param[out] error * Error details. Filled in only on error, when not NULL. * @return - * 0 on success, non-zero error code otherwise. + * A valid handle in case of success, NULL otherwise and rte_errno is set + * to the positive version of one of the error codes. */ __rte_experimental -int +struct rte_mtr_policy * rte_mtr_meter_policy_add(uint16_t port_id, - uint32_t policy_id, const struct rte_flow_action *actions[RTE_COLORS], struct rte_mtr_error *error); @@ -516,8 +516,8 @@ rte_mtr_meter_policy_add(uint16_t port_id, * * @param[in] port_id * The port identifier of the Ethernet device. - * @param[in] policy_id - * Policy identifier. + * @param[in] policy + * Policy pointer. Needs to be valid. * @param[out] error * Error details. Filled in only on error, when not NULL. * @return @@ -526,20 +526,28 @@ rte_mtr_meter_policy_add(uint16_t port_id, __rte_experimental int rte_mtr_meter_policy_delete(uint16_t port_id, - uint32_t policy_id, + struct rte_mtr_policy *policy, struct rte_mtr_error *error); +/** + * Opaque type returned after successfully creating a meter. + * + * This handle can be used to manage the related meter (e.g. to destroy it). + */ +struct rte_mtr; + /** * MTR object create * * Create a new MTR object for the current port. This object is run as part of * associated flow action for traffic metering and policing. + * Policy pointer NULL is default policy. + * Action per color as below: + * green - no action, yellow - no action, red - drop + * It can be used without creating it by the rte_mtr_meter_policy_add function. * * @param[in] port_id * The port identifier of the Ethernet device. - * @param[in] mtr_id - * MTR object ID. Needs to be unused by any of the existing MTR objects. - * created for the current port. * @param[in] params * MTR object params. Needs to be pre-allocated and valid. * @param[in] shared @@ -548,14 +556,14 @@ rte_mtr_meter_policy_delete(uint16_t port_id, * @param[out] error * Error details. Filled in only on error, when not NULL. * @return - * 0 on success, non-zero error code otherwise. + * A valid handle in case of success, NULL otherwise and rte_errno is set + * to the positive version of one of the error codes. * * @see enum rte_flow_action_type::RTE_FLOW_ACTION_TYPE_METER */ __rte_experimental -int +struct rte_mtr * rte_mtr_create(uint16_t port_id, - uint32_t mtr_id, struct rte_mtr_params *params, int shared, struct rte_mtr_error *error); @@ -568,8 +576,8 @@ rte_mtr_create(uint16_t port_id, * * @param[in] port_id * The port identifier of the Ethernet device. - * @param[in] mtr_id - * MTR object ID. Needs to be valid. + * @param[in] mtr + * MTR pointer. Needs to be valid. * created for the current port. * @param[out] error * Error details. Filled in only on error, when not NULL. @@ -579,7 +587,7 @@ rte_mtr_create(uint16_t port_id, __rte_experimental int rte_mtr_destroy(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error); /** @@ -607,7 +615,7 @@ rte_mtr_destroy(uint16_t port_id, __rte_experimental int rte_mtr_meter_disable(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error); /** @@ -629,7 +637,7 @@ rte_mtr_meter_disable(uint16_t port_id, __rte_experimental int rte_mtr_meter_enable(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error); /** @@ -649,8 +657,8 @@ rte_mtr_meter_enable(uint16_t port_id, __rte_experimental int rte_mtr_meter_profile_update(uint16_t port_id, - uint32_t mtr_id, - uint32_t meter_profile_id, + struct rte_mtr *mtr, + struct rte_mtr_profile *profile, struct rte_mtr_error *error); /** @@ -660,8 +668,6 @@ rte_mtr_meter_profile_update(uint16_t port_id, * The port identifier of the Ethernet device. * @param[in] mtr_id * MTR object ID. Needs to be valid. - * @param[in] meter_policy_id - * Meter policy ID for the current MTR object. Needs to be valid. * @param[out] error * Error details. Filled in only on error, when not NULL. * @return @@ -670,8 +676,8 @@ rte_mtr_meter_profile_update(uint16_t port_id, __rte_experimental int rte_mtr_meter_policy_update(uint16_t port_id, - uint32_t mtr_id, - uint32_t meter_policy_id, + struct rte_mtr *mtr, + struct rte_mtr_policy *policy, struct rte_mtr_error *error); /** @@ -695,7 +701,7 @@ rte_mtr_meter_policy_update(uint16_t port_id, __rte_experimental int rte_mtr_meter_dscp_table_update(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, enum rte_color *dscp_table, struct rte_mtr_error *error); @@ -720,7 +726,7 @@ rte_mtr_meter_dscp_table_update(uint16_t port_id, __rte_experimental int rte_mtr_stats_update(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, uint64_t stats_mask, struct rte_mtr_error *error); @@ -752,7 +758,7 @@ rte_mtr_stats_update(uint16_t port_id, __rte_experimental int rte_mtr_stats_read(uint16_t port_id, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_stats *stats, uint64_t *stats_mask, int clear, diff --git a/lib/librte_ethdev/rte_mtr_driver.h b/lib/librte_ethdev/rte_mtr_driver.h index 1ad8fb4c40..d7a8853b51 100644 --- a/lib/librte_ethdev/rte_mtr_driver.h +++ b/lib/librte_ethdev/rte_mtr_driver.h @@ -30,82 +30,80 @@ typedef int (*rte_mtr_capabilities_get_t)(struct rte_eth_dev *dev, struct rte_mtr_error *error); /**< @internal MTR capabilities get */ -typedef int (*rte_mtr_meter_profile_add_t)(struct rte_eth_dev *dev, - uint32_t meter_profile_id, +typedef struct rte_mtr_profile *(*rte_mtr_meter_profile_add_t) + (struct rte_eth_dev *dev, struct rte_mtr_meter_profile *profile, struct rte_mtr_error *error); /**< @internal MTR meter profile add */ typedef int (*rte_mtr_meter_profile_delete_t)(struct rte_eth_dev *dev, - uint32_t meter_profile_id, + struct rte_mtr_profile *profile, struct rte_mtr_error *error); /**< @internal MTR meter profile delete */ typedef int (*rte_mtr_meter_policy_validate_t)(struct rte_eth_dev *dev, - uint32_t policy_id, const struct rte_flow_action *actions[RTE_COLORS], struct rte_mtr_error *error); /**< @internal MTR meter policy validate */ -typedef int (*rte_mtr_meter_policy_add_t)(struct rte_eth_dev *dev, - uint32_t policy_id, +typedef struct rte_mtr_policy *(*rte_mtr_meter_policy_add_t) + (struct rte_eth_dev *dev, const struct rte_flow_action *actions[RTE_COLORS], struct rte_mtr_error *error); /**< @internal MTR meter policy add */ typedef int (*rte_mtr_meter_policy_delete_t)(struct rte_eth_dev *dev, - uint32_t policy_id, + struct rte_mtr_policy *policy, struct rte_mtr_error *error); /**< @internal MTR meter policy delete */ -typedef int (*rte_mtr_create_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, +typedef struct rte_mtr *(*rte_mtr_create_t)(struct rte_eth_dev *dev, struct rte_mtr_params *params, int shared, struct rte_mtr_error *error); /**< @internal MTR object create */ typedef int (*rte_mtr_destroy_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error); /**< @internal MTR object destroy */ typedef int (*rte_mtr_meter_enable_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error); /**< @internal MTR object meter enable */ typedef int (*rte_mtr_meter_disable_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_error *error); /**< @internal MTR object meter disable */ typedef int (*rte_mtr_meter_profile_update_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, - uint32_t meter_profile_id, + struct rte_mtr *mtr, + struct rte_mtr_profile *profile, struct rte_mtr_error *error); /**< @internal MTR object meter profile update */ typedef int (*rte_mtr_meter_policy_update_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, - uint32_t meter_policy_id, + struct rte_mtr *mtr, + struct rte_mtr_policy *policy, struct rte_mtr_error *error); /**< @internal MTR object meter policy update */ typedef int (*rte_mtr_meter_dscp_table_update_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, + struct rte_mtr *mtr, enum rte_color *dscp_table, struct rte_mtr_error *error); /**< @internal MTR object meter DSCP table update */ typedef int (*rte_mtr_stats_update_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, + struct rte_mtr *mtr, uint64_t stats_mask, struct rte_mtr_error *error); /**< @internal MTR object enabled stats update */ typedef int (*rte_mtr_stats_read_t)(struct rte_eth_dev *dev, - uint32_t mtr_id, + struct rte_mtr *mtr, struct rte_mtr_stats *stats, uint64_t *stats_mask, int clear,