<commit_before>/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2017 6WIND S.A.
 * Copyright 2017 Mellanox Technologies, Ltd
 */

/**
 * @file
 * Flow API operations for mlx4 driver.
 */

#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <sys/queue.h>

/* Verbs headers do not support -pedantic. */
#ifdef PEDANTIC
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include <infiniband/verbs.h>
#ifdef PEDANTIC
#pragma GCC diagnostic error "-Wpedantic"
#endif

#include <rte_byteorder.h>
#include <rte_errno.h>
#include <rte_eth_ctrl.h>
#include <rte_ethdev_driver.h>
#include <rte_ether.h>
#include <rte_flow.h>
#include <rte_flow_driver.h>
#include <rte_malloc.h>

/* PMD headers. */
#include "mlx4.h"
#include "mlx4_glue.h"
#include "mlx4_flow.h"
#include "mlx4_rxtx.h"
#include "mlx4_utils.h"

/** Static initializer for a list of subsequent item types. */
#define NEXT_ITEM(...) \
	(const enum rte_flow_item_type []){ \
		__VA_ARGS__, RTE_FLOW_ITEM_TYPE_END, \
	}

/** Processor structure associated with a flow item. */
struct mlx4_flow_proc_item {
	/** Bit-mask for fields supported by this PMD. */
	const void *mask_support;
	/** Bit-mask to use when @p item->mask is not provided. */
	const void *mask_default;
	/** Size in bytes for @p mask_support and @p mask_default. */
	const unsigned int mask_sz;
	/** Merge a pattern item into a flow rule handle. */
	int (*merge)(struct rte_flow *flow,
		     const struct rte_flow_item *item,
		     const struct mlx4_flow_proc_item *proc,
		     struct rte_flow_error *error);
	/** Size in bytes of the destination structure. */
	const unsigned int dst_sz;
	/** List of possible subsequent items. */
	const enum rte_flow_item_type *const next_item;
};

/** Shared resources for drop flow rules. */
struct mlx4_drop {
	struct ibv_qp *qp; /**< QP target. */
	struct ibv_cq *cq; /**< CQ associated with above QP. */
	struct priv *priv; /**< Back pointer to private data. */
	uint32_t refcnt; /**< Reference count. */
};

/**
 * Convert DPDK RSS hash types to their Verbs equivalent.
 *
 * This function returns the supported (default) set when @p types has
 * special value (uint64_t)-1.
 *
 * @param priv
 *   Pointer to private structure.
 * @param types
 *   Hash types in DPDK format (see struct rte_eth_rss_conf).
 *
 * @return
 *   A valid Verbs RSS hash fields mask for mlx4 on success, (uint64_t)-1
 *   otherwise and rte_errno is set.
 */
uint64_t
mlx4_conv_rss_types(struct priv *priv, uint64_t types)
{
	enum { IPV4, IPV6, TCP, UDP, };
	const uint64_t in[] = {
		[IPV4] = (ETH_RSS_IPV4 |
			  ETH_RSS_FRAG_IPV4 |
			  ETH_RSS_NONFRAG_IPV4_TCP |
			  ETH_RSS_NONFRAG_IPV4_UDP |
			  ETH_RSS_NONFRAG_IPV4_OTHER),
		[IPV6] = (ETH_RSS_IPV6 |
			  ETH_RSS_FRAG_IPV6 |
			  ETH_RSS_NONFRAG_IPV6_TCP |
			  ETH_RSS_NONFRAG_IPV6_UDP |
			  ETH_RSS_NONFRAG_IPV6_OTHER |
			  ETH_RSS_IPV6_EX |
			  ETH_RSS_IPV6_TCP_EX |
			  ETH_RSS_IPV6_UDP_EX),
		[TCP] = (ETH_RSS_NONFRAG_IPV4_TCP |
			 ETH_RSS_NONFRAG_IPV6_TCP |
			 ETH_RSS_IPV6_TCP_EX),
		[UDP] = (ETH_RSS_NONFRAG_IPV4_UDP |
			 ETH_RSS_NONFRAG_IPV6_UDP |
			 ETH_RSS_IPV6_UDP_EX),
	};
	const uint64_t out[RTE_DIM(in)] = {
		[IPV4] = IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4,
		[IPV6] = IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6,
		[TCP] = IBV_RX_HASH_SRC_PORT_TCP | IBV_RX_HASH_DST_PORT_TCP,
		[UDP] = IBV_RX_HASH_SRC_PORT_UDP | IBV_RX_HASH_DST_PORT_UDP,
	};
	uint64_t seen = 0;
	uint64_t conv = 0;
	unsigned int i;

	if (types == (uint64_t)-1)
		return priv->hw_rss_sup;
	for (i = 0; i != RTE_DIM(in); ++i)
		if (types & in[i]) {
			seen |= types & in[i];
			conv |= out[i];
		}
	if ((conv & priv->hw_rss_sup) == conv && !(types & ~seen))<commit_msg>net/mlx4: avoid constant recreations in function<commit_after>/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2017 6WIND S.A.
 * Copyright 2017 Mellanox Technologies, Ltd
 */

/**
 * @file
 * Flow API operations for mlx4 driver.
 */

#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <sys/queue.h>

/* Verbs headers do not support -pedantic. */
#ifdef PEDANTIC
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include <infiniband/verbs.h>
#ifdef PEDANTIC
#pragma GCC diagnostic error "-Wpedantic"
#endif

#include <rte_byteorder.h>
#include <rte_errno.h>
#include <rte_eth_ctrl.h>
#include <rte_ethdev_driver.h>
#include <rte_ether.h>
#include <rte_flow.h>
#include <rte_flow_driver.h>
#include <rte_malloc.h>

/* PMD headers. */
#include "mlx4.h"
#include "mlx4_glue.h"
#include "mlx4_flow.h"
#include "mlx4_rxtx.h"
#include "mlx4_utils.h"

/** Static initializer for a list of subsequent item types. */
#define NEXT_ITEM(...) \
	(const enum rte_flow_item_type []){ \
		__VA_ARGS__, RTE_FLOW_ITEM_TYPE_END, \
	}

/** Processor structure associated with a flow item. */
struct mlx4_flow_proc_item {
	/** Bit-mask for fields supported by this PMD. */
	const void *mask_support;
	/** Bit-mask to use when @p item->mask is not provided. */
	const void *mask_default;
	/** Size in bytes for @p mask_support and @p mask_default. */
	const unsigned int mask_sz;
	/** Merge a pattern item into a flow rule handle. */
	int (*merge)(struct rte_flow *flow,
		     const struct rte_flow_item *item,
		     const struct mlx4_flow_proc_item *proc,
		     struct rte_flow_error *error);
	/** Size in bytes of the destination structure. */
	const unsigned int dst_sz;
	/** List of possible subsequent items. */
	const enum rte_flow_item_type *const next_item;
};

/** Shared resources for drop flow rules. */
struct mlx4_drop {
	struct ibv_qp *qp; /**< QP target. */
	struct ibv_cq *cq; /**< CQ associated with above QP. */
	struct priv *priv; /**< Back pointer to private data. */
	uint32_t refcnt; /**< Reference count. */
};

/**
 * Convert DPDK RSS hash types to their Verbs equivalent.
 *
 * This function returns the supported (default) set when @p types has
 * special value (uint64_t)-1.
 *
 * @param priv
 *   Pointer to private structure.
 * @param types
 *   Hash types in DPDK format (see struct rte_eth_rss_conf).
 *
 * @return
 *   A valid Verbs RSS hash fields mask for mlx4 on success, (uint64_t)-1
 *   otherwise and rte_errno is set.
 */
uint64_t
mlx4_conv_rss_types(struct priv *priv, uint64_t types)
{
	enum { IPV4, IPV6, TCP, UDP, };
	static const uint64_t in[] = {
		[IPV4] = (ETH_RSS_IPV4 |
			  ETH_RSS_FRAG_IPV4 |
			  ETH_RSS_NONFRAG_IPV4_TCP |
			  ETH_RSS_NONFRAG_IPV4_UDP |
			  ETH_RSS_NONFRAG_IPV4_OTHER),
		[IPV6] = (ETH_RSS_IPV6 |
			  ETH_RSS_FRAG_IPV6 |
			  ETH_RSS_NONFRAG_IPV6_TCP |
			  ETH_RSS_NONFRAG_IPV6_UDP |
			  ETH_RSS_NONFRAG_IPV6_OTHER |
			  ETH_RSS_IPV6_EX |
			  ETH_RSS_IPV6_TCP_EX |
			  ETH_RSS_IPV6_UDP_EX),
		[TCP] = (ETH_RSS_NONFRAG_IPV4_TCP |
			 ETH_RSS_NONFRAG_IPV6_TCP |
			 ETH_RSS_IPV6_TCP_EX),
		[UDP] = (ETH_RSS_NONFRAG_IPV4_UDP |
			 ETH_RSS_NONFRAG_IPV6_UDP |
			 ETH_RSS_IPV6_UDP_EX),
	};
	static const uint64_t out[RTE_DIM(in)] = {
		[IPV4] = IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4,
		[IPV6] = IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6,
		[TCP] = IBV_RX_HASH_SRC_PORT_TCP | IBV_RX_HASH_DST_PORT_TCP,
		[UDP] = IBV_RX_HASH_SRC_PORT_UDP | IBV_RX_HASH_DST_PORT_UDP,
	};
	uint64_t seen = 0;
	uint64_t conv = 0;
	unsigned int i;

	if (types == (uint64_t)-1)
		return priv->hw_rss_sup;
	for (i = 0; i != RTE_DIM(in); ++i)
		if (types & in[i]) {
			seen |= types & in[i];
			conv |= out[i];
		}
	if ((conv & priv->hw_rss_sup) == conv && !(types & ~seen))
{'fraction_non_alphanumeric': 0.1222178322138812, 'fraction_numerical': 0.020150138285262742, 'mean_word_length': 3.8836012861736333, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, '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': '7363341', 'n_tokens_mistral': 3393, 'n_tokens_neox': 3085, 'n_words': 742}