From: Ira Weiny <ira.weiny@intel.com>
To: Srirangan Madhavan <smadhavan@nvidia.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
"Dave Jiang" <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
"Dan Williams" <dan.j.williams@intel.com>
Cc: Zhi Wang <zhiw@nvidia.com>, Vishal Aslot <vaslot@nvidia.com>,
"Shanker Donthineni" <sdonthineni@nvidia.com>,
<linux-cxl@vger.kernel.org>
Subject: Re: [PATCH v1 1/1] cxl: add support for cxl reset
Date: Fri, 7 Feb 2025 11:15:55 -0600 [thread overview]
Message-ID: <67a63fcb6350_32b9f22943c@iweiny-mobl.notmuch> (raw)
In-Reply-To: <20250207090327.172478-2-smadhavan@nvidia.com>
Srirangan Madhavan wrote:
Generally this looks good. Some minor issues below.
> This change adds the support and implements the CXL reset
> steps as laid out by the CXL Spec v3.1 Sections 9.6 & 9.7.
>
> With support for Type 2 devices being introduced, more devices will
> require finer-grained reset mechanisms beyond bus-wide reset methods.
>
> This change defines the necessary CXL DVSEC register macros.
> For devices that support CXL Reset, cache lines are disabled, WB+I is
> asserted, wait for cache invalid status, Mem Clr bit is asserted and
> finally reset is initiated.
This commit message should be in the imperative. For example:
"Type 2 devices are being introduced and will require finer-grained
reset.
Add support for CXL reset per CXL v3.1 Section 9.6/9.7."
The rest of the details are given in the code itself. BTW why not just
update to 3.2?
>
> Signed-off-by: Srirangan Madhavan <smadhavan@nvidia.com>
> ---
> drivers/pci/pci.c | 183 ++++++++++++++++++++++++++++++++++
> include/linux/pci.h | 2 +-
> include/uapi/linux/pci_regs.h | 25 +++++
> 3 files changed, 209 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 869d204a70a3..cf6009f5bd6c 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5026,6 +5026,12 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, bool probe)
> return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
> }
>
> +static u16 cxl_device_dvsec(struct pci_dev *dev)
> +{
> + return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_CXL,
> + PCI_DVSEC_CXL_DEV);
> +}
NIT: probably not worth having a whole function but...
> +
> static u16 cxl_port_dvsec(struct pci_dev *dev)
> {
> return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_CXL,
> @@ -5116,6 +5122,182 @@ static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
> return rc;
> }
>
> +static int cxl_reset_prepare(struct pci_dev *dev, u16 dvsec)
> +{
> + u16 reg, val, cap;
> + int rc;
> + u32 timeout_us = 100, timeout_tot_us = 10000;
> +
> + /*
> + * Wait for any pending transactions.
> + * Assuming this does cxl.io stuff.
> + */
The comment here is generally not needed. In particular the first
sentence is the same as the function name being called.
> + if (!pci_wait_for_pending_transaction(dev))
> + pci_err(dev, "timed out waiting for pending transaction; performing cxl reset anyway\n");
> +
> + /*
> + * Disable caching and then write back and invalidate lines.
> + */
I think this comment is wrong...
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCAP,
> + &cap);
> + if (rc)
> + return rc;
> +
> + if (!(cap & PCI_DVSEC_CXL_DEVCAP_CACHE_CAPABLE))
> + return 0;
Isn't this checking for a cache capable device?
> +
> + /*
> + * Disable cache.
> + * WB and invalidate cahce if capability is advertised.
> + */
Then disabling and invalidating the cache here.
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + ®);
> + if (rc)
> + return rc;
> + val = reg | PCI_DVSEC_CXL_DEVCTL2_DISABLE_CACHING;
> +
> + if (cap & PCI_DVSEC_CXL_DEVCAP_CACHE_WB_INVALIDATE)
> + val = reg | PCI_DVSEC_CXL_DEVCTL2_INIT_CACHE_WB_INVALIDATE;
> + pci_write_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + val);
> +
> + /*
> + * From Section 9.6: "Software may leverage the cache size reported in
> + * the DVSEC CXL Capability2 register to compute a suitable timeout
> + * value".
> + * Given there is no conversion factor for cache size -> timeout,
> + * setting timer for default 10ms.
> + */
> + do {
> + if (timeout_tot_us < 0)
> + return -ETIMEDOUT;
> + usleep_range(timeout_us, timeout_us+1);
> + timeout_tot_us -= timeout_us;
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + ®);
> + if (rc)
> + return rc;
> + } while (!(reg & PCI_DVSEC_CXL_DEVSTATUS2_CACHE_INVALID));
> +
> + return 0;
> +}
> +
> +/**
> + * cxl_reset_init - initiate a cxl reset
> + * @dev: device to reset
@dvsec?
> + *
> + * Initiate a cxl reset.
> + */
Given this is a static internal call it seems best to leave out the kdoc
altogether rather than add the dvsec parameter to the doc.
> +static int cxl_reset_init(struct pci_dev *dev, u16 dvsec)
> +{
> + u16 reg, val;
> + u32 timeout_ms;
> + int rc;
> + u32 reset_timeouts_ms[] = {10, 100, 1000, 10000, 100000};
NIT: Maybe... give the spec reference for the timeout values.
> +
> + /*
> + * Check if CXL Reset MEM CLR is supported.
> + */
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCAP,
> + ®);
> + if (rc)
> + return rc;
> +
> + if (reg & PCI_DVSEC_CXL_DEVCAP_CXL_RST_MEM_CLR) {
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + ®);
> + if (rc)
> + return rc;
> +
> + val = reg | PCI_DVSEC_CXL_DEVCTL2_CXL_RST_MEM_CLR_ENABLE;
> + pci_write_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + val);
> + }
> +
> + /*
> + * Read timeout value
> + */
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCAP,
> + ®);
> + if (rc)
> + return rc;
> + timeout_ms = reset_timeouts_ms[FIELD_GET(PCI_DVSEC_CXL_DEVCAP_CXL_RST_TIMEOUT_MASK, reg)];
> +
> + /*
> + * Write reset config
> + */
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + ®);
> + if (rc)
> + return rc;
> +
> + val = reg | PCI_DVSEC_CXL_DEVCTL2_CXL_INIT_RST;
> + pci_write_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + val);
> +
> + /*
> + * Wait till timeout and then check reset status is complete.
> + */
> + msleep(timeout_ms);
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVSTATUS2,
> + ®);
> + if (rc)
> + return rc;
> + if (reg & PCI_DVSEC_CXL_DEVSTATUS2_RST_ERR ||
> + ~reg & PCI_DVSEC_CXL_DEVSTATUS2_RST_COMPLETE)
> + return -ETIMEDOUT;
> +
> + /*
> + * Revert cashing disable.
NIT caching
Probably best to remove the comment.
> + */
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + ®);
> + if (rc)
> + return rc;
> + val = (reg & (~PCI_DVSEC_CXL_DEVCTL2_DISABLE_CACHING));
> + pci_write_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCTL2,
> + val);
> +
> + return 0;
> +}
> +
> +/**
> + * cxl_reset - initiate a cxl reset
> + * @dev: device to reset
> + * @probe: if true, return 0 if device can be reset this way
> + *
> + * Initiate a cxl reset on @dev.
> + */
> +static int cxl_reset(struct pci_dev *dev, bool probe)
> +{
> + u16 dvsec, reg;
> + int rc;
> +
> + dvsec = cxl_device_dvsec(dev);
> + if (!dvsec)
> + return -ENOTTY;
> +
> + /*
> + * Check if CXL Reset is supported.
> + */
> + rc = pci_read_config_word(dev, dvsec + PCI_DVSEC_CXL_DEVCAP,
> + ®);
> + if (rc)
> + return -ENOTTY;
> +
> + if (~(reg & PCI_DVSEC_CXL_DEVCAP_CXL_RST))
> + return -ENOTTY;
> +
> + if (probe)
> + return 0;
> +
> + rc = cxl_reset_prepare(dev, dvsec);
> + if (rc)
> + return rc;
> +
> + return cxl_reset_init(dev, dvsec);
> +}
> +
> void pci_dev_lock(struct pci_dev *dev)
> {
> /* block PM suspend, driver probe, etc. */
> @@ -5202,6 +5384,7 @@ const struct pci_reset_fn_method pci_reset_fn_methods[] = {
> { pci_dev_acpi_reset, .name = "acpi" },
> { pcie_reset_flr, .name = "flr" },
> { pci_af_flr, .name = "af_flr" },
> + { cxl_reset, .name = "cxl_reset" },
> { pci_pm_reset, .name = "pm" },
> { pci_reset_bus_function, .name = "bus" },
> { cxl_reset_bus_function, .name = "cxl_bus" },
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 47b31ad724fa..efcb06598f26 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -51,7 +51,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
> diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
> index 3445c4970e4d..52618c5b095d 100644
> --- a/include/uapi/linux/pci_regs.h
> +++ b/include/uapi/linux/pci_regs.h
> @@ -1209,6 +1209,31 @@
> #define PCI_DOE_DATA_OBJECT_DISC_RSP_3_NEXT_INDEX 0xff000000
>
> /* Compute Express Link (CXL r3.1, sec 8.1.5) */
v3.2
Ira
[snip]
next prev parent reply other threads:[~2025-02-07 17:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 9:03 [PATCH v1 0/1] Add CXL Reset Support for CXL Devices Srirangan Madhavan
2025-02-07 9:03 ` [PATCH v1 1/1] cxl: add support for cxl reset Srirangan Madhavan
2025-02-07 15:19 ` Dave Jiang
2025-02-07 17:15 ` Ira Weiny [this message]
2025-02-13 7:35 ` Srirangan Madhavan
2025-02-08 11:48 ` kernel test robot
2025-02-14 16:57 ` Jonathan Cameron
2025-02-21 5:15 ` Srirangan Madhavan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=67a63fcb6350_32b9f22943c@iweiny-mobl.notmuch \
--to=ira.weiny@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=sdonthineni@nvidia.com \
--cc=smadhavan@nvidia.com \
--cc=vaslot@nvidia.com \
--cc=vishal.l.verma@intel.com \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox