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>, <dave@stgolabs.net>,
	<alison.schofield@intel.com>, <vishal.l.verma@intel.com>,
	<ira.weiny@intel.com>, <dan.j.williams@intel.com>,
	<rrichter@amd.com>
Subject: Re: [PATCH v4 6/9] cxl/test: Add mock version of devm_cxl_add_dport_by_dev()
Date: Tue, 1 Jul 2025 12:17:40 +0100	[thread overview]
Message-ID: <20250701121740.000011ed@huawei.com> (raw)
In-Reply-To: <20250624213916.1665889-7-dave.jiang@intel.com>

On Tue, 24 Jun 2025 14:39:13 -0700
Dave Jiang <dave.jiang@intel.com> wrote:

> devm_cxl_add_dport_by_dev() outside of cxl_test is done through PCI
> hierarchy. However with cxl_test, it needs to be done through the
> platform device hierarchy. Add the mock function for
> devm_cxl_add_dport_by_dev().
> 
> When cxl_core calls a cxl_core exported function and that function is
> mocked by cxl_test, the call chain causes a circular dependency issue. Dan
> provided a workaround to avoid this issue. Apply the method to changes from
> the late dport allocation changes in order to enable cxl-test.
> 
> In cxl_core they are defined with "__" added in front of the function. A
> macro is used to define the original function names for when non-test
> version of the kernel is built. A bit of macros and typedefs are used to
> allow mocking of those functions in cxl_test.
> 
> Co-developed-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>

One comment inline.  I'm not fond of the macro dance in here but don't have
a better suggestion, so fair enough.

> index 5d6585d4b15e..b13f9796687c 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -1037,6 +1037,64 @@ static int mock_cxl_port_enumerate_dports(struct cxl_port *port)
>  	return 0;
>  }
>  
> +static struct cxl_dport *mock_cxl_add_dport_by_dev(struct cxl_port *port,
> +						   struct device *dport_dev)
> +{
> +	struct platform_device **array;
> +	int i, array_size;
> +
> +	if (port->depth == 1) {
> +		if (is_multi_bridge(port->uport_dev)) {
> +			array_size = ARRAY_SIZE(cxl_root_port);
> +			array = cxl_root_port;
> +		} else if (is_single_bridge(port->uport_dev)) {
> +			array_size = ARRAY_SIZE(cxl_root_single);
> +			array = cxl_root_single;
> +		} else {
> +			dev_dbg(&port->dev, "%s: unknown bridge type\n",
> +				dev_name(port->uport_dev));
> +			return ERR_PTR(-ENXIO);
> +		}

This is all duplicating code in mock_cxl_port_get_total_dports.  
Helper to at least get the array_size and array?  Probably not
worth combining the final loops.

> +	} else if (port->depth == 2) {
> +		struct cxl_port *parent = to_cxl_port(port->dev.parent);
> +
> +		if (is_multi_bridge(parent->uport_dev)) {
> +			array_size = ARRAY_SIZE(cxl_switch_dport);
> +			array = cxl_switch_dport;
> +		} else if (is_single_bridge(parent->uport_dev)) {
> +			array_size = ARRAY_SIZE(cxl_swd_single);
> +			array = cxl_swd_single;
> +		} else {
> +			dev_dbg(&port->dev, "%s: unknown bridge type\n",
> +				dev_name(port->uport_dev));
> +			return ERR_PTR(-ENXIO);
> +		}
> +	} else {
> +		dev_WARN_ONCE(&port->dev, 1, "unexpected depth %d\n",
> +			      port->depth);
> +		return ERR_PTR(-ENXIO);
> +	}
> +
> +	for (i = 0; i < array_size; i++) {
> +		struct platform_device *pdev = array[i];
> +
> +		if (pdev->dev.parent != port->uport_dev) {
> +			dev_dbg(&port->dev, "%s: mismatch parent %s\n",
> +				dev_name(port->uport_dev),
> +				dev_name(pdev->dev.parent));
> +			continue;
> +		}
> +
> +		if (&pdev->dev != dport_dev)
> +			continue;
> +
> +		return devm_cxl_add_dport(port, &pdev->dev, pdev->id,
> +					  CXL_RESOURCE_NONE);
> +	}
> +
> +	return ERR_PTR(-ENODEV);
> +}



  reply	other threads:[~2025-07-01 11:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24 21:39 [PATCH v4 0/9] cxl: Delay HB port and switch dport probing until endpoint dev probe Dave Jiang
2025-06-24 21:39 ` [PATCH v4 1/9] cxl/region: Add decoder check to check_commit_order() Dave Jiang
2025-06-24 21:39 ` [PATCH v4 2/9] cxl: Add helper to detect top of CXL device topology Dave Jiang
2025-06-24 21:39 ` [PATCH v4 3/9] cxl: Add helper to reap dport Dave Jiang
2025-07-01 10:31   ` Jonathan Cameron
2025-06-24 21:39 ` [PATCH v4 4/9] cxl: Defer dport allocation for switch ports Dave Jiang
2025-07-01 11:10   ` Jonathan Cameron
2025-07-01 20:18     ` Dave Jiang
2025-07-02 10:18       ` Jonathan Cameron
2025-06-24 21:39 ` [PATCH v4 5/9] cxl/test: Add cxl_test support for new dport allocation scheme Dave Jiang
2025-07-01 11:12   ` Jonathan Cameron
2025-06-24 21:39 ` [PATCH v4 6/9] cxl/test: Add mock version of devm_cxl_add_dport_by_dev() Dave Jiang
2025-07-01 11:17   ` Jonathan Cameron [this message]
2025-06-24 21:39 ` [PATCH v4 7/9] cxl: Change sslbis handler to only handle single dport Dave Jiang
2025-06-24 21:39 ` [PATCH v4 8/9] cxl: Create an xarray to tie a host bridge to the cxl_root Dave Jiang
2025-07-01 11:20   ` Jonathan Cameron
2025-06-24 21:39 ` [PATCH v4 9/9] cxl: Move enumeration of hostbridge ports to the memdev probe path Dave Jiang
2025-07-01 11:32   ` Jonathan Cameron
2025-07-03 23:22     ` Dave Jiang
2025-07-04  9:39       ` Jonathan Cameron
2025-07-07 18:35         ` Dave Jiang

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