2015-12-03 09:55:06

by Ley Foon Tan

[permalink] [raw]
Subject: [PATCH 0/3] 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(-)

--
1.8.2.1


2015-12-03 09:56:10

by Ley Foon Tan

[permalink] [raw]
Subject: [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.

Signed-off-by: Ley Foon Tan <[email protected]>
---
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

2015-12-03 09:55:13

by Ley Foon Tan

[permalink] [raw]
Subject: [PATCH 2/3] PCI: altera: check TLP completion status

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 <[email protected]>
---
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

2015-12-03 10:10:11

by Ley Foon Tan

[permalink] [raw]
Subject: [PATCH 3/3] PCI: altera: fix error when INTX is 4

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 <[email protected]>
---
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

2015-12-03 10:48:33

by Ley Foon Tan

[permalink] [raw]
Subject: Re: [PATCH 0/3] fixes to support multi-functions device

On Thu, Dec 3, 2015 at 5:54 PM, Ley Foon Tan <[email protected]> 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