From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id B8F2045B9C;
	Tue, 22 Oct 2024 09:01:29 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 8E48D4029B;
	Tue, 22 Oct 2024 09:01:29 +0200 (CEST)
Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14])
 by mails.dpdk.org (Postfix) with ESMTP id 4CEED4029A
 for <dev@dpdk.org>; Tue, 22 Oct 2024 09:01:28 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1729580488; x=1761116488;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=JQZKc0eK0fuY5JZVlZPrkEoUTCEdVsXL+IjvCshvKdw=;
 b=mLR6f2GtBvtvpjw9EjNM5dW3hrpExMqsPYD53fZSdEsvDqZdaIYRvgSC
 U4eI1FoEm/ih6eDybt0FlsDwOKktukQgxxUz+2cbX28oWvurLrHMXgUqc
 PIYU/m7KldI4piZwCFJ+EXUm4qosymXBSImHE3lzyhhQOCZ4DnVhyVuJr
 0MC3wWKPEgQDoAp2utrQStAmmM2t1j3a66VfyRdVgpgSjNeXYWKJX4jWh
 Xsh7mqtCMrcbd1UK3xyzZau4sY7RTPzWWyOzYrwbAJCK6G6ZkJ8DQXDlY
 0h8KrI6T/IQE9EzNeJuO/wTU+aLez1N0A4UmxJxJJOfXUc/byrMOknz/C g==;
X-CSE-ConnectionGUID: hJG+eKwCSROeU/wjDpgcwA==
X-CSE-MsgGUID: kUbL/RDCTOe+IUI/Lx0Nzw==
X-IronPort-AV: E=McAfee;i="6700,10204,11232"; a="32905650"
X-IronPort-AV: E=Sophos;i="6.11,222,1725346800"; d="scan'208";a="32905650"
Received: from orviesa010.jf.intel.com ([10.64.159.150])
 by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 22 Oct 2024 00:01:27 -0700
X-CSE-ConnectionGUID: oqPLnLlXSe+5bl198PrDBQ==
X-CSE-MsgGUID: 6W8RuILcTFm2GD7N9fURHQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.11,222,1725346800"; d="scan'208";a="79698168"
Received: from unknown (HELO localhost.localdomain) ([10.239.252.253])
 by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 22 Oct 2024 00:01:26 -0700
From: Mingjin Ye <mingjinx.ye@intel.com>
To: dev@dpdk.org
Cc: Mingjin Ye <mingjinx.ye@intel.com>
Subject: [RFC v2] net/ice: add devargs to control link update
Date: Tue, 22 Oct 2024 06:38:49 +0000
Message-Id: <20241022063849.1834740-1-mingjinx.ye@intel.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20241022062043.1833554-1-mingjinx.ye@intel.com>
References: <20241022062043.1833554-1-mingjinx.ye@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

This patch adds the ‘link_period’ devargs to adjust the link update
period (microseconds), when the value is less than or equal to 0
it will be disabled, by default it is not enabled.

Signed-off-by: Mingjin Ye <mingjinx.ye@intel.com>
---
v2: Fix using the wrong variable.
---
 doc/guides/nics/ice.rst      |  7 ++++
 drivers/net/ice/ice_ethdev.c | 69 ++++++++++++++++++++++++++++++++++++
 drivers/net/ice/ice_ethdev.h |  1 +
 3 files changed, 77 insertions(+)

diff --git a/doc/guides/nics/ice.rst b/doc/guides/nics/ice.rst
index 91b5a9b461..ccfff3f294 100644
--- a/doc/guides/nics/ice.rst
+++ b/doc/guides/nics/ice.rst
@@ -303,6 +303,13 @@ Runtime Configuration
   * ``segment``: Check number of mbuf segments does not exceed HW limits.
   * ``offload``: Check for use of an unsupported offload flag.
 
+- ``Cycle link update`` (default ``not enabled``)
+
+  Cyclic link update is enabled when the PMD status changes to STARTED. Setting
+  the ``devargs`` parameter ``link_period`` adjusts the link update period in
+  microseconds, and is disabled when the value set is less than or equal to 0.
+  For example ``-a 81:00.0,link_period=5000`` or ``-a 81:00.0,link_period=0``.
+
 Driver compilation and testing
 ------------------------------
 
diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index 70298ac330..3d7443c5ec 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -15,6 +15,7 @@
 
 #include <rte_tailq.h>
 #include <rte_os_shim.h>
