|
Jeff Moyer |
2c91dc |
From 93122376250a8a5cfae635e9729c34dfaa0fd116 Mon Sep 17 00:00:00 2001
|
|
Jeff Moyer |
2c91dc |
From: Vishal Verma <vishal.l.verma@intel.com>
|
|
Jeff Moyer |
2c91dc |
Date: Mon, 15 Aug 2022 13:22:11 -0600
|
|
Jeff Moyer |
2c91dc |
Subject: [PATCH 196/217] cxl: add commands to {enable,disable,destroy}-region
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
With a template from cxl-create-region in place, add its friends:
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
cxl enable-region
|
|
Jeff Moyer |
2c91dc |
cxl disable-region
|
|
Jeff Moyer |
2c91dc |
cxl destroy-region
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
Link: https://lore.kernel.org/r/20220815192214.545800-9-vishal.l.verma@intel.com
|
|
Jeff Moyer |
2c91dc |
Cc: Dan Williams <dan.j.williams@intel.com>
|
|
Jeff Moyer |
2c91dc |
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
|
|
Jeff Moyer |
2c91dc |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
Jeff Moyer |
2c91dc |
---
|
|
Jeff Moyer |
2c91dc |
Documentation/cxl/cxl-destroy-region.txt | 41 +++++
|
|
Jeff Moyer |
2c91dc |
Documentation/cxl/cxl-disable-region.txt | 36 +++++
|
|
Jeff Moyer |
2c91dc |
Documentation/cxl/cxl-enable-region.txt | 36 +++++
|
|
Jeff Moyer |
2c91dc |
Documentation/cxl/decoder-option.txt | 6 +
|
|
Jeff Moyer |
2c91dc |
Documentation/cxl/meson.build | 4 +
|
|
Jeff Moyer |
2c91dc |
cxl/builtin.h | 3 +
|
|
Jeff Moyer |
2c91dc |
cxl/cxl.c | 3 +
|
|
Jeff Moyer |
2c91dc |
cxl/region.c | 193 ++++++++++++++++++++++-
|
|
Jeff Moyer |
2c91dc |
8 files changed, 321 insertions(+), 1 deletion(-)
|
|
Jeff Moyer |
2c91dc |
create mode 100644 Documentation/cxl/cxl-destroy-region.txt
|
|
Jeff Moyer |
2c91dc |
create mode 100644 Documentation/cxl/cxl-disable-region.txt
|
|
Jeff Moyer |
2c91dc |
create mode 100644 Documentation/cxl/cxl-enable-region.txt
|
|
Jeff Moyer |
2c91dc |
create mode 100644 Documentation/cxl/decoder-option.txt
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
diff --git a/Documentation/cxl/cxl-destroy-region.txt b/Documentation/cxl/cxl-destroy-region.txt
|
|
Jeff Moyer |
2c91dc |
new file mode 100644
|
|
Jeff Moyer |
2c91dc |
index 0000000..74f4093
|
|
Jeff Moyer |
2c91dc |
--- /dev/null
|
|
Jeff Moyer |
2c91dc |
+++ b/Documentation/cxl/cxl-destroy-region.txt
|
|
Jeff Moyer |
2c91dc |
@@ -0,0 +1,41 @@
|
|
Jeff Moyer |
2c91dc |
+// SPDX-License-Identifier: GPL-2.0
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+cxl-destroy-region(1)
|
|
Jeff Moyer |
2c91dc |
+=====================
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+NAME
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+cxl-destroy-region - destroy specified region(s).
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+SYNOPSIS
|
|
Jeff Moyer |
2c91dc |
+--------
|
|
Jeff Moyer |
2c91dc |
+[verse]
|
|
Jeff Moyer |
2c91dc |
+'cxl destroy-region <region> [<options>]'
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::region-description.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+EXAMPLE
|
|
Jeff Moyer |
2c91dc |
+-------
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+# cxl destroy-region all
|
|
Jeff Moyer |
2c91dc |
+destroyed 2 regions
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+OPTIONS
|
|
Jeff Moyer |
2c91dc |
+-------
|
|
Jeff Moyer |
2c91dc |
+include::bus-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+-f::
|
|
Jeff Moyer |
2c91dc |
+--force::
|
|
Jeff Moyer |
2c91dc |
+ Force a destroy operation even if the region is active.
|
|
Jeff Moyer |
2c91dc |
+ This will attempt to disable the region first.
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::decoder-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::debug-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::../copyright.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+SEE ALSO
|
|
Jeff Moyer |
2c91dc |
+--------
|
|
Jeff Moyer |
2c91dc |
+linkcxl:cxl-list[1], linkcxl:cxl-create-region[1]
|
|
Jeff Moyer |
2c91dc |
diff --git a/Documentation/cxl/cxl-disable-region.txt b/Documentation/cxl/cxl-disable-region.txt
|
|
Jeff Moyer |
2c91dc |
new file mode 100644
|
|
Jeff Moyer |
2c91dc |
index 0000000..6a39aee
|
|
Jeff Moyer |
2c91dc |
--- /dev/null
|
|
Jeff Moyer |
2c91dc |
+++ b/Documentation/cxl/cxl-disable-region.txt
|
|
Jeff Moyer |
2c91dc |
@@ -0,0 +1,36 @@
|
|
Jeff Moyer |
2c91dc |
+// SPDX-License-Identifier: GPL-2.0
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+cxl-disable-region(1)
|
|
Jeff Moyer |
2c91dc |
+=====================
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+NAME
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+cxl-disable-region - disable specified region(s).
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+SYNOPSIS
|
|
Jeff Moyer |
2c91dc |
+--------
|
|
Jeff Moyer |
2c91dc |
+[verse]
|
|
Jeff Moyer |
2c91dc |
+'cxl disable-region <region> [<options>]'
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::region-description.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+EXAMPLE
|
|
Jeff Moyer |
2c91dc |
+-------
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+# cxl disable-region all
|
|
Jeff Moyer |
2c91dc |
+disabled 2 regions
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+OPTIONS
|
|
Jeff Moyer |
2c91dc |
+-------
|
|
Jeff Moyer |
2c91dc |
+include::bus-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::decoder-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::debug-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::../copyright.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+SEE ALSO
|
|
Jeff Moyer |
2c91dc |
+--------
|
|
Jeff Moyer |
2c91dc |
+linkcxl:cxl-list[1], linkcxl:cxl-enable-region[1]
|
|
Jeff Moyer |
2c91dc |
diff --git a/Documentation/cxl/cxl-enable-region.txt b/Documentation/cxl/cxl-enable-region.txt
|
|
Jeff Moyer |
2c91dc |
new file mode 100644
|
|
Jeff Moyer |
2c91dc |
index 0000000..f6ef00f
|
|
Jeff Moyer |
2c91dc |
--- /dev/null
|
|
Jeff Moyer |
2c91dc |
+++ b/Documentation/cxl/cxl-enable-region.txt
|
|
Jeff Moyer |
2c91dc |
@@ -0,0 +1,36 @@
|
|
Jeff Moyer |
2c91dc |
+// SPDX-License-Identifier: GPL-2.0
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+cxl-enable-region(1)
|
|
Jeff Moyer |
2c91dc |
+=====================
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+NAME
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+cxl-enable-region - enable specified region(s).
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+SYNOPSIS
|
|
Jeff Moyer |
2c91dc |
+--------
|
|
Jeff Moyer |
2c91dc |
+[verse]
|
|
Jeff Moyer |
2c91dc |
+'cxl enable-region <region> [<options>]'
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::region-description.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+EXAMPLE
|
|
Jeff Moyer |
2c91dc |
+-------
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+# cxl enable-region all
|
|
Jeff Moyer |
2c91dc |
+enabled 2 regions
|
|
Jeff Moyer |
2c91dc |
+----
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+OPTIONS
|
|
Jeff Moyer |
2c91dc |
+-------
|
|
Jeff Moyer |
2c91dc |
+include::bus-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::decoder-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::debug-option.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+include::../copyright.txt[]
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+SEE ALSO
|
|
Jeff Moyer |
2c91dc |
+--------
|
|
Jeff Moyer |
2c91dc |
+linkcxl:cxl-list[1], linkcxl:cxl-disable-region[1]
|
|
Jeff Moyer |
2c91dc |
diff --git a/Documentation/cxl/decoder-option.txt b/Documentation/cxl/decoder-option.txt
|
|
Jeff Moyer |
2c91dc |
new file mode 100644
|
|
Jeff Moyer |
2c91dc |
index 0000000..e638d6e
|
|
Jeff Moyer |
2c91dc |
--- /dev/null
|
|
Jeff Moyer |
2c91dc |
+++ b/Documentation/cxl/decoder-option.txt
|
|
Jeff Moyer |
2c91dc |
@@ -0,0 +1,6 @@
|
|
Jeff Moyer |
2c91dc |
+// SPDX-License-Identifier: GPL-2.0
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+-d::
|
|
Jeff Moyer |
2c91dc |
+--decoder=::
|
|
Jeff Moyer |
2c91dc |
+ The root decoder to limit the operation to. Only regions that are
|
|
Jeff Moyer |
2c91dc |
+ children of the specified decoder will be acted upon.
|
|
Jeff Moyer |
2c91dc |
diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build
|
|
Jeff Moyer |
2c91dc |
index 340cdee..147ea71 100644
|
|
Jeff Moyer |
2c91dc |
--- a/Documentation/cxl/meson.build
|
|
Jeff Moyer |
2c91dc |
+++ b/Documentation/cxl/meson.build
|
|
Jeff Moyer |
2c91dc |
@@ -24,6 +24,7 @@ filedeps = [
|
|
Jeff Moyer |
2c91dc |
'labels-options.txt',
|
|
Jeff Moyer |
2c91dc |
'debug-option.txt',
|
|
Jeff Moyer |
2c91dc |
'region-description.txt',
|
|
Jeff Moyer |
2c91dc |
+ 'decoder-option.txt',
|
|
Jeff Moyer |
2c91dc |
]
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
cxl_manpages = [
|
|
Jeff Moyer |
2c91dc |
@@ -41,6 +42,9 @@ cxl_manpages = [
|
|
Jeff Moyer |
2c91dc |
'cxl-reserve-dpa.txt',
|
|
Jeff Moyer |
2c91dc |
'cxl-free-dpa.txt',
|
|
Jeff Moyer |
2c91dc |
'cxl-create-region.txt',
|
|
Jeff Moyer |
2c91dc |
+ 'cxl-disable-region.txt',
|
|
Jeff Moyer |
2c91dc |
+ 'cxl-enable-region.txt',
|
|
Jeff Moyer |
2c91dc |
+ 'cxl-destroy-region.txt',
|
|
Jeff Moyer |
2c91dc |
]
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
foreach man : cxl_manpages
|
|
Jeff Moyer |
2c91dc |
diff --git a/cxl/builtin.h b/cxl/builtin.h
|
|
Jeff Moyer |
2c91dc |
index 843bada..b28c221 100644
|
|
Jeff Moyer |
2c91dc |
--- a/cxl/builtin.h
|
|
Jeff Moyer |
2c91dc |
+++ b/cxl/builtin.h
|
|
Jeff Moyer |
2c91dc |
@@ -19,4 +19,7 @@ int cmd_enable_port(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
int cmd_set_partition(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
int cmd_disable_bus(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
int cmd_create_region(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
+int cmd_enable_region(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
+int cmd_disable_region(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
+int cmd_destroy_region(int argc, const char **argv, struct cxl_ctx *ctx);
|
|
Jeff Moyer |
2c91dc |
#endif /* _CXL_BUILTIN_H_ */
|
|
Jeff Moyer |
2c91dc |
diff --git a/cxl/cxl.c b/cxl/cxl.c
|
|
Jeff Moyer |
2c91dc |
index f0afcfe..dd1be7a 100644
|
|
Jeff Moyer |
2c91dc |
--- a/cxl/cxl.c
|
|
Jeff Moyer |
2c91dc |
+++ b/cxl/cxl.c
|
|
Jeff Moyer |
2c91dc |
@@ -73,6 +73,9 @@ static struct cmd_struct commands[] = {
|
|
Jeff Moyer |
2c91dc |
{ "set-partition", .c_fn = cmd_set_partition },
|
|
Jeff Moyer |
2c91dc |
{ "disable-bus", .c_fn = cmd_disable_bus },
|
|
Jeff Moyer |
2c91dc |
{ "create-region", .c_fn = cmd_create_region },
|
|
Jeff Moyer |
2c91dc |
+ { "enable-region", .c_fn = cmd_enable_region },
|
|
Jeff Moyer |
2c91dc |
+ { "disable-region", .c_fn = cmd_disable_region },
|
|
Jeff Moyer |
2c91dc |
+ { "destroy-region", .c_fn = cmd_destroy_region },
|
|
Jeff Moyer |
2c91dc |
};
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
int main(int argc, const char **argv)
|
|
Jeff Moyer |
2c91dc |
diff --git a/cxl/region.c b/cxl/region.c
|
|
Jeff Moyer |
2c91dc |
index 2791ac9..b22d3c8 100644
|
|
Jeff Moyer |
2c91dc |
--- a/cxl/region.c
|
|
Jeff Moyer |
2c91dc |
+++ b/cxl/region.c
|
|
Jeff Moyer |
2c91dc |
@@ -45,6 +45,9 @@ struct parsed_params {
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
enum region_actions {
|
|
Jeff Moyer |
2c91dc |
ACTION_CREATE,
|
|
Jeff Moyer |
2c91dc |
+ ACTION_ENABLE,
|
|
Jeff Moyer |
2c91dc |
+ ACTION_DISABLE,
|
|
Jeff Moyer |
2c91dc |
+ ACTION_DESTROY,
|
|
Jeff Moyer |
2c91dc |
};
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
static struct log_ctx rl;
|
|
Jeff Moyer |
2c91dc |
@@ -78,7 +81,22 @@ static const struct option create_options[] = {
|
|
Jeff Moyer |
2c91dc |
OPT_END(),
|
|
Jeff Moyer |
2c91dc |
};
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
+static const struct option enable_options[] = {
|
|
Jeff Moyer |
2c91dc |
+ BASE_OPTIONS(),
|
|
Jeff Moyer |
2c91dc |
+ OPT_END(),
|
|
Jeff Moyer |
2c91dc |
+};
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
+static const struct option disable_options[] = {
|
|
Jeff Moyer |
2c91dc |
+ BASE_OPTIONS(),
|
|
Jeff Moyer |
2c91dc |
+ OPT_END(),
|
|
Jeff Moyer |
2c91dc |
+};
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+static const struct option destroy_options[] = {
|
|
Jeff Moyer |
2c91dc |
+ BASE_OPTIONS(),
|
|
Jeff Moyer |
2c91dc |
+ OPT_BOOLEAN('f', "force", ¶m.force,
|
|
Jeff Moyer |
2c91dc |
+ "destroy region even if currently active"),
|
|
Jeff Moyer |
2c91dc |
+ OPT_END(),
|
|
Jeff Moyer |
2c91dc |
+};
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
static int parse_create_options(int argc, const char **argv,
|
|
Jeff Moyer |
2c91dc |
struct parsed_params *p)
|
|
Jeff Moyer |
2c91dc |
@@ -519,12 +537,122 @@ err_delete:
|
|
Jeff Moyer |
2c91dc |
return rc;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
+static int destroy_region(struct cxl_region *region)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ const char *devname = cxl_region_get_devname(region);
|
|
Jeff Moyer |
2c91dc |
+ unsigned int ways, i;
|
|
Jeff Moyer |
2c91dc |
+ int rc;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ /* First, unbind/disable the region if needed */
|
|
Jeff Moyer |
2c91dc |
+ if (cxl_region_is_enabled(region)) {
|
|
Jeff Moyer |
2c91dc |
+ if (param.force) {
|
|
Jeff Moyer |
2c91dc |
+ rc = cxl_region_disable(region);
|
|
Jeff Moyer |
2c91dc |
+ if (rc) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s: error disabling region: %s\n",
|
|
Jeff Moyer |
2c91dc |
+ devname, strerror(-rc));
|
|
Jeff Moyer |
2c91dc |
+ return rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ } else {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s active. Disable it or use --force\n",
|
|
Jeff Moyer |
2c91dc |
+ devname);
|
|
Jeff Moyer |
2c91dc |
+ return -EBUSY;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ /* Reset the region decode in preparation for removal */
|
|
Jeff Moyer |
2c91dc |
+ rc = cxl_region_decode_reset(region);
|
|
Jeff Moyer |
2c91dc |
+ if (rc) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s: failed to reset decode: %s\n", devname,
|
|
Jeff Moyer |
2c91dc |
+ strerror(-rc));
|
|
Jeff Moyer |
2c91dc |
+ return rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ /* Reset all endpoint decoders and region targets */
|
|
Jeff Moyer |
2c91dc |
+ ways = cxl_region_get_interleave_ways(region);
|
|
Jeff Moyer |
2c91dc |
+ if (ways == 0 || ways == UINT_MAX) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s: error getting interleave ways\n", devname);
|
|
Jeff Moyer |
2c91dc |
+ return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ for (i = 0; i < ways; i++) {
|
|
Jeff Moyer |
2c91dc |
+ struct cxl_decoder *ep_decoder;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ ep_decoder = cxl_region_get_target_decoder(region, i);
|
|
Jeff Moyer |
2c91dc |
+ if (!ep_decoder)
|
|
Jeff Moyer |
2c91dc |
+ return -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = cxl_region_clear_target(region, i);
|
|
Jeff Moyer |
2c91dc |
+ if (rc) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s: clearing target%d failed: %s\n",
|
|
Jeff Moyer |
2c91dc |
+ devname, i, strerror(abs(rc)));
|
|
Jeff Moyer |
2c91dc |
+ return rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = cxl_decoder_set_dpa_size(ep_decoder, 0);
|
|
Jeff Moyer |
2c91dc |
+ if (rc) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s: set_dpa_size failed: %s\n",
|
|
Jeff Moyer |
2c91dc |
+ cxl_decoder_get_devname(ep_decoder),
|
|
Jeff Moyer |
2c91dc |
+ strerror(abs(rc)));
|
|
Jeff Moyer |
2c91dc |
+ return rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ /* Finally, delete the region */
|
|
Jeff Moyer |
2c91dc |
+ return cxl_region_delete(region);
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+static int do_region_xable(struct cxl_region *region, enum region_actions action)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ switch (action) {
|
|
Jeff Moyer |
2c91dc |
+ case ACTION_ENABLE:
|
|
Jeff Moyer |
2c91dc |
+ return cxl_region_enable(region);
|
|
Jeff Moyer |
2c91dc |
+ case ACTION_DISABLE:
|
|
Jeff Moyer |
2c91dc |
+ return cxl_region_disable(region);
|
|
Jeff Moyer |
2c91dc |
+ case ACTION_DESTROY:
|
|
Jeff Moyer |
2c91dc |
+ return destroy_region(region);
|
|
Jeff Moyer |
2c91dc |
+ default:
|
|
Jeff Moyer |
2c91dc |
+ return -EINVAL;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+static int decoder_region_action(struct parsed_params *p,
|
|
Jeff Moyer |
2c91dc |
+ struct cxl_decoder *decoder,
|
|
Jeff Moyer |
2c91dc |
+ enum region_actions action, int *count)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ struct cxl_region *region, *_r;
|
|
Jeff Moyer |
2c91dc |
+ int rc = 0, err_rc = 0;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ cxl_region_foreach_safe (decoder, region, _r) {
|
|
Jeff Moyer |
2c91dc |
+ int i, match = 0;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ for (i = 0; i < p->num_targets; i++) {
|
|
Jeff Moyer |
2c91dc |
+ if (util_cxl_region_filter(region, p->targets[i])) {
|
|
Jeff Moyer |
2c91dc |
+ match = 1;
|
|
Jeff Moyer |
2c91dc |
+ break;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ if (!match)
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = do_region_xable(region, action);
|
|
Jeff Moyer |
2c91dc |
+ if (rc == 0) {
|
|
Jeff Moyer |
2c91dc |
+ *count += 1;
|
|
Jeff Moyer |
2c91dc |
+ } else {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "%s: failed: %s\n",
|
|
Jeff Moyer |
2c91dc |
+ cxl_region_get_devname(region), strerror(-rc));
|
|
Jeff Moyer |
2c91dc |
+ err_rc = rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ return err_rc ? err_rc : rc;
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,
|
|
Jeff Moyer |
2c91dc |
enum region_actions action,
|
|
Jeff Moyer |
2c91dc |
const struct option *options, struct parsed_params *p,
|
|
Jeff Moyer |
2c91dc |
int *count, const char *u)
|
|
Jeff Moyer |
2c91dc |
{
|
|
Jeff Moyer |
2c91dc |
- int rc = -ENXIO;
|
|
Jeff Moyer |
2c91dc |
+ int rc = 0, err_rc = 0;
|
|
Jeff Moyer |
2c91dc |
+ struct cxl_bus *bus;
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
log_init(&rl, "cxl region", "CXL_REGION_LOG");
|
|
Jeff Moyer |
2c91dc |
rc = parse_region_options(argc, argv, ctx, action, options, p, u);
|
|
Jeff Moyer |
2c91dc |
@@ -534,6 +662,33 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx,
|
|
Jeff Moyer |
2c91dc |
if (action == ACTION_CREATE)
|
|
Jeff Moyer |
2c91dc |
return create_region(ctx, count, p);
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
+ cxl_bus_foreach(ctx, bus) {
|
|
Jeff Moyer |
2c91dc |
+ struct cxl_decoder *decoder;
|
|
Jeff Moyer |
2c91dc |
+ struct cxl_port *port;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (!util_cxl_bus_filter(bus, param.bus))
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ port = cxl_bus_get_port(bus);
|
|
Jeff Moyer |
2c91dc |
+ if (!cxl_port_is_root(port))
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ cxl_decoder_foreach (port, decoder) {
|
|
Jeff Moyer |
2c91dc |
+ decoder = util_cxl_decoder_filter(decoder,
|
|
Jeff Moyer |
2c91dc |
+ param.root_decoder);
|
|
Jeff Moyer |
2c91dc |
+ if (!decoder)
|
|
Jeff Moyer |
2c91dc |
+ continue;
|
|
Jeff Moyer |
2c91dc |
+ rc = decoder_region_action(p, decoder, action, count);
|
|
Jeff Moyer |
2c91dc |
+ if (rc)
|
|
Jeff Moyer |
2c91dc |
+ err_rc = rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ if (err_rc) {
|
|
Jeff Moyer |
2c91dc |
+ log_err(&rl, "one or more failures, last failure: %s\n",
|
|
Jeff Moyer |
2c91dc |
+ strerror(-err_rc));
|
|
Jeff Moyer |
2c91dc |
+ return err_rc;
|
|
Jeff Moyer |
2c91dc |
+ }
|
|
Jeff Moyer |
2c91dc |
return rc;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
|
|
Jeff Moyer |
2c91dc |
@@ -548,3 +703,39 @@ int cmd_create_region(int argc, const char **argv, struct cxl_ctx *ctx)
|
|
Jeff Moyer |
2c91dc |
log_info(&rl, "created %d region%s\n", count, count == 1 ? "" : "s");
|
|
Jeff Moyer |
2c91dc |
return rc == 0 ? 0 : EXIT_FAILURE;
|
|
Jeff Moyer |
2c91dc |
}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int cmd_enable_region(int argc, const char **argv, struct cxl_ctx *ctx)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ const char *u = "cxl enable-region <region0> ... [<options>]";
|
|
Jeff Moyer |
2c91dc |
+ struct parsed_params p = { 0 };
|
|
Jeff Moyer |
2c91dc |
+ int rc, count = 0;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = region_action(argc, argv, ctx, ACTION_ENABLE, enable_options, &p,
|
|
Jeff Moyer |
2c91dc |
+ &count, u);
|
|
Jeff Moyer |
2c91dc |
+ log_info(&rl, "enabled %d region%s\n", count, count == 1 ? "" : "s");
|
|
Jeff Moyer |
2c91dc |
+ return rc == 0 ? 0 : EXIT_FAILURE;
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int cmd_disable_region(int argc, const char **argv, struct cxl_ctx *ctx)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ const char *u = "cxl disable-region <region0> ... [<options>]";
|
|
Jeff Moyer |
2c91dc |
+ struct parsed_params p = { 0 };
|
|
Jeff Moyer |
2c91dc |
+ int rc, count = 0;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = region_action(argc, argv, ctx, ACTION_DISABLE, disable_options, &p,
|
|
Jeff Moyer |
2c91dc |
+ &count, u);
|
|
Jeff Moyer |
2c91dc |
+ log_info(&rl, "disabled %d region%s\n", count, count == 1 ? "" : "s");
|
|
Jeff Moyer |
2c91dc |
+ return rc == 0 ? 0 : EXIT_FAILURE;
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+int cmd_destroy_region(int argc, const char **argv, struct cxl_ctx *ctx)
|
|
Jeff Moyer |
2c91dc |
+{
|
|
Jeff Moyer |
2c91dc |
+ const char *u = "cxl destroy-region <region0> ... [<options>]";
|
|
Jeff Moyer |
2c91dc |
+ struct parsed_params p = { 0 };
|
|
Jeff Moyer |
2c91dc |
+ int rc, count = 0;
|
|
Jeff Moyer |
2c91dc |
+
|
|
Jeff Moyer |
2c91dc |
+ rc = region_action(argc, argv, ctx, ACTION_DESTROY, destroy_options, &p,
|
|
Jeff Moyer |
2c91dc |
+ &count, u);
|
|
Jeff Moyer |
2c91dc |
+ log_info(&rl, "destroyed %d region%s\n", count, count == 1 ? "" : "s");
|
|
Jeff Moyer |
2c91dc |
+ return rc == 0 ? 0 : EXIT_FAILURE;
|
|
Jeff Moyer |
2c91dc |
+}
|
|
Jeff Moyer |
2c91dc |
--
|
|
Jeff Moyer |
2c91dc |
2.27.0
|
|
Jeff Moyer |
2c91dc |
|