Contributors: 34
Author |
Tokens |
Token Proportion |
Commits |
Commit Proportion |
Nathan Fontenot |
1743 |
57.62% |
13 |
21.31% |
Haren Myneni |
775 |
25.62% |
2 |
3.28% |
John Allen |
154 |
5.09% |
2 |
3.28% |
Nathan T. Lynch |
57 |
1.88% |
5 |
8.20% |
Michael Ellerman |
41 |
1.36% |
1 |
1.64% |
Tyrel Datwyler |
37 |
1.22% |
3 |
4.92% |
Daniel Henrique Barboza |
34 |
1.12% |
1 |
1.64% |
Sahil Mehta |
26 |
0.86% |
1 |
1.64% |
Andrew Morton |
21 |
0.69% |
1 |
1.64% |
Paul Mackerras |
18 |
0.60% |
1 |
1.64% |
Bharata B Rao |
18 |
0.60% |
1 |
1.64% |
Anton Blanchard |
14 |
0.46% |
3 |
4.92% |
Gen Zhang |
12 |
0.40% |
1 |
1.64% |
Oliver O'Halloran |
11 |
0.36% |
1 |
1.64% |
Tom Rini |
8 |
0.26% |
1 |
1.64% |
Gautham R. Shenoy |
7 |
0.23% |
2 |
3.28% |
Rob Herring |
7 |
0.23% |
3 |
4.92% |
Frank Rowand |
5 |
0.17% |
1 |
1.64% |
Greg Kroah-Hartman |
5 |
0.17% |
2 |
3.28% |
Andrew Donnellan |
5 |
0.17% |
1 |
1.64% |
Nishanth Aravamudan |
3 |
0.10% |
1 |
1.64% |
Andy Shevchenko |
3 |
0.10% |
1 |
1.64% |
Zhang Zekun |
3 |
0.10% |
1 |
1.64% |
Daniel Axtens |
2 |
0.07% |
1 |
1.64% |
Tejun Heo |
2 |
0.07% |
1 |
1.64% |
Dan Streetman |
2 |
0.07% |
1 |
1.64% |
Dave C Boutcher |
2 |
0.07% |
1 |
1.64% |
Thomas Gleixner |
2 |
0.07% |
1 |
1.64% |
Linus Torvalds |
2 |
0.07% |
2 |
3.28% |
Linus Torvalds (pre-git) |
2 |
0.07% |
1 |
1.64% |
Pekka J Enberg |
1 |
0.03% |
1 |
1.64% |
Akinobu Mita |
1 |
0.03% |
1 |
1.64% |
Julia Lawall |
1 |
0.03% |
1 |
1.64% |
Yan Burman |
1 |
0.03% |
1 |
1.64% |
Total |
3025 |
|
61 |
|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
// SPDX-License-Identifier: GPL-2.0-only
/*
* Support for dynamic reconfiguration for PCI, Memory, and CPU
* Hotplug and Dynamic Logical Partitioning on RPA platforms.
*
* Copyright (C) 2009 Nathan Fontenot
* Copyright (C) 2009 IBM Corporation
*/
#define pr_fmt(fmt) "dlpar: " fmt
#include <linux/kernel.h>
#include <linux/notifier.h>
#include <linux/spinlock.h>
#include <linux/cpu.h>
#include <linux/slab.h>
#include <linux/of.h>
#include "of_helpers.h"
#include "pseries.h"
#include <asm/machdep.h>
#include <linux/uaccess.h>
#include <asm/rtas.h>
#include <asm/rtas-work-area.h>
#include <asm/prom.h>
static struct workqueue_struct *pseries_hp_wq;
struct pseries_hp_work {
struct work_struct work;
struct pseries_hp_errorlog *errlog;
};
struct cc_workarea {
__be32 drc_index;
__be32 zero;
__be32 name_offset;
__be32 prop_length;
__be32 prop_offset;
};
void dlpar_free_cc_property(struct property *prop)
{
kfree(prop->name);
kfree(prop->value);
kfree(prop);
}
static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa)
{
struct property *prop;
char *name;
char *value;
prop = kzalloc(sizeof(*prop), GFP_KERNEL);
if (!prop)
return NULL;
name = (char *)ccwa + be32_to_cpu(ccwa->name_offset);
prop->name = kstrdup(name, GFP_KERNEL);
if (!prop->name) {
dlpar_free_cc_property(prop);
return NULL;
}
prop->length = be32_to_cpu(ccwa->prop_length);
value = (char *)ccwa + be32_to_cpu(ccwa->prop_offset);
prop->value = kmemdup(value, prop->length, GFP_KERNEL);
if (!prop->value) {
dlpar_free_cc_property(prop);
return NULL;
}
return prop;
}
static struct device_node *dlpar_parse_cc_node(struct cc_workarea *ccwa)
{
struct device_node *dn;
const char *name;
dn = kzalloc(sizeof(*dn), GFP_KERNEL);
if (!dn)
return NULL;
name = (const char *)ccwa + be32_to_cpu(ccwa->name_offset);
dn->full_name = kstrdup(name, GFP_KERNEL);
if (!dn->full_name) {
kfree(dn);
return NULL;
}
of_node_set_flag(dn, OF_DYNAMIC);
of_node_init(dn);
return dn;
}
static void dlpar_free_one_cc_node(struct device_node *dn)
{
struct property *prop;
while (dn->properties) {
prop = dn->properties;
dn->properties = prop->next;
dlpar_free_cc_property(prop);
}
kfree(dn->full_name);
kfree(dn);
}
void dlpar_free_cc_nodes(struct device_node *dn)
{
if (dn->child)
dlpar_free_cc_nodes(dn->child);
if (dn->sibling)
dlpar_free_cc_nodes(dn->sibling);
dlpar_free_one_cc_node(dn);
}
#define COMPLETE 0
#define NEXT_SIBLING 1
#define NEXT_CHILD 2
#define NEXT_PROPERTY 3
#define PREV_PARENT 4
#define MORE_MEMORY 5
#define ERR_CFG_USE -9003
struct device_node *dlpar_configure_connector(__be32 drc_index,
struct device_node *parent)
{
struct device_node *dn;
struct device_node *first_dn = NULL;
struct device_node *last_dn = NULL;
struct property *property;
struct property *last_property = NULL;
struct cc_workarea *ccwa;
struct rtas_work_area *work_area;
char *data_buf;
int cc_token;
int rc = -1;
cc_token = rtas_function_token(RTAS_FN_IBM_CONFIGURE_CONNECTOR);
if (cc_token == RTAS_UNKNOWN_SERVICE)
return NULL;
work_area = rtas_work_area_alloc(SZ_4K);
data_buf = rtas_work_area_raw_buf(work_area);
ccwa = (struct cc_workarea *)&data_buf[0];
ccwa->drc_index = drc_index;
ccwa->zero = 0;
do {
do {
rc = rtas_call(cc_token, 2, 1, NULL,
rtas_work_area_phys(work_area), NULL);
} while (rtas_busy_delay(rc));
switch (rc) {
case COMPLETE:
break;
case NEXT_SIBLING:
dn = dlpar_parse_cc_node(ccwa);
if (!dn)
goto cc_error;
dn->parent = last_dn->parent;
last_dn->sibling = dn;
last_dn = dn;
break;
case NEXT_CHILD:
dn = dlpar_parse_cc_node(ccwa);
if (!dn)
goto cc_error;
if (!first_dn) {
dn->parent = parent;
first_dn = dn;
} else {
dn->parent = last_dn;
if (last_dn)
last_dn->child = dn;
}
last_dn = dn;
break;
case NEXT_PROPERTY:
property = dlpar_parse_cc_property(ccwa);
if (!property)
goto cc_error;
if (!last_dn->properties)
last_dn->properties = property;
else
last_property->next = property;
last_property = property;
break;
case PREV_PARENT:
last_dn = last_dn->parent;
break;
case MORE_MEMORY:
case ERR_CFG_USE:
default:
printk(KERN_ERR "Unexpected Error (%d) "
"returned from configure-connector\n", rc);
goto cc_error;
}
} while (rc);
cc_error:
rtas_work_area_free(work_area);
if (rc) {
if (first_dn)
dlpar_free_cc_nodes(first_dn);
return NULL;
}
return first_dn;
}
int dlpar_attach_node(struct device_node *dn, struct device_node *parent)
{
int rc;
dn->parent = parent;
rc = of_attach_node(dn);
if (rc) {
printk(KERN_ERR "Failed to add device node %pOF\n", dn);
return rc;
}
return 0;
}
int dlpar_detach_node(struct device_node *dn)
{
struct device_node *child;
int rc;
for_each_child_of_node(dn, child)
dlpar_detach_node(child);
rc = of_detach_node(dn);
if (rc)
return rc;
of_node_put(dn);
return 0;
}
static int dlpar_changeset_attach_cc_nodes(struct of_changeset *ocs,
struct device_node *dn)
{
int rc;
rc = of_changeset_attach_node(ocs, dn);
if (!rc && dn->child)
rc = dlpar_changeset_attach_cc_nodes(ocs, dn->child);
if (!rc && dn->sibling)
rc = dlpar_changeset_attach_cc_nodes(ocs, dn->sibling);
return rc;
}
#define DR_ENTITY_SENSE 9003
#define DR_ENTITY_PRESENT 1
#define DR_ENTITY_UNUSABLE 2
#define ALLOCATION_STATE 9003
#define ALLOC_UNUSABLE 0
#define ALLOC_USABLE 1
#define ISOLATION_STATE 9001
#define ISOLATE 0
#define UNISOLATE 1
int dlpar_acquire_drc(u32 drc_index)
{
int dr_status, rc;
rc = rtas_get_sensor(DR_ENTITY_SENSE, drc_index, &dr_status);
if (rc || dr_status != DR_ENTITY_UNUSABLE)
return -1;
rc = rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_USABLE);
if (rc)
return rc;
rc = rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE);
if (rc) {
rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_UNUSABLE);
return rc;
}
return 0;
}
int dlpar_release_drc(u32 drc_index)
{
int dr_status, rc;
rc = rtas_get_sensor(DR_ENTITY_SENSE, drc_index, &dr_status);
if (rc || dr_status != DR_ENTITY_PRESENT)
return -1;
rc = rtas_set_indicator(ISOLATION_STATE, drc_index, ISOLATE);
if (rc)
return rc;
rc = rtas_set_indicator(ALLOCATION_STATE, drc_index, ALLOC_UNUSABLE);
if (rc) {
rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE);
return rc;
}
return 0;
}
int dlpar_unisolate_drc(u32 drc_index)
{
int dr_status, rc;
rc = rtas_get_sensor(DR_ENTITY_SENSE, drc_index, &dr_status);
if (rc || dr_status != DR_ENTITY_PRESENT)
return -1;
rtas_set_indicator(ISOLATION_STATE, drc_index, UNISOLATE);
return 0;
}
static struct device_node *
get_device_node_with_drc_index(u32 index)
{
struct device_node *np = NULL;
u32 node_index;
int rc;
for_each_node_with_property(np, "ibm,my-drc-index") {
rc = of_property_read_u32(np, "ibm,my-drc-index",
&node_index);
if (rc) {
pr_err("%s: %pOF: of_property_read_u32 %s: %d\n",
__func__, np, "ibm,my-drc-index", rc);
of_node_put(np);
return NULL;
}
if (index == node_index)
break;
}
return np;
}
static struct device_node *
get_device_node_with_drc_info(u32 index)
{
struct device_node *np = NULL;
struct of_drc_info drc;
struct property *info;
const __be32 *value;
u32 node_index;
int i, j, count;
for_each_node_with_property(np, "ibm,drc-info") {
info = of_find_property(np, "ibm,drc-info", NULL);
if (info == NULL) {
/* XXX can this happen? */
of_node_put(np);
return NULL;
}
value = of_prop_next_u32(info, NULL, &count);
if (value == NULL)
continue;
value++;
for (i = 0; i < count; i++) {
if (of_read_drc_info_cell(&info, &value, &drc))
break;
if (index > drc.last_drc_index)
continue;
node_index = drc.drc_index_start;
for (j = 0; j < drc.num_sequential_elems; j++) {
if (index == node_index)
return np;
node_index += drc.sequential_inc;
}
}
}
return NULL;
}
static int dlpar_hp_dt_add(u32 index)
{
struct device_node *np, *nodes;
struct of_changeset ocs;
int rc;
/*
* Do not add device node(s) if already exists in the
* device tree.
*/
np = get_device_node_with_drc_index(index);
if (np) {
pr_err("%s: Adding device node for index (%d), but "
"already exists in the device tree\n",
__func__, index);
rc = -EINVAL;
goto out;
}
np = get_device_node_with_drc_info(index);
if (!np)
return -EIO;
/* Next, configure the connector. */
nodes = dlpar_configure_connector(cpu_to_be32(index), np);
if (!nodes) {
rc = -EIO;
goto out;
}
/*
* Add the new nodes from dlpar_configure_connector() onto
* the device-tree.
*/
of_changeset_init(&ocs);
rc = dlpar_changeset_attach_cc_nodes(&ocs, nodes);
if (!rc)
rc = of_changeset_apply(&ocs);
else
dlpar_free_cc_nodes(nodes);
of_changeset_destroy(&ocs);
out:
of_node_put(np);
return rc;
}
static int changeset_detach_node_recursive(struct of_changeset *ocs,
struct device_node *node)
{
struct device_node *child;
int rc;
for_each_child_of_node(node, child) {
rc = changeset_detach_node_recursive(ocs, child);
if (rc) {
of_node_put(child);
return rc;
}
}
return of_changeset_detach_node(ocs, node);
}
static int dlpar_hp_dt_remove(u32 drc_index)
{
struct device_node *np;
struct of_changeset ocs;
u32 index;
int rc = 0;
/*
* Prune all nodes with a matching index.
*/
of_changeset_init(&ocs);
for_each_node_with_property(np, "ibm,my-drc-index") {
rc = of_property_read_u32(np, "ibm,my-drc-index", &index);
if (rc) {
pr_err("%s: %pOF: of_property_read_u32 %s: %d\n",
__func__, np, "ibm,my-drc-index", rc);
of_node_put(np);
goto out;
}
if (index == drc_index) {
rc = changeset_detach_node_recursive(&ocs, np);
if (rc) {
of_node_put(np);
goto out;
}
}
}
rc = of_changeset_apply(&ocs);
out:
of_changeset_destroy(&ocs);
return rc;
}
static int dlpar_hp_dt(struct pseries_hp_errorlog *phpe)
{
u32 drc_index;
int rc;
if (phpe->id_type != PSERIES_HP_ELOG_ID_DRC_INDEX)
return -EINVAL;
drc_index = be32_to_cpu(phpe->_drc_u.drc_index);
lock_device_hotplug();
switch (phpe->action) {
case PSERIES_HP_ELOG_ACTION_ADD:
rc = dlpar_hp_dt_add(drc_index);
break;
case PSERIES_HP_ELOG_ACTION_REMOVE:
rc = dlpar_hp_dt_remove(drc_index);
break;
default:
pr_err("Invalid action (%d) specified\n", phpe->action);
rc = -EINVAL;
break;
}
unlock_device_hotplug();
return rc;
}
int handle_dlpar_errorlog(struct pseries_hp_errorlog *hp_elog)
{
int rc;
switch (hp_elog->resource) {
case PSERIES_HP_ELOG_RESOURCE_MEM:
rc = dlpar_memory(hp_elog);
break;
case PSERIES_HP_ELOG_RESOURCE_CPU:
rc = dlpar_cpu(hp_elog);
break;
case PSERIES_HP_ELOG_RESOURCE_PMEM:
rc = dlpar_hp_pmem(hp_elog);
break;
case PSERIES_HP_ELOG_RESOURCE_DT:
rc = dlpar_hp_dt(hp_elog);
break;
default:
pr_warn_ratelimited("Invalid resource (%d) specified\n",
hp_elog->resource);
rc = -EINVAL;
}
return rc;
}
static void pseries_hp_work_fn(struct work_struct *work)
{
struct pseries_hp_work *hp_work =
container_of(work, struct pseries_hp_work, work);
handle_dlpar_errorlog(hp_work->errlog);
kfree(hp_work->errlog);
kfree(work);
}
void queue_hotplug_event(struct pseries_hp_errorlog *hp_errlog)
{
struct pseries_hp_work *work;
struct pseries_hp_errorlog *hp_errlog_copy;
hp_errlog_copy = kmemdup(hp_errlog, sizeof(*hp_errlog), GFP_ATOMIC);
if (!hp_errlog_copy)
return;
work = kmalloc(sizeof(struct pseries_hp_work), GFP_ATOMIC);
if (work) {
INIT_WORK((struct work_struct *)work, pseries_hp_work_fn);
work->errlog = hp_errlog_copy;
queue_work(pseries_hp_wq, (struct work_struct *)work);
} else {
kfree(hp_errlog_copy);
}
}
static int dlpar_parse_resource(char **cmd, struct pseries_hp_errorlog *hp_elog)
{
char *arg;
arg = strsep(cmd, " ");
if (!arg)
return -EINVAL;
if (sysfs_streq(arg, "memory")) {
hp_elog->resource = PSERIES_HP_ELOG_RESOURCE_MEM;
} else if (sysfs_streq(arg, "cpu")) {
hp_elog->resource = PSERIES_HP_ELOG_RESOURCE_CPU;
} else if (sysfs_streq(arg, "dt")) {
hp_elog->resource = PSERIES_HP_ELOG_RESOURCE_DT;
} else {
pr_err("Invalid resource specified.\n");
return -EINVAL;
}
return 0;
}
static int dlpar_parse_action(char **cmd, struct pseries_hp_errorlog *hp_elog)
{
char *arg;
arg = strsep(cmd, " ");
if (!arg)
return -EINVAL;
if (sysfs_streq(arg, "add")) {
hp_elog->action = PSERIES_HP_ELOG_ACTION_ADD;
} else if (sysfs_streq(arg, "remove")) {
hp_elog->action = PSERIES_HP_ELOG_ACTION_REMOVE;
} else {
pr_err("Invalid action specified.\n");
return -EINVAL;
}
return 0;
}
static int dlpar_parse_id_type(char **cmd, struct pseries_hp_errorlog *hp_elog)
{
char *arg;
u32 count, index;
arg = strsep(cmd, " ");
if (!arg)
return -EINVAL;
if (sysfs_streq(arg, "indexed-count")) {
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_IC;
arg = strsep(cmd, " ");
if (!arg) {
pr_err("No DRC count specified.\n");
return -EINVAL;
}
if (kstrtou32(arg, 0, &count)) {
pr_err("Invalid DRC count specified.\n");
return -EINVAL;
}
arg = strsep(cmd, " ");
if (!arg) {
pr_err("No DRC Index specified.\n");
return -EINVAL;
}
if (kstrtou32(arg, 0, &index)) {
pr_err("Invalid DRC Index specified.\n");
return -EINVAL;
}
hp_elog->_drc_u.ic.count = cpu_to_be32(count);
hp_elog->_drc_u.ic.index = cpu_to_be32(index);
} else if (sysfs_streq(arg, "index")) {
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_INDEX;
arg = strsep(cmd, " ");
if (!arg) {
pr_err("No DRC Index specified.\n");
return -EINVAL;
}
if (kstrtou32(arg, 0, &index)) {
pr_err("Invalid DRC Index specified.\n");
return -EINVAL;
}
hp_elog->_drc_u.drc_index = cpu_to_be32(index);
} else if (sysfs_streq(arg, "count")) {
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_COUNT;
arg = strsep(cmd, " ");
if (!arg) {
pr_err("No DRC count specified.\n");
return -EINVAL;
}
if (kstrtou32(arg, 0, &count)) {
pr_err("Invalid DRC count specified.\n");
return -EINVAL;
}
hp_elog->_drc_u.drc_count = cpu_to_be32(count);
} else {
pr_err("Invalid id_type specified.\n");
return -EINVAL;
}
return 0;
}
static ssize_t dlpar_store(const struct class *class, const struct class_attribute *attr,
const char *buf, size_t count)
{
struct pseries_hp_errorlog hp_elog;
char *argbuf;
char *args;
int rc;
args = argbuf = kstrdup(buf, GFP_KERNEL);
if (!argbuf)
return -ENOMEM;
/*
* Parse out the request from the user, this will be in the form:
* <resource> <action> <id_type> <id>
*/
rc = dlpar_parse_resource(&args, &hp_elog);
if (rc)
goto dlpar_store_out;
rc = dlpar_parse_action(&args, &hp_elog);
if (rc)
goto dlpar_store_out;
rc = dlpar_parse_id_type(&args, &hp_elog);
if (rc)
goto dlpar_store_out;
rc = handle_dlpar_errorlog(&hp_elog);
dlpar_store_out:
kfree(argbuf);
if (rc)
pr_err("Could not handle DLPAR request \"%s\"\n", buf);
return rc ? rc : count;
}
static ssize_t dlpar_show(const struct class *class, const struct class_attribute *attr,
char *buf)
{
return sprintf(buf, "%s\n", "memory,cpu,dt");
}
static CLASS_ATTR_RW(dlpar);
int __init dlpar_workqueue_init(void)
{
if (pseries_hp_wq)
return 0;
pseries_hp_wq = alloc_ordered_workqueue("pseries hotplug workqueue", 0);
return pseries_hp_wq ? 0 : -ENOMEM;
}
static int __init dlpar_sysfs_init(void)
{
int rc;
rc = dlpar_workqueue_init();
if (rc)
return rc;
return sysfs_create_file(kernel_kobj, &class_attr_dlpar.attr);
}
machine_device_initcall(pseries, dlpar_sysfs_init);