[RFC] ethdev: add calcualte hash function

Message ID 20230803131014.3436-1-orika@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Series [RFC] ethdev: add calcualte hash function |


Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Functional success Functional PASS

Commit Message

Ori Kam Aug. 3, 2023, 1:10 p.m. UTC
  rte_flow supports insert by index table[1].

Using the above table, the application can create rules
that are based on hash.
For example application can create the following logic in order
to create load balancing:
1. Create insert by index table with 2 rules, that hashes based on dmac
2. Insert to index 0 a rule that sends the traffic to port A.
3. Insert to index 1 a rule that sends the traffic to port B.

Let's also assume that before this table, there is a 5 tuple
match table that jumps to the above table.

So each packet that matches one of the 5 tuple rules is RSSed
to port A or B, based on dmac hash.

The issue arises when there is a miss on the 5 tuple table,
which resulted due to the packet being the first packet of this flow, or
fragmented packet or any other reason.
In this case, the application must calculate what would be the
hash calculated by the HW so it can send the packet to the correct

This new API allows applications to calculate the hash value of a given
packet for a given table.

[1] - http://patches.dpdk.org/project/dpdk/patch/20230208030624.78465-2-akozyrev@nvidia.com/

Signed-off-by: Ori Kam <orika@nvidia.com>
 lib/ethdev/rte_flow.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)


diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 86ed98c562..85a9964437 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -6636,6 +6636,38 @@  rte_flow_async_action_list_handle_query_update(uint16_t port_id, uint32_t queue_
 					  void *user_data,
 					  struct rte_flow_error *error);
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Calculate the hash for a given pattern in a given table as
+ * calculated by the HW.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param table
+ *   The table the SW wishes to simulate.
+ * @param pattern_template_index
+ *   The pattern index in the table to be used for the calculation.
+ * @param pattern
+ *   The values to be used in the hash calculation.
+ * @param hash
+ *   Used to return the calculated hash.
+ * @param error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   - (0) if success.
+ * - (-ENODEV) if *port_id* invalid.
+ * - (-ENOTSUP) if underlying device does not support this functionality.
+ */
+rte_flow_calc_table_hash(uint16_t port_id, const struct rte_flow_template_table *table,
+			 uint8_t pattern_template_index, const struct rte_flow_item pattern[],
+			 uint32_t *hash, struct rte_flow_error *error);
 #ifdef __cplusplus