2015-12-03 11:18:09

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 11:19:01

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 11:18:18

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 11:18:21

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, 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.

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..1a2d4a6 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -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");
--
1.8.2.1

2015-12-04 22:28:45

by Bjorn Helgaas

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

On Thu, Dec 03, 2015 at 07:17:51PM +0800, Ley Foon Tan 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(-)

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

2015-12-07 01:49:19

by Ley Foon Tan

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

On Sat, Dec 5, 2015 at 6:28 AM, Bjorn Helgaas <[email protected]> wrote:
> On Thu, Dec 03, 2015 at 07:17:51PM +0800, Ley Foon Tan 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(-)
>
> 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