blob: fff4ff485d9bcbb8e3bc25c05d465b8214f8774b [file] [log] [blame]
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001/*
2 * drivers/s390/char/sclp_config.c
3 *
4 * Copyright IBM Corp. 2007
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
6 */
7
8#include <linux/init.h>
9#include <linux/errno.h>
10#include <linux/cpu.h>
Heiko Carstensb9732ca2008-07-14 09:57:28 +020011#include <linux/kthread.h>
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020012#include <linux/sysdev.h>
13#include <linux/workqueue.h>
Heiko Carstens1e489512008-04-30 13:38:37 +020014#include <asm/smp.h>
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020015#include "sclp.h"
16
17#define TAG "sclp_config: "
18
19struct conf_mgm_data {
20 u8 reserved;
21 u8 ev_qualifier;
22} __attribute__((packed));
23
Heiko Carstens1e489512008-04-30 13:38:37 +020024#define EV_QUAL_CPU_CHANGE 1
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020025#define EV_QUAL_CAP_CHANGE 3
26
27static struct work_struct sclp_cpu_capability_work;
Heiko Carstens1e489512008-04-30 13:38:37 +020028static struct work_struct sclp_cpu_change_work;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020029
30static void sclp_cpu_capability_notify(struct work_struct *work)
31{
32 int cpu;
33 struct sys_device *sysdev;
34
35 printk(KERN_WARNING TAG "cpu capability changed.\n");
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010036 get_online_cpus();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020037 for_each_online_cpu(cpu) {
38 sysdev = get_cpu_sysdev(cpu);
39 kobject_uevent(&sysdev->kobj, KOBJ_CHANGE);
40 }
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010041 put_online_cpus();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020042}
43
Heiko Carstensb9732ca2008-07-14 09:57:28 +020044static int sclp_cpu_kthread(void *data)
Heiko Carstens1e489512008-04-30 13:38:37 +020045{
46 smp_rescan_cpus();
Heiko Carstensb9732ca2008-07-14 09:57:28 +020047 return 0;
48}
49
50static void __ref sclp_cpu_change_notify(struct work_struct *work)
51{
52 /* Can't call smp_rescan_cpus() from workqueue context since it may
53 * deadlock in case of cpu hotplug. So we have to create a kernel
54 * thread in order to call it.
55 */
56 kthread_run(sclp_cpu_kthread, NULL, "cpu_rescan");
Heiko Carstens1e489512008-04-30 13:38:37 +020057}
58
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020059static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
60{
61 struct conf_mgm_data *cdata;
62
63 cdata = (struct conf_mgm_data *)(evbuf + 1);
Heiko Carstens1e489512008-04-30 13:38:37 +020064 switch (cdata->ev_qualifier) {
65 case EV_QUAL_CPU_CHANGE:
66 schedule_work(&sclp_cpu_change_work);
67 break;
68 case EV_QUAL_CAP_CHANGE:
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020069 schedule_work(&sclp_cpu_capability_work);
Heiko Carstens1e489512008-04-30 13:38:37 +020070 break;
71 }
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020072}
73
74static struct sclp_register sclp_conf_register =
75{
76 .receive_mask = EVTYP_CONFMGMDATA_MASK,
77 .receiver_fn = sclp_conf_receiver_fn,
78};
79
80static int __init sclp_conf_init(void)
81{
82 int rc;
83
84 INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
Heiko Carstens1e489512008-04-30 13:38:37 +020085 INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020086
87 rc = sclp_register(&sclp_conf_register);
Martin Schwidefskya12c53f2008-07-14 09:59:28 +020088 if (rc)
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020089 return rc;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020090
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +010091 if (!(sclp_conf_register.sclp_send_mask & EVTYP_CONFMGMDATA_MASK)) {
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020092 printk(KERN_WARNING TAG "no configuration management.\n");
93 sclp_unregister(&sclp_conf_register);
94 rc = -ENOSYS;
95 }
96 return rc;
97}
98
99__initcall(sclp_conf_init);