linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] fixes to support multi-functions device
@ 2015-12-03  9:54 Ley Foon Tan
  2015-12-03  9:54 ` [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID Ley Foon Tan
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Ley Foon Tan @ 2015-12-03  9:54 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, Ley Foon Tan, lftan.linux

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(-)

-- 
1.8.2.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID
  2015-12-03  9:54 [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
@ 2015-12-03  9:54 ` Ley Foon Tan
  2015-12-03  9:54 ` [PATCH 2/3] PCI: altera: check TLP completion status Ley Foon Tan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Ley Foon Tan @ 2015-12-03  9:54 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, Ley Foon Tan, lftan.linux

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.

Signed-off-by: Ley Foon Tan <lftan@altera.com>
---
 drivers/pci/host/pcie-altera.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c
index e5dda38..f05180f 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -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);
 
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] PCI: altera: check TLP completion status
  2015-12-03  9:54 [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
  2015-12-03  9:54 ` [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID Ley Foon Tan
@ 2015-12-03  9:54 ` Ley Foon Tan
  2015-12-03  9:54 ` [PATCH 3/3] PCI: altera: fix error when INTX is 4 Ley Foon Tan
  2015-12-03 10:48 ` [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
  3 siblings, 0 replies; 6+ messages in thread
From: Ley Foon Tan @ 2015-12-03  9:54 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, Ley Foon Tan, lftan.linux

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.

Signed-off-by: Ley Foon Tan <lftan@altera.com>
---
 drivers/pci/host/pcie-altera.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c
index f05180f..e4176b3 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -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,
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] PCI: altera: fix error when INTX is 4
  2015-12-03  9:54 [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
  2015-12-03  9:54 ` [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID Ley Foon Tan
  2015-12-03  9:54 ` [PATCH 2/3] PCI: altera: check TLP completion status Ley Foon Tan
@ 2015-12-03  9:54 ` Ley Foon Tan
  2015-12-03 10:48 ` [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
  3 siblings, 0 replies; 6+ messages in thread
From: Ley Foon Tan @ 2015-12-03  9:54 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, Ley Foon Tan, lftan.linux

PCI interrupt lines start at 1, not at 0. So, change INTX_NUM to 5.

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.

Signed-off-by: Ley Foon Tan <lftan@altera.com>
---
 drivers/pci/host/pcie-altera.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c
index e4176b3..8b30d4a 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -60,7 +60,7 @@
 #define TLP_LOOP			500
 #define RP_DEVFN			0
 
-#define INTX_NUM			4
+#define INTX_NUM			5
 
 #define DWORD_MASK			3
 
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] fixes to support multi-functions device
  2015-12-03  9:54 [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
                   ` (2 preceding siblings ...)
  2015-12-03  9:54 ` [PATCH 3/3] PCI: altera: fix error when INTX is 4 Ley Foon Tan
@ 2015-12-03 10:48 ` Ley Foon Tan
  3 siblings, 0 replies; 6+ messages in thread
From: Ley Foon Tan @ 2015-12-03 10:48 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, linux-kernel@vger.kernel.org, Ley Foon Tan,
	Ley Foon Tan

On Thu, Dec 3, 2015 at 5:54 PM, Ley Foon Tan <lftan@altera.com> wrote:
> 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(-)
>
Hi

Sorry, please ignore this patchset, Will resend again.

Thanks.

Regards
Ley Foon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID
  2015-12-03 11:17 Ley Foon Tan
@ 2015-12-03 11:17 ` Ley Foon Tan
  0 siblings, 0 replies; 6+ messages in thread
From: Ley Foon Tan @ 2015-12-03 11:17 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, Ley Foon Tan, lftan.linux

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.

Signed-off-by: Ley Foon Tan <lftan@altera.com>
---
 drivers/pci/host/pcie-altera.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c
index e5dda38..f05180f 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -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);
 
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-03 11:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03  9:54 [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
2015-12-03  9:54 ` [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID Ley Foon Tan
2015-12-03  9:54 ` [PATCH 2/3] PCI: altera: check TLP completion status Ley Foon Tan
2015-12-03  9:54 ` [PATCH 3/3] PCI: altera: fix error when INTX is 4 Ley Foon Tan
2015-12-03 10:48 ` [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
  -- strict thread matches above, loose matches on Subject: below --
2015-12-03 11:17 Ley Foon Tan
2015-12-03 11:17 ` [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID Ley Foon Tan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).