Re: [PATCH v16 16/18] PCI/CXL: Expose CXL Reset as a PCI reset method
From: Richard Cheng
Date: Fri Oct 30 2026 - 04:36:51 EST
On Thu, Oct 29, 2026 at 02:57:01PM +0800, Srirangan Madhavan wrote:
> 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, function scope, cached HDM state,
> or required cache synchronization do not permit a safe reset.
>
> Signed-off-by: Srirangan Madhavan <smadhavan@xxxxxxxxxx>
Reviewed-by: Richard Cheng <icheng@xxxxxxxxxx>
> ---
> drivers/pci/cxl.c | 12 +++++++++---
> drivers/pci/pci.c | 1 +
> include/linux/pci.h | 2 +-
> 3 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/cxl.c b/drivers/pci/cxl.c
> index 58bbd5b47539..0c4ac0832b34 100644
> --- a/drivers/pci/cxl.c
> +++ b/drivers/pci/cxl.c
> @@ -672,7 +672,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) ||
> @@ -681,9 +681,9 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
>
> rc = pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_CTRL, &ctrl);
> if (rc)
> - return pcibios_err_to_errno(rc);
> + return probe ? -ENOTTY : pcibios_err_to_errno(rc);
> if (PCI_POSSIBLE_ERROR(ctrl))
> - return -ENODEV;
> + return probe ? -ENOTTY : -ENODEV;
> if (!(ctrl & PCI_DVSEC_CXL_CACHE_ENABLE) ||
> !(ctrl & PCI_DVSEC_CXL_MEM_ENABLE))
> return -ENOTTY;
> @@ -706,5 +706,11 @@ int cxl_reset_function(struct pci_dev *pdev, bool probe)
> !IS_ENABLED(CONFIG_CXL_REGION_INVALIDATION_TEST))
> return -ENOTTY;
>
> + /* 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 9031060423cc..f5990d6cc51b 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5148,6 +5148,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 7bb37fcb556d..743b57ff885a 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
>