Linux CXL
 help / color / mirror / Atom feed
* [PATCH] cxl/region: Match auto-discovered region decoders by HPA range
@ 2023-08-04 21:30 alison.schofield
  2023-08-04 22:13 ` Dan Williams
  0 siblings, 1 reply; 4+ messages in thread
From: alison.schofield @ 2023-08-04 21:30 UTC (permalink / raw)
  To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
	Vishal Verma, Ira Weiny, Dan Williams
  Cc: linux-cxl

From: Alison Schofield <alison.schofield@intel.com>

Today, when the region driver attaches a region to a port, it
selects the ports next available decoder to program.

With the addition of auto-discovered regions, a port decoder has
already been programmed, so grabbing the next available decoder
can be a mismatch when there is more than one region using the
port. Match on the port HPA range for auto-discovered regions.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 
 drivers/cxl/core/region.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index e115ba382e04..8bfec7a96975 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -717,13 +717,37 @@ static int match_free_decoder(struct device *dev, void *data)
 	return 0;
 }
 
+static int match_auto_decoder(struct device *dev, void *data)
+{
+	struct cxl_endpoint_decoder *cxled = data;
+	struct cxl_decoder *cxld;
+
+	if (!is_switch_decoder(dev))
+		return 0;
+
+	cxld = to_cxl_decoder(dev);
+
+	if (!range_contains(&cxld->hpa_range, &cxled->cxld.hpa_range))
+		return 0;
+
+	if (!cxld->region)
+		return 1;
+
+	return 0;
+}
+
 static struct cxl_decoder *cxl_region_find_decoder(struct cxl_port *port,
-						   struct cxl_region *cxlr)
+						   struct cxl_region *cxlr,
+						   struct cxl_endpoint_decoder *cxled)
 {
 	struct device *dev;
 	int id = 0;
 
-	dev = device_find_child(&port->dev, &id, match_free_decoder);
+	if (test_bit(CXL_REGION_F_AUTO, &cxlr->flags))
+		dev = device_find_child(&port->dev, cxled, match_auto_decoder);
+	else
+		dev = device_find_child(&port->dev, &id, match_free_decoder);
+
 	if (!dev)
 		return NULL;
 	/*
@@ -839,7 +863,8 @@ static int cxl_rr_alloc_decoder(struct cxl_port *port, struct cxl_region *cxlr,
 	if (port == cxled_to_port(cxled))
 		cxld = &cxled->cxld;
 	else
-		cxld = cxl_region_find_decoder(port, cxlr);
+		cxld = cxl_region_find_decoder(port, cxlr, cxled);
+
 	if (!cxld) {
 		dev_dbg(&cxlr->dev, "%s: no decoder available\n",
 			dev_name(&port->dev));

base-commit: fe77cc2e5a6a7c85f5c6ef8a39d7694ffc7f41c9
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-16  1:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04 21:30 [PATCH] cxl/region: Match auto-discovered region decoders by HPA range alison.schofield
2023-08-04 22:13 ` Dan Williams
2023-08-16  0:13   ` Alison Schofield
2023-08-16  1:43     ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox