Skip to content

Commit d1c9ba4

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/region: Factor out code into cxl_region_setup_poison()
Poison injection setup code is embedded in cxl_region_probe(). For improved encapsulation, readability, and maintainability, factor out code into function cxl_region_setup_poison(). This patch is a prerequisite to disable poison by region offset for Normalized Addressing. No functional changes. Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Signed-off-by: Robert Richter <rrichter@amd.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20260114164837.1076338-13-rrichter@amd.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent a2e7948 commit d1c9ba4

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

drivers/cxl/core/region.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,6 +3916,31 @@ static int cxl_region_debugfs_poison_clear(void *data, u64 offset)
39163916
DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_clear_fops, NULL,
39173917
cxl_region_debugfs_poison_clear, "%llx\n");
39183918

3919+
static int cxl_region_setup_poison(struct cxl_region *cxlr)
3920+
{
3921+
struct device *dev = &cxlr->dev;
3922+
struct cxl_region_params *p = &cxlr->params;
3923+
struct dentry *dentry;
3924+
3925+
/* Create poison attributes if all memdevs support the capabilities */
3926+
for (int i = 0; i < p->nr_targets; i++) {
3927+
struct cxl_endpoint_decoder *cxled = p->targets[i];
3928+
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
3929+
3930+
if (!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_INJECT) ||
3931+
!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_CLEAR))
3932+
return 0;
3933+
}
3934+
3935+
dentry = cxl_debugfs_create_dir(dev_name(dev));
3936+
debugfs_create_file("inject_poison", 0200, dentry, cxlr,
3937+
&cxl_poison_inject_fops);
3938+
debugfs_create_file("clear_poison", 0200, dentry, cxlr,
3939+
&cxl_poison_clear_fops);
3940+
3941+
return devm_add_action_or_reset(dev, remove_debugfs, dentry);
3942+
}
3943+
39193944
static int cxl_region_can_probe(struct cxl_region *cxlr)
39203945
{
39213946
struct cxl_region_params *p = &cxlr->params;
@@ -3945,7 +3970,6 @@ static int cxl_region_probe(struct device *dev)
39453970
{
39463971
struct cxl_region *cxlr = to_cxl_region(dev);
39473972
struct cxl_region_params *p = &cxlr->params;
3948-
bool poison_supported = true;
39493973
int rc;
39503974

39513975
rc = cxl_region_can_probe(cxlr);
@@ -3969,30 +3993,9 @@ static int cxl_region_probe(struct device *dev)
39693993
if (rc)
39703994
return rc;
39713995

3972-
/* Create poison attributes if all memdevs support the capabilities */
3973-
for (int i = 0; i < p->nr_targets; i++) {
3974-
struct cxl_endpoint_decoder *cxled = p->targets[i];
3975-
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
3976-
3977-
if (!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_INJECT) ||
3978-
!cxl_memdev_has_poison_cmd(cxlmd, CXL_POISON_ENABLED_CLEAR)) {
3979-
poison_supported = false;
3980-
break;
3981-
}
3982-
}
3983-
3984-
if (poison_supported) {
3985-
struct dentry *dentry;
3986-
3987-
dentry = cxl_debugfs_create_dir(dev_name(dev));
3988-
debugfs_create_file("inject_poison", 0200, dentry, cxlr,
3989-
&cxl_poison_inject_fops);
3990-
debugfs_create_file("clear_poison", 0200, dentry, cxlr,
3991-
&cxl_poison_clear_fops);
3992-
rc = devm_add_action_or_reset(dev, remove_debugfs, dentry);
3993-
if (rc)
3994-
return rc;
3995-
}
3996+
rc = cxl_region_setup_poison(cxlr);
3997+
if (rc)
3998+
return rc;
39963999

39974000
switch (cxlr->mode) {
39984001
case CXL_PARTMODE_PMEM:

0 commit comments

Comments
 (0)