Skip to content

Commit fcb461e

Browse files
Evan WangLorenzo Pieralisi
authored andcommitted
PCI: aardvark: Fix checking for PIO status
There is an issue that when PCIe switch is connected to an Armada 3700 board, there will be lots of warnings about PIO errors when reading the config space. According to Aardvark PIO read and write sequence in HW specification, the current way to check PIO status has the following issues: 1) For PIO read operation, it reports the error message, which should be avoided according to HW specification. 2) For PIO read and write operations, it only checks PIO operation complete status, which is not enough, and error status should also be checked. This patch aligns the code with Aardvark PIO read and write sequence in HW specification on PIO status check and fix the warnings when reading config space. [pali: Fix CRS handling when CRSSVE is not enabled] Link: https://lore.kernel.org/r/20210722144041.12661-2-pali@kernel.org Tested-by: Victor Gu <xigu@marvell.com> Signed-off-by: Evan Wang <xswang@marvell.com> Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Victor Gu <xigu@marvell.com> Reviewed-by: Marek Behún <kabel@kernel.org> Cc: stable@vger.kernel.org # b1bd571 ("PCI: aardvark: Indicate error in 'val' when config read fails")
1 parent e73f0f0 commit fcb461e

1 file changed

Lines changed: 54 additions & 8 deletions

File tree

‎drivers/pci/controller/pci-aardvark.c‎

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#define PIO_COMPLETION_STATUS_CRS 2
5959
#define PIO_COMPLETION_STATUS_CA 4
6060
#define PIO_NON_POSTED_REQ BIT(10)
61+
#define PIO_ERR_STATUS BIT(11)
6162
#define PIO_ADDR_LS (PIO_BASE_ADDR + 0x8)
6263
#define PIO_ADDR_MS (PIO_BASE_ADDR + 0xc)
6364
#define PIO_WR_DATA (PIO_BASE_ADDR + 0x10)
@@ -472,7 +473,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
472473
advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG);
473474
}
474475

475-
static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
476+
static int advk_pcie_check_pio_status(struct advk_pcie *pcie, u32 *val)
476477
{
477478
struct device *dev = &pcie->pdev->dev;
478479
u32 reg;
@@ -483,14 +484,49 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
483484
status = (reg & PIO_COMPLETION_STATUS_MASK) >>
484485
PIO_COMPLETION_STATUS_SHIFT;
485486

486-
if (!status)
487-
return;
488-
487+
/*
488+
* According to HW spec, the PIO status check sequence as below:
489+
* 1) even if COMPLETION_STATUS(bit9:7) indicates successful,
490+
* it still needs to check Error Status(bit11), only when this bit
491+
* indicates no error happen, the operation is successful.
492+
* 2) value Unsupported Request(1) of COMPLETION_STATUS(bit9:7) only
493+
* means a PIO write error, and for PIO read it is successful with
494+
* a read value of 0xFFFFFFFF.
495+
* 3) value Completion Retry Status(CRS) of COMPLETION_STATUS(bit9:7)
496+
* only means a PIO write error, and for PIO read it is successful
497+
* with a read value of 0xFFFF0001.
498+
* 4) value Completer Abort (CA) of COMPLETION_STATUS(bit9:7) means
499+
* error for both PIO read and PIO write operation.
500+
* 5) other errors are indicated as 'unknown'.
501+
*/
489502
switch (status) {
503+
case PIO_COMPLETION_STATUS_OK:
504+
if (reg & PIO_ERR_STATUS) {
505+
strcomp_status = "COMP_ERR";
506+
break;
507+
}
508+
/* Get the read result */
509+
if (val)
510+
*val = advk_readl(pcie, PIO_RD_DATA);
511+
/* No error */
512+
strcomp_status = NULL;
513+
break;
490514
case PIO_COMPLETION_STATUS_UR:
491515
strcomp_status = "UR";
492516
break;
493517
case PIO_COMPLETION_STATUS_CRS:
518+
/* PCIe r4.0, sec 2.3.2, says:
519+
* If CRS Software Visibility is not enabled, the Root Complex
520+
* must re-issue the Configuration Request as a new Request.
521+
* A Root Complex implementation may choose to limit the number
522+
* of Configuration Request/CRS Completion Status loops before
523+
* determining that something is wrong with the target of the
524+
* Request and taking appropriate action, e.g., complete the
525+
* Request to the host as a failed transaction.
526+
*
527+
* To simplify implementation do not re-issue the Configuration
528+
* Request and complete the Request as a failed transaction.
529+
*/
494530
strcomp_status = "CRS";
495531
break;
496532
case PIO_COMPLETION_STATUS_CA:
@@ -501,13 +537,18 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
501537
break;
502538
}
503539

540+
if (!strcomp_status)
541+
return 0;
542+
504543
if (reg & PIO_NON_POSTED_REQ)
505544
str_posted = "Non-posted";
506545
else
507546
str_posted = "Posted";
508547

509548
dev_err(dev, "%s PIO Response Status: %s, %#x @ %#x\n",
510549
str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS));
550+
551+
return -EFAULT;
511552
}
512553

513554
static int advk_pcie_wait_pio(struct advk_pcie *pcie)
@@ -745,10 +786,13 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
745786
return PCIBIOS_SET_FAILED;
746787
}
747788

748-
advk_pcie_check_pio_status(pcie);
789+
/* Check PIO status and get the read result */
790+
ret = advk_pcie_check_pio_status(pcie, val);
791+
if (ret < 0) {
792+
*val = 0xffffffff;
793+
return PCIBIOS_SET_FAILED;
794+
}
749795

750-
/* Get the read result */
751-
*val = advk_readl(pcie, PIO_RD_DATA);
752796
if (size == 1)
753797
*val = (*val >> (8 * (where & 3))) & 0xff;
754798
else if (size == 2)
@@ -812,7 +856,9 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
812856
if (ret < 0)
813857
return PCIBIOS_SET_FAILED;
814858

815-
advk_pcie_check_pio_status(pcie);
859+
ret = advk_pcie_check_pio_status(pcie, NULL);
860+
if (ret < 0)
861+
return PCIBIOS_SET_FAILED;
816862

817863
return PCIBIOS_SUCCESSFUL;
818864
}

0 commit comments

Comments
 (0)