Skip to contentSkip to conversation

PCI: Move reset and restore related code to reset-restore.c

PATCH Superseded Ilpo Järvinen 2 participants 5 messages May 12, 2025 – May 14, 2025 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Move reset and restore related code to reset-restore.c

There are quite many reset and restore related functions in pci.c that barely depend on the other functions in pci.c. Create reset-restore.c for reset and restore related logic to keep those 1k lines in one place.

---

Based on top of the pci/reset branch. AFAIK, there shouldn't be major conflicts because of this with what's currently among the accepted changes.

 drivers/pci/Makefile        |    4 +-
 drivers/pci/pci.c           | 1015 +----------------------------------
 drivers/pci/pci.h           |   10 +
 drivers/pci/reset-restore.c | 1014 ++++++++++++++++++++++++++++++++++
 4 files changed, 1028 insertions(+), 1015 deletions(-)
 create mode 100644 drivers/pci/reset-restore.c
drivers/pci/Makefile +2 -2
index 67647f1880fb..28f4748a63e9 100644
@@ -3,8 +3,8 @@
 # Makefile for the PCI bus specific drivers.
 
 obj-$(CONFIG_PCI)		+= access.o bus.o probe.o host-bridge.o \
-				   remove.o pci.o pci-driver.o search.o \
-				   rom.o setup-res.o irq.o vpd.o \
+				   remove.o reset-restore.o pci.o pci-driver.o \
+				   search.o rom.o setup-res.o irq.o vpd.o \
 				   setup-bus.o vc.o mmap.o devres.o
 
 obj-$(CONFIG_PCI)		+= msi/
drivers/pci/pci.c +2 -1013

1,057 lines not on this page · raw message

drivers/pci/pci.h +10 -0
index b81e99cd4b62..10b96bfd9a72 100644
@@ -46,6 +46,14 @@ struct pcie_tlp_log;
  */
 #define PCIE_PME_TO_L2_TIMEOUT_US	10000
 
+/*
+ * Devices may extend the 1 sec period through Request Retry Status
+ * completions (PCIe r6.0 sec 2.3.1).  The spec does not provide an upper
+ * limit, but 60 sec ought to be enough for any device to become
+ * responsive.
+ */
+#define PCIE_RESET_READY_POLL_MS 60000 /* msec */
+
 /*
  * PCIe r6.0, sec 6.6.1 <Conventional Reset>
  *
@@ -154,7 +162,9 @@ void pci_msi_init(struct pci_dev *dev);
 void pci_msix_init(struct pci_dev *dev);
 bool pci_bridge_d3_possible(struct pci_dev *dev);
 void pci_bridge_d3_update(struct pci_dev *dev);
+void pci_dev_d3_sleep(struct pci_dev *dev);
 int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type);
+int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout);
 
 static inline bool pci_bus_rrs_vendor_id(u32 l)
 {
drivers/pci/reset-restore.c new file +1014 -0

1,014 lines not on this page · raw message

base-commit: f3efb9569b4a21354ef2caf7ab0608a3e14cc6e4

Signature · 1 line
2.39.5
#1 lore raw
Quoted 5 lines · Ilpo Järvinen

There are quite many reset and restore related functions in pci.c that barely depend on the other functions in pci.c. Create reset-restore.c for reset and restore related logic to keep those 1k lines in one place.

Hm, could I get a:

... per:

https://lore.kernel.org/r/[email protected]/

Quoted 4 lines
 drivers/pci/Makefile        |    4 +-
 drivers/pci/pci.c           | 1015 +----------------------------------
 drivers/pci/pci.h           |   10 +
 drivers/pci/reset-restore.c | 1014 ++++++++++++++++++++++++++++++++++

I'd prefer reset.c for succinctness.

That said, this patch conflicts with Mani's slot reset patches which a lot of people seem to be interested in:

https://lore.kernel.org/r/[email protected]/

Maybe it's better to give Mani's series the advantage and defer this patch here to the next cycle.

drivers/pci/pci.c struct pci_pme_device { · line 70

Quoted 5 lines
drivers/pci/pci.c +0 -0
@@ -69,15 +69,7 @@ struct pci_pme_device {
  */
 #define PCI_RESET_WAIT 1000 /* msec */

I'd move PCI_RESET_WAIT, pci_dev_wait() and pci_bridge_wait_for_secondary_bus() to reset.c as well.

Then pci_dev_d3_sleep() is the only function which is no longer static.

Thanks,

Lukas

#2 lore raw
Quoted 7 lines · Lukas Wunner
Quoted 5 lines · Ilpo Järvinen

There are quite many reset and restore related functions in pci.c that barely depend on the other functions in pci.c. Create reset-restore.c for reset and restore related logic to keep those 1k lines in one place.

Quoted 7 lines

Hm, could I get a:

... per:

https://lore.kernel.org/r/[email protected]/

Ah, I hadn't even noticed you suggested it (I recall reading the first paragraph of that but not the last one which made the suggestion). I made this patch first back in 2024 and have just sit on top of the change until there seems to be reasonably conflict free window.

