From: Ori Kam <orika@nvidia.com>
To: <dsosnowski@nvidia.com>, <ferruh.yigit@amd.com>,
<cristian.dumitrescu@intel.com>, <andrew.rybchenko@oktetlabs.ru>,
<stephen@networkplumber.org>,
Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
Suanming Mou <suanmingm@nvidia.com>,
Matan Azrad <matan@nvidia.com>
Cc: <dev@dpdk.org>, <orika@nvidia.com>, <rasland@nvidia.com>
Subject: [PATCH v2 3/4] net/mlx5: add calc encap hash support
Date: Thu, 8 Feb 2024 11:09:18 +0200 [thread overview]
Message-ID: <20240208090919.11565-3-orika@nvidia.com> (raw)
In-Reply-To: <20240208090919.11565-1-orika@nvidia.com>
This commit adds support for encap hash calculation.
Signed-off-by: Ori Kam <orika@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
drivers/net/mlx5/mlx5_flow.c | 29 +++++++++++++++
drivers/net/mlx5/mlx5_flow.h | 8 ++++
drivers/net/mlx5/mlx5_flow_hw.c | 66 +++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+)
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 5159e8e773..0fb6b3b374 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -1197,6 +1197,12 @@ mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
const struct rte_flow_item pattern[],
uint8_t pattern_template_index,
uint32_t *hash, struct rte_flow_error *error);
+static int
+mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
+ const struct rte_flow_item pattern[],
+ enum rte_flow_encap_hash_field dest_field,
+ uint8_t *hash,
+ struct rte_flow_error *error);
static const struct rte_flow_ops mlx5_flow_ops = {
.validate = mlx5_flow_validate,
@@ -1253,6 +1259,7 @@ static const struct rte_flow_ops mlx5_flow_ops = {
.async_action_list_handle_query_update =
mlx5_flow_async_action_list_handle_query_update,
.flow_calc_table_hash = mlx5_flow_calc_table_hash,
+ .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
};
/* Tunnel information. */
@@ -11121,6 +11128,28 @@ mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
hash, error);
}
+static int
+mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
+ const struct rte_flow_item pattern[],
+ enum rte_flow_encap_hash_field dest_field,
+ uint8_t *hash,
+ struct rte_flow_error *error)
+{
+ enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
+ const struct mlx5_flow_driver_ops *fops;
+
+ if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
+ return rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ NULL, "invalid driver type");
+ fops = flow_get_drv_ops(drv_type);
+ if (!fops || !fops->flow_calc_encap_hash)
+ return rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ NULL, "no calc encap hash handler");
+ return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
+}
+
/**
* Destroy all indirect actions (shared RSS).
*
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index c9cc942d80..5a8404b9b3 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -2195,6 +2195,13 @@ typedef int
const struct rte_flow_item pattern[],
uint8_t pattern_template_index,
uint32_t *hash, struct rte_flow_error *error);
+typedef int
+(*mlx5_flow_calc_encap_hash_t)
+ (struct rte_eth_dev *dev,
+ const struct rte_flow_item pattern[],
+ enum rte_flow_encap_hash_field dest_field,
+ uint8_t *hash,
+ struct rte_flow_error *error);
struct mlx5_flow_driver_ops {
mlx5_flow_validate_t validate;
@@ -2268,6 +2275,7 @@ struct mlx5_flow_driver_ops {
mlx5_flow_async_action_list_handle_query_update_t
async_action_list_handle_query_update;
mlx5_flow_calc_table_hash_t flow_calc_table_hash;
+ mlx5_flow_calc_encap_hash_t flow_calc_encap_hash;
};
/* mlx5_flow.c */
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index 7510715189..d81ca96b7b 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -11628,6 +11628,71 @@ flow_hw_calc_table_hash(struct rte_eth_dev *dev,
return 0;
}
+static int
+flow_hw_calc_encap_hash(struct rte_eth_dev *dev,
+ const struct rte_flow_item pattern[],
+ enum rte_flow_encap_hash_field dest_field,
+ uint8_t *hash,
+ struct rte_flow_error *error)
+{
+ struct mlx5_priv *priv = dev->data->dev_private;
+ struct mlx5dr_crc_encap_entropy_hash_fields data;
+ enum mlx5dr_crc_encap_entropy_hash_size res_size =
+ dest_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ?
+ MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16 :
+ MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8;
+ int res;
+
+ memset(&data, 0, sizeof(struct mlx5dr_crc_encap_entropy_hash_fields));
+
+ for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
+ switch (pattern->type) {
+ case RTE_FLOW_ITEM_TYPE_IPV4:
+ data.dst.ipv4_addr =
+ ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.dst_addr;
+ data.src.ipv4_addr =
+ ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.src_addr;
+ break;
+ case RTE_FLOW_ITEM_TYPE_IPV6:
+ memcpy(data.dst.ipv6_addr,
+ ((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.dst_addr,
+ sizeof(data.dst.ipv6_addr));
+ memcpy(data.src.ipv6_addr,
+ ((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.src_addr,
+ sizeof(data.src.ipv6_addr));
+ break;
+ case RTE_FLOW_ITEM_TYPE_UDP:
+ data.next_protocol = IPPROTO_UDP;
+ data.dst_port =
+ ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.dst_port;
+ data.src_port =
+ ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.src_port;
+ break;
+ case RTE_FLOW_ITEM_TYPE_TCP:
+ data.next_protocol = IPPROTO_TCP;
+ data.dst_port =
+ ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.dst_port;
+ data.src_port =
+ ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.src_port;
+ break;
+ case RTE_FLOW_ITEM_TYPE_ICMP:
+ data.next_protocol = IPPROTO_ICMP;
+ break;
+ case RTE_FLOW_ITEM_TYPE_ICMP6:
+ data.next_protocol = IPPROTO_ICMPV6;
+ break;
+ default:
+ break;
+ }
+ }
+ res = mlx5dr_crc_encap_entropy_hash_calc(priv->dr_ctx, &data, hash, res_size);
+ if (res)
+ return rte_flow_error_set(error, res,
+ RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+ NULL, "error while calculating encap hash");
+ return 0;
+}
+
const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = {
.info_get = flow_hw_info_get,
.configure = flow_hw_configure,
@@ -11673,6 +11738,7 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = {
.item_create = flow_dv_item_create,
.item_release = flow_dv_item_release,
.flow_calc_table_hash = flow_hw_calc_table_hash,
+ .flow_calc_encap_hash = flow_hw_calc_encap_hash,
};
/**
--
2.34.1
next prev parent reply other threads:[~2024-02-08 9:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 9:39 [PATCH 0/4] introduce encap hash calculation Ori Kam
2024-01-28 9:39 ` [PATCH 1/4] ethdev: " Ori Kam
2024-02-01 8:40 ` Ori Kam
2024-02-06 22:39 ` Thomas Monjalon
2024-02-07 6:56 ` Ori Kam
2024-02-07 9:25 ` Thomas Monjalon
2024-01-28 9:39 ` [PATCH 2/4] net/mlx5/hws: introduce encap entropy hash calculation API Ori Kam
2024-01-28 9:39 ` [PATCH 3/4] net/mlx5: add calc encap hash support Ori Kam
2024-01-28 9:39 ` [PATCH 4/4] app/testpmd: add encap hash calculation Ori Kam
2024-01-31 18:30 ` [PATCH 0/4] introduce " Dariusz Sosnowski
2024-02-08 9:09 ` [PATCH v2 1/4] ethdev: " Ori Kam
2024-02-08 9:09 ` [PATCH v2 2/4] net/mlx5/hws: introduce encap entropy hash calculation API Ori Kam
2024-02-08 9:09 ` Ori Kam [this message]
2024-02-08 9:09 ` [PATCH v2 4/4] app/testpmd: add encap hash calculation Ori Kam
2024-02-08 17:13 ` [PATCH v2 1/4] ethdev: introduce " Ferruh Yigit
2024-02-11 7:29 ` Ori Kam
2024-02-12 17:05 ` Ferruh Yigit
2024-02-12 18:44 ` Ori Kam
2024-02-12 20:09 ` Ferruh Yigit
2024-02-13 7:05 ` Ori Kam
2024-02-13 13:48 ` [PATCH v3 " Ori Kam
2024-02-13 13:48 ` [PATCH v3 2/4] net/mlx5/hws: introduce encap entropy hash calculation API Ori Kam
2024-02-13 13:48 ` [PATCH v3 3/4] net/mlx5: add calc encap hash support Ori Kam
2024-02-13 13:48 ` [PATCH v3 4/4] app/testpmd: add encap hash calculation Ori Kam
2024-02-13 14:16 ` [PATCH v4 1/4] ethdev: introduce " Ori Kam
2024-02-13 14:16 ` [PATCH v4 2/4] net/mlx5/hws: introduce encap entropy hash calculation API Ori Kam
2024-02-13 14:16 ` [PATCH v4 3/4] net/mlx5: add calc encap hash support Ori Kam
2024-02-13 14:16 ` [PATCH v4 4/4] app/testpmd: add encap hash calculation Ori Kam
2024-02-13 15:45 ` Ferruh Yigit
2024-02-13 15:45 ` [PATCH v4 1/4] ethdev: introduce " Ferruh Yigit
2024-02-13 15:45 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240208090919.11565-3-orika@nvidia.com \
--to=orika@nvidia.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=cristian.dumitrescu@intel.com \
--cc=dev@dpdk.org \
--cc=dsosnowski@nvidia.com \
--cc=ferruh.yigit@amd.com \
--cc=matan@nvidia.com \
--cc=rasland@nvidia.com \
--cc=stephen@networkplumber.org \
--cc=suanmingm@nvidia.com \
--cc=viacheslavo@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).