Skip to contentSkip to conversation

fpga: altera-cvp: Add recovery retry mechanism for teardown failures

PATCH New Kuhanh Murugasen Krishnan 1 participant 1 message Nov 4, 2025 1 message not in the archive FPGA manager framework

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 fpga: altera-cvp: Add recovery retry mechanism for teardown failures

From: "Murugasen Krishnan, Kuhanh" <[email protected]>

When an incorrect bitstream is sent during configuration, the teardown sequence may fail and leave the CVP hardware in an undefined or unrecoverable state. This prevents subsequent configuration attempts from succeeding without a full PCIe reset.

To improve reliability, introduce a recovery mechanism that retries the teardown operation up to 10 times. Each teardown failure triggers a cleanup sequence that resets the CVP_MODE_CTRL register by clearing the CVP_MODE and HIP_CLK_SEL bits before retrying. This ensures the hardware is returned to a known idle state between attempts.

A new macro, CVP_TEARDOWN_MAX_RETRY, defines the maximum number of teardown retry attempts. The recovery routine is integrated into both the write initialization and completion paths to ensure consistent error handling and improved robustness across configuration cycles.

This change prevents the driver from remaining in an unrecoverable state and enables safe retry attempts without requiring a full PCIe re-enumeration.

---
 drivers/fpga/altera-cvp.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
drivers/fpga/altera-cvp.c +27 -3
index 5af0bd33890c..5c4f4a5bae76 100644
@@ -66,6 +66,8 @@
 #define ALTERA_CVP_V1_SIZE	4
 #define ALTERA_CVP_V2_SIZE	4096
 
+/* Tear-down retry */
+#define CVP_TEARDOWN_MAX_RETRY 10
 /* Optional CvP config error status check for debugging */
 static bool altera_cvp_chkcfg;
 
@@ -308,12 +310,34 @@ static int altera_cvp_teardown(struct fpga_manager *mgr,
 	/* STEP 15 - poll CVP_CONFIG_READY bit for 0 with 10us timeout */
 	ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, 0,
 				     conf->priv->poll_time_us);
-	if (ret)
+	if (ret) {
 		dev_err(&mgr->dev, "CFG_RDY == 0 timeout\n");
+		/* reset CVP_MODE and HIP_CLK_SEL bit */
+		altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val);
+		val &= ~VSE_CVP_MODE_CTRL_HIP_CLK_SEL;
+		val &= ~VSE_CVP_MODE_CTRL_CVP_MODE;
+		altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val);
 
+		return -EAGAIN;
+	}
 	return ret;
 }
 
+static int altera_cvp_recovery(struct fpga_manager *mgr,
+			       struct fpga_image_info *info)
+{
+	int ret, retry;
+
+	for (retry = 0; retry < CVP_TEARDOWN_MAX_RETRY; retry++) {
+		ret = altera_cvp_teardown(mgr, info);
+		if (!ret)
+			break;
+		dev_warn(&mgr->dev,
+			 "%s: [%d] Tear-down failed. Retrying\n",
+			  __func__, retry);
+	}
+	return ret;
+}
 static int altera_cvp_write_init(struct fpga_manager *mgr,
 				 struct fpga_image_info *info,
 				 const char *buf, size_t count)
@@ -346,7 +370,7 @@ static int altera_cvp_write_init(struct fpga_manager *mgr,
 
 	if (val & VSE_CVP_STATUS_CFG_RDY) {
 		dev_warn(&mgr->dev, "CvP already started, tear down first\n");
-		ret = altera_cvp_teardown(mgr, info);
+		ret = altera_cvp_recovery(mgr, info);
 		if (ret)
 			return ret;
 	}
@@ -487,7 +511,7 @@ static int altera_cvp_write_complete(struct fpga_manager *mgr,
 	u32 mask, val;
 	int ret;
 
-	ret = altera_cvp_teardown(mgr, info);
+	ret = altera_cvp_recovery(mgr, info);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.25.1