Skip to contentSkip to conversation

fixes to support multi-functions device

PATCH In review Ley Foon Tan 2 participants 6 messages Dec 3, 2015 – Dec 7, 2015 PCI

lore
Share & tools
lore
#0 lore raw

cover fixes to support multi-functions device

This series of patch fixes the issues when work with multi-functions PCIe devices. Host controller can't access to endpoint with non-zero devfn, due to incorrect rootport devfn. It also add checking for TLP status and fix issue in interrupt probing.

Tested on Ethernet adapter card with multi-functions enabled.

Ley Foon Tan (3):
PCI: altera: fix incorrect devfn for requester ID
PCI: altera: check TLP completion status
PCI: altera: fix error when INTX is 4

 drivers/pci/host/pcie-altera.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 1/3 PCI: altera: fix incorrect devfn for requester ID

Requester ID should use the rootport devfn and it should be always 0. But, devfn argument in these 2 functions can be rootport or endpoint. It causes the issue when accessing configuration register from multi-functions PCIe devices.

Tested on Ethernet adapter card with multi-functions.

---
 drivers/pci/host/pcie-altera.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pci/host/pcie-altera.c +3 -2
index e5dda38..f05180f 100644
@@ -57,6 +57,7 @@
 #define TLP_REQ_ID(bus, devfn)		(((bus) << 8) | (devfn))
 #define TLP_HDR_SIZE			3
 #define TLP_LOOP			500
+#define RP_DEVFN			0
 
 #define INTX_NUM			4
 
@@ -233,7 +234,7 @@ static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
 	else
 		headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD1);
 
-	headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, devfn),
+	headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN),
 					TLP_READ_TAG, byte_en);
 	headers[2] = TLP_CFG_DW2(bus, devfn, where);
 
@@ -253,7 +254,7 @@ static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
 	else
 		headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR1);
 
-	headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, devfn),
+	headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN),
 					TLP_WRITE_TAG, byte_en);
 	headers[2] = TLP_CFG_DW2(bus, devfn, where);
 
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH 2/3 PCI: altera: check TLP completion status

In reply to Ley Foon Tan

Check TLP packet successful completion status. This fix the issue when accessing multi-function devices in enumeration process, TLP will return error when accessing non-exist function number. Returns PCI error code instead of generic errno.

Tested on Ethernet adapter card with multi-functions.

---
 drivers/pci/host/pcie-altera.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/pci/host/pcie-altera.c +13 -5
index f05180f..e4176b3 100644
@@ -55,6 +55,7 @@
 #define TLP_CFG_DW2(bus, devfn, offset)	\
 				(((bus) << 24) | ((devfn) << 16) | (offset))
 #define TLP_REQ_ID(bus, devfn)		(((bus) << 8) | (devfn))
+#define TLP_COMP_STATUS(s)		(((s) >> 12) & 7)
 #define TLP_HDR_SIZE			3
 #define TLP_LOOP			500
 #define RP_DEVFN			0
@@ -171,6 +172,7 @@ static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
 	bool sop = 0;
 	u32 ctrl;
 	u32 reg0, reg1;
+	u32 comp_status = 1;
 
 	/*
 	 * Minimum 2 loops to read TLP headers and 1 loop to read data
@@ -182,19 +184,25 @@ static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
 			reg0 = cra_readl(pcie, RP_RXCPL_REG0);
 			reg1 = cra_readl(pcie, RP_RXCPL_REG1);
 
-			if (ctrl & RP_RXCPL_SOP)
+			if (ctrl & RP_RXCPL_SOP) {
 				sop = true;
+				comp_status = TLP_COMP_STATUS(reg1);
+			}
 
 			if (ctrl & RP_RXCPL_EOP) {
-				if (value)
-					*value = reg0;
-				return PCIBIOS_SUCCESSFUL;
+				if (!comp_status) {
+					if (value)
+						*value = reg0;
+					return PCIBIOS_SUCCESSFUL;
+				} else {
+					return PCIBIOS_DEVICE_NOT_FOUND;
+				}
 			}
 		}
 		udelay(5);
 	}
 
-	return -ENOENT;
+	return PCIBIOS_DEVICE_NOT_FOUND;
 }
 
 static void tlp_write_packet(struct altera_pcie *pcie, u32 *headers,
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH 3/3 PCI: altera: fix error when INTX is 4

In reply to Ley Foon Tan

PCI interrupt lines start at 1, not at 0. So, creates additional one interrupt when register for irq domain.

Error when PCIe devices have 4 INTX:

WARNING: CPU: 1 PID: 1 at kernel/irq/irqdomain.c:280
	irq_domain_associate+0x17c/0x1cc()

error: hwirq 0x4 is too large for dummy

Tested on Ethernet adapter card with multi-functions.

---
 drivers/pci/host/pcie-altera.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/host/pcie-altera.c +1 -1
index e4176b3..1a2d4a6 100644
@@ -467,7 +467,7 @@ static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
 	struct device_node *node = dev->of_node;
 
 	/* Setup INTx */
-	pcie->irq_domain = irq_domain_add_linear(node, INTX_NUM,
+	pcie->irq_domain = irq_domain_add_linear(node, INTX_NUM + 1,
 					&intx_domain_ops, pcie);
 	if (!pcie->irq_domain) {
 		dev_err(dev, "Failed to get a INTx IRQ domain\n");
Signature · 1 line
1.8.2.1
#4 lore raw
In reply to Ley Foon Tan
Quoted 7 lines · Ley Foon Tan

This series of patch fixes the issues when work with multi-functions PCIe devices. Host controller can't access to endpoint with non-zero devfn, due to incorrect rootport devfn. It also add checking for TLP status and fix issue in interrupt probing.

Tested on Ethernet adapter card with multi-functions enabled.

Quoted 7 lines

Ley Foon Tan (3):
PCI: altera: fix incorrect devfn for requester ID
PCI: altera: check TLP completion status
PCI: altera: fix error when INTX is 4

 drivers/pci/host/pcie-altera.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

We initially merged the Altera driver for v4.4-rc1, it looks like it's not really useful without these changes, and there's no danger of breaking anything in the field, so I put these on my for-linus branch and will ask Linus to pull them before v4.4. Thanks!

Bjorn

#5 lore raw
Quoted 13 lines · Bjorn Helgaas
Quoted 12 lines · Ley Foon Tan

This series of patch fixes the issues when work with multi-functions PCIe devices. Host controller can't access to endpoint with non-zero devfn, due to incorrect rootport devfn. It also add checking for TLP status and fix issue in interrupt probing.

Tested on Ethernet adapter card with multi-functions enabled.

Ley Foon Tan (3):
PCI: altera: fix incorrect devfn for requester ID
PCI: altera: check TLP completion status
PCI: altera: fix error when INTX is 4

Quoted 8 lines
Quoted 2 lines
 drivers/pci/host/pcie-altera.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

We initially merged the Altera driver for v4.4-rc1, it looks like it's not really useful without these changes, and there's no danger of breaking anything in the field, so I put these on my for-linus branch and will ask Linus to pull them before v4.4. Thanks!

That's great!
Thanks.

Regards
Ley Foon