Skip to contentSkip to conversation

pci/doe: add a 1 second retry window to pci_doe

PATCH In review Gregory Price 4 participants 7 messages Sep 13, 2024 – Oct 4, 2024 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci/doe: add a 1 second retry window to pci_doe

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

---
 drivers/pci/doe.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pci/doe.c +8 -4
index 652d63df9d22..5573fa1a0008 100644
@@ -647,12 +647,16 @@ int pci_doe(struct pci_doe_mb *doe_mb, u16 vendor, u8 type,
 		.private = &c,
 	};
 	int rc;
+	unsigned long timeout_jiffies = jiffies + (PCI_DOE_TIMEOUT * 1);
 
-	rc = pci_doe_submit_task(doe_mb, &task);
-	if (rc)
-		return rc;
+	do {
+		rc = pci_doe_submit_task(doe_mb, &task);
+
+		if (rc)
+			return rc;
 
-	wait_for_completion(&c);
+		wait_for_completion(&c);
+	} while (task.rv == -EBUSY && !time_after(jiffies, timeout_jiffies));
 
 	return task.rv;
 }
Signature · 1 line
2.43.0
#1 lore raw

[ add linux-pci and Lukas ]

Quoted 4 lines · Gregory Price

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

I would have expected this to be handled as part of finishing off pci_doe_recv_resp() not retrying on a new submission.

It also occurs to me that instead of warning "another entity is sending conflicting requests" message, the doe core should just ensure that it is the only agent using the mailbox. Something like hold the PCI config lock over DOE transactions. Then it will remove ambiguity of "conflicting agent" vs "device is slow to clear BUSY".

#2 lore raw
Quoted 8 lines · On Fri, 13 Sep 2024 22:32:28 -0700 Dan Williams <[email protected]>…

[ add linux-pci and Lukas ]

Quoted 4 lines · Gregory Price

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

Quoted 9 lines

I would have expected this to be handled as part of finishing off pci_doe_recv_resp() not retrying on a new submission.

It also occurs to me that instead of warning "another entity is sending conflicting requests" message, the doe core should just ensure that it is the only agent using the mailbox. Something like hold the PCI config lock over DOE transactions. Then it will remove ambiguity of "conflicting agent" vs "device is slow to clear BUSY".

I believe we put that dance in to not fail too horribly if a firmware was messing with the DOE behind our backs rather than another OS level actor was messing with it.

We wouldn't expect firmware to be using a DOE that Linux wants, but the problem is the discovery protocol which the firmware might run to find the DOE it does want to use.

My memory might be wrong though as this was a while back.

Jonathan

#3 lore raw
Quoted 25 lines · Jonathan Cameron
Quoted 8 lines · On Fri, 13 Sep 2024 22:32:28 -0700 Dan Williams <[email protected]>…

[ add linux-pci and Lukas ]

Quoted 4 lines · Gregory Price

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

Quoted 9 lines

I would have expected this to be handled as part of finishing off pci_doe_recv_resp() not retrying on a new submission.

It also occurs to me that instead of warning "another entity is sending conflicting requests" message, the doe core should just ensure that it is the only agent using the mailbox. Something like hold the PCI config lock over DOE transactions. Then it will remove ambiguity of "conflicting agent" vs "device is slow to clear BUSY".

I believe we put that dance in to not fail too horribly if a firmware was messing with the DOE behind our backs rather than another OS level actor was messing with it.

Quoted 7 lines

We wouldn't expect firmware to be using a DOE that Linux wants, but the problem is the discovery protocol which the firmware might run to find the DOE it does want to use.

My memory might be wrong though as this was a while back.

Jonathan

Just following up here, it sounds like everyone is unsure of this change.

I can confirm that this handles the CDAT retry issue I am seeing, and that the BUSY bit is set upon entry into the initial call. Only 1 or 2 retries are attempted before it is cleared and returns successfully.

I'd explored putting the retry logic in the CDAT code that calls into here, but that just seemed wrong. Is there a suggestion or a nak here?

Trying to find a path forward.

~Gregory

#4 lore raw
Quoted 8 lines · Gregory Price
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines · Gregory Price

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

Just following up here, it sounds like everyone is unsure of this change.

Quoted 8 lines

I can confirm that this handles the CDAT retry issue I am seeing, and that the BUSY bit is set upon entry into the initial call. Only 1 or 2 retries are attempted before it is cleared and returns successfully.

I'd explored putting the retry logic in the CDAT code that calls into here, but that just seemed wrong. Is there a suggestion or a nak here?

Trying to find a path forward.

The PCIe Base Spec doesn't prescribe a maximum timeout for the DOE BUSY bit to clear. Thus it seems fine to me in principle to add a (or raise the) timeout if it turns out to be necessary for real-life hardware.

That said, the proposed patch has room for improvement:

* The patch seems to wait for DOE BUSY bit to clear *after* completion. That's odd. The kernel waits for DOE Busy bit to clear *before* sending a new request, in pci_doe_send_req(). My expectation would have been that you'd add a loop there which polls for DOE Busy bit to clear before sending a request.

