<commit_before>/* SPDX-License-Identifier: BSD-3-Clause
 *
 * Copyright(c) 2019-2021 Xilinx, Inc.
 * Copyright(c) 2016-2019 Solarflare Communications Inc.
 *
 * This software was jointly developed between OKTET Labs (under contract
 * for Solarflare) and Solarflare Communications, Inc.
 */

#include "sfc.h"
#include "sfc_debug.h"
#include "sfc_log.h"
#include "sfc_ev.h"
#include "sfc_tx.h"
#include "sfc_tweak.h"
#include "sfc_kvargs.h"

/*
 * Maximum number of TX queue flush attempts in case of
 * failure or flush timeout
 */
#define SFC_TX_QFLUSH_ATTEMPTS		(3)

/*
 * Time to wait between event queue polling attempts when waiting for TX
 * queue flush done or flush failed events
 */
#define SFC_TX_QFLUSH_POLL_WAIT_MS	(1)

/*
 * Maximum number of event queue polling attempts when waiting for TX queue
 * flush done or flush failed events; it defines TX queue flush attempt timeout
 * together with SFC_TX_QFLUSH_POLL_WAIT_MS
 */
#define SFC_TX_QFLUSH_POLL_ATTEMPTS	(2000)

static uint64_t
sfc_tx_get_offload_mask(struct sfc_adapter *sa)
{
	const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
	uint64_t no_caps = 0;

	if (!encp->enc_hw_tx_insert_vlan_enabled)
		no_caps |= DEV_TX_OFFLOAD_VLAN_INSERT;

	if (!encp->enc_tunnel_encapsulations_supported)
		no_caps |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;

	if (!sa->tso)
		no_caps |= DEV_TX_OFFLOAD_TCP_TSO;

	if (!sa->tso_encap)
		no_caps |= (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
			    DEV_TX_OFFLOAD_GENEVE_TNL_TSO);

	return ~no_caps;
}

uint64_t
sfc_tx_get_dev_offload_caps(struct sfc_adapter *sa)
{
	return sa->priv.dp_tx->dev_offload_capa & sfc_tx_get_offload_mask(sa);
}

uint64_t
sfc_tx_get_queue_offload_caps(struct sfc_adapter *sa)
{
	return sa->priv.dp_tx->queue_offload_capa & sfc_tx_get_offload_mask(sa);
}

static int
sfc_tx_qcheck_conf(struct sfc_adapter *sa, unsigned int txq_max_fill_level,
		   const struct rte_eth_txconf *tx_conf,
		   uint64_t offloads)
{
	int rc = 0;

	if (tx_conf->tx_rs_thresh != 0) {
		sfc_err(sa, "RS bit in transmit descriptor is not supported");
		rc = EINVAL;
	}
<commit_msg>net/sfc: improve tunnel TSO mask calculation<commit_after>/* SPDX-License-Identifier: BSD-3-Clause
 *
 * Copyright(c) 2019-2021 Xilinx, Inc.
 * Copyright(c) 2016-2019 Solarflare Communications Inc.
 *
 * This software was jointly developed between OKTET Labs (under contract
 * for Solarflare) and Solarflare Communications, Inc.
 */

#include "sfc.h"
#include "sfc_debug.h"
#include "sfc_log.h"
#include "sfc_ev.h"
#include "sfc_tx.h"
#include "sfc_tweak.h"
#include "sfc_kvargs.h"

/*
 * Maximum number of TX queue flush attempts in case of
 * failure or flush timeout
 */
#define SFC_TX_QFLUSH_ATTEMPTS		(3)

/*
 * Time to wait between event queue polling attempts when waiting for TX
 * queue flush done or flush failed events
 */
#define SFC_TX_QFLUSH_POLL_WAIT_MS	(1)

/*
 * Maximum number of event queue polling attempts when waiting for TX queue
 * flush done or flush failed events; it defines TX queue flush attempt timeout
 * together with SFC_TX_QFLUSH_POLL_WAIT_MS
 */
#define SFC_TX_QFLUSH_POLL_ATTEMPTS	(2000)

static uint64_t
sfc_tx_get_offload_mask(struct sfc_adapter *sa)
{
	const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
	uint64_t no_caps = 0;

	if (!encp->enc_hw_tx_insert_vlan_enabled)
		no_caps |= DEV_TX_OFFLOAD_VLAN_INSERT;

	if (!encp->enc_tunnel_encapsulations_supported)
		no_caps |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;

	if (!sa->tso)
		no_caps |= DEV_TX_OFFLOAD_TCP_TSO;

	if (!sa->tso_encap ||
	    (encp->enc_tunnel_encapsulations_supported &
	     (1u << EFX_TUNNEL_PROTOCOL_VXLAN)) == 0)
		no_caps |= DEV_TX_OFFLOAD_VXLAN_TNL_TSO;

	if (!sa->tso_encap ||
	    (encp->enc_tunnel_encapsulations_supported &
	     (1u << EFX_TUNNEL_PROTOCOL_GENEVE)) == 0)
		no_caps |= DEV_TX_OFFLOAD_GENEVE_TNL_TSO;

	return ~no_caps;
}

uint64_t
sfc_tx_get_dev_offload_caps(struct sfc_adapter *sa)
{
	return sa->priv.dp_tx->dev_offload_capa & sfc_tx_get_offload_mask(sa);
}

uint64_t
sfc_tx_get_queue_offload_caps(struct sfc_adapter *sa)
{
	return sa->priv.dp_tx->queue_offload_capa & sfc_tx_get_offload_mask(sa);
}

static int
sfc_tx_qcheck_conf(struct sfc_adapter *sa, unsigned int txq_max_fill_level,
		   const struct rte_eth_txconf *tx_conf,
		   uint64_t offloads)
{
	int rc = 0;

	if (tx_conf->tx_rs_thresh != 0) {
		sfc_err(sa, "RS bit in transmit descriptor is not supported");
		rc = EINVAL;
	}

{'fraction_non_alphanumeric': 0.0953790120646483, 'fraction_numerical': 0.017755520145686318, 'mean_word_length': 5.069060773480663, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, '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': '4858394', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1753, 'n_words': 392}