fpga: altera-cvp: Add support for truncated bitstream error handling
PATCH 1/1 fpga: altera-cvp: Add support for truncated bitstream error handling
In reply to a message not in the archiveFrom: "Murugasen Krishnan, Kuhanh" <[email protected]>
The Advanced Interface Bus (AIB) CvP firmware cannot handle bitstreams smaller than 4096 bytes. When a truncated bitstream is sent, the firmware’s DMA engine waits indefinitely for the remaining data, causing the CvP transfer to hang and the configuration to fail.
To address this limitation, the driver now ensures that all transfers are aligned to the 4096-byte block size by padding smaller bitstreams. A dedicated 4096-byte transmit buffer (send_buf) is used to copy and pad host data for each transaction. This guarantees that the firmware always receives a full block.
Additionally, the driver now checks for CVP_CONFIG_ERROR in the CvP status register at the end of configuration to detect truncated or mismatched bitstream errors and aborts cleanly with -EPROTO.
These changes ensure proper error handling for truncated bitstreams and prevent system hangs due to incomplete DMA transfers.
--- drivers/fpga/altera-cvp.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/fpga/altera-cvp.c +19 -5
@@ -80,6 +80,7 @@ struct altera_cvp_conf {u8 numclks;u32 sent_packets;u32 vsec_offset; +u8 *send_buf;const struct cvp_priv *priv; };
@@ -452,7 +453,10 @@ static int altera_cvp_write(struct fpga_manager *mgr, const char *buf, } len =min (conf->priv->block_size, remaining); -altera_cvp_send_block (conf, data, len); +/* Copy the requested host data into the transmit buffer */ +memcpy (conf->send_buf, data, len); +altera_cvp_send_block (conf, (const u32 *)conf->send_buf, + conf->priv->block_size); data += len /sizeof (u32); done += len; remaining -= len;
@@ -491,10 +495,13 @@ static int altera_cvp_write_complete(struct fpga_manager *mgr,if (ret)return ret; -/* STEP 16 - check CVP_CONFIG_ERROR_LATCHED bit */ -altera_read_config_dword (conf,VSE_UNCOR_ERR_STATUS , &val); -if (val &VSE_UNCOR_ERR_CVP_CFG_ERR ) { -dev_err (&mgr->dev,"detected CVP_CONFIG_ERROR_LATCHED!\n" ); +/* +* STEP 16 - If bitstream error (truncated/miss-matched), +* we shall exit here. +*/ + ret =altera_read_config_dword (conf,VSE_CVP_STATUS , &val); +if (ret || (val &VSE_CVP_STATUS_CFG_ERR )) { +dev_err (&mgr->dev,"CVP_CONFIG_ERROR!\n" );return -EPROTO ; }
@@ -660,6 +667,13 @@ static int altera_cvp_probe(struct pci_dev *pdev,pci_set_drvdata (pdev, mgr); +/* Allocate the 4096 block size transmit buffer */ + conf->send_buf =devm_kzalloc (&pdev->dev, conf->priv->block_size,GFP_KERNEL ); +if (!conf->send_buf) { + ret = -ENOMEM ; +fpga_mgr_unregister (mgr); + goto err_unmap; + }return 0 ; err_unmap:
Signature · 1 line
2.25.1