1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2007
6 #define KMSG_COMPONENT "sclp_config"
7 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9 #include <linux/init.h>
10 #include <linux/errno.h>
11 #include <linux/cpu.h>
12 #include <linux/device.h>
13 #include <linux/workqueue.h>
14 #include <linux/slab.h>
15 #include <linux/sysfs.h>
20 struct conf_mgm_data
{
23 } __attribute__((packed
));
25 #define OFB_DATA_MAX 64
27 struct sclp_ofb_evbuf
{
28 struct evbuf_header header
;
29 struct conf_mgm_data cm_data
;
30 char ev_data
[OFB_DATA_MAX
];
33 struct sclp_ofb_sccb
{
34 struct sccb_header header
;
35 struct sclp_ofb_evbuf ofb_evbuf
;
38 #define EV_QUAL_CPU_CHANGE 1
39 #define EV_QUAL_CAP_CHANGE 3
40 #define EV_QUAL_OPEN4BUSINESS 5
42 static struct work_struct sclp_cpu_capability_work
;
43 static struct work_struct sclp_cpu_change_work
;
45 static void sclp_cpu_capability_notify(struct work_struct
*work
)
50 s390_update_cpu_mhz();
51 pr_info("CPU capability may have changed\n");
53 for_each_online_cpu(cpu
) {
54 dev
= get_cpu_device(cpu
);
55 kobject_uevent(&dev
->kobj
, KOBJ_CHANGE
);
60 static void __ref
sclp_cpu_change_notify(struct work_struct
*work
)
62 lock_device_hotplug();
63 smp_rescan_cpus(false);
64 unlock_device_hotplug();
67 static void sclp_conf_receiver_fn(struct evbuf_header
*evbuf
)
69 struct conf_mgm_data
*cdata
;
71 cdata
= (struct conf_mgm_data
*)(evbuf
+ 1);
72 switch (cdata
->ev_qualifier
) {
73 case EV_QUAL_CPU_CHANGE
:
74 schedule_work(&sclp_cpu_change_work
);
76 case EV_QUAL_CAP_CHANGE
:
77 schedule_work(&sclp_cpu_capability_work
);
82 static struct sclp_register sclp_conf_register
=
84 #ifdef CONFIG_SCLP_OFB
85 .send_mask
= EVTYP_CONFMGMDATA_MASK
,
87 .receive_mask
= EVTYP_CONFMGMDATA_MASK
,
88 .receiver_fn
= sclp_conf_receiver_fn
,
91 #ifdef CONFIG_SCLP_OFB
92 static int sclp_ofb_send_req(char *ev_data
, size_t len
)
94 static DEFINE_MUTEX(send_mutex
);
95 struct sclp_ofb_sccb
*sccb
;
98 if (len
> OFB_DATA_MAX
)
100 sccb
= (struct sclp_ofb_sccb
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
103 /* Setup SCCB for Control-Program Identification */
104 sccb
->header
.length
= sizeof(struct sclp_ofb_sccb
);
105 sccb
->ofb_evbuf
.header
.length
= sizeof(struct sclp_ofb_evbuf
);
106 sccb
->ofb_evbuf
.header
.type
= EVTYP_CONFMGMDATA
;
107 sccb
->ofb_evbuf
.cm_data
.ev_qualifier
= EV_QUAL_OPEN4BUSINESS
;
108 memcpy(sccb
->ofb_evbuf
.ev_data
, ev_data
, len
);
110 if (!(sclp_conf_register
.sclp_receive_mask
& EVTYP_CONFMGMDATA_MASK
))
111 pr_warn("SCLP receiver did not register to receive "
112 "Configuration Management Data Events.\n");
114 mutex_lock(&send_mutex
);
115 rc
= sclp_sync_request(SCLP_CMDW_WRITE_EVENT_DATA
, sccb
);
116 mutex_unlock(&send_mutex
);
119 response
= sccb
->header
.response_code
;
120 if (response
!= 0x0020) {
121 pr_err("Open for Business request failed with response code "
122 "0x%04x\n", response
);
126 free_page((unsigned long)sccb
);
130 static ssize_t
sysfs_ofb_data_write(struct file
*filp
, struct kobject
*kobj
,
131 struct bin_attribute
*bin_attr
,
132 char *buf
, loff_t off
, size_t count
)
136 rc
= sclp_ofb_send_req(buf
, count
);
140 static const struct bin_attribute ofb_bin_attr
= {
142 .name
= "event_data",
145 .write
= sysfs_ofb_data_write
,
149 static int __init
sclp_ofb_setup(void)
151 #ifdef CONFIG_SCLP_OFB
152 struct kset
*ofb_kset
;
155 ofb_kset
= kset_create_and_add("ofb", NULL
, firmware_kobj
);
158 rc
= sysfs_create_bin_file(&ofb_kset
->kobj
, &ofb_bin_attr
);
160 kset_unregister(ofb_kset
);
167 static int __init
sclp_conf_init(void)
171 INIT_WORK(&sclp_cpu_capability_work
, sclp_cpu_capability_notify
);
172 INIT_WORK(&sclp_cpu_change_work
, sclp_cpu_change_notify
);
173 rc
= sclp_register(&sclp_conf_register
);
176 return sclp_ofb_setup();
179 __initcall(sclp_conf_init
);