Skip to contentSkip to conversation

fpga: dfl: pci: generalize find_dfls_by_vsec()

PATCH In review [email protected] 2 participants 4 messages Nov 13, 2021 – Nov 16, 2021

Subsystems (2)
lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

PATCH 1/1 fpga: dfl: pci: generalize find_dfls_by_vsec()

From: Tom Rix <[email protected]>

find_dfls_by_vsec() is a general dfl function. Although dfl has multiple vendors, only Intel is supported. Move vsec and vendor id to an array variable. Other vendors can append the array to enable their support.

---
 drivers/fpga/dfl-pci.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/fpga/dfl-pci.c +24 -7
index 4d68719e608f..9dc0815c8274 100644
@@ -136,19 +136,36 @@ static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int nvec)
 	return table;
 }
 
-static int find_dfls_by_vsec(struct pci_dev *pcidev, struct dfl_fpga_enum_info *info)
+struct dfl_vsec {
+	u16 vendor;
+	u16 id;
+};
+
+static struct dfl_vsec vsecs[] = {
+	{ PCI_VENDOR_ID_INTEL, PCI_VSEC_ID_INTEL_DFLS },
+};
+
+static int find_dfls_by_vsec(struct pci_dev *pcidev,
+			     struct dfl_fpga_enum_info *info)
 {
 	u32 bir, offset, vndr_hdr, dfl_cnt, dfl_res;
 	int dfl_res_off, i, bars, voff = 0;
 	resource_size_t start, len;
 
-	while ((voff = pci_find_next_ext_capability(pcidev, voff, PCI_EXT_CAP_ID_VNDR))) {
-		vndr_hdr = 0;
-		pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER, &vndr_hdr);
+	for (i = 0; i < ARRAY_SIZE(vsecs); i++) {
+		if (pcidev->vendor != vsecs[i].vendor)
+			continue;
+
+		while ((voff =
+			pci_find_next_ext_capability(pcidev, voff,
+						     PCI_EXT_CAP_ID_VNDR))) {
+			vndr_hdr = 0;
+			pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER,
+					      &vndr_hdr);
 
-		if (PCI_VNDR_HEADER_ID(vndr_hdr) == PCI_VSEC_ID_INTEL_DFLS &&
-		    pcidev->vendor == PCI_VENDOR_ID_INTEL)
-			break;
+			if (PCI_VNDR_HEADER_ID(vndr_hdr) == vsecs[i].id)
+				break;
+		}
 	}
 
 	if (!voff) {
Signature · 1 line
2.26.3
maintainer
#1 lore raw
Quoted 6 lines · On Sat, Nov 13, 2021 at 02:12:52PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

find_dfls_by_vsec() is a general dfl function. Although dfl has multiple vendors, only Intel is supported. Move vsec and vendor id to an array variable. Other vendors can append the array to enable their support.

As Hao mentioned, DVSEC could be a better solution if DFL should be present in components by a variety of vendors. This is not finally determined, but I think we should not add new features for VSEC now.

Thanks,
Yilun

Quoted 56 lines
---
 drivers/fpga/dfl-pci.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/fpga/dfl-pci.c +24 -7
index 4d68719e608f..9dc0815c8274 100644
@@ -136,19 +136,36 @@ static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int nvec)
 	return table;
 }
 
-static int find_dfls_by_vsec(struct pci_dev *pcidev, struct dfl_fpga_enum_info *info)
+struct dfl_vsec {
+	u16 vendor;
+	u16 id;
+};
+
+static struct dfl_vsec vsecs[] = {
+	{ PCI_VENDOR_ID_INTEL, PCI_VSEC_ID_INTEL_DFLS },
+};
+
+static int find_dfls_by_vsec(struct pci_dev *pcidev,
+			     struct dfl_fpga_enum_info *info)
 {
 	u32 bir, offset, vndr_hdr, dfl_cnt, dfl_res;
 	int dfl_res_off, i, bars, voff = 0;
 	resource_size_t start, len;
 
-	while ((voff = pci_find_next_ext_capability(pcidev, voff, PCI_EXT_CAP_ID_VNDR))) {
-		vndr_hdr = 0;
-		pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER, &vndr_hdr);
+	for (i = 0; i < ARRAY_SIZE(vsecs); i++) {
+		if (pcidev->vendor != vsecs[i].vendor)
+			continue;
+
+		while ((voff =
+			pci_find_next_ext_capability(pcidev, voff,
+						     PCI_EXT_CAP_ID_VNDR))) {
+			vndr_hdr = 0;
+			pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER,
+					      &vndr_hdr);
 
-		if (PCI_VNDR_HEADER_ID(vndr_hdr) == PCI_VSEC_ID_INTEL_DFLS &&
-		    pcidev->vendor == PCI_VENDOR_ID_INTEL)
-			break;
+			if (PCI_VNDR_HEADER_ID(vndr_hdr) == vsecs[i].id)
+				break;
+		}
 	}
 
 	if (!voff) {
Signature · 1 line
2.26.3
author reviewer
#2 lore raw
Quoted 10 lines · Xu Yilun
Quoted 6 lines · On Sat, Nov 13, 2021 at 02:12:52PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

find_dfls_by_vsec() is a general dfl function. Although dfl has multiple vendors, only Intel is supported. Move vsec and vendor id to an array variable. Other vendors can append the array to enable their support.

As Hao mentioned, DVSEC could be a better solution if DFL should be present in components by a variety of vendors. This is not finally determined, but I think we should not add new features for VSEC now.

Can you expand what you mean by this ?

I am considering the n5010 usecase, the vendor is not intel and will go through this dfl function and always fail.

This is broken.

Either the function should be generalized or moved to an intel specific call.

Tom

Quoted 59 lines

Thanks,
Yilun

Quoted 55 lines
---
  drivers/fpga/dfl-pci.c | 31 ++++++++++++++++++++++++-------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/fpga/dfl-pci.c +24 -7
index 4d68719e608f..9dc0815c8274 100644
@@ -136,19 +136,36 @@ static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int nvec)
  	return table;
  }
 