Quoted 6 lines
Quoted 4 lines
 drivers/pci/Makefile        |    4 +-
 drivers/pci/pci.c           | 1015 +----------------------------------
 drivers/pci/pci.h           |   10 +
 drivers/pci/reset-restore.c | 1014 ++++++++++++++++++++++++++++++++++

I'd prefer reset.c for succinctness.

I initially had reset.c but was worried the name is too narrow scoped, I can change back to reset.c.

Quoted 7 lines

That said, this patch conflicts with Mani's slot reset patches which a lot of people seem to be interested in:

https://lore.kernel.org/r/[email protected]/

Maybe it's better to give Mani's series the advantage and defer this patch here to the next cycle.

Fine for me but those conflicts looks quite simple. Next cycle will have its own share of conflicts, I'm sure :-).

Quoted 9 lines

drivers/pci/pci.c struct pci_pme_device { · line 70

Quoted 5 lines
drivers/pci/pci.c +0 -0
@@ -69,15 +69,7 @@ struct pci_pme_device {
  */
 #define PCI_RESET_WAIT 1000 /* msec */

I'd move PCI_RESET_WAIT, pci_dev_wait() and pci_bridge_wait_for_secondary_bus() to reset.c as well.
Then pci_dev_d3_sleep() is the only function which is no longer static.

Okay I'll move those as well but that static statement is not exactly true, I'll these need to do these as well:

- move pci_bus_max_d3cold_delay() along with pci_bridge_wait_for_secondary_bus() to keep that static, or turn that into a non-static.

- make pcie_wait_for_link_delay() non-static.

Signature · 1 line
 i.
#3 lore raw
Quoted 11 lines · Ilpo Järvinen
Quoted 9 lines · Lukas Wunner

drivers/pci/pci.c struct pci_pme_device { · line 70

Quoted 5 lines
drivers/pci/pci.c +0 -0
@@ -69,15 +69,7 @@ struct pci_pme_device {
  */
 #define PCI_RESET_WAIT 1000 /* msec */

I'd move PCI_RESET_WAIT, pci_dev_wait() and pci_bridge_wait_for_secondary_bus() to reset.c as well.
Then pci_dev_d3_sleep() is the only function which is no longer static.

Quoted 8 lines

Okay I'll move those as well but that static statement is not exactly true, I'll these need to do these as well:

- move pci_bus_max_d3cold_delay() along with pci_bridge_wait_for_secondary_bus() to keep that static, or turn that into a non-static.

- make pcie_wait_for_link_delay() non-static.

Sorry, missed that. In that case I suggest moving pcie_wait_for_link() as well. It is already non-static. Then you can keep the static on pcie_wait_for_link_delay().

Per PCIe r6.2 sec 5.8, a transition from D3cold to D0uninitialized implies a Fundamental Reset. That could serve as a creative justification in the commit message or in the code comment at the top of reset.c why it contains D3cold-related functions. ;)

Thanks,

Lukas

#4 lore raw
Quoted 21 lines · Lukas Wunner
Quoted 11 lines · Ilpo Järvinen
Quoted 9 lines · Lukas Wunner

drivers/pci/pci.c struct pci_pme_device { · line 70

Quoted 5 lines
drivers/pci/pci.c +0 -0
@@ -69,15 +69,7 @@ struct pci_pme_device {
  */
 #define PCI_RESET_WAIT 1000 /* msec */

I'd move PCI_RESET_WAIT, pci_dev_wait() and pci_bridge_wait_for_secondary_bus() to reset.c as well.
Then pci_dev_d3_sleep() is the only function which is no longer static.

Quoted 8 lines

Okay I'll move those as well but that static statement is not exactly true, I'll these need to do these as well:

- move pci_bus_max_d3cold_delay() along with pci_bridge_wait_for_secondary_bus() to keep that static, or turn that into a non-static.

- make pcie_wait_for_link_delay() non-static.

Quoted 8 lines

Sorry, missed that. In that case I suggest moving pcie_wait_for_link() as well. It is already non-static. Then you can keep the static on pcie_wait_for_link_delay().

Per PCIe r6.2 sec 5.8, a transition from D3cold to D0uninitialized implies a Fundamental Reset. That could serve as a creative justification in the commit message or in the code comment at the top of reset.c why it contains D3cold-related functions. ;)

Great, this is mushrooming fast :-).

That implies making pcie_wait_for_link_status() non-static, regardless of location or moving also pcie_retrain_link() which I suppose can't really be excused to reside in reset.c :-). Now that I think about it, I recall I ran across this problem which is why the split ended where it was in this submission.

Maybe, it would make sense to have not only reset.c but also link.c (for waiting, retraining, and link speed related functions). Those two files (link.c and reset.c) are kind of inter-related still but the interface between looks relatively sane and should be one-way (I think, I didn't attempt this dual split yet).

Signature · 1 line
 i.