Commit 458ba818 authored by Dave Jiang's avatar Dave Jiang Committed by Dan Williams

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: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarAlison Schofield <alison.schofield@intel.com>
Link: https://lore.kernel.org/r/169747906849.272156.1729290904857372335.stgit@djiang5-mobl3Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 8f61d48c
...@@ -643,10 +643,11 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld) ...@@ -643,10 +643,11 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld)
if (cxld->flags & CXL_DECODER_F_ENABLE) if (cxld->flags & CXL_DECODER_F_ENABLE)
return 0; return 0;
if (port->commit_end + 1 != id) { if (cxl_num_decoders_committed(port) != id) {
dev_dbg(&port->dev, dev_dbg(&port->dev,
"%s: out of order commit, expected decoder%d.%d\n", "%s: out of order commit, expected decoder%d.%d\n",
dev_name(&cxld->dev), port->id, port->commit_end + 1); dev_name(&cxld->dev), port->id,
cxl_num_decoders_committed(port));
return -EBUSY; return -EBUSY;
} }
...@@ -863,7 +864,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, ...@@ -863,7 +864,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
cxld->target_type = CXL_DECODER_HOSTONLYMEM; cxld->target_type = CXL_DECODER_HOSTONLYMEM;
else else
cxld->target_type = CXL_DECODER_DEVMEM; cxld->target_type = CXL_DECODER_DEVMEM;
if (cxld->id != port->commit_end + 1) { if (cxld->id != cxl_num_decoders_committed(port)) {
dev_warn(&port->dev, dev_warn(&port->dev,
"decoder%d.%d: Committed out of order\n", "decoder%d.%d: Committed out of order\n",
port->id, cxld->id); port->id, cxld->id);
......
...@@ -1200,7 +1200,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) ...@@ -1200,7 +1200,7 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd)
* Require an endpoint to be safe otherwise the driver can not * Require an endpoint to be safe otherwise the driver can not
* be sure that the device is unmapped. * be sure that the device is unmapped.
*/ */
if (endpoint && endpoint->commit_end == -1) if (endpoint && cxl_num_decoders_committed(endpoint) == 0)
rc = __cxl_mem_sanitize(mds, cmd); rc = __cxl_mem_sanitize(mds, cmd);
else else
rc = -EBUSY; rc = -EBUSY;
......
...@@ -231,7 +231,7 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd) ...@@ -231,7 +231,7 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd)
if (rc) if (rc)
return rc; return rc;
if (port->commit_end == -1) { if (cxl_num_decoders_committed(port) == 0) {
/* No regions mapped to this memdev */ /* No regions mapped to this memdev */
rc = cxl_get_poison_by_memdev(cxlmd); rc = cxl_get_poison_by_memdev(cxlmd);
} else { } else {
...@@ -282,7 +282,7 @@ static struct cxl_region *cxl_dpa_to_region(struct cxl_memdev *cxlmd, u64 dpa) ...@@ -282,7 +282,7 @@ static struct cxl_region *cxl_dpa_to_region(struct cxl_memdev *cxlmd, u64 dpa)
.dpa = dpa, .dpa = dpa,
}; };
port = cxlmd->endpoint; port = cxlmd->endpoint;
if (port && is_cxl_endpoint(port) && port->commit_end != -1) if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port))
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region); device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
return ctx.cxlr; return ctx.cxlr;
......
...@@ -37,6 +37,13 @@ DECLARE_RWSEM(cxl_region_rwsem); ...@@ -37,6 +37,13 @@ DECLARE_RWSEM(cxl_region_rwsem);
static DEFINE_IDA(cxl_port_ida); static DEFINE_IDA(cxl_port_ida);
static DEFINE_XARRAY(cxl_root_buses); static DEFINE_XARRAY(cxl_root_buses);
int cxl_num_decoders_committed(struct cxl_port *port)
{
lockdep_assert_held(&cxl_region_rwsem);
return port->commit_end + 1;
}
static ssize_t devtype_show(struct device *dev, struct device_attribute *attr, static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
......
...@@ -679,6 +679,7 @@ static inline bool is_cxl_root(struct cxl_port *port) ...@@ -679,6 +679,7 @@ static inline bool is_cxl_root(struct cxl_port *port)
return port->uport_dev == port->dev.parent; return port->uport_dev == port->dev.parent;
} }
int cxl_num_decoders_committed(struct cxl_port *port);
bool is_cxl_port(const struct device *dev); bool is_cxl_port(const struct device *dev);
struct cxl_port *to_cxl_port(const struct device *dev); struct cxl_port *to_cxl_port(const struct device *dev);
struct pci_bus; struct pci_bus;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment