On Thu, 23 Jun 2022 21:19:42 -0700 Dan Williams <dan.j.williams@xxxxxxxxx> wrote: > The region provisioning process involves allocating DPA to a set of > endpoint decoders, and HPA plus the region geometry to a region device. > Then the decoder is assigned to the region. At this point several > validation steps can be performed to validate that the decoder is > suitable to participate in the region. > > Co-developed-by: Ben Widawsky <bwidawsk@xxxxxxxxxx> > Signed-off-by: Ben Widawsky <bwidawsk@xxxxxxxxxx> > Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> > --- > Documentation/ABI/testing/sysfs-bus-cxl | 19 ++ > drivers/cxl/core/core.h | 6 + > drivers/cxl/core/hdm.c | 13 +- > drivers/cxl/core/port.c | 12 +- > drivers/cxl/core/region.c | 286 +++++++++++++++++++++++- > drivers/cxl/cxl.h | 11 + > 6 files changed, 342 insertions(+), 5 deletions(-) > A few fixes seems to have ended up in wrong patch. Other trivial typos etc inline plus what looks to be an item left from a todo list... ... > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index a604c24ff918..4830365f3857 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -24,6 +24,7 @@ > * but is only visible for persistent regions. > * 1. Interleave granularity > * 2. Interleave size > + * 3. Decoder targets > */ > > /* > @@ -138,6 +139,8 @@ static ssize_t interleave_ways_show(struct device *dev, > return rc; > } > > +static const struct attribute_group *get_cxl_region_target_group(void); > + > static ssize_t interleave_ways_store(struct device *dev, > struct device_attribute *attr, > const char *buf, size_t len) > @@ -146,7 +149,7 @@ static ssize_t interleave_ways_store(struct device *dev, > struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; > struct cxl_region *cxlr = to_cxl_region(dev); > struct cxl_region_params *p = &cxlr->params; > - int rc, val; > + int rc, val, save; > u8 iw; > > rc = kstrtoint(buf, 0, &val); > @@ -175,9 +178,13 @@ static ssize_t interleave_ways_store(struct device *dev, > goto out; > } > > + save = p->interleave_ways; > p->interleave_ways = val; > + rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); > + if (rc) > + p->interleave_ways = save; > out: > - up_read(&cxl_region_rwsem); > + up_write(&cxl_region_rwsem); Bug in earlier patch? > if (rc) > return rc; > return len; > @@ -234,7 +241,7 @@ static ssize_t interleave_granularity_store(struct device *dev, > > p->interleave_granularity = val; > out: > - up_read(&cxl_region_rwsem); > + up_write(&cxl_region_rwsem); Bug in earlier patch? > if (rc) > return rc; > return len; > @@ -393,9 +400,262 @@ static const struct attribute_group cxl_region_group = { > .is_visible = cxl_region_visible, > }; ... > +/* > + * - Check that the given endpoint is attached to a host-bridge identified > + * in the root interleave. Comment on something to fix? Or stale comment that can be dropped? > + */ > +static int cxl_region_attach(struct cxl_region *cxlr, > + struct cxl_endpoint_decoder *cxled, int pos) > +{ > + struct cxl_region_params *p = &cxlr->params; > + > + if (cxled->mode == CXL_DECODER_DEAD) { > + dev_dbg(&cxlr->dev, "%s dead\n", dev_name(&cxled->cxld.dev)); > + return -ENODEV; > + } > + > + if (pos >= p->interleave_ways) { > + dev_dbg(&cxlr->dev, "position %d out of range %d\n", pos, > + p->interleave_ways); > + return -ENXIO; > + } > + > + if (p->targets[pos] == cxled) > + return 0; > + > + if (p->targets[pos]) { > + struct cxl_endpoint_decoder *cxled_target = p->targets[pos]; > + struct cxl_memdev *cxlmd_target = cxled_to_memdev(cxled_target); > + > + dev_dbg(&cxlr->dev, "position %d already assigned to %s:%s\n", > + pos, dev_name(&cxlmd_target->dev), > + dev_name(&cxled_target->cxld.dev)); > + return -EBUSY; > + } > + > + p->targets[pos] = cxled; > + cxled->pos = pos; > + p->nr_targets++; > + > + return 0; > +} > + > +static void cxl_region_detach(struct cxl_endpoint_decoder *cxled) > +{ > + struct cxl_region *cxlr = cxled->cxld.region; > + struct cxl_region_params *p; > + > + lockdep_assert_held_write(&cxl_region_rwsem); > + > + if (!cxlr) > + return; > + > + p = &cxlr->params; > + get_device(&cxlr->dev); > + > + if (cxled->pos < 0 || cxled->pos >= p->interleave_ways || > + p->targets[cxled->pos] != cxled) { > + struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); > + > + dev_WARN_ONCE(&cxlr->dev, 1, "expected %s:%s at position %d\n", > + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), > + cxled->pos); > + goto out; > + } > + > + p->targets[cxled->pos] = NULL; > + p->nr_targets--; > + > + /* notify the region driver that one of its targets has deparated */ departed? > + up_write(&cxl_region_rwsem); > + device_release_driver(&cxlr->dev); > + down_write(&cxl_region_rwsem); > +out: > + put_device(&cxlr->dev); > +} > +