Skip to content

Commit df57480

Browse files
paligregkh
authored andcommitted
PCI: aardvark: Implement re-issuing config requests on CRS response
commit 223dec1 upstream. 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> Signed-off-by: Marek Behún <kabel@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e7f2e2c commit df57480

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
@@ -699,6 +699,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
699699
u32 reg;
700700
unsigned int status;
701701
char *strcomp_status, *str_posted;
702+
int ret;
702703

703704
reg = advk_readl(pcie, PIO_STAT);
704705
status = (reg & PIO_COMPLETION_STATUS_MASK) >>
@@ -723,16 +724,19 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
723724
case PIO_COMPLETION_STATUS_OK:
724725
if (reg & PIO_ERR_STATUS) {
725726
strcomp_status = "COMP_ERR";
727+
ret = -EFAULT;
726728
break;
727729
}
728730
/* Get the read result */
729731
if (val)
730732
*val = advk_readl(pcie, PIO_RD_DATA);
731733
/* No error */
732734
strcomp_status = NULL;
735+
ret = 0;
733736
break;
734737
case PIO_COMPLETION_STATUS_UR:
735738
strcomp_status = "UR";
739+
ret = -EOPNOTSUPP;
736740
break;
737741
case PIO_COMPLETION_STATUS_CRS:
738742
if (allow_crs && val) {
@@ -750,6 +754,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
750754
*/
751755
*val = CFG_RD_CRS_VAL;
752756
strcomp_status = NULL;
757+
ret = 0;
753758
break;
754759
}
755760
/* PCIe r4.0, sec 2.3.2, says:
@@ -765,21 +770,24 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
765770
* Request and taking appropriate action, e.g., complete the
766771
* Request to the host as a failed transaction.
767772
*
768-
* To simplify implementation do not re-issue the Configuration
769-
* Request and complete the Request as a failed transaction.
773+
* So return -EAGAIN and caller (pci-aardvark.c driver) will
774+
* re-issue request again up to the PIO_RETRY_CNT retries.
770775
*/
771776
strcomp_status = "CRS";
777+
ret = -EAGAIN;
772778
break;
773779
case PIO_COMPLETION_STATUS_CA:
774780
strcomp_status = "CA";
781+
ret = -ECANCELED;
775782
break;
776783
default:
777784
strcomp_status = "Unknown";
785+
ret = -EINVAL;
778786
break;
779787
}
780788

781789
if (!strcomp_status)
782-
return 0;
790+
return ret;
783791

784792
if (reg & PIO_NON_POSTED_REQ)
785793
str_posted = "Non-posted";
@@ -789,21 +797,21 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
789797
dev_dbg(dev, "%s PIO Response Status: %s, %#x @ %#x\n",
790798
str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS));
791799

792-
return -EFAULT;
800+
return ret;
793801
}
794802

795803
static int advk_pcie_wait_pio(struct advk_pcie *pcie)
796804
{
797805
struct device *dev = &pcie->pdev->dev;
798806
int i;
799807

800-
for (i = 0; i < PIO_RETRY_CNT; i++) {
808+
for (i = 1; i <= PIO_RETRY_CNT; i++) {
801809
u32 start, isr;
802810

803811
start = advk_readl(pcie, PIO_START);
804812
isr = advk_readl(pcie, PIO_ISR);
805813
if (!start && isr)
806-
return 0;
814+
return i;
807815
udelay(PIO_RETRY_DELAY);
808816
}
809817

@@ -1075,6 +1083,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
10751083
int where, int size, u32 *val)
10761084
{
10771085
struct advk_pcie *pcie = bus->sysdata;
1086+
int retry_count;
10781087
bool allow_crs;
10791088
u32 reg;
10801089
int ret;
@@ -1117,16 +1126,22 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
11171126
/* Program the data strobe */
11181127
advk_writel(pcie, 0xf, PIO_WR_DATA_STRB);
11191128

1120-
/* Clear PIO DONE ISR and start the transfer */
1121-
advk_writel(pcie, 1, PIO_ISR);
1122-
advk_writel(pcie, 1, PIO_START);
1129+
retry_count = 0;
1130+
do {
1131+
/* Clear PIO DONE ISR and start the transfer */
1132+
advk_writel(pcie, 1, PIO_ISR);
1133+
advk_writel(pcie, 1, PIO_START);
11231134

1124-
ret = advk_pcie_wait_pio(pcie);
1125-
if (ret < 0)
1126-
goto try_crs;
1135+
ret = advk_pcie_wait_pio(pcie);
1136+
if (ret < 0)
1137+
goto try_crs;
1138+
1139+
retry_count += ret;
1140+
1141+
/* Check PIO status and get the read result */
1142+
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
1143+
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
11271144

1128-
/* Check PIO status and get the read result */
1129-
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
11301145
if (ret < 0)
11311146
goto fail;
11321147

@@ -1158,6 +1173,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
11581173
struct advk_pcie *pcie = bus->sysdata;
11591174
u32 reg;
11601175
u32 data_strobe = 0x0;
1176+
int retry_count;
11611177
int offset;
11621178
int ret;
11631179

@@ -1199,19 +1215,22 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
11991215
/* Program the data strobe */
12001216
advk_writel(pcie, data_strobe, PIO_WR_DATA_STRB);
12011217

1202-
/* Clear PIO DONE ISR and start the transfer */
1203-
advk_writel(pcie, 1, PIO_ISR);
1204-
advk_writel(pcie, 1, PIO_START);
1218+
retry_count = 0;
1219+
do {
1220+
/* Clear PIO DONE ISR and start the transfer */
1221+
advk_writel(pcie, 1, PIO_ISR);
1222+
advk_writel(pcie, 1, PIO_START);
12051223

1206-
ret = advk_pcie_wait_pio(pcie);
1207-
if (ret < 0)
1208-
return PCIBIOS_SET_FAILED;
1224+
ret = advk_pcie_wait_pio(pcie);
1225+
if (ret < 0)
1226+
return PCIBIOS_SET_FAILED;
12091227

1210-
ret = advk_pcie_check_pio_status(pcie, false, NULL);
1211-
if (ret < 0)
1212-
return PCIBIOS_SET_FAILED;
1228+
retry_count += ret;
12131229

1214-
return PCIBIOS_SUCCESSFUL;
1230+
ret = advk_pcie_check_pio_status(pcie, false, NULL);
1231+
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
1232+
1233+
return ret < 0 ? PCIBIOS_SET_FAILED : PCIBIOS_SUCCESSFUL;
12151234
}
12161235

12171236
static struct pci_ops advk_pcie_ops = {

0 commit comments

Comments
 (0)