It seems that polling is the only option as no interrupt is raised on DOE Busy bit clear, per PCIe r6.2 sec 6.30.3. (Please add this bit of information to the commit message.)

* The commit message should clearly specify the device(s) affected by the issue (Vendor and Device ID plus name). Comments such as "Depending on the device, sometimes ..." are a little too vague.

* The "1 or 2 retries" bit of information you're mentioning above should likewise be in the commit message.

* Please use "PCI/DOE:" as subject prefix to match previous commits which touched drivers/pci/doe.c.

* Please adhere to spec language, e.g. use "DOE Busy bit" instead of "busy bit" so it's unambiguous for readers what you're referring to.

Thanks,

Lukas

#5 lore raw
Quoted 16 lines · Lukas Wunner
Quoted 15 lines · Gregory Price
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines · Gregory Price

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

Just following up here, it sounds like everyone is unsure of this change.

I can confirm that this handles the CDAT retry issue I am seeing, and that the BUSY bit is set upon entry into the initial call. Only 1 or 2 retries are attempted before it is cleared and returns successfully.

I'd explored putting the retry logic in the CDAT code that calls into here, but that just seemed wrong. Is there a suggestion or a nak here?

Quoted 8 lines
Quoted 1 line

Trying to find a path forward.

The PCIe Base Spec doesn't prescribe a maximum timeout for the DOE BUSY bit to clear. Thus it seems fine to me in principle to add a (or raise the) timeout if it turns out to be necessary for real-life hardware.

That said, the proposed patch has room for improvement:

Will address and resubmit, thanks!

Quoted 29 lines

* The patch seems to wait for DOE BUSY bit to clear *after* completion. That's odd. The kernel waits for DOE Busy bit to clear *before* sending a new request, in pci_doe_send_req(). My expectation would have been that you'd add a loop there which polls for DOE Busy bit to clear before sending a request.

It seems that polling is the only option as no interrupt is raised on DOE Busy bit clear, per PCIe r6.2 sec 6.30.3. (Please add this bit of information to the commit message.)

* The commit message should clearly specify the device(s) affected by the issue (Vendor and Device ID plus name). Comments such as "Depending on the device, sometimes ..." are a little too vague.

* The "1 or 2 retries" bit of information you're mentioning above should likewise be in the commit message.

* Please use "PCI/DOE:" as subject prefix to match previous commits which touched drivers/pci/doe.c.

* Please adhere to spec language, e.g. use "DOE Busy bit" instead of "busy bit" so it's unambiguous for readers what you're referring to.

Thanks,

Lukas

#6 lore raw
In reply to Lukas Wunner
Quoted 31 lines · On Tue, 1 Oct 2024 17:47:03 +0200 Lukas Wunner <[email protected]> wrote:
Quoted 8 lines · Gregory Price
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines · Gregory Price

Depending on the device, sometimes firmware clears the busy flag later than expected. This can cause the device to appear busy when calling multiple commands in quick sucession. Add a 1 second retry window to all doe commands that end with -EBUSY.

Just following up here, it sounds like everyone is unsure of this change.

Quoted 8 lines

I can confirm that this handles the CDAT retry issue I am seeing, and that the BUSY bit is set upon entry into the initial call. Only 1 or 2 retries are attempted before it is cleared and returns successfully.

I'd explored putting the retry logic in the CDAT code that calls into here, but that just seemed wrong. Is there a suggestion or a nak here?

Trying to find a path forward.

The PCIe Base Spec doesn't prescribe a maximum timeout for the DOE BUSY bit to clear. Thus it seems fine to me in principle to add a (or raise the) timeout if it turns out to be necessary for real-life hardware.

That said, the proposed patch has room for improvement:

* The patch seems to wait for DOE BUSY bit to clear *after* completion. That's odd. The kernel waits for DOE Busy bit to clear *before* sending a new request, in pci_doe_send_req(). My expectation would have been that you'd add a loop there which polls for DOE Busy bit to clear before sending a request.

Quoted 3 lines

It seems that polling is the only option as no interrupt is raised on DOE Busy bit clear, per PCIe r6.2 sec 6.30.3. (Please add this bit of information to the commit message.)

This changed at some point. In PCI 6.0 the clearing of this bit is explicitly called out in DOE interrupt status as a reason to trigger the interrupt. By 6.1 that's gone. This was a problem for the original implementation as we had to assume that we'd get random spurious interrupts because of that delight.

Anyhow, hopefully doesn't matter to us here as you are correct that we have to poll for it.

Mind you we still have to allow for spurious garbage interrupts and eat them silently. :(

Quoted 20 lines

* The commit message should clearly specify the device(s) affected by the issue (Vendor and Device ID plus name). Comments such as "Depending on the device, sometimes ..." are a little too vague.

* The "1 or 2 retries" bit of information you're mentioning above should likewise be in the commit message.

* Please use "PCI/DOE:" as subject prefix to match previous commits which touched drivers/pci/doe.c.

* Please adhere to spec language, e.g. use "DOE Busy bit" instead of "busy bit" so it's unambiguous for readers what you're referring to.

Thanks,

Lukas