Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: PCI: Amend error recovery doc with pci_save_state() rules

After recovering from a PCI error through reset, affected devices are in
D0_uninitialized state and need to be brought into D0_active state by
re-initializing their Config Space registers (PCIe r7.0 sec 5.3.1.1).

To facilitate that, the PCI core provides pci_restore_state() and
pci_save_state() helpers. Document rules governing their usage.

As Bjorn notes, so far no file in "Documentation/ includes anything about
the idea of a driver using pci_save_state() to capture the state it wants
to restore after an error", even though it is a common pattern in drivers.
So that's obviously a gap that should be closed.

Reported-by: Bjorn Helgaas <helgaas@kernel.org>
Closes: https://lore.kernel.org/r/20251113161556.GA2284238@bhelgaas/
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Link: https://patch.msgid.link/077596ba70202be0e43fdad3bb9b93d356cbe4ec.1763746079.git.lukas@wunner.de

authored by

Lukas Wunner and committed by
Bjorn Helgaas
5e09895b 383d8969

+15
+15
Documentation/PCI/pci-error-recovery.rst
··· 326 326 will typically report a "permanent failure" in such a case. The 327 327 device will be considered "dead" in this case. 328 328 329 + Drivers typically need to call pci_restore_state() after reset to 330 + re-initialize the device's config space registers and thereby 331 + bring it from D0\ :sub:`uninitialized` into D0\ :sub:`active` state 332 + (PCIe r7.0 sec 5.3.1.1). The PCI core invokes pci_save_state() 333 + on enumeration after initializing config space to ensure that a 334 + saved state is available for subsequent error recovery. 335 + Drivers which modify config space on probe may need to invoke 336 + pci_save_state() afterwards to record those changes for later 337 + error recovery. When going into system suspend, pci_save_state() 338 + is called for every PCI device and that state will be restored 339 + not only on resume, but also on any subsequent error recovery. 340 + In the unlikely event that the saved state recorded on suspend 341 + is unsuitable for error recovery, drivers should call 342 + pci_save_state() on resume. 343 + 329 344 Drivers for multi-function cards will need to coordinate among 330 345 themselves as to which driver instance will perform any "one-shot" 331 346 or global device initialization. For example, the Symbios sym53cxx2