Linux CXL
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Dave Jiang <dave.jiang@intel.com>
Cc: <linux-cxl@vger.kernel.org>, <dan.j.williams@intel.com>,
	<ira.weiny@intel.com>, <vishal.l.verma@intel.com>,
	<alison.schofield@intel.com>
Subject: Re: [PATCH v2 3/8] cxl: refactor cxl_hdm_decode_init()
Date: Fri, 13 Jan 2023 13:46:27 +0000	[thread overview]
Message-ID: <20230113134627.00005117@Huawei.com> (raw)
In-Reply-To: <167330060509.975161.6672958439144493413.stgit@djiang5-mobl3.local>

On Mon, 09 Jan 2023 14:43:26 -0700
Dave Jiang <dave.jiang@intel.com> wrote:

> With the previous refactoring of DVSEC range registers out of
> cxl_hdm_decode_init(), it basically becomes a skeleton function. Squash
> __cxl_hdm_decode_init() with cxl_hdm_decode_init() to simplify the code.
> cxl_hdm_decode_init() now returns more error codes than just -EBUSY.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>

One trivial style comment.  Either way

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

>  int cxl_dvsec_rr_decode(struct pci_dev *pdev, int d,
>  			struct cxl_endpoint_dvsec_info *info)
>  {
> @@ -449,17 +375,68 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
>  {
>  	struct pci_dev *pdev = to_pci_dev(cxlds->dev);
>  	struct device *dev = &pdev->dev;
> +	void __iomem *hdm = cxlhdm->regs.hdm_decoder;
> +	struct cxl_port *port = cxlhdm->port;
> +	struct cxl_port *root;
> +	int i, rc, allowed;
> +	u32 global_ctrl;
> +
> +	global_ctrl = readl(hdm + CXL_HDM_DECODER_CTRL_OFFSET);
>  
>  	/*
> -	 * If DVSEC ranges are being used instead of HDM decoder registers there
> -	 * is no use in trying to manage those.
> +	 * If the HDM Decoder Capability is already enabled then assume
> +	 * that some other agent like platform firmware set it up.
>  	 */
> -	if (!__cxl_hdm_decode_init(cxlds, cxlhdm, info)) {
> -		dev_err(dev,
> -			"Legacy range registers configuration prevents HDM operation.\n");
> -		return -EBUSY;
> +	if (global_ctrl & CXL_HDM_DECODER_ENABLE)
> +		return devm_cxl_enable_mem(&port->dev, cxlds);
> +
> +	root = to_cxl_port(port->dev.parent);
> +	while (!is_cxl_root(root) && is_cxl_port(root->dev.parent))
> +		root = to_cxl_port(root->dev.parent);
> +	if (!is_cxl_root(root)) {
> +		dev_err(dev, "Failed to acquire root port for HDM enable\n");
> +		return -ENODEV;
> +	}
> +
> +	for (i = 0, allowed = 0; info->mem_enabled && i < info->ranges; i++) {
> +		struct device *cxld_dev;
> +
> +		cxld_dev = device_find_child(&root->dev, &info->dvsec_range[i],
> +					     dvsec_range_allowed);
> +		if (!cxld_dev) {
> +			dev_dbg(dev, "DVSEC Range%d denied by platform\n", i);
> +			continue;
> +		}
> +		dev_dbg(dev, "DVSEC Range%d allowed by platform\n", i);
> +		put_device(cxld_dev);
> +		allowed++;
>  	}
>  
> +	if (!allowed) {
> +		cxl_set_mem_enable(cxlds, 0);
> +		info->mem_enabled = 0;
> +	}
> +
> +	/*
> +	 * Per CXL 2.0 Section 8.1.3.8.3 and 8.1.3.8.4 DVSEC CXL Range 1 Base
> +	 * [High,Low] when HDM operation is enabled the range register values
> +	 * are ignored by the device, but the spec also recommends matching the
> +	 * DVSEC Range 1,2 to HDM Decoder Range 0,1. So, non-zero info->ranges
> +	 * are expected even though Linux does not require or maintain that
> +	 * match. If at least one DVSEC range is enabled and allowed, skip HDM
> +	 * Decoder Capability Enable.
> +	 */
> +	if (info->mem_enabled)
> +		return -EBUSY;
> +
> +	rc = devm_cxl_enable_hdm(&port->dev, cxlhdm);
> +	if (rc)
> +		return rc;
> +
> +	rc = devm_cxl_enable_mem(&port->dev, cxlds);
> +	if (rc)
> +		return rc;
> +
>  	return 0;

Maybe simplify to
	return devm_cxl_enable_mem(...);
if not touched again in later patches.

>  }
>  EXPORT_SYMBOL_NS_GPL(cxl_hdm_decode_init, CXL);
> 
> 


  reply	other threads:[~2023-01-13 13:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 21:43 [PATCH v2 0/8] cxl: Introduce HDM decoder emulation from DVSEC range registers Dave Jiang
2023-01-09 21:43 ` [PATCH v2 1/8] cxl: break out range register decoding from cxl_hdm_decode_init() Dave Jiang
2023-01-13 13:36   ` Jonathan Cameron
2023-01-17 20:12     ` Dave Jiang
2023-01-09 21:43 ` [PATCH v2 2/8] cxl: export cxl_dvsec_rr_decode() to cxl_port Dave Jiang
2023-01-13 13:43   ` Jonathan Cameron
2023-01-09 21:43 ` [PATCH v2 3/8] cxl: refactor cxl_hdm_decode_init() Dave Jiang
2023-01-13 13:46   ` Jonathan Cameron [this message]
2023-01-09 21:43 ` [PATCH v2 4/8] cxl: emulate HDM decoder from DVSEC range registers Dave Jiang
2023-01-13 13:51   ` Jonathan Cameron
2023-01-09 21:43 ` [PATCH v2 5/8] cxl: create emulated cxl_hdm for devices that do not have HDM decoders Dave Jiang
2023-01-13 13:54   ` Jonathan Cameron
2023-01-13 14:01   ` Jonathan Cameron
2023-01-09 21:43 ` [PATCH v2 6/8] cxl: create emulated decoders for devices without " Dave Jiang
2023-01-13 14:02   ` Jonathan Cameron
2023-01-09 21:44 ` [PATCH v2 7/8] cxl: Add emulation when HDM decoders are not committed Dave Jiang
2023-01-13 14:07   ` Jonathan Cameron
2023-01-17 23:19     ` Dave Jiang
2023-01-18 10:12       ` Jonathan Cameron
2023-01-18 15:22         ` Dave Jiang
2023-01-09 21:44 ` [PATCH v2 8/8] cxl: remove locked check for dvsec_range_allowed() Dave Jiang
2023-01-13 14:08   ` Jonathan Cameron

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=20230113134627.00005117@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --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