Skip to content

Commit 59b748c

Browse files
committed
Merge branch 'pci/crs'
- Wait for device readiness after reset by polling Vendor ID and looking for Configuration RRS instead of polling the Command register and looking for non-error completions (Bjorn Helgaas) - Fix an aardvark issue with emulating Configuration RRS for two-byte reads of Vendor ID; previously it only worked for four-byte reads (Bjorn Helgaas) - Rename CRS Completion Status to RRS to match spec usage (Bjorn Helgaas) * pci/crs: PCI: Rename CRS Completion Status to RRS PCI: aardvark: Correct Configuration RRS checking PCI: Wait for device readiness with Configuration RRS
2 parents 1a34655 + 87f10fa commit 59b748c

12 files changed

Lines changed: 117 additions & 97 deletions

File tree

drivers/bcma/driver_pci_host.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static u8 bcma_find_pci_capability(struct bcma_drv_pci *pc, unsigned int dev,
334334
}
335335

336336
/* If the root port is capable of returning Config Request
337-
* Retry Status (CRS) Completion Status to software then
337+
* Retry Status (RRS) Completion Status to software then
338338
* enable the feature.
339339
*/
340340
static void bcma_core_pci_enable_crs(struct bcma_drv_pci *pc)
@@ -348,10 +348,10 @@ static void bcma_core_pci_enable_crs(struct bcma_drv_pci *pc)
348348
NULL);
349349
root_cap = cap_ptr + PCI_EXP_RTCAP;
350350
bcma_extpci_read_config(pc, 0, 0, root_cap, &val16, sizeof(u16));
351-
if (val16 & BCMA_CORE_PCI_RC_CRS_VISIBILITY) {
352-
/* Enable CRS software visibility */
351+
if (val16 & BCMA_CORE_PCI_RC_RRS_VISIBILITY) {
352+
/* Enable Configuration RRS Software Visibility */
353353
root_ctrl = cap_ptr + PCI_EXP_RTCTL;
354-
val16 = PCI_EXP_RTCTL_CRSSVE;
354+
val16 = PCI_EXP_RTCTL_RRS_SVE;
355355
bcma_extpci_read_config(pc, 0, 0, root_ctrl, &val16,
356356
sizeof(u16));
357357

@@ -360,7 +360,7 @@ static void bcma_core_pci_enable_crs(struct bcma_drv_pci *pc)
360360
* 100 ms wait time from the end of Reset. If the device is
361361
* not done with its internal initialization, it must at
362362
* least return a completion TLP, with a completion status
363-
* of "Configuration Request Retry Status (CRS)". The root
363+
* of "Configuration Request Retry Status (RRS)". The root
364364
* complex must complete the request to the host by returning
365365
* a read-data value of 0001h for the Vendor ID field and
366366
* all 1s for any additional bytes included in the request.

drivers/pci/controller/dwc/pcie-tegra194.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@
183183
#define GEN3_EQ_CONTROL_OFF_FB_MODE_MASK GENMASK(3, 0)
184184

185185
#define PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT 0x8D0
186-
#define AMBA_ERROR_RESPONSE_CRS_SHIFT 3
187-
#define AMBA_ERROR_RESPONSE_CRS_MASK GENMASK(1, 0)
188-
#define AMBA_ERROR_RESPONSE_CRS_OKAY 0
189-
#define AMBA_ERROR_RESPONSE_CRS_OKAY_FFFFFFFF 1
190-
#define AMBA_ERROR_RESPONSE_CRS_OKAY_FFFF0001 2
186+
#define AMBA_ERROR_RESPONSE_RRS_SHIFT 3
187+
#define AMBA_ERROR_RESPONSE_RRS_MASK GENMASK(1, 0)
188+
#define AMBA_ERROR_RESPONSE_RRS_OKAY 0
189+
#define AMBA_ERROR_RESPONSE_RRS_OKAY_FFFFFFFF 1
190+
#define AMBA_ERROR_RESPONSE_RRS_OKAY_FFFF0001 2
191191

192192
#define MSIX_ADDR_MATCH_LOW_OFF 0x940
193193
#define MSIX_ADDR_MATCH_LOW_OFF_EN BIT(0)
@@ -907,11 +907,11 @@ static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
907907

908908
dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
909909

910-
/* Enable as 0xFFFF0001 response for CRS */
910+
/* Enable as 0xFFFF0001 response for RRS */
911911
val = dw_pcie_readl_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT);
912-
val &= ~(AMBA_ERROR_RESPONSE_CRS_MASK << AMBA_ERROR_RESPONSE_CRS_SHIFT);
913-
val |= (AMBA_ERROR_RESPONSE_CRS_OKAY_FFFF0001 <<
914-
AMBA_ERROR_RESPONSE_CRS_SHIFT);
912+
val &= ~(AMBA_ERROR_RESPONSE_RRS_MASK << AMBA_ERROR_RESPONSE_RRS_SHIFT);
913+
val |= (AMBA_ERROR_RESPONSE_RRS_OKAY_FFFF0001 <<
914+
AMBA_ERROR_RESPONSE_RRS_SHIFT);
915915
dw_pcie_writel_dbi(pci, PORT_LOGIC_AMBA_ERROR_RESPONSE_DEFAULT, val);
916916

917917
/* Clear Slot Clock Configuration bit if SRNS configuration */

drivers/pci/controller/pci-aardvark.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#define PIO_COMPLETION_STATUS_MASK GENMASK(9, 7)
5151
#define PIO_COMPLETION_STATUS_OK 0
5252
#define PIO_COMPLETION_STATUS_UR 1
53-
#define PIO_COMPLETION_STATUS_CRS 2
53+
#define PIO_COMPLETION_STATUS_RRS 2
5454
#define PIO_COMPLETION_STATUS_CA 4
5555
#define PIO_NON_POSTED_REQ BIT(10)
5656
#define PIO_ERR_STATUS BIT(11)
@@ -262,7 +262,7 @@ enum {
262262

263263
#define MSI_IRQ_NUM 32
264264

265-
#define CFG_RD_CRS_VAL 0xffff0001
265+
#define CFG_RD_RRS_VAL 0xffff0001
266266

267267
struct advk_pcie {
268268
struct platform_device *pdev;
@@ -649,7 +649,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
649649
advk_pcie_train_link(pcie);
650650
}
651651

652-
static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u32 *val)
652+
static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_rrs, u32 *val)
653653
{
654654
struct device *dev = &pcie->pdev->dev;
655655
u32 reg;
@@ -669,7 +669,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
669669
* 2) value Unsupported Request(1) of COMPLETION_STATUS(bit9:7) only
670670
* means a PIO write error, and for PIO read it is successful with
671671
* a read value of 0xFFFFFFFF.
672-
* 3) value Completion Retry Status(CRS) of COMPLETION_STATUS(bit9:7)
672+
* 3) value Config Request Retry Status(RRS) of COMPLETION_STATUS(bit9:7)
673673
* only means a PIO write error, and for PIO read it is successful
674674
* with a read value of 0xFFFF0001.
675675
* 4) value Completer Abort (CA) of COMPLETION_STATUS(bit9:7) means
@@ -694,10 +694,10 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
694694
strcomp_status = "UR";
695695
ret = -EOPNOTSUPP;
696696
break;
697-
case PIO_COMPLETION_STATUS_CRS:
698-
if (allow_crs && val) {
699-
/* PCIe r4.0, sec 2.3.2, says:
700-
* If CRS Software Visibility is enabled:
697+
case PIO_COMPLETION_STATUS_RRS:
698+
if (allow_rrs && val) {
699+
/* PCIe r6.0, sec 2.3.2, says:
700+
* If Configuration RRS Software Visibility is enabled:
701701
* For a Configuration Read Request that includes both
702702
* bytes of the Vendor ID field of a device Function's
703703
* Configuration Space Header, the Root Complex must
@@ -706,30 +706,30 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3
706706
* all '1's for any additional bytes included in the
707707
* request.
708708
*
709-
* So CRS in this case is not an error status.
709+
* So RRS in this case is not an error status.
710710
*/
711-
*val = CFG_RD_CRS_VAL;
711+
*val = CFG_RD_RRS_VAL;
712712
strcomp_status = NULL;
713713
ret = 0;
714714
break;
715715
}
716-
/* PCIe r4.0, sec 2.3.2, says:
717-
* If CRS Software Visibility is not enabled, the Root Complex
716+
/* PCIe r6.0, sec 2.3.2, says:
717+
* If RRS Software Visibility is not enabled, the Root Complex
718718
* must re-issue the Configuration Request as a new Request.
719-
* If CRS Software Visibility is enabled: For a Configuration
719+
* If RRS Software Visibility is enabled: For a Configuration
720720
* Write Request or for any other Configuration Read Request,
721721
* the Root Complex must re-issue the Configuration Request as
722722
* a new Request.
723723
* A Root Complex implementation may choose to limit the number
724-
* of Configuration Request/CRS Completion Status loops before
724+
* of Configuration Request/RRS Completion Status loops before
725725
* determining that something is wrong with the target of the
726726
* Request and taking appropriate action, e.g., complete the
727727
* Request to the host as a failed transaction.
728728
*
729729
* So return -EAGAIN and caller (pci-aardvark.c driver) will
730730
* re-issue request again up to the PIO_RETRY_CNT retries.
731731
*/
732-
strcomp_status = "CRS";
732+
strcomp_status = "RRS";
733733
ret = -EAGAIN;
734734
break;
735735
case PIO_COMPLETION_STATUS_CA:
@@ -920,8 +920,8 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
920920