-static int find_dfls_by_vsec(struct pci_dev *pcidev, struct dfl_fpga_enum_info *info)
+struct dfl_vsec {
+	u16 vendor;
+	u16 id;
+};
+
+static struct dfl_vsec vsecs[] = {
+	{ PCI_VENDOR_ID_INTEL, PCI_VSEC_ID_INTEL_DFLS },
+};
+
+static int find_dfls_by_vsec(struct pci_dev *pcidev,
+			     struct dfl_fpga_enum_info *info)
  {
  	u32 bir, offset, vndr_hdr, dfl_cnt, dfl_res;
  	int dfl_res_off, i, bars, voff = 0;
  	resource_size_t start, len;
 
-	while ((voff = pci_find_next_ext_capability(pcidev, voff, PCI_EXT_CAP_ID_VNDR))) {
-		vndr_hdr = 0;
-		pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER, &vndr_hdr);
+	for (i = 0; i < ARRAY_SIZE(vsecs); i++) {
+		if (pcidev->vendor != vsecs[i].vendor)
+			continue;
+
+		while ((voff =
+			pci_find_next_ext_capability(pcidev, voff,
+						     PCI_EXT_CAP_ID_VNDR))) {
+			vndr_hdr = 0;
+			pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER,
+					      &vndr_hdr);
 
-		if (PCI_VNDR_HEADER_ID(vndr_hdr) == PCI_VSEC_ID_INTEL_DFLS &&
-		    pcidev->vendor == PCI_VENDOR_ID_INTEL)
-			break;
+			if (PCI_VNDR_HEADER_ID(vndr_hdr) == vsecs[i].id)
+				break;
+		}
  	}
 
  	if (!voff) {
Signature · 1 line
2.26.3
maintainer
#3 lore raw
Quoted 9 lines · Tom Rix
Quoted 7 lines · Xu Yilun
Quoted 6 lines · On Sat, Nov 13, 2021 at 02:12:52PM -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

find_dfls_by_vsec() is a general dfl function. Although dfl has multiple vendors, only Intel is supported. Move vsec and vendor id to an array variable. Other vendors can append the array to enable their support.

Quoted 5 lines
Quoted 3 lines

As Hao mentioned, DVSEC could be a better solution if DFL should be present in components by a variety of vendors. This is not finally determined, but I think we should not add new features for VSEC now.

Can you expand what you mean by this ?

Using vendor_id-vsec pair is not a good way. It requires a specific VSEC ID for each vendor to describe DFL. DVSEC is actually the existing solution for these cases. I expect we switch to DVSEC for DFL and drop this VSEC solution.

Quoted 3 lines

I am considering the n5010 usecase, the vendor is not intel and will go through this dfl function and always fail.

Is n5010 using the DFL VSEC, or it just finds DFL by default? Its devId is supported several month ago and no issue reported so I assume it is using the default DFL finding. It would be better to stick to it.

Thanks,
Yilun

Quoted 63 lines

This is broken.

Either the function should be generalized or moved to an intel specific call.

Tom

Quoted 55 lines

Thanks,
Yilun

Quoted 51 lines
---
  drivers/fpga/dfl-pci.c | 31 ++++++++++++++++++++++++-------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/fpga/dfl-pci.c +24 -7
index 4d68719e608f..9dc0815c8274 100644
@@ -136,19 +136,36 @@ static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int nvec)
  	return table;
  }
-static int find_dfls_by_vsec(struct pci_dev *pcidev, struct dfl_fpga_enum_info *info)
+struct dfl_vsec {
+	u16 vendor;
+	u16 id;
+};
+
+static struct dfl_vsec vsecs[] = {
+	{ PCI_VENDOR_ID_INTEL, PCI_VSEC_ID_INTEL_DFLS },
+};
+
+static int find_dfls_by_vsec(struct pci_dev *pcidev,
+			     struct dfl_fpga_enum_info *info)
  {
  	u32 bir, offset, vndr_hdr, dfl_cnt, dfl_res;
  	int dfl_res_off, i, bars, voff = 0;
  	resource_size_t start, len;
-	while ((voff = pci_find_next_ext_capability(pcidev, voff, PCI_EXT_CAP_ID_VNDR))) {
-		vndr_hdr = 0;
-		pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER, &vndr_hdr);
+	for (i = 0; i < ARRAY_SIZE(vsecs); i++) {
+		if (pcidev->vendor != vsecs[i].vendor)
+			continue;
+
+		while ((voff =
+			pci_find_next_ext_capability(pcidev, voff,
+						     PCI_EXT_CAP_ID_VNDR))) {
+			vndr_hdr = 0;
+			pci_read_config_dword(pcidev, voff + PCI_VNDR_HEADER,
+					      &vndr_hdr);
-		if (PCI_VNDR_HEADER_ID(vndr_hdr) == PCI_VSEC_ID_INTEL_DFLS &&
-		    pcidev->vendor == PCI_VENDOR_ID_INTEL)
-			break;
+			if (PCI_VNDR_HEADER_ID(vndr_hdr) == vsecs[i].id)
+				break;
+		}
  	}
  	if (!voff) {
Signature · 1 line
2.26.3