+#include <rte_alarm.h>
 
 #include "eal_firmware.h"
 
@@ -38,6 +39,7 @@
 #define ICE_ONE_PPS_OUT_ARG       "pps_out"
 #define ICE_RX_LOW_LATENCY_ARG    "rx_low_latency"
 #define ICE_MBUF_CHECK_ARG       "mbuf_check"
+#define ICE_LINK_UPDATE_ARG       "link_period"
 
 #define ICE_CYCLECOUNTER_MASK  0xffffffffffffffffULL
 
@@ -54,6 +56,7 @@ static const char * const ice_valid_args[] = {
 	ICE_RX_LOW_LATENCY_ARG,
 	ICE_DEFAULT_MAC_DISABLE,
 	ICE_MBUF_CHECK_ARG,
+	ICE_LINK_UPDATE_ARG,
 	NULL
 };
 
@@ -1389,6 +1392,44 @@ ice_handle_aq_msg(struct rte_eth_dev *dev)
 }
 #endif
 
+static void
+ice_link_cycle_update(void *cb_arg)
+{
+	int ret;
+	struct rte_eth_dev *dev = cb_arg;
+	struct ice_adapter *adapter =
+		ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	ret = ice_link_update(dev, 0);
+	if (!ret)
+		rte_eth_dev_callback_process
+			(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+
+	if (dev->data->dev_started) {
+		/* re-alarm link update */
+		if (rte_eal_alarm_set(adapter->devargs.link_update_period,
+					&ice_link_cycle_update, cb_arg))
+			PMD_DRV_LOG(ERR, "Failed to enable cycle link update");
+	}
+}
+
+static void
+ice_link_cycle_update_init(struct rte_eth_dev *dev)
+{
+	struct ice_adapter *adapter =
+		ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
+
+	if (adapter->devargs.link_update_period <= 0) {
+		PMD_DRV_LOG(INFO, "Device cycle link update is disabled");
+	} else {
+		PMD_DRV_LOG(INFO, "Enabling cycle link update, period is %dμs",
+					adapter->devargs.link_update_period);
+		if (rte_eal_alarm_set(adapter->devargs.link_update_period,
+					&ice_link_cycle_update, (void *)dev))
+			PMD_DRV_LOG(ERR, "Failed to enable cycle link update");
+	}
+}
+
 /**
  * Interrupt handler triggered by NIC for handling
  * specific interrupt.
@@ -2196,6 +2237,26 @@ ice_parse_mbuf_check(__rte_unused const char *key, const char *value, void *args
 	return ret;
 }
 
+static int
+ice_parse_clean_subtask_period(__rte_unused const char *key,
+		const char *value, void *args)
+{
+	int *num = (int *)args;
+	int tmp;
+
+	errno = 0;
+	tmp = atoi(value);
+	if (tmp < 0) {
+		PMD_DRV_LOG(WARNING, "%s: \"%s\" is not greater than or equal to zero",
+						key, value);
+		return -1;
+	}
+
+	*num = tmp;
+
+	return 0;
+}
+
 static int ice_parse_devargs(struct rte_eth_dev *dev)
 {
 	struct ice_adapter *ad =
@@ -2257,6 +2318,12 @@ static int ice_parse_devargs(struct rte_eth_dev *dev)
 	if (ret)
 		goto bail;
 
+	ret = rte_kvargs_process(kvlist, ICE_LINK_UPDATE_ARG,
+				 &ice_parse_clean_subtask_period,
+				 &ad->devargs.link_update_period);
+	if (ret)
+		goto bail;
+
 	ret = rte_kvargs_process(kvlist, ICE_RX_LOW_LATENCY_ARG,
 				 &parse_bool, &ad->devargs.rx_low_latency);
 
@@ -2598,6 +2665,8 @@ ice_dev_init(struct rte_eth_dev *dev)
 	/* reset all stats of the device, including pf and main vsi */
 	ice_stats_reset(dev);
 
+	ice_link_cycle_update_init(dev);
+
 	return 0;
 
 err_flow_init:
diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index 57087c98ed..4cbe119ac4 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -569,6 +569,7 @@ struct ice_devargs {
 	/* Name of the field. */
 	char xtr_field_name[RTE_MBUF_DYN_NAMESIZE];
 	uint64_t mbuf_check;
+	uint32_t link_update_period;
 };
 
 /**
-- 
2.25.1