On Tue, 17 Jun 2025 18:09:42 +0530 Neeraj Kumar <s.nee...@samsung.com> wrote:
> Add support of cxl lsa 2.1 using NDD_CXL_LABEL flag. It also creates cxl > region based on region information parsed from LSA. > > Signed-off-by: Neeraj Kumar <s.nee...@samsung.com> > --- > drivers/cxl/pmem.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 59 insertions(+) > > diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c > index ffcebb8d382f..2733d79b32d5 100644 > --- a/drivers/cxl/pmem.c > +++ b/drivers/cxl/pmem.c > @@ -58,6 +58,63 @@ static const struct attribute_group > *cxl_dimm_attribute_groups[] = { > NULL > }; > > +static int match_ep_decoder(struct device *dev, void *data) > +{ > + struct cxl_decoder *cxld = to_cxl_decoder(dev); > + > + if (!cxld->region) > + return 1; > + else > + return 0; > +} > + > +static struct cxl_decoder *cxl_find_free_decoder(struct cxl_port *port) > +{ > + struct device *dev; > + > + dev = device_find_child(&port->dev, NULL, match_ep_decoder); > + if (!dev) > + return NULL; > + > + return to_cxl_decoder(dev); > +} > + > +static int create_pmem_region(struct nvdimm *nvdimm) > +{ > + struct cxl_nvdimm *cxl_nvd; > + struct cxl_memdev *cxlmd; > + struct cxl_nvdimm_bridge *cxl_nvb; > + struct cxl_pmem_region_params *params; > + struct cxl_root_decoder *cxlrd; > + struct cxl_decoder *cxld; > + struct cxl_region *cxlr; > + > + if (!nvdimm) > + return -ENOTTY; As with other checks like this, it is useful to add a comment on when you can call this function with a null parameter. > + > + if (!nvdimm_has_cxl_region(nvdimm)) > + return 0; > + > + cxl_nvd = nvdimm_provider_data(nvdimm); > + params = nvdimm_get_cxl_region_param(nvdimm); > + cxlmd = cxl_nvd->cxlmd; > + cxl_nvb = cxlmd->cxl_nvb; > + cxlrd = cxlmd->cxlrd; > + > + /* FIXME: Limitation: Region creation only when interleave way == 1 */ > + if (params->nlabel == 1) { > + cxld = cxl_find_free_decoder(cxlmd->endpoint); > + cxlr = cxl_create_pmem_region(cxlrd, cxld, params, > + atomic_read(&cxlrd->region_id)); > + if (IS_ERR(cxlr)) > + dev_dbg(&cxlmd->dev, "Region Creation failed\n"); > + } else { > + dev_dbg(&cxlmd->dev, "Region Creation is not supported with iw > > 1\n"); > + } Flip logic to check for unhandled case first and also return an error if this happens rather than silently carrying on. dev_info() is appropriate here. > + > + return 0; > +} > + > static int cxl_nvdimm_probe(struct device *dev) > { > struct cxl_nvdimm *cxl_nvd = to_cxl_nvdimm(dev); > @@ -74,6 +131,7 @@ static int cxl_nvdimm_probe(struct device *dev) > return rc; > > set_bit(NDD_LABELING, &flags); > + set_bit(NDD_CXL_LABEL, &flags); > set_bit(NDD_REGISTER_SYNC, &flags); > set_bit(ND_CMD_GET_CONFIG_SIZE, &cmd_mask); > set_bit(ND_CMD_GET_CONFIG_DATA, &cmd_mask); > @@ -86,6 +144,7 @@ static int cxl_nvdimm_probe(struct device *dev) > return -ENOMEM; > > dev_set_drvdata(dev, nvdimm); > + create_pmem_region(nvdimm); > return devm_add_action_or_reset(dev, unregister_nvdimm, nvdimm); > } >