[PATCH v18 16/19] PCI/CXL: Expose CXL Reset as a PCI reset method
From: Srirangan Madhavan
Date: Fri Dec 04 2026 - 23:16:29 EST
Register cxl_reset with the PCI reset-method interface and place it before
FLR, which does not reset CXL.cache or CXL.mem protocol state.
Return -ENOTTY when device capabilities or function scope do not permit a
reset, so that the next method is tried. Refuse with another error when
cached HDM state or required cache synchronization cannot make the reset
safe, since FLR would not reset the CXL state.
Signed-off-by: Srirangan Madhavan <smadhavan@xxxxxxxxxx>
Reviewed-by: Richard Cheng <icheng@xxxxxxxxxx>
---
Changes in v18:
- Return -ENOTTY only when the device or its function scope does not
permit CXL Reset. Refuse with another error when cached HDM state or
cache synchronization cannot make it safe, so a refused reset no longer
falls back to FLR, which would not reset the CXL state (Sashiko)
https://sashiko.dev/#/patchset/20261105185917.2667656-1-smadhavan@xxxxxxxxxx?part=13
---
drivers/pci/cxl.c | 10 ++++++++--
drivers/pci/pci.c | 1 +
include/linux/pci.h | 2 +-
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c
index 1053aa2f6607..cc2d5a4f67df 100644
--- a/drivers/pci/cxl.c
+++ b/drivers/pci/cxl.c
@@ -814,7 +814,7 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
rc = cxl_pci_device_dvsec(pdev, &dvsec, &cap);
if (rc)
- return rc;
+ return probe ? -ENOTTY : rc;
if (!(cap & PCI_DVSEC_CXL_CACHE_CAPABLE) ||
!(cap & PCI_DVSEC_CXL_MEM_CAPABLE) ||
!(cap & PCI_DVSEC_CXL_RST_CAPABLE) ||
@@ -823,7 +823,7 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
rc = cxl_pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_CTRL, &ctrl);
if (rc)
- return rc;
+ return probe ? -ENOTTY : rc;
if (!(ctrl & PCI_DVSEC_CXL_CACHE_ENABLE) ||
!(ctrl & PCI_DVSEC_CXL_MEM_ENABLE))
return -ENOTTY;
@@ -831,5 +831,11 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
if (probe)
return 0;
+ /* Raw reset callers may not have saved the PCI state needed for restore. */
+ if (!pdev->state_saved) {
+ pci_err(pdev, "CXL reset requires saved PCI state\n");
+ return -EINVAL;
+ }
+
return cxl_reset_execute(pdev, dvsec, cap);
}
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 5a8338340d23..9ab647719c9f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5204,6 +5204,7 @@ const struct pci_reset_fn_method pci_reset_fn_methods[] = {
{ },
{ pci_dev_specific_reset, .name = "device_specific" },
{ pci_dev_acpi_reset, .name = "acpi" },
+ { cxl_reset_function, .name = "cxl_reset" },
{ pcie_reset_flr, .name = "flr" },
{ pci_af_flr, .name = "af_flr" },
{ pci_pm_reset, .name = "pm" },
diff --git a/include/linux/pci.h b/include/linux/pci.h
index f62aab652770..6dba622430f4 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -52,7 +52,7 @@
PCI_STATUS_PARITY)
/* Number of reset methods used in pci_reset_fn_methods array in pci.c */
-#define PCI_NUM_RESET_METHODS 8
+#define PCI_NUM_RESET_METHODS 9
#define PCI_RESET_PROBE true
#define PCI_RESET_DO_RESET false
--
2.43.0