Skip to contentSkip to conversation

fpga: altera-cvp: Use pci_find_vsec_capability() when probing FPGA device

PATCH Superseded Andy Shevchenko 2 participants 3 messages Jun 27, 2025 – Jul 9, 2025 FPGA manager framework

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fpga: altera-cvp: Use pci_find_vsec_capability() when probing FPGA device

Currently altera_cvp_probe() open-codes pci_find_vsec_capability(). Refactor the former to use the latter. No functional change intended.

---

v2: removed unused variable (LKP)

 drivers/fpga/altera-cvp.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/fpga/altera-cvp.c +5 -15
index 5af0bd33890c..514d2ac18e5f 100644
@@ -22,9 +22,6 @@
 #define TIMEOUT_US	2000	/* CVP STATUS timeout for USERMODE polling */
 
 /* Vendor Specific Extended Capability Registers */
-#define VSE_PCIE_EXT_CAP_ID		0x0
-#define VSE_PCIE_EXT_CAP_ID_VAL		0x000b	/* 16bit */
-
 #define VSE_CVP_STATUS			0x1c	/* 32bit */
 #define VSE_CVP_STATUS_CFG_RDY		BIT(18)	/* CVP_CONFIG_READY */
 #define VSE_CVP_STATUS_CFG_ERR		BIT(19)	/* CVP_CONFIG_ERROR */
@@ -577,25 +574,18 @@ static int altera_cvp_probe(struct pci_dev *pdev,
 {
 	struct altera_cvp_conf *conf;
 	struct fpga_manager *mgr;
-	int ret, offset;
-	u16 cmd, val;
+	u16 cmd, offset;
 	u32 regval;
-
-	/* Discover the Vendor Specific Offset for this device */
-	offset = pci_find_next_ext_capability(pdev, 0, PCI_EXT_CAP_ID_VNDR);
-	if (!offset) {
-		dev_err(&pdev->dev, "No Vendor Specific Offset.\n");
-		return -ENODEV;
-	}
+	int ret;
 
 	/*
 	 * First check if this is the expected FPGA device. PCI config
 	 * space access works without enabling the PCI device, memory
 	 * space access is enabled further down.
 	 */
-	pci_read_config_word(pdev, offset + VSE_PCIE_EXT_CAP_ID, &val);
-	if (val != VSE_PCIE_EXT_CAP_ID_VAL) {
-		dev_err(&pdev->dev, "Wrong EXT_CAP_ID value 0x%x\n", val);
+	offset = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_ALTERA, 0);
+	if (!offset) {
+		dev_err(&pdev->dev, "Wrong EXT_CAP_ID value\n");
 		return -ENODEV;
 	}
 
Signature · 1 line
2.47.2
#1 lore raw
Quoted 2 lines · Andy Shevchenko

Currently altera_cvp_probe() open-codes pci_find_vsec_capability(). Refactor the former to use the latter. No functional change intended.

Any comments, please?
Can it be applied now?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Andy Shevchenko
Quoted 41 lines · Andy Shevchenko

Currently altera_cvp_probe() open-codes pci_find_vsec_capability(). Refactor the former to use the latter. No functional change intended.

---

v2: removed unused variable (LKP)

 drivers/fpga/altera-cvp.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/fpga/altera-cvp.c +2 -12
index 5af0bd33890c..514d2ac18e5f 100644
@@ -22,9 +22,6 @@
 #define TIMEOUT_US	2000	/* CVP STATUS timeout for USERMODE polling */
 
 /* Vendor Specific Extended Capability Registers */
-#define VSE_PCIE_EXT_CAP_ID		0x0
-#define VSE_PCIE_EXT_CAP_ID_VAL		0x000b	/* 16bit */
-
 #define VSE_CVP_STATUS			0x1c	/* 32bit */
 #define VSE_CVP_STATUS_CFG_RDY		BIT(18)	/* CVP_CONFIG_READY */
 #define VSE_CVP_STATUS_CFG_ERR		BIT(19)	/* CVP_CONFIG_ERROR */
@@ -577,25 +574,18 @@ static int altera_cvp_probe(struct pci_dev *pdev,
 {
 	struct altera_cvp_conf *conf;
 	struct fpga_manager *mgr;
-	int ret, offset;
-	u16 cmd, val;
+	u16 cmd, offset;
 	u32 regval;
-
-	/* Discover the Vendor Specific Offset for this device */
-	offset = pci_find_next_ext_capability(pdev, 0, PCI_EXT_CAP_ID_VNDR);
-	if (!offset) {
-		dev_err(&pdev->dev, "No Vendor Specific Offset.\n");
-		return -ENODEV;
-	}
+	int ret;

drivers/fpga/altera-cvp.c static int altera_cvp_probe(struct pci_dev *pdev, · line 586

Quoted 10 lines
drivers/fpga/altera-cvp.c +1 -3
 
 	/*
 	 * First check if this is the expected FPGA device. PCI config
 	 * space access works without enabling the PCI device, memory
 	 * space access is enabled further down.
 	 */
-	pci_read_config_word(pdev, offset + VSE_PCIE_EXT_CAP_ID, &val);
-	if (val != VSE_PCIE_EXT_CAP_ID_VAL) {
-		dev_err(&pdev->dev, "Wrong EXT_CAP_ID value 0x%x\n", val);
+	offset = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_ALTERA, 0);

Mm.. the original code seems broken. It doesn't check the VSEC ID. And you filled '0'. Is '0' specified in any SPEC? I didn't see it as a wildcard.

Anyway, we should describe the change and remove "No functional change intended".

drivers/fpga/altera-cvp.c static int altera_cvp_probe(struct pci_dev *pdev, · line 588

Quoted 2 lines
drivers/fpga/altera-cvp.c +2 -0
+	if (!offset) {
+		dev_err(&pdev->dev, "Wrong EXT_CAP_ID value\n");

Should be "VSEC ID not found"

Thanks,
Yilun

Quoted 7 lines
drivers/fpga/altera-cvp.c +0 -0
 		return -ENODEV;
 	}
 
Signature · 1 line
2.47.2