Skip to content

Commit 70b131f

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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c37f836 commit 70b131f

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
@@ -692,6 +692,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
692692
u32 reg;
693693
unsigned int status;
694694
char *strcomp_status, *str_posted;
695+
int ret;
695696

696697
reg = advk_readl(pcie, PIO_STAT);
697698
status = (reg & PIO_COMPLETION_STATUS_MASK) >>
@@ -716,16 +717,19 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
716717
case PIO_COMPLETION_STATUS_OK:
717718
if (reg & PIO_ERR_STATUS) {
718719
strcomp_status = "COMP_ERR";
720+
ret = -EFAULT;
719721
break;
720722
}
721723
/* Get the read result */
722724
if (val)
723725
*val = advk_readl(pcie, PIO_RD_DATA);
724726
/* No error */
725727
strcomp_status = NULL;
728+
ret = 0;
726729
break;
727730
case PIO_COMPLETION_STATUS_UR:
728731
strcomp_status = "UR";
732+
ret = -EOPNOTSUPP;
729733
break;
730734
case PIO_COMPLETION_STATUS_CRS:
731735
if (allow_crs && val) {
@@ -743,6 +747,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
743747
*/
744748
*val = CFG_RD_CRS_VAL;
745749
strcomp_status = NULL;
750+
ret = 0;
746751
break;
747752
}
748753
/* PCIe r4.0, sec 2.3.2, says:
@@ -758,21 +763,24 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
758763
* Request and taking appropriate action, e.g., complete the
759764
* Request to the host as a failed transaction.
760765
*
761-
* To simplify implementation do not re-issue the Configuration
762-
* Request and complete the Request as a failed transaction.
766+
* So return -EAGAIN and caller (pci-aardvark.c driver) will
767+
* re-issue request again up to the PIO_RETRY_CNT retries.
763768
*/
764769
strcomp_status = "CRS";
770+
ret = -EAGAIN;
765771
break;
766772
case PIO_COMPLETION_STATUS_CA:
767773
strcomp_status = "CA";
774+
ret = -ECANCELED;
768775
break;
769776
default:
770777
strcomp_status = "Unknown";
778+
ret = -EINVAL;
771779
break;
772780
}
773781

774782
if (!strcomp_status)
775-
return 0;
783+
return ret;
776784

777785
if (reg & PIO_NON_POSTED_REQ)
778786
str_posted = "Non-posted";
@@ -782,21 +790,21 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
782790
dev_dbg(dev, "%s PIO Response Status: %s, %#x @ %#x\n",
783791
str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS));
784792

785-
return -EFAULT;
793+
return ret;
786794
}
787795

788796
static int advk_pcie_wait_pio(struct advk_pcie *pcie)
789797
{
790798
struct device *dev = &pcie->pdev->dev;
791799
int i;
792800

793-
for (i = 0; i < PIO_RETRY_CNT; i++) {
801+
for (i = 1; i <= PIO_RETRY_CNT; i++) {
794802
u32 start, isr;
795803

796804
start = advk_readl(pcie, PIO_START);
797805
isr = advk_readl(pcie, PIO_ISR);
798806
if (!start && isr)
799-
return 0;
807+
return i;
800808
udelay(PIO_RETRY_DELAY);
801809
}
802810

@@ -1068,6 +1076,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
10681076
int where, int size, u32 *val)
10691077
{
10701078
struct advk_pcie *pcie = bus->sysdata;
1079+
int retry_count;
10711080
bool allow_crs;
10721081
u32 reg;
10731082
int ret;
@@ -1110,16 +1119,22 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
11101119
/* Program the data strobe */
11111120
advk_writel(pcie, 0xf, PIO_WR_DATA_STRB);
11121121

1113-
/* Clear PIO DONE ISR and start the transfer */
1114-
advk_writel(pcie, 1, PIO_ISR);
1115-
advk_writel(pcie, 1, PIO_START);
1122+
retry_count = 0;
1123+
do {
1124+
/* Clear PIO DONE ISR and start the transfer */
1125+
advk_writel(pcie, 1, PIO_ISR);
1126+
advk_writel(pcie, 1, PIO_START);
11161127

1117-
ret = advk_pcie_wait_pio(pcie);
1118-
if (ret < 0)
1119-
goto try_crs;
1128+
ret = advk_pcie_wait_pio(pcie);
1129+
if (ret < 0)
1130+
goto try_crs;
1131+
1132+
retry_count += ret;
1133+
1134+
/* Check PIO status and get the read result */
1135+
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
1136+
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
11201137

1121-
/* Check PIO status and get the read result */
1122-
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
11231138
if (ret < 0)
11241139
goto fail;
11251140

@@ -1151,6 +1166,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
11511166
struct advk_pcie *pcie = bus->sysdata;
11521167
u32 reg;
11531168
u32 data_strobe = 0x0;
1169+
int retry_count;
11541170
int offset;
11551171
int ret;
11561172

@@ -1192,19 +1208,22 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
11921208
/* Program the data strobe */
11931209
advk_writel(pcie, data_strobe, PIO_WR_DATA_STRB);
11941210

1195-
/* Clear PIO DONE ISR and start the transfer */
1196-
advk_writel(pcie, 1, PIO_ISR);
1197-
advk_writel(pcie, 1, PIO_START);
1211+
retry_count = 0;
1212+
do {
1213+
/* Clear PIO DONE ISR and start the transfer */
1214+
advk_writel(pcie, 1, PIO_ISR);
1215+
advk_writel(pcie, 1, PIO_START);
11981216

1199-
ret = advk_pcie_wait_pio(pcie);
1200-
if (ret < 0)
1201-
return PCIBIOS_SET_FAILED;
1217+
ret = advk_pcie_wait_pio(pcie);
1218+
if (ret < 0)
1219+
return PCIBIOS_SET_FAILED;
12021220

1203-
ret = advk_pcie_check_pio_status(pcie, false, NULL);
1204-
if (ret < 0)
1205-
return PCIBIOS_SET_FAILED;
1221+
retry_count += ret;
12061222

1207-
return PCIBIOS_SUCCESSFUL;
1223+
ret = advk_pcie_check_pio_status(pcie, false, NULL);
1224+
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
1225+
1226+
return ret < 0 ? PCIBIOS_SET_FAILED : PCIBIOS_SUCCESSFUL;
12081227
}
12091228

12101229
static struct pci_ops advk_pcie_ops = {

0 commit comments

Comments
 (0)