[16/21] net/ena: make Tx completion timeout configurable

Message ID 20220222160634.24489-17-mk@semihalf.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/ena: v2.6.0 driver update |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Michal Krawczyk Feb. 22, 2022, 4:06 p.m. UTC
  The default missing Tx completion timeout was set to 5 seconds.
In order to provide users with the interface to control this timeout
to adjust it with the application's watchdog, the device argument for
controlling this value was added.

The parameter is called 'miss_txc_to' and can be modified using the
devargs interface:

  ./app -a <bdf>,miss_txc_to=UINT_NUMBER

This parameter accepts values from 0 to 60 and indicates number of
seconds after which the Tx packet will be considered as missing.

HW hints for the Tx completions timeout were removed to do not overwrite
parameter from the user. Also specyfing default Tx completion timeout
value was moved from the configuration to init phase in order to
simplify default value assignment.

Signed-off-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Dawid Gorecki <dgr@semihalf.com>
Reviewed-by: Shai Brandes <shaibran@amazon.com>
---
 doc/guides/nics/ena.rst                |  9 ++++
 doc/guides/rel_notes/release_22_03.rst |  1 +
 drivers/net/ena/ena_ethdev.c           | 66 ++++++++++++++++++++------
 drivers/net/ena/ena_ethdev.h           |  1 +
 4 files changed, 62 insertions(+), 15 deletions(-)
  

Patch

diff --git a/doc/guides/nics/ena.rst b/doc/guides/nics/ena.rst
index 85c790e80f..3d780acac9 100644
--- a/doc/guides/nics/ena.rst
+++ b/doc/guides/nics/ena.rst
@@ -87,6 +87,15 @@  Configuration information
      effect only if the device also supports large LLQ headers. Otherwise, the
      default value will be used.
 
+   * **miss_txc_to** (default 5)
+
+     Number of seconds after which the Tx packet will be considered missing.
+     If the missing packets number will exceed dynamically calculated threshold,
+     the driver will trigger the device reset which should be handled by the
+     application. Checking for missing Tx completions happens in the driver's
+     timer service. Setting this parameter to 0 disables this feature. Maximum
+     allowed value is 60 seconds.
+
 **ENA Configuration Parameters**
 
    * **Number of Queues**
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 1b87b9c174..d0d2824371 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -116,6 +116,7 @@  New Features
   * Added ENA admin queue support for the MP applications.
   * Added free Tx mbuf on demand feature support.
   * Added ``rte_eth_xstats_get_names_by_id`` API support.
+  * Added ``miss_txc_to`` device argument for setting the Tx completion timeout.
 
 * **Updated Cisco enic driver.**
 
diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index d413111b08..4bb2b195b1 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -62,6 +62,10 @@  struct ena_stats {
 
 /* Device arguments */
 #define ENA_DEVARG_LARGE_LLQ_HDR "large_llq_hdr"
+/* Timeout in seconds after which a single uncompleted Tx packet should be
+ * considered as a missing.
+ */
+#define ENA_DEVARG_MISS_TXC_TO "miss_txc_to"
 
 /*
  * Each rte_memzone should have unique name.
@@ -2132,6 +2136,8 @@  static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
 	snprintf(adapter->name, ENA_NAME_MAX_LEN, "ena_%d",
 		 adapter->id_number);
 
+	adapter->missing_tx_completion_to = ENA_TX_TIMEOUT;
+
 	rc = ena_parse_devargs(adapter, pci_dev->device.devargs);
 	if (rc != 0) {
 		PMD_INIT_LOG(CRIT, "Failed to parse devargs\n");
@@ -2307,7 +2313,6 @@  static int ena_dev_configure(struct rte_eth_dev *dev)
 	adapter->missing_tx_completion_budget =
 		RTE_MIN(ENA_MONITORED_TX_QUEUES, dev->data->nb_tx_queues);
 
-	adapter->missing_tx_completion_to = ENA_TX_TIMEOUT;
 	/* To avoid detection of the spurious Tx completion timeout due to
 	 * application not calling the Tx cleanup function, set timeout for the
 	 * Tx queue which should be half of the missing completion timeout for a
@@ -2830,20 +2835,6 @@  static void ena_update_hints(struct ena_adapter *adapter,
 		adapter->ena_dev.mmio_read.reg_read_to =
 			hints->mmio_read_timeout * 1000;
 
-	if (hints->missing_tx_completion_timeout) {
-		if (hints->missing_tx_completion_timeout ==
-		    ENA_HW_HINTS_NO_TIMEOUT) {
-			adapter->missing_tx_completion_to =
-				ENA_HW_HINTS_NO_TIMEOUT;
-		} else {
-			/* Convert from msecs to ticks */
-			adapter->missing_tx_completion_to = rte_get_timer_hz() *
-				hints->missing_tx_completion_timeout / 1000;
-			adapter->tx_cleanup_stall_delay =
-				adapter->missing_tx_completion_to / 2;
-		}
-	}
-
 	if (hints->driver_watchdog_timeout) {
 		if (hints->driver_watchdog_timeout == ENA_HW_HINTS_NO_TIMEOUT)
 			adapter->keep_alive_timeout = ENA_HW_HINTS_NO_TIMEOUT;
@@ -3396,6 +3387,45 @@  static int ena_xstats_get_by_id(struct rte_eth_dev *dev,
 	return valid;
 }
 
+static int ena_process_uint_devarg(const char *key,
+				  const char *value,
+				  void *opaque)
+{
+	struct ena_adapter *adapter = opaque;
+	char *str_end;
+	uint64_t uint_value;
+
+	uint_value = strtoull(value, &str_end, 10);
+	if (value == str_end) {
+		PMD_INIT_LOG(ERR,
+			"Invalid value for key '%s'. Only uint values are accepted.\n",
+			key);
+		return -EINVAL;
+	}
+
+	if (strcmp(key, ENA_DEVARG_MISS_TXC_TO) == 0) {
+		if (uint_value > ENA_MAX_TX_TIMEOUT_SECONDS) {
+			PMD_INIT_LOG(ERR,
+				"Tx timeout too high: %" PRIu64 " sec. Maximum allowed: %d sec.\n",
+				uint_value, ENA_MAX_TX_TIMEOUT_SECONDS);
+			return -EINVAL;
+		} else if (uint_value == 0) {
+			PMD_INIT_LOG(INFO,
+				"Check for missing Tx completions has been disabled.\n");
+			adapter->missing_tx_completion_to =
+				ENA_HW_HINTS_NO_TIMEOUT;
+		} else {
+			PMD_INIT_LOG(INFO,
+				"Tx packet completion timeout set to %" PRIu64 " seconds.\n",
+				uint_value);
+			adapter->missing_tx_completion_to =
+				uint_value * rte_get_timer_hz();
+		}
+	}
+
+	return 0;
+}
+
 static int ena_process_bool_devarg(const char *key,
 				   const char *value,
 				   void *opaque)
@@ -3427,6 +3457,7 @@  static int ena_parse_devargs(struct ena_adapter *adapter,
 {
 	static const char * const allowed_args[] = {
 		ENA_DEVARG_LARGE_LLQ_HDR,
+		ENA_DEVARG_MISS_TXC_TO,
 		NULL,
 	};
 	struct rte_kvargs *kvlist;
@@ -3444,7 +3475,12 @@  static int ena_parse_devargs(struct ena_adapter *adapter,
 
 	rc = rte_kvargs_process(kvlist, ENA_DEVARG_LARGE_LLQ_HDR,
 		ena_process_bool_devarg, adapter);
+	if (rc != 0)
+		goto exit;
+	rc = rte_kvargs_process(kvlist, ENA_DEVARG_MISS_TXC_TO,
+		ena_process_uint_devarg, adapter);
 
+exit:
 	rte_kvargs_free(kvlist);
 
 	return rc;
diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h
index ca3e5ed691..c0094b03ee 100644
--- a/drivers/net/ena/ena_ethdev.h
+++ b/drivers/net/ena/ena_ethdev.h
@@ -40,6 +40,7 @@ 
 #define ENA_DEVICE_KALIVE_TIMEOUT (ENA_WD_TIMEOUT_SEC * rte_get_timer_hz())
 
 #define ENA_TX_TIMEOUT			(5 * rte_get_timer_hz())
+#define ENA_MAX_TX_TIMEOUT_SECONDS	60
 #define ENA_MONITORED_TX_QUEUES		3
 #define ENA_DEFAULT_MISSING_COMP	256U