Skip to content

Commit 458ba81

Browse files
davejiangdjbw
authored andcommitted
cxl: Add cxl_decoders_committed() helper
Add a helper to retrieve the number of decoders committed for the port. Replace all the open coding of the calculation with the helper. Link: https://lore.kernel.org/linux-cxl/651c98472dfed_ae7e729495@dwillia2-xfh.jf.intel.com.notmuch/ Suggested-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Jim Harris <jim.harris@samsung.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Link: https://lore.kernel.org/r/169747906849.272156.1729290904857372335.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 8f61d48 commit 458ba81

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

drivers/cxl/core/hdm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,11 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
643643
if (cxld->flags & CXL_DECODER_F_ENABLE)
644644
return 0;
645645

646-
if (port->commit_end + 1 != id) {
646+
if (cxl_num_decoders_committed(port) != id) {
647647
dev_dbg(&port->dev,
648648
"%s: out of order commit, expected decoder%d.%d\n",
649-
dev_name(&cxld->dev), port->id, port->commit_end + 1);
649+
dev_name(&cxld->dev), port->id,
650+
cxl_num_decoders_committed(port));
650651
return -EBUSY;
651652
}
652653

@@ -863,7 +864,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
863864
cxld->target_type = CXL_DECODER_HOSTONLYMEM;
864865
else
865866
cxld->target_type = CXL_DECODER_DEVMEM;
866-
if (cxld->id != port->commit_end + 1) {
867+
if (cxld->id != cxl_num_decoders_committed(port)) {
867868
dev_warn(&port->dev,
868869
"decoder%d.%d: Committed out of order\n",
869870
port->id, cxld->id);

drivers/cxl/core/mbox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)
12001200
* Require an endpoint to be safe otherwise the driver can not
12011201
* be sure that the device is unmapped.
12021202
*/
1203-
if (endpoint && endpoint->commit_end == -1)
1203+
if (endpoint && cxl_num_decoders_committed(endpoint) == 0)
12041204
rc = __cxl_mem_sanitize(mds, cmd);
12051205
else
12061206
rc = -EBUSY;

drivers/cxl/core/memdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
231231
if (rc)
232232
return rc;
233233

234-
if (port->commit_end == -1) {
234+
if (cxl_num_decoders_committed(port) == 0) {
235235
/* No regions mapped to this memdev */
236236
rc = cxl_get_poison_by_memdev(cxlmd);
237237
} else {
@@ -282,7 +282,7 @@ static struct cxl_region *cxl_dpa_to_region(struct cxl_memdev *cxlmd, u64 dpa)
282282
.dpa = dpa,
283283
};
284284
port = cxlmd->endpoint;
285-
if (port && is_cxl_endpoint(port) && port->commit_end != -1)
285+
if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port))
286286
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
287287

288288
return ctx.cxlr;

drivers/cxl/core/port.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ DECLARE_RWSEM(cxl_region_rwsem);
3737
static DEFINE_IDA(cxl_port_ida);
3838
static DEFINE_XARRAY(cxl_root_buses);
3939

40+
int cxl_num_decoders_committed(struct cxl_port *port)
41+
{
42+
lockdep_assert_held(&cxl_region_rwsem);
43+
44+
return port->commit_end + 1;
45+
}
46+
4047
static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
4148
char *buf)
4249
{

drivers/cxl/cxl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ static inline bool is_cxl_root(struct cxl_port *port)
679679
return port->uport_dev == port->dev.parent;
680680
}
681681

682+
int cxl_num_decoders_committed(struct cxl_port *port);
682683
bool is_cxl_port(const struct device *dev);
683684
struct cxl_port *to_cxl_port(const struct device *dev);
684685
struct pci_bus;

0 commit comments

Comments
 (0)