From: Dave Jiang <dave.jiang@intel.com>
To: Alison Schofield <alison.schofield@intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jic23@kernel.org>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <iweiny@kernel.org>, Li Ming <ming.li@zohomail.com>,
Richard Cheng <icheng@nvidia.com>,
Robert Richter <rrichter@amd.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH 6/7] cxl/region: Factor out cxl_port_setup_decoder()
Date: Fri, 9 Oct 2026 15:46:33 -0700 [thread overview]
Message-ID: <cd492b18-e246-49ae-901a-f47f887c4abd@intel.com> (raw)
In-Reply-To: <0ded5beebbcf283885a0e5876dc7d8dd758827a2.1791575481.git.alison.schofield@intel.com>
On 10/9/26 1:24 PM, Alison Schofield wrote:
> Once cxl_port_setup_targets() has calculated the interleave for a port's
> decoder, it either checks that interleave against the decoder settings
> found for an auto region, or checks the decoder's interleave capabilities
> and programs the decoder for a user created region. Both paths are open
> coded in cxl_port_setup_targets().
>
> Move both paths to a new helper, cxl_port_setup_decoder().
>
> No functional change.
>
> Assisted-by: LLM
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/cxl/core/region.c | 88 ++++++++++++++++++++++-----------------
> 1 file changed, 50 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 43f1ffbe64c0..4e9b0880663d 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1561,46 +1561,11 @@ static int cxl_port_calc_interleave(struct cxl_port *port, struct cxl_region *cx
> return 0;
> }
>
> -static int cxl_port_setup_targets(struct cxl_port *port, struct cxl_region *cxlr,
> - struct cxl_endpoint_decoder *cxled)
> +static int cxl_port_setup_decoder(struct cxl_port *port, struct cxl_region *cxlr,
> + struct cxl_decoder *cxld, int child_iw, int child_ig)
> {
> - int child_iw, child_ig, rc, pos = cxled->pos;
> - struct cxl_region_ref *cxl_rr = cxl_rr_load(port, cxlr);
> - struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> - struct cxl_ep *ep = cxl_ep_load(port, cxlmd);
> struct cxl_region_params *p = &cxlr->params;
> - struct cxl_decoder *cxld = cxl_rr->decoder;
> - struct cxl_switch_decoder *cxlsd;
> -
> - /*
> - * While root level decoders support x3, x6, x12, switch level
> - * decoders only support powers of 2 up to x16.
> - */
> - if (!is_power_of_2(cxl_rr->nr_targets)) {
> - dev_dbg(&cxlr->dev, "%s:%s: invalid target count %d\n",
> - dev_name(port->uport_dev), dev_name(&port->dev),
> - cxl_rr->nr_targets);
> - return -EINVAL;
> - }
> -
> - cxlsd = to_cxl_switch_decoder(&cxld->dev);
> - if (cxl_rr->nr_targets_set) {
> - int distance = cxl_port_peer_distance(port, cxlr);
> -
> - for (int i = 0; i < cxl_rr->nr_targets_set; i++)
> - if (ep->dport == cxlsd->target[i]) {
> - rc = check_last_peer(cxled, ep, cxl_rr,
> - distance);
> - if (rc)
> - return rc;
> - goto out_target_set;
> - }
> - goto add_target;
> - }
> -
> - rc = cxl_port_calc_interleave(port, cxlr, cxl_rr, &child_iw, &child_ig);
> - if (rc)
> - return rc;
> + int rc;
>
> if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags)) {
> if (cxld->interleave_ways != child_iw ||
> @@ -1639,6 +1604,53 @@ static int cxl_port_setup_targets(struct cxl_port *port, struct cxl_region *cxlr
> }
> dev_dbg(&cxlr->dev, "%s:%s iw: %d ig: %d\n", dev_name(port->uport_dev),
> dev_name(&port->dev), child_iw, child_ig);
> +
> + return 0;
> +}
> +
> +static int cxl_port_setup_targets(struct cxl_port *port, struct cxl_region *cxlr,
> + struct cxl_endpoint_decoder *cxled)
> +{
> + int child_iw, child_ig, rc, pos = cxled->pos;
> + struct cxl_region_ref *cxl_rr = cxl_rr_load(port, cxlr);
> + struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> + struct cxl_ep *ep = cxl_ep_load(port, cxlmd);
> + struct cxl_decoder *cxld = cxl_rr->decoder;
> + struct cxl_switch_decoder *cxlsd;
> +
> + /*
> + * While root level decoders support x3, x6, x12, switch level
> + * decoders only support powers of 2 up to x16.
> + */
> + if (!is_power_of_2(cxl_rr->nr_targets)) {
> + dev_dbg(&cxlr->dev, "%s:%s: invalid target count %d\n",
> + dev_name(port->uport_dev), dev_name(&port->dev),
> + cxl_rr->nr_targets);
> + return -EINVAL;
> + }
> +
> + cxlsd = to_cxl_switch_decoder(&cxld->dev);
> + if (cxl_rr->nr_targets_set) {
> + int distance = cxl_port_peer_distance(port, cxlr);
> +
> + for (int i = 0; i < cxl_rr->nr_targets_set; i++)
> + if (ep->dport == cxlsd->target[i]) {
> + rc = check_last_peer(cxled, ep, cxl_rr,
> + distance);
> + if (rc)
> + return rc;
> + goto out_target_set;
> + }
> + goto add_target;
> + }
> +
> + rc = cxl_port_calc_interleave(port, cxlr, cxl_rr, &child_iw, &child_ig);
> + if (rc)
> + return rc;
> +
> + rc = cxl_port_setup_decoder(port, cxlr, cxld, child_iw, child_ig);
> + if (rc)
> + return rc;
> add_target:
> if (cxl_rr->nr_targets_set == cxl_rr->nr_targets) {
> dev_dbg(&cxlr->dev,
next prev parent reply other threads:[~2026-10-09 22:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 20:24 [PATCH 0/7] cxl/region: Refactor cxl_port_setup_targets() Alison Schofield
2026-10-09 20:24 ` [PATCH 1/7] cxl: Add interleave encoding validity helpers Alison Schofield
2026-10-09 22:14 ` Dave Jiang
2026-10-09 20:24 ` [PATCH 2/7] cxl/region: Name the interleave locals in cxl_port_setup_targets() Alison Schofield
2026-10-09 22:23 ` Dave Jiang
2026-10-09 20:24 ` [PATCH 3/7] cxl/region: Factor out cxl_port_peer_distance() Alison Schofield
2026-10-09 22:27 ` Dave Jiang
2026-10-09 20:24 ` [PATCH 4/7] cxl/region: Factor out cxl_port_parent_interleave() Alison Schofield
2026-10-09 22:39 ` Dave Jiang
2026-10-10 0:33 ` Alison Schofield
2026-10-09 20:24 ` [PATCH 5/7] cxl/region: Factor out cxl_port_calc_interleave() Alison Schofield
2026-10-09 22:45 ` Dave Jiang
2026-10-09 20:24 ` [PATCH 6/7] cxl/region: Factor out cxl_port_setup_decoder() Alison Schofield
2026-10-09 22:46 ` Dave Jiang [this message]
2026-10-09 20:24 ` [PATCH 7/7] cxl/region: Factor out cxl_port_add_target() Alison Schofield
2026-10-09 22:48 ` Dave Jiang
2026-10-10 0:36 ` Alison Schofield
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=cd492b18-e246-49ae-901a-f47f887c4abd@intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=dave@stgolabs.net \
--cc=icheng@nvidia.com \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=ming.li@zohomail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.