diff mbox series

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

Message ID 20240913183241.17320-1-gourry@gourry.net
State New
Headers show
Series pci/doe: add a 1 second retry window to pci_doe | expand

Commit Message

Gregory Price Sept. 13, 2024, 6:32 p.m. UTC
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.

Signed-off-by: Gregory Price <gourry@gourry.net>
---
 drivers/pci/doe.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Dan Williams Sept. 14, 2024, 5:32 a.m. UTC | #1
[ add linux-pci and Lukas ]

Gregory Price wrote:
> 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".
Jonathan Cameron Sept. 16, 2024, 9:15 a.m. UTC | #2
On Fri, 13 Sep 2024 22:32:28 -0700
Dan Williams <dan.j.williams@intel.com> wrote:

> [ add linux-pci and Lukas ]
> 
> Gregory Price wrote:
> > 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".
> 

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
diff mbox series

Patch

diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c
index 652d63df9d22..5573fa1a0008 100644
--- a/drivers/pci/doe.c
+++ b/drivers/pci/doe.c
@@ -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;
 }