Skip to content

Commit a5c2580

Browse files
committed
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for the single dport exceptional case, it missed populating the target_list for the typical multi-dport case. Root decoders always know their target list at the beginning of time, and even switch-level decoders should have a target list of one or more zeros by default, depending on the interleave-ways setting. Walk the hosting port's dport list and populate based on the passed in map. Move devm_cxl_add_passthrough_decoder() out of line now that it does the work of generating a target_map. Before: $ cat /sys/bus/cxl/devices/root2/decoder*/target_list 0 0 After: $ cat /sys/bus/cxl/devices/root2/decoder*/target_list 0 0,1,2,3 0 0,1,2,3 Where root2 is a CXL topology root object generated by 'cxl_test'. Acked-by: Ben Widawsky <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 67dcdd4 commit a5c2580

File tree

3 files changed

+91
-27
lines changed

3 files changed

+91
-27
lines changed

drivers/cxl/acpi.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ static int cxl_acpi_cfmws_verify(struct device *dev,
5252
return -EINVAL;
5353
}
5454

55+
if (CFMWS_INTERLEAVE_WAYS(cfmws) > CXL_DECODER_MAX_INTERLEAVE) {
56+
dev_err(dev, "CFMWS Interleave Ways (%d) too large\n",
57+
CFMWS_INTERLEAVE_WAYS(cfmws));
58+
return -EINVAL;
59+
}
60+
5561
expected_len = struct_size((cfmws), interleave_targets,
5662
CFMWS_INTERLEAVE_WAYS(cfmws));
5763