921921
case PCI_EXP_RTCTL: {
922922
u16 rootctl = le16_to_cpu(bridge->pcie_conf.rootctl);
923-
/* Only emulation of PMEIE and CRSSVE bits is provided */
924-
rootctl &= PCI_EXP_RTCTL_PMEIE | PCI_EXP_RTCTL_CRSSVE;
923+
/* Only emulation of PMEIE and RRS_SVE bits is provided */
924+
rootctl &= PCI_EXP_RTCTL_PMEIE | PCI_EXP_RTCTL_RRS_SVE;
925925
bridge->pcie_conf.rootctl = cpu_to_le16(rootctl);
926926
break;
927927
}
@@ -1075,7 +1075,7 @@ static int advk_sw_pci_bridge_init(struct advk_pcie *pcie)
10751075
bridge->pcie_conf.slotsta = cpu_to_le16(PCI_EXP_SLTSTA_PDS);
10761076

10771077
/* Indicates supports for Completion Retry Status */
1078-
bridge->pcie_conf.rootcap = cpu_to_le16(PCI_EXP_RTCAP_CRSVIS);
1078+
bridge->pcie_conf.rootcap = cpu_to_le16(PCI_EXP_RTCAP_RRS_SV);
10791079

10801080
bridge->subsystem_vendor_id = advk_readl(pcie, PCIE_CORE_SSDEV_ID_REG) & 0xffff;
10811081
bridge->subsystem_id = advk_readl(pcie, PCIE_CORE_SSDEV_ID_REG) >> 16;
@@ -1141,7 +1141,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
11411141
{
11421142
struct advk_pcie *pcie = bus->sysdata;
11431143
int retry_count;
1144-
bool allow_crs;
1144+
bool allow_rrs;
11451145
u32 reg;
11461146
int ret;
11471147

@@ -1153,16 +1153,16 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
11531153
size, val);
11541154

11551155
/*
1156-
* Completion Retry Status is possible to return only when reading all
1157-
* 4 bytes from PCI_VENDOR_ID and PCI_DEVICE_ID registers at once and
1158-
* CRSSVE flag on Root Bridge is enabled.
1156+
* Configuration Request Retry Status (RRS) is possible to return
1157+
* only when reading both bytes from PCI_VENDOR_ID at once and
1158+
* RRS_SVE flag on Root Port is enabled.
11591159
*/
1160-
allow_crs = (where == PCI_VENDOR_ID) && (size == 4) &&
1160+
allow_rrs = (where == PCI_VENDOR_ID) && (size >= 2) &&
11611161
(le16_to_cpu(pcie->bridge.pcie_conf.rootctl) &
1162-
PCI_EXP_RTCTL_CRSSVE);
1162+
PCI_EXP_RTCTL_RRS_SVE);
11631163

11641164
if (advk_pcie_pio_is_running(pcie))
1165-
goto try_crs;
1165+
goto try_rrs;
11661166

11671167
/* Program the control register */
11681168
reg = advk_readl(pcie, PIO_CTRL);
@@ -1189,12 +1189,12 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
11891189

11901190
ret = advk_pcie_wait_pio(pcie);
11911191
if (ret < 0)
1192-
goto try_crs;
1192+
goto try_rrs;
11931193

11941194
retry_count += ret;
11951195

11961196
/* Check PIO status and get the read result */
1197-
ret = advk_pcie_check_pio_status(pcie, allow_crs, val);
1197+
ret = advk_pcie_check_pio_status(pcie, allow_rrs, val);
11981198
} while (ret == -EAGAIN && retry_count < PIO_RETRY_CNT);
11991199

12001200
if (ret < 0)
@@ -1207,13 +1207,13 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,
12071207

12081208
return PCIBIOS_SUCCESSFUL;
12091209

1210-
try_crs:
1210+
try_rrs:
12111211
/*
1212-
* If it is possible, return Completion Retry Status so that caller
1213-
* tries to issue the request again instead of failing.
1212+
* If it is possible, return Configuration Request Retry Status so
1213+
* that caller tries to issue the request again instead of failing.
12141214
*/
1215-
if (allow_crs) {
1216-
*val = CFG_RD_CRS_VAL;
1215+
if (allow_rrs) {
1216+
*val = CFG_RD_RRS_VAL;
12171217
return PCIBIOS_SUCCESSFUL;
12181218
}
12191219

drivers/pci/controller/pci-xgene.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ static int xgene_pcie_config_read32(struct pci_bus *bus, unsigned int devfn,
171171

172172
/*
173173
* The v1 controller has a bug in its Configuration Request Retry
174-
* Status (CRS) logic: when CRS Software Visibility is enabled and
174+
* Status (RRS) logic: when RRS Software Visibility is enabled and
175175
* we read the Vendor and Device ID of a non-existent device, the
176176
* controller fabricates return data of 0xFFFF0001 ("device exists
177177
* but is not ready") instead of 0xFFFFFFFF (PCI_ERROR_RESPONSE)
178178
* ("device does not exist"). This causes the PCI core to retry
179179
* the read until it times out. Avoid this by not claiming to
180-
* support CRS SV.
180+
* support RRS SV.
181181
*/
182182
if (pci_is_root_bus(bus) && (port->version == XGENE_PCIE_IP_VER_1) &&
183183
((where & ~0x3) == XGENE_V1_PCI_EXP_CAP + PCI_EXP_RTCTL))
184-
*val &= ~(PCI_EXP_RTCAP_CRSVIS << 16);
184+
*val &= ~(PCI_EXP_RTCAP_RRS_SV << 16);
185185

186186
if (size <= 2)
187187
*val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1);

drivers/pci/controller/pcie-iproc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
#define CFG_RD_SUCCESS 0
5656
#define CFG_RD_UR 1
57-
#define CFG_RD_CRS 2
57+
#define CFG_RD_RRS 2
5858
#define CFG_RD_CA 3
5959
#define CFG_RETRY_STATUS 0xffff0001
6060
#define CFG_RETRY_STATUS_TIMEOUT_US 500000 /* 500 milliseconds */
@@ -485,31 +485,31 @@ static unsigned int iproc_pcie_cfg_retry(struct iproc_pcie *pcie,
485485
u32 status;
486486

487487
/*
488-
* As per PCIe spec r3.1, sec 2.3.2, CRS Software Visibility only
488+
* As per PCIe r6.0, sec 2.3.2, Config RRS Software Visibility only
489489
* affects config reads of the Vendor ID. For config writes or any
490490
* other config reads, the Root may automatically reissue the
491491
* configuration request again as a new request.
492492
*
493493
* For config reads, this hardware returns CFG_RETRY_STATUS data
494-
* when it receives a CRS completion, regardless of the address of
495-
* the read or the CRS Software Visibility Enable bit. As a
494+
* when it receives a RRS completion, regardless of the address of
495+
* the read or the RRS Software Visibility Enable bit. As a
496496
* partial workaround for this, we retry in software any read that
497497
* returns CFG_RETRY_STATUS.
498498
*
499499
* Note that a non-Vendor ID config register may have a value of
500500
* CFG_RETRY_STATUS. If we read that, we can't distinguish it from
501-
* a CRS completion, so we will incorrectly retry the read and
501+
* a RRS completion, so we will incorrectly retry the read and
502502
* eventually return the wrong data (0xffffffff).
503503
*/
504504
data = readl(cfg_data_p);
505505
while (data == CFG_RETRY_STATUS && timeout--) {
506506
/*
507-
* CRS state is set in CFG_RD status register
507+
* RRS state is set in CFG_RD status register
508508
* This will handle the case where CFG_RETRY_STATUS is
509509
* valid config data.
510510
*/
511511
status = iproc_pcie_read_reg(pcie, IPROC_PCIE_CFG_RD_STATUS);
512-
if (status != CFG_RD_CRS)
512+
if (status != CFG_RD_RRS)
513513
return data;
514514

515515
udelay(1);
@@ -556,8 +556,8 @@ static void iproc_pcie_fix_cap(struct iproc_pcie *pcie, int where, u32 *val)
556556
break;
557557

558558
case IPROC_PCI_EXP_CAP + PCI_EXP_RTCTL:
559-
/* Don't advertise CRS SV support */
560-
*val &= ~(PCI_EXP_RTCAP_CRSVIS << 16);
559+
/* Don't advertise RRS SV support */
560+
*val &= ~(PCI_EXP_RTCAP_RRS_SV << 16);
561561
break;
562562

563563
default:

drivers/pci/pci-bridge-emul.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ struct pci_bridge_reg_behavior pcie_cap_regs_behavior[PCI_CAP_PCIE_SIZEOF / 4] =
257257
*/
258258
.rw = (PCI_EXP_RTCTL_SECEE | PCI_EXP_RTCTL_SENFEE |
259259
PCI_EXP_RTCTL_SEFEE | PCI_EXP_RTCTL_PMEIE |
260-
PCI_EXP_RTCTL_CRSSVE),
261-
.ro = PCI_EXP_RTCAP_CRSVIS << 16,
260+
PCI_EXP_RTCTL_RRS_SVE),
261+
.ro = PCI_EXP_RTCAP_RRS_SV << 16,
262262
},
263263

264264
[PCI_EXP_RTSTA / 4] = {

drivers/pci/pci.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,9 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
12831283
{
12841284
int delay = 1;
12851285
bool retrain = false;
1286-
struct pci_dev *bridge;
1286+
struct pci_dev *root, *bridge;
1287+
1288+
root = pcie_find_root_port(dev);
12871289

12881290
if (pci_is_pcie(dev)) {
12891291
bridge = pci_upstream_bridge(dev);
@@ -1292,16 +1294,23 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
12921294
}
12931295

12941296
/*
1295-
* After reset, the device should not silently discard config
1296-
* requests, but it may still indicate that it needs more time by
1297-
* responding to them with CRS completions. The Root Port will
1298-
* generally synthesize ~0 (PCI_ERROR_RESPONSE) data to complete
1299-
* the read (except when CRS SV is enabled and the read was for the
1300-
* Vendor ID; in that case it synthesizes 0x0001 data).
1297+
* The caller has already waited long enough after a reset that the
1298+
* device should respond to config requests, but it may respond
1299+
* with Request Retry Status (RRS) if it needs more time to
1300+
* initialize.
1301+
*
1302+
* If the device is below a Root Port with Configuration RRS
1303+
* Software Visibility enabled, reading the Vendor ID returns a
1304+
* special data value if the device responded with RRS. Read the
1305+
* Vendor ID until we get non-RRS status.
13011306
*
1302-
* Wait for the device to return a non-CRS completion. Read the
1303-
* Command register instead of Vendor ID so we don't have to
1304-
* contend with the CRS SV value.
1307+
* If there's no Root Port or Configuration RRS Software Visibility
1308+
* is not enabled, the device may still respond with RRS, but
1309+
* hardware may retry the config request. If no retries receive
1310+
* Successful Completion, hardware generally synthesizes ~0
1311+
* (PCI_ERROR_RESPONSE) data to complete the read. Reading Vendor
1312+
* ID for VFs and non-existent devices also returns ~0, so read the
1313+
* Command register until it returns something other than ~0.
13051314
*/
13061315
for (;;) {
13071316
u32 id;
@@ -1311,9 +1320,15 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
13111320
return -ENOTTY;
13121321
}
13131322

1314-
pci_read_config_dword(dev, PCI_COMMAND, &id);
1315-
if (!PCI_POSSIBLE_ERROR(id))
1316-
break;
1323+
if (root && root->config_rrs_sv) {
1324+
pci_read_config_dword(dev, PCI_VENDOR_ID, &id);
1325+
if (!pci_bus_rrs_vendor_id(id))
1326+
break;
1327+
} else {
1328+
pci_read_config_dword(dev, PCI_COMMAND, &id);
1329+
if (!PCI_POSSIBLE_ERROR(id))
1330+
break;
1331+
}
13171332

13181333
if (delay > timeout) {
13191334
pci_warn(dev, "not ready %dms after %s; giving up\n",

0 commit comments

Comments
 (0)