blob: 10383e936461707c838aa8c61c4bd37430480dfd [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02002/*
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02003 * Copyright IBM Corp. 2007
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02004 */
5
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +01006#define KMSG_COMPONENT "sclp_config"
7#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
8
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02009#include <linux/init.h>
10#include <linux/errno.h>
11#include <linux/cpu.h>
Kay Sievers8a25a2f2011-12-21 14:29:42 -080012#include <linux/device.h>
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020013#include <linux/workqueue.h>
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010014#include <linux/slab.h>
15#include <linux/sysfs.h>
Heiko Carstens1e489512008-04-30 13:38:37 +020016#include <asm/smp.h>
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020017
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +010018#include "sclp.h"
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020019
20struct conf_mgm_data {
21 u8 reserved;
22 u8 ev_qualifier;
23} __attribute__((packed));
24
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010025#define OFB_DATA_MAX 64
26
27struct sclp_ofb_evbuf {
28 struct evbuf_header header;
29 struct conf_mgm_data cm_data;
30 char ev_data[OFB_DATA_MAX];
31} __packed;
32
33struct sclp_ofb_sccb {
34 struct sccb_header header;
35 struct sclp_ofb_evbuf ofb_evbuf;
36} __packed;
37
Heiko Carstens1e489512008-04-30 13:38:37 +020038#define EV_QUAL_CPU_CHANGE 1
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020039#define EV_QUAL_CAP_CHANGE 3
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010040#define EV_QUAL_OPEN4BUSINESS 5
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020041
42static struct work_struct sclp_cpu_capability_work;
Heiko Carstens1e489512008-04-30 13:38:37 +020043static struct work_struct sclp_cpu_change_work;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020044
45static void sclp_cpu_capability_notify(struct work_struct *work)
46{
47 int cpu;
Kay Sievers8a25a2f2011-12-21 14:29:42 -080048 struct device *dev;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020049
Heiko Carstens097a1162016-04-14 12:35:22 +020050 s390_update_cpu_mhz();
Heiko Carstens363fd4c2013-07-26 11:03:16 +020051 pr_info("CPU capability may have changed\n");
Sebastian Andrzej Siewior52b6def2021-08-03 16:15:48 +020052 cpus_read_lock();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020053 for_each_online_cpu(cpu) {
Kay Sievers8a25a2f2011-12-21 14:29:42 -080054 dev = get_cpu_device(cpu);
55 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020056 }
Sebastian Andrzej Siewior52b6def2021-08-03 16:15:48 +020057 cpus_read_unlock();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020058}
59
Heiko Carstensb9732ca2008-07-14 09:57:28 +020060static void __ref sclp_cpu_change_notify(struct work_struct *work)
61{
Gerald Schaeferb7cb7072019-01-09 13:00:03 +010062 lock_device_hotplug();
Heiko Carstensfc7e1e42008-08-01 16:39:23 +020063 smp_rescan_cpus();
Gerald Schaeferb7cb7072019-01-09 13:00:03 +010064 unlock_device_hotplug();
Heiko Carstens1e489512008-04-30 13:38:37 +020065}
66
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020067static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
68{
69 struct conf_mgm_data *cdata;
70
71 cdata = (struct conf_mgm_data *)(evbuf + 1);
Heiko Carstens1e489512008-04-30 13:38:37 +020072 switch (cdata->ev_qualifier) {
73 case EV_QUAL_CPU_CHANGE:
74 schedule_work(&sclp_cpu_change_work);
75 break;
76 case EV_QUAL_CAP_CHANGE:
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020077 schedule_work(&sclp_cpu_capability_work);
Heiko Carstens1e489512008-04-30 13:38:37 +020078 break;
79 }
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020080}
81
82static struct sclp_register sclp_conf_register =
83{
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010084#ifdef CONFIG_SCLP_OFB
85 .send_mask = EVTYP_CONFMGMDATA_MASK,
86#endif
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020087 .receive_mask = EVTYP_CONFMGMDATA_MASK,
88 .receiver_fn = sclp_conf_receiver_fn,
89};
90
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010091#ifdef CONFIG_SCLP_OFB
92static int sclp_ofb_send_req(char *ev_data, size_t len)
93{
94 static DEFINE_MUTEX(send_mutex);
95 struct sclp_ofb_sccb *sccb;
96 int rc, response;
97
98 if (len > OFB_DATA_MAX)
99 return -EINVAL;
100 sccb = (struct sclp_ofb_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
101 if (!sccb)
102 return -ENOMEM;
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);
109
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");
113
114 mutex_lock(&send_mutex);
115 rc = sclp_sync_request(SCLP_CMDW_WRITE_EVENT_DATA, sccb);
116 mutex_unlock(&send_mutex);
117 if (rc)
118 goto out;
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);
123 rc = -EIO;
124 }
125out:
126 free_page((unsigned long)sccb);
127 return rc;
128}
129
130static 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)
133{
134 int rc;
135
136 rc = sclp_ofb_send_req(buf, count);
137 return rc ?: count;
138}
139
Bhumika Goyalc7e85ae2017-08-02 21:37:22 +0530140static const struct bin_attribute ofb_bin_attr = {
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +0100141 .attr = {
142 .name = "event_data",
143 .mode = S_IWUSR,
144 },
145 .write = sysfs_ofb_data_write,
146};
147#endif
148
149static int __init sclp_ofb_setup(void)
150{
151#ifdef CONFIG_SCLP_OFB
152 struct kset *ofb_kset;
153 int rc;
154
155 ofb_kset = kset_create_and_add("ofb", NULL, firmware_kobj);
156 if (!ofb_kset)
157 return -ENOMEM;
158 rc = sysfs_create_bin_file(&ofb_kset->kobj, &ofb_bin_attr);
159 if (rc) {
160 kset_unregister(ofb_kset);
161 return rc;
162 }
163#endif
164 return 0;
165}
166
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200167static int __init sclp_conf_init(void)
168{
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +0100169 int rc;
170
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200171 INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
Heiko Carstens1e489512008-04-30 13:38:37 +0200172 INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +0100173 rc = sclp_register(&sclp_conf_register);
174 if (rc)
175 return rc;
176 return sclp_ofb_setup();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200177}
178
179__initcall(sclp_conf_init);