public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Dave Jiang <dave.jiang@intel.com>, <linux-cxl@vger.kernel.org>,
	<linux-pci@vger.kernel.org>
Cc: <dan.j.williams@intel.com>, <ira.weiny@intel.com>,
	<vishal.l.verma@intel.com>, <alison.schofield@intel.com>,
	<Jonathan.Cameron@huawei.com>, <dave@stgolabs.net>,
	<bhelgaas@google.com>, <lukas@wunner.de>
Subject: RE: [PATCH v2 2/3] PCI: Create new reset method to force SBR for CXL
Date: Wed, 27 Mar 2024 18:53:19 -0700	[thread overview]
Message-ID: <6604cd8fddef5_7702a294c4@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <20240325235914.1897647-3-dave.jiang@intel.com>

Dave Jiang wrote:
> CXL spec r3.1 8.1.5.2
> By default Secondary Bus Reset (SBR) is masked for CXL ports. Introduce a
> new PCI reset method "cxl_bus_force" to force SBR on CXL ports by setting
> the unmask SBR bit in the CXL DVSEC port control register before performing
> the bus reset and restore the original value of the bit post reset. The
> new reset method allows the user to intentionally perform SBR on a CXL
> device without needing to set the "Unmask SBR" bit via a user tool.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
> v2:
> - Use pci_upstream_bridge() instead of dev->bus->self.
> - Return -ENOTTY as error for reset function
> ---
>  drivers/pci/pci.c   | 52 +++++++++++++++++++++++++++++++++++++++++++--
>  include/linux/pci.h |  2 +-
>  2 files changed, 51 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 259e5d6538bb..cbcad8f0880d 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -4933,6 +4933,12 @@ static bool pci_is_cxl(struct pci_dev *dev)
>  					 CXL_DVSEC_PCIE_DEVICE);
>  }
>  
> +static int cxl_port_dvsec(struct pci_dev *dev)
> +{
> +	return pci_find_dvsec_capability(dev, PCI_DVSEC_VENDOR_ID_CXL,
> +					 CXL_DVSEC_PCIE_PORT);
> +}
> +
>  static bool is_cxl_port_sbr_masked(struct pci_dev *dev)
>  {
>  	int dvsec;
> @@ -4942,8 +4948,7 @@ static bool is_cxl_port_sbr_masked(struct pci_dev *dev)
>  	/*
>  	 * No DVSEC found, must not be CXL port.
>  	 */
> -	dvsec = pci_find_dvsec_capability(dev, PCI_DVSEC_VENDOR_ID_CXL,
> -					  CXL_DVSEC_PCIE_PORT);

Once applied, those 2 lines had a very short life in mainline. Perhaps
just define cxl_port_dvsec() in patch1?

> +	dvsec = cxl_port_dvsec(dev);
>  	if (!dvsec)
>  		return false;
>  
> @@ -4982,6 +4987,48 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe)
>  	return pci_parent_bus_reset(dev, probe);
>  }
>  
> +static int cxl_reset_bus_function(struct pci_dev *dev, bool probe)
> +{
> +	struct pci_dev *bridge;
> +	int dvsec;
> +	int rc;
> +	u16 reg, val;
> +
> +	if (!pci_is_cxl(dev))
> +		return -ENOTTY;
> +
> +	bridge = pci_upstream_bridge(dev);
> +	if (!bridge)
> +		return -ENOTTY;
> +
> +	dvsec = cxl_port_dvsec(bridge);
> +	if (!dvsec)
> +		return -ENOTTY;
> +
> +	if (probe)
> +		return 0;
> +
> +	rc = pci_read_config_word(bridge, dvsec + CXL_DVSEC_PORT_CONTROL,
> +				  &reg);
> +	if (rc)
> +		return -ENOTTY;
> +
> +	if (!(reg & CXL_DVSEC_PORT_CONTROL_UNMASK_SBR)) {
> +		val = reg | CXL_DVSEC_PORT_CONTROL_UNMASK_SBR;
> +		pci_write_config_word(bridge,
> +				      dvsec + CXL_DVSEC_PORT_CONTROL, val);
> +	} else {
> +		val = reg;
> +	}
> +
> +	rc = pci_reset_bus_function(dev, probe);
> +
> +	if (reg != val)
> +		pci_write_config_word(bridge, dvsec + CXL_DVSEC_PORT_CONTROL, reg);

Doesn't this whole sequence need to be wrapped in pci_cfg_access_lock()?
Otherwise userspace can get confused if it races to access
CXL_DVSEC_PCIE_PORT while the link is down, or if it races to write
Unmask SBR and messes up the saved value.

I took a quick look and did not see this lock taken from
reset_method_store().

> +
> +	return rc;
> +}
> +
>  void pci_dev_lock(struct pci_dev *dev)
>  {
>  	/* block PM suspend, driver probe, etc. */
> @@ -5066,6 +5113,7 @@ static const struct pci_reset_fn_method pci_reset_fn_methods[] = {
>  	{ pci_af_flr, .name = "af_flr" },
>  	{ pci_pm_reset, .name = "pm" },
>  	{ pci_reset_bus_function, .name = "bus" },
> +	{ cxl_reset_bus_function, .name = "cxl_bus_force" },

Why include "_force" in the name? "cxl_bus" already implies "do what is
needed to bus reset this CXL link".

  reply	other threads:[~2024-03-28  1:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 23:58 [PATCH 0/3 v2] PCI: Add Secondary Bus Reset (SBR) support for CXL Dave Jiang
2024-03-25 23:58 ` [PATCH v2 1/3] PCI: Add check for CXL Secondary Bus Reset Dave Jiang
2024-03-27 21:26   ` Bjorn Helgaas
2024-03-27 23:57     ` Dave Jiang
2024-03-28 17:38       ` Bjorn Helgaas
2024-03-28 19:03         ` Dan Williams
2024-03-28 19:14           ` Bjorn Helgaas
2024-04-02 17:23           ` Bjorn Helgaas
2024-04-02 17:46             ` Dan Williams
2024-04-03 14:44               ` Jonathan Cameron
2024-04-03 20:36                 ` Dan Williams
2024-04-04  9:02                 ` Lukas Wunner
2024-04-04 13:52                   ` Jonathan Cameron
2024-03-28  1:43   ` Dan Williams
2024-03-25 23:58 ` [PATCH v2 2/3] PCI: Create new reset method to force SBR for CXL Dave Jiang
2024-03-28  1:53   ` Dan Williams [this message]
2024-03-25 23:58 ` [PATCH v2 3/3] cxl: Add post reset warning if reset is detected as Secondary Bus Reset (SBR) Dave Jiang
2024-03-28  2:03   ` Dan Williams
  -- strict thread matches above, loose matches on Subject: below --
2024-05-21 17:34 [PATCH v2 2/3] PCI: Create new reset method to force SBR for CXL Vishal Aslot
2024-05-21 18:11 ` Dan Williams
2024-05-21 21:04   ` Vikram Sethi
2024-05-21 21:23     ` Dan Williams
2024-05-22  2:51       ` Vikram Sethi
2024-05-29  4:10         ` Dan Williams

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=6604cd8fddef5_7702a294c4@dwillia2-xfh.jf.intel.com.notmuch \
    --to=dan.j.williams@intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=alison.schofield@intel.com \
    --cc=bhelgaas@google.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=vishal.l.verma@intel.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