@@ -71,6 +77,7 @@ static int cxl_acpi_cfmws_verify(struct device *dev,
7177
static void cxl_add_cfmws_decoders(struct device *dev,
7278
struct cxl_port *root_port)
7379
{
80+
int target_map[CXL_DECODER_MAX_INTERLEAVE];
7481
struct acpi_cedt_cfmws *cfmws;
7582
struct cxl_decoder *cxld;
7683
acpi_size len, cur = 0;
@@ -83,6 +90,7 @@ static void cxl_add_cfmws_decoders(struct device *dev,
8390

8491
while (cur < len) {
8592
struct acpi_cedt_header *c = cedt_subtable + cur;
93+
int i;
8694

8795
if (c->type != ACPI_CEDT_TYPE_CFMWS) {
8896
cur += c->length;
@@ -108,14 +116,17 @@ static void cxl_add_cfmws_decoders(struct device *dev,
108116
continue;
109117
}
110118

119+
for (i = 0; i < CFMWS_INTERLEAVE_WAYS(cfmws); i++)
120+
target_map[i] = cfmws->interleave_targets[i];
121+
111122
flags = cfmws_to_decoder_flags(cfmws->restrictions);
112123
cxld = devm_cxl_add_decoder(dev, root_port,
113124
CFMWS_INTERLEAVE_WAYS(cfmws),
114125
cfmws->base_hpa, cfmws->window_size,
115126
CFMWS_INTERLEAVE_WAYS(cfmws),
116127
CFMWS_INTERLEAVE_GRANULARITY(cfmws),
117128
CXL_DECODER_EXPANDER,
118-
flags);
129+
flags, target_map);
119130

120131
if (IS_ERR(cxld)) {
121132
dev_err(dev, "Failed to add decoder for %#llx-%#llx\n",

drivers/cxl/core/bus.c

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,38 @@ int cxl_add_dport(struct cxl_port *port, struct device *dport_dev, int port_id,
453453
}
454454
EXPORT_SYMBOL_GPL(cxl_add_dport);
455455

456+
static int decoder_populate_targets(struct device *host,
457+
struct cxl_decoder *cxld,
458+
struct cxl_port *port, int *target_map,
459+
int nr_targets)
460+
{
461+
int rc = 0, i;
462+
463+
if (!target_map)
464+
return 0;
465+
466+
device_lock(&port->dev);
467+
for (i = 0; i < nr_targets; i++) {
468+
struct cxl_dport *dport = find_dport(port, target_map[i]);
469+
470+
if (!dport) {
471+
rc = -ENXIO;
472+
break;
473+
}
474+
dev_dbg(host, "%s: target: %d\n", dev_name(dport->dport), i);
475+
cxld->target[i] = dport;
476+
}
477+
device_unlock(&port->dev);
478+
479+
return rc;
480+
}
481+
456482
static struct cxl_decoder *
457-
cxl_decoder_alloc(struct cxl_port *port, int nr_targets, resource_size_t base,
458-
resource_size_t len, int interleave_ways,
459-
int interleave_granularity, enum cxl_decoder_type type,
460-
unsigned long flags)
483+
cxl_decoder_alloc(struct device *host, struct cxl_port *port, int nr_targets,
484+
resource_size_t base, resource_size_t len,
485+
int interleave_ways, int interleave_granularity,
486+
enum cxl_decoder_type type, unsigned long flags,
487+
int *target_map)
461488
{
462489
struct cxl_decoder *cxld;
463490
struct device *dev;
@@ -493,10 +520,10 @@ cxl_decoder_alloc(struct cxl_port *port, int nr_targets, resource_size_t base,
493520
.target_type = type,
494521
};
495522

496-
/* handle implied target_list */
497-
if (interleave_ways == 1)
498-
cxld->target[0] =
499-
list_first_entry(&port->dports, struct cxl_dport, list);
523+
rc = decoder_populate_targets(host, cxld, port, target_map, nr_targets);
524+
if (rc)
525+
goto err;
526+
500527
dev = &cxld->dev;
501528
device_initialize(dev);
502529
device_set_pm_not_required(dev);
@@ -519,14 +546,19 @@ struct cxl_decoder *
519546
devm_cxl_add_decoder(struct device *host, struct cxl_port *port, int nr_targets,
520547
resource_size_t base, resource_size_t len,
521548
int interleave_ways, int interleave_granularity,
522-
enum cxl_decoder_type type, unsigned long flags)
549+
enum cxl_decoder_type type, unsigned long flags,
550+
int *target_map)
523551
{
524552
struct cxl_decoder *cxld;
525553
struct device *dev;
526554
int rc;
527555

528-
cxld = cxl_decoder_alloc(port, nr_targets, base, len, interleave_ways,
529-
interleave_granularity, type, flags);
556+
if (nr_targets > CXL_DECODER_MAX_INTERLEAVE)
557+
return ERR_PTR(-EINVAL);
558+
559+
cxld = cxl_decoder_alloc(host, port, nr_targets, base, len,
560+
interleave_ways, interleave_granularity, type,
561+
flags, target_map);
530562
if (IS_ERR(cxld))
531563
return cxld;
532564

@@ -550,6 +582,32 @@ devm_cxl_add_decoder(struct device *host, struct cxl_port *port, int nr_targets,
550582
}
551583
EXPORT_SYMBOL_GPL(devm_cxl_add_decoder);
552584

585+
/*
586+
* Per the CXL specification (8.2.5.12 CXL HDM Decoder Capability Structure)
587+
* single ported host-bridges need not publish a decoder capability when a
588+
* passthrough decode can be assumed, i.e. all transactions that the uport sees
589+
* are claimed and passed to the single dport. Default the range a 0-base
590+
* 0-length until the first CXL region is activated.
591+
*/
592+
struct cxl_decoder *devm_cxl_add_passthrough_decoder(struct device *host,
593+
struct cxl_port *port)
594+
{
595+
struct cxl_dport *dport;
596+
int target_map[1];
597+
598+
device_lock(&port->dev);
599+
dport = list_first_entry_or_null(&port->dports, typeof(*dport), list);
600+
device_unlock(&port->dev);
601+
602+
if (!dport)
603+
return ERR_PTR(-ENXIO);
604+
605+
target_map[0] = dport->port_id;
606+
return devm_cxl_add_decoder(host, port, 1, 0, 0, 1, PAGE_SIZE,
607+
CXL_DECODER_EXPANDER, 0, target_map);
608+
}
609+
EXPORT_SYMBOL_GPL(devm_cxl_add_passthrough_decoder);
610+
553611
/**
554612
* __cxl_driver_register - register a driver for the cxl bus
555613
* @cxl_drv: cxl driver structure to attach

drivers/cxl/cxl.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ enum cxl_decoder_type {
180180
CXL_DECODER_EXPANDER = 3,
181181
};
182182

183+
/*
184+
* Current specification goes up to 8, double that seems a reasonable
185+
* software max for the foreseeable future
186+
*/
187+
#define CXL_DECODER_MAX_INTERLEAVE 16
188+
183189
/**
184190
* struct cxl_decoder - CXL address range decode configuration
185191
* @dev: this decoder's device
@@ -284,22 +290,11 @@ struct cxl_decoder *
284290
devm_cxl_add_decoder(struct device *host, struct cxl_port *port, int nr_targets,
285291
resource_size_t base, resource_size_t len,
286292
int interleave_ways, int interleave_granularity,
287-
enum cxl_decoder_type type, unsigned long flags);
288-
289-
/*
290-
* Per the CXL specification (8.2.5.12 CXL HDM Decoder Capability Structure)
291-
* single ported host-bridges need not publish a decoder capability when a
292-
* passthrough decode can be assumed, i.e. all transactions that the uport sees
293-
* are claimed and passed to the single dport. Default the range a 0-base
294-
* 0-length until the first CXL region is activated.
295-
*/
296-
static inline struct cxl_decoder *
297-
devm_cxl_add_passthrough_decoder(struct device *host, struct cxl_port *port)
298-
{
299-
return devm_cxl_add_decoder(host, port, 1, 0, 0, 1, PAGE_SIZE,
300-
CXL_DECODER_EXPANDER, 0);
301-
}
293+
enum cxl_decoder_type type, unsigned long flags,
294+
int *target_map);
302295

296+
struct cxl_decoder *devm_cxl_add_passthrough_decoder(struct device *host,
297+
struct cxl_port *port);
303298
extern struct bus_type cxl_bus_type;
304299

305300
struct cxl_driver {

0 commit comments

Comments
 (0)