<commit_before>/* SPDX-License-Identifier: BSD-3-Clause
 *
 *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
 *   Copyright 2016-2019 NXP
 *
 */

#include <time.h>
#include <net/if.h>

#include <rte_mbuf.h>
#include <rte_ethdev_driver.h>
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_string_fns.h>
#include <rte_cycles.h>
#include <rte_kvargs.h>
#include <rte_dev.h>

#include <dpaa2_pmd_logs.h>
#include <dpaa2_hw_pvt.h>
#include <dpaa2_hw_mempool.h>

#include "../dpaa2_ethdev.h"

int
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.extracts[0].num_of_byte_masks = 0;
	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, int tc_index)
{
	struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
	struct fsl_mc_io *dpni = priv->hw;
	struct dpni_rx_dist_cfg tc_cfg;
	struct dpkg_profile_cfg kg_cfg;
	void *p_params;
	int ret;

	p_params = rte_malloc(
		NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
	if (!p_params) {
		DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
		return -ENOMEM;
	}

	memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
	memset(&tc_cfg, 0, sizeof(struct dpni_rx_dist_cfg));

	ret = dpaa2_distset_to_dpkg_profile_cfg(req_dist_set, &kg_cfg);
	if (ret) {
		DPAA2_PMD_ERR("Given RSS Hash (%" PRIx64 ") not supported",
			      req_dist_set);
		rte_free(p_params);
		return ret;
	}

	tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
	tc_cfg.dist_size = priv->dist_queues;
	tc_cfg.enable = true;
	tc_cfg.tc = tc_index;

	ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);<commit_msg>net/dpaa2: configure per-class distribution size<commit_after>/* SPDX-License-Identifier: BSD-3-Clause
 *
 *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
 *   Copyright 2016-2019 NXP
 *
 */

#include <time.h>
#include <net/if.h>

#include <rte_mbuf.h>
#include <rte_ethdev_driver.h>
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_string_fns.h>
#include <rte_cycles.h>
#include <rte_kvargs.h>
#include <rte_dev.h>

#include <dpaa2_pmd_logs.h>
#include <dpaa2_hw_pvt.h>
#include <dpaa2_hw_mempool.h>

#include "../dpaa2_ethdev.h"

int
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.extracts[0].num_of_byte_masks = 0;
	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, int tc_index)
{
	struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
	struct fsl_mc_io *dpni = priv->hw;
	struct dpni_rx_dist_cfg tc_cfg;
	struct dpkg_profile_cfg kg_cfg;
	void *p_params;
	int ret, tc_dist_queues;

	/*TC distribution size is set with dist_queues or
	 * nb_rx_queues % dist_queues in order of TC priority index.
	 * Calculating dist size for this tc_index:-
	 */
	tc_dist_queues = eth_dev->data->nb_rx_queues -
		tc_index * priv->dist_queues;
	if (tc_dist_queues <= 0) {
		DPAA2_PMD_INFO("No distribution on TC%d", tc_index);
		return 0;
	}

	if (tc_dist_queues > priv->dist_queues)
		tc_dist_queues = priv->dist_queues;

	p_params = rte_malloc(
		NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
	if (!p_params) {
		DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
		return -ENOMEM;
	}

	memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
	memset(&tc_cfg, 0, sizeof(struct dpni_rx_dist_cfg));

	ret = dpaa2_distset_to_dpkg_profile_cfg(req_dist_set, &kg_cfg);
	if (ret) {
		DPAA2_PMD_ERR("Given RSS Hash (%" PRIx64 ") not supported",
			      req_dist_set);
		rte_free(p_params);
		return ret;
	}

	tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
	tc_cfg.dist_size = tc_dist_queues;
	tc_cfg.enable = true;
	tc_cfg.tc = tc_index;

	ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
{'fraction_non_alphanumeric': 0.11529484985218609, 'fraction_numerical': 0.01742648202894041, 'mean_word_length': 5.081362346263009, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4808454', 'n_tokens_mistral': 2980, 'n_tokens_neox': 2831, 'n_words': 493}