diff mbox series

[v2,16/20] net/dpaa2: add API to support custom hash key

Message ID 20190111115712.6482-17-shreyansh.jain@nxp.com
State New
Headers show
Series None | expand

Commit Message

Shreyansh Jain Jan. 11, 2019, 11:58 a.m. UTC
From: Nipun Gupta <nipun.gupta@nxp.com>


The DPAA2 hw can support a special offset based
configuration to program distribution on hash.
This is for all cases, which are not directly supported.

e.g. HASH based distribution on inner ip header
of a GRE tunnel.

Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>

---
 drivers/net/dpaa2/base/dpaa2_hw_dpni.c      | 52 ++++++++++++++++++++-
 drivers/net/dpaa2/rte_pmd_dpaa2.h           | 28 +++++++++++
 drivers/net/dpaa2/rte_pmd_dpaa2_version.map |  1 +
 3 files changed, 80 insertions(+), 1 deletion(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/drivers/net/dpaa2/base/dpaa2_hw_dpni.c b/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
index a6f86df8c..11f14931e 100644
--- a/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
+++ b/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
@@ -1,7 +1,7 @@ 
 /* SPDX-License-Identifier: BSD-3-Clause
  *
  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
- *   Copyright 2016 NXP
+ *   Copyright 2016-2018 NXP
  *
  */
 
@@ -28,6 +28,56 @@  dpaa2_distset_to_dpkg_profile_cfg(
 		uint64_t req_dist_set,
 		struct dpkg_profile_cfg *kg_cfg);
 
+int
+rte_pmd_dpaa2_set_custom_hash(uint16_t port_id,
+			      uint16_t offset,
+			      uint8_t size)
+{
+	struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
+	struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
+	struct fsl_mc_io *dpni = priv->hw;
+	struct dpni_rx_tc_dist_cfg tc_cfg;
+	struct dpkg_profile_cfg kg_cfg;
+	void *p_params;
+	int ret, tc_index = 0;
+
+	p_params = rte_zmalloc(
+		NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
+	if (!p_params) {
+		DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
+		return -ENOMEM;
+	}
+
+	kg_cfg.extracts[0].type = DPKG_EXTRACT_FROM_DATA;
+	kg_cfg.extracts[0].extract.from_data.offset = offset;
+	kg_cfg.extracts[0].extract.from_data.size = size;
+	kg_cfg.num_extracts = 1;
+
+	ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
+	if (ret) {
+		DPAA2_PMD_ERR("Unable to prepare extract parameters");
+		rte_free(p_params);
+		return ret;
+	}
+
+	memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
+	tc_cfg.key_cfg_iova = (size_t)(DPAA2_VADDR_TO_IOVA(p_params));
+	tc_cfg.dist_size = eth_dev->data->nb_rx_queues;
+	tc_cfg.dist_mode = DPNI_DIST_MODE_HASH;
+
+	ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
+				  &tc_cfg);
+	rte_free(p_params);
+	if (ret) {
+		DPAA2_PMD_ERR(
+			     "Setting distribution for Rx failed with err: %d",
+			     ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 int
 dpaa2_setup_flow_dist(struct rte_eth_dev *eth_dev,
 		      uint64_t req_dist_set)
diff --git a/drivers/net/dpaa2/rte_pmd_dpaa2.h b/drivers/net/dpaa2/rte_pmd_dpaa2.h
index 57de27f21..7052d9da9 100644
--- a/drivers/net/dpaa2/rte_pmd_dpaa2.h
+++ b/drivers/net/dpaa2/rte_pmd_dpaa2.h
@@ -59,4 +59,32 @@  rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id,
 			      struct rte_flow_item *pattern[],
 			      struct rte_flow_action *actions[]);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Create a custom hash key on basis of offset of start of packet and size.
+ * for e.g. if we need GRE packets (non-vlan and without any extra headers)
+ * to be hashed on basis of inner IP header, we will provide offset as:
+ * 14 (eth) + 20 (IP) + 4 (GRE) + 12 (Inner Src offset) = 50 and size
+ * as 8 bytes.
+ *
+ * @param port_id
+ *    The port identifier of the Ethernet device.
+ * @param offset
+ *    Offset from the start of packet which needs to be included to
+ *    calculate hash
+ * @param size
+ *    Size of the hash input key
+ *
+ * @return
+ *   - 0 if successful.
+ *   - Negative in case of failure.
+ */
+__rte_experimental
+int
+rte_pmd_dpaa2_set_custom_hash(uint16_t port_id,
+			      uint16_t offset,
+			      uint8_t size);
+
 #endif /* _RTE_PMD_DPAA2_H */
diff --git a/drivers/net/dpaa2/rte_pmd_dpaa2_version.map b/drivers/net/dpaa2/rte_pmd_dpaa2_version.map
index 1661c5fb5..d1b4cdb23 100644
--- a/drivers/net/dpaa2/rte_pmd_dpaa2_version.map
+++ b/drivers/net/dpaa2/rte_pmd_dpaa2_version.map
@@ -15,5 +15,6 @@  EXPERIMENTAL {
 	global:
 
 	rte_pmd_dpaa2_mux_flow_create;
+	rte_pmd_dpaa2_set_custom_hash;
 	rte_pmd_dpaa2_set_timestamp;
 } DPDK_17.11;