Skip to content

Commit 223dec1

Browse files
paliLorenzo Pieralisi
authored andcommitted
PCI: aardvark: Implement re-issuing config requests on CRS response
Commit 43f5c77 ("PCI: aardvark: Fix reporting CRS value") fixed handling of CRS response and when CRSSVE flag was not enabled it marked CRS response as failed transaction (due to simplicity). But pci-aardvark.c driver is already waiting up to the PIO_RETRY_CNT count for PIO config response and so we can with a small change implement re-issuing of config requests as described in PCIe base specification. This change implements re-issuing of config requests when response is CRS. Set upper bound of wait cycles to around PIO_RETRY_CNT, afterwards the transaction is marked as failed and an all-ones value is returned as before. We do this by returning appropriate error codes from function advk_pcie_check_pio_status(). On CRS we return -EAGAIN and caller then reissues transaction. Link: https://lore.kernel.org/r/20211005180952.6812-10-kabel@kernel.org Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Marek Behún <kabel@kernel.org> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Marek Behún <kabel@kernel.org>
1 parent 67cb2a4 commit 223dec1

1 file changed

Lines changed: 43 additions & 24 deletions

File tree

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

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
603603
u32 reg;
604604
unsigned int status;
605605
char *strcomp_status, *str_posted;
606+
int ret;
606607

607608
reg = advk_readl(pcie, PIO_STAT);
608609
status = (reg & PIO_COMPLETION_STATUS_MASK) >>
@@ -627,16 +628,19 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
627628
case PIO_COMPLETION_STATUS_OK:
628629
if (reg & PIO_ERR_STATUS) {
629630
strcomp_status = "COMP_ERR";
631+
ret = -EFAULT;
630632
break;
631633
}
632634
/* Get the read result */
633635
if (val)
634636
*val = advk_readl(pcie, PIO_RD_DATA);
635637
/* No error */
636638
strcomp_status = NULL;
639+
ret = 0;
637640
break;
638641
case PIO_COMPLETION_STATUS_UR:
639642
strcomp_status = "UR";
643+
ret = -EOPNOTSUPP;
640644
break;
641645
case PIO_COMPLETION_STATUS_CRS:
642646
if (allow_crs && val) {
@@ -654,6 +658,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
654658
*/
655659
*val = CFG_RD_CRS_VAL;
656660
strcomp_status = NULL;
661+
ret = 0;
657662
break;
658663
}
659664
/* PCIe r4.0, sec 2.3.2, says:
@@ -669,21 +674,24 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
669674
* Request and taking appropriate action, e.g., complete the
670675
* Request to the host as a failed transaction.
671676
*
672-
* To simplify implementation do not re-issue the Configuration
673-
* Request and complete the Request as a failed transaction.
677+
* So return -EAGAIN and caller (pci-aardvark.c driver) will
678+
* re-issue request again up to the PIO_RETRY_CNT retries.
674679
*/
675680
strcomp_status = "CRS";
681+
ret = -EAGAIN;
676682
break;
677683
case PIO_COMPLETION_STATUS_CA:
678684
strcomp_status = "CA";
685+
ret = -ECANCELED;
679686
break;
680687
default:
681688
strcomp_status = "Unknown";
689+
ret = -EINVAL;
682690
break;
683691
}
684692

685693
if (!strcomp_status)
686-
return 0;
694+
return ret;
687695

688696
if (reg & PIO_NON_POSTED_REQ)
689697
str_posted = "Non-posted";
@@ -693,21 +701,21 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
693701
dev_dbg(dev, "%s PIO Response Status: %s, %#x @ %#x\n",
694702
str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS));
695703

696-
return -EFAULT;
704+
return ret;
697705
}
698706

699707
static int advk_pcie_wait_pio(struct advk_pcie *pcie)
700708
{
701709
struct device *dev = &pcie->pdev->dev;
702710
int i;
703711

704-
for (i = 0; i < PIO_RETRY_CNT; i++) {
712+
for (i = 1; i <= PIO_RETRY_CNT; i++) {
705713
u32 start, isr;
706714

707715
start = advk_readl(pcie, PIO_START);
708716
isr = advk_readl(pcie, PIO_ISR);
709717
if (!start && isr)
710-
return 0;
718+
return i;
711719
udelay(PIO_RETRY_DELAY);
712720
}
713721

@@ -898,6 +906,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
898906
int where, int size, u32 *val)
899907
{
900908
struct advk_pcie *pcie = bus->sysdata;
909+
int retry_count;
901910
bool allow_crs;
902911
u32 reg;
903912
int ret;
@@ -940,16 +949,22 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
940949
/* Program the data strobe */
941950
advk_writel(pcie, 0xf, PIO_WR_DATA_STRB);
942951

943-
/* Clear PIO DONE ISR and start the transfer */
944-
advk_writel(pcie, 1, PIO_ISR);
945-
advk_writel(pcie, 1, PIO_START);
952+
retry_count = 0;
953+
do {
954+
/* Clear PIO DONE ISR and start the transfer */
955+
advk_writel(pcie, 1, PIO_ISR);
956+
advk_writel(pcie, 1, PIO_START);
946957

947-
ret = advk_pcie_wait_pio(pcie);
948-
if (ret < 0)
949-
goto try_crs;
958+
ret = advk_pcie_wait_pio(pcie);
959+
if (ret < 0)
960+
goto try_crs;
961+
962+
retry_count += ret;
963+
964+
/* Check PIO status and get the read result */
965+
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
966+
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
950967

951-
/* Check PIO status and get the read result */
952-
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
953968
if (ret < 0)
954969
goto fail;
955970

@@ -981,6 +996,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
981996
struct advk_pcie *pcie = bus->sysdata;
982997
u32 reg;
983998
u32 data_strobe = 0x0;
999+
int retry_count;
9841000
int offset;
9851001
int ret;
9861002

@@ -1022,19 +1038,22 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
10221038
/* Program the data strobe */
10231039
advk_writel(pcie, data_strobe, PIO_WR_DATA_STRB);
10241040

1025-
/* Clear PIO DONE ISR and start the transfer */
1026-
advk_writel(pcie, 1, PIO_ISR);
1027-
advk_writel(pcie, 1, PIO_START);
1041+
retry_count = 0;
1042+
do {
1043+
/* Clear PIO DONE ISR and start the transfer */
1044+
advk_writel(pcie, 1, PIO_ISR);
1045+
advk_writel(pcie, 1, PIO_START);
10281046

1029-
ret = advk_pcie_wait_pio(pcie);
1030-
if (ret < 0)
1031-
return PCIBIOS_SET_FAILED;
1047+
ret = advk_pcie_wait_pio(pcie);
1048+
if (ret < 0)
1049+
return PCIBIOS_SET_FAILED;
10321050

1033-
ret = advk_pcie_check_pio_status(pcie, false, NULL);
1034-
if (ret < 0)
1035-
return PCIBIOS_SET_FAILED;
1051+
retry_count += ret;
10361052

1037-
return PCIBIOS_SUCCESSFUL;
1053+
ret = advk_pcie_check_pio_status(pcie, false, NULL);
1054+
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
1055+
1056+
return ret < 0 ? PCIBIOS_SET_FAILED : PCIBIOS_SUCCESSFUL;
10381057
}
10391058

10401059
static struct pci_ops advk_pcie_ops = {

0 commit comments

Comments
 (0)