public inbox for linux-cxl@vger.kernel.org
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Dave Jiang <dave.jiang@intel.com>
Cc: <linux-cxl@vger.kernel.org>, <dave@stgolabs.net>,
	<jic23@kernel.org>, <vishal.l.verma@intel.com>,
	<ira.weiny@intel.com>, <djbw@kernel.org>
Subject: Re: [PATCH 1/7] cxl/test: Refactor mock_init_hdm_decoder() to prep for type2 decoder
Date: Tue, 5 May 2026 21:31:43 -0700	[thread overview]
Message-ID: <afrELziKpyUDuZXS@aschofie-mobl2.lan> (raw)
In-Reply-To: <20260422230237.2599333-2-dave.jiang@intel.com>

On Wed, Apr 22, 2026 at 04:02:31PM -0700, Dave Jiang wrote:
> Split mock_init_hdm_decoder() into different types of initialization.
> Currently the code deals with default initialization, saved decoders,
> and type3 auto region initialization. In the future, a type2 auto
> initialization will also be added. This refactor will make it cleaner
> to add additional init types.

Nice refactor! A couple of nits below...

> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  tools/testing/cxl/test/cxl.c | 184 ++++++++++++++++++++++-------------
>  1 file changed, 115 insertions(+), 69 deletions(-)
> 
> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index cd47fdd7ccb5..c26c37cef12c 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -1052,74 +1052,25 @@ static int first_decoder(struct device *dev, const void *data)
>  	return 0;
>  }
>  
> -/*
> - * Initialize a decoder during HDM enumeration.
> - *
> - * If a saved registry entry exists:
> - *   - enabled decoders are restored from the saved programming
> - *   - disabled decoders are initialized in a clean disabled state
> - *
> - * If no registry entry exists the decoder follows the normal mock
> - * initialization path, including the special auto-region setup for
> - * the first endpoints under host-bridge0.
> - *
> - * Returns true if decoder state was restored from the registry. In
> - * that case the saved decode configuration (including target mapping)
> - * has already been applied and the map_targets() is skipped.
> - */
> -static bool mock_init_hdm_decoder(struct cxl_decoder *cxld)
> +enum cxld_init_type {
> +	MOCK_DECODER_INIT_DEFAULT,
> +	MOCK_DECODER_INIT_SAVED,
> +	MOCK_DECODER_INIT_TYPE3_AUTO,
> +};

skip

> +/*
> + * Initialize a decoder during HDM enumeration.
> + *
> + * If a saved registry entry exists:
> + *   - enabled decoders are restored from the saved programming
> + *   - disabled decoders are initialized in a clean disabled state
> + *
> + * If no registry entry exists the decoder follows the normal mock
> + * initialization path, including the special auto-region setup for
> + * the first endpoints under host-bridge0.
> + *
> + * Returns true if decoder state was restored from the registry. In
> + * that case the saved decode configuration (including target mapping)
> + * has already been applied and the map_targets() is skipped.
> + */
> +static bool mock_init_hdm_decoder(struct cxl_decoder *cxld)
> +{
> +	struct cxl_endpoint_decoder *cxled = NULL;
> +	struct platform_device *pdev = NULL;
> +	struct cxl_test_decoder *td;
> +	struct cxl_memdev *cxlmd;
> +	struct cxl_port *port;
> +	bool hb0 = false;
> +
> +	if (is_endpoint_decoder(&cxld->dev)) {
> +		cxled = to_cxl_endpoint_decoder(&cxld->dev);
> +		cxlmd = cxled_to_memdev(cxled);
> +		WARN_ON(!dev_is_platform(cxlmd->dev.parent));
> +		pdev = to_platform_device(cxlmd->dev.parent);
> +
> +		/* check is endpoint is attach to host-bridge0 */
> +		port = cxled_to_port(cxled);
> +		do {
> +			if (port->uport_dev == &cxl_host_bridge[0]->dev) {
> +				hb0 = true;
> +				break;
> +			}
> +			if (is_cxl_port(port->dev.parent))
> +				port = to_cxl_port(port->dev.parent);
> +			else
> +				port = NULL;
> +		} while (port);
> +		port = cxled_to_port(cxled);
> +	} else {
> +		port = to_cxl_port(cxld->dev.parent);
> +	}
> +
> +	switch (get_decoder_init_type(cxld, pdev, hb0, &td)) {
> +	case MOCK_DECODER_INIT_SAVED:
> +		if (!td)
> +			return false;

get_decoder_init_type never returns NULL w _SAVED.

suggest replace w
		if (WARN_ON(!td))
			return false;


> +		return mock_decoder_handle_saved(cxld, td);
> +	case MOCK_DECODER_INIT_DEFAULT:
> +		/*
> +		 * The default path picks up all the decoders that are not
> +		 * endpoint.
> +		 */
> +		default_mock_decoder(cxld);
> +		return false;
> +	case MOCK_DECODER_INIT_TYPE3_AUTO:
> +		mock_init_hdm_type3_cxled(cxled, port, pdev);
> +		return false;
> +	default:
> +		return false;

default is unreachable since the enum has 4 names values.
suggest dropping it.


> +	}
>  }
>  
>  static int mock_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,
> -- 
> 2.53.0
> 

  reply	other threads:[~2026-05-06  4:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 23:02 [PATCH 0/7] cxl: Add CXL type2 accelerator support for cxl_test Dave Jiang
2026-04-22 23:02 ` [PATCH 1/7] cxl/test: Refactor mock_init_hdm_decoder() to prep for type2 decoder Dave Jiang
2026-05-06  4:31   ` Alison Schofield [this message]
2026-04-22 23:02 ` [PATCH 2/7] cxl/test: Add type2 support for mock CFMWS0 Dave Jiang
2026-05-06  4:38   ` Alison Schofield
2026-04-22 23:02 ` [PATCH 3/7] cxl/test: Refactor platform device enumerations Dave Jiang
2026-05-06  4:45   ` Alison Schofield
2026-04-22 23:02 ` [PATCH 4/7] cxl/test: Add hierarchy enumeration support for type2 device Dave Jiang
2026-05-06  5:05   ` Alison Schofield
2026-04-22 23:02 ` [PATCH 5/7] cxl/test: Fixup hdm init for auto region to support type2 Dave Jiang
2026-05-06  5:07   ` Alison Schofield
2026-04-22 23:02 ` [PATCH 6/7] cxl/test: Add cxl_test accelerator driver Dave Jiang
2026-05-06  5:19   ` Alison Schofield
2026-04-22 23:02 ` [PATCH 7/7] cxl: Fix double unregistration of CXL regions for type2 devices Dave Jiang
2026-04-23  7:10   ` Alejandro Lucero Palau
2026-04-23 14:36     ` Dave Jiang
2026-04-29 23:45   ` Dan Williams (nvidia)
2026-04-23  7:16 ` [PATCH 0/7] cxl: Add CXL type2 accelerator support for cxl_test Alejandro Lucero Palau
2026-05-06  4:20 ` Alison Schofield
2026-05-06 14:59   ` 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=afrELziKpyUDuZXS@aschofie-mobl2.lan \
    --to=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=djbw@kernel.org \
    --cc=ira.weiny@intel.com \
    --cc=jic23@kernel.org \
    --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