blob: 194ffd5c8580401a13eefb3f85e61fdba2d5e7e6 [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
4 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
5 */
6
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +01007#define KMSG_COMPONENT "sclp_config"
8#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020010#include <linux/init.h>
11#include <linux/errno.h>
12#include <linux/cpu.h>
Kay Sievers8a25a2f2011-12-21 14:29:42 -080013#include <linux/device.h>
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020014#include <linux/workqueue.h>
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010015#include <linux/slab.h>
16#include <linux/sysfs.h>
Heiko Carstens1e489512008-04-30 13:38:37 +020017#include <asm/smp.h>
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020018
Martin Schwidefskyb3ff0882008-12-25 13:39:48 +010019#include "sclp.h"
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020020
21struct conf_mgm_data {
22 u8 reserved;
23 u8 ev_qualifier;
24} __attribute__((packed));
25
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010026#define OFB_DATA_MAX 64
27
28struct sclp_ofb_evbuf {
29 struct evbuf_header header;
30 struct conf_mgm_data cm_data;
31 char ev_data[OFB_DATA_MAX];
32} __packed;
33
34struct sclp_ofb_sccb {
35 struct sccb_header header;
36 struct sclp_ofb_evbuf ofb_evbuf;
37} __packed;
38
Heiko Carstens1e489512008-04-30 13:38:37 +020039#define EV_QUAL_CPU_CHANGE 1
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020040#define EV_QUAL_CAP_CHANGE 3
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010041#define EV_QUAL_OPEN4BUSINESS 5
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020042
43static struct work_struct sclp_cpu_capability_work;
Heiko Carstens1e489512008-04-30 13:38:37 +020044static struct work_struct sclp_cpu_change_work;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020045
46static void sclp_cpu_capability_notify(struct work_struct *work)
47{
48 int cpu;
Kay Sievers8a25a2f2011-12-21 14:29:42 -080049 struct device *dev;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020050
Heiko Carstens097a1162016-04-14 12:35:22 +020051 s390_update_cpu_mhz();
Heiko Carstens363fd4c2013-07-26 11:03:16 +020052 pr_info("CPU capability may have changed\n");
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010053 get_online_cpus();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020054 for_each_online_cpu(cpu) {
Kay Sievers8a25a2f2011-12-21 14:29:42 -080055 dev = get_cpu_device(cpu);
56 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020057 }
Gautham R Shenoy86ef5c92008-01-25 21:08:02 +010058 put_online_cpus();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020059}
60
Heiko Carstensb9732ca2008-07-14 09:57:28 +020061static void __ref sclp_cpu_change_notify(struct work_struct *work)
62{
Heiko Carstensfc7e1e42008-08-01 16:39:23 +020063 smp_rescan_cpus();
Heiko Carstens1e489512008-04-30 13:38:37 +020064}
65
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020066static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
67{
68 struct conf_mgm_data *cdata;
69
70 cdata = (struct conf_mgm_data *)(evbuf + 1);
Heiko Carstens1e489512008-04-30 13:38:37 +020071 switch (cdata->ev_qualifier) {
72 case EV_QUAL_CPU_CHANGE:
73 schedule_work(&sclp_cpu_change_work);
74 break;
75 case EV_QUAL_CAP_CHANGE:
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020076 schedule_work(&sclp_cpu_capability_work);
Heiko Carstens1e489512008-04-30 13:38:37 +020077 break;
78 }
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020079}
80
81static struct sclp_register sclp_conf_register =
82{
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010083#ifdef CONFIG_SCLP_OFB
84 .send_mask = EVTYP_CONFMGMDATA_MASK,
85#endif
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +020086 .receive_mask = EVTYP_CONFMGMDATA_MASK,
87 .receiver_fn = sclp_conf_receiver_fn,
88};
89
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +010090#ifdef CONFIG_SCLP_OFB
91static int sclp_ofb_send_req(char *ev_data, size_t len)
92{
93 static DEFINE_MUTEX(send_mutex);
94 struct sclp_ofb_sccb *sccb;
95 int rc, response;
96
97 if (len > OFB_DATA_MAX)
98 return -EINVAL;
99 sccb = (struct sclp_ofb_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
100 if (!sccb)
101 return -ENOMEM;
102 /* Setup SCCB for Control-Program Identification */
103 sccb->header.length = sizeof(struct sclp_ofb_sccb);
104 sccb->ofb_evbuf.header.length = sizeof(struct sclp_ofb_evbuf);
105 sccb->ofb_evbuf.header.type = EVTYP_CONFMGMDATA;
106 sccb->ofb_evbuf.cm_data.ev_qualifier = EV_QUAL_OPEN4BUSINESS;
107 memcpy(sccb->ofb_evbuf.ev_data, ev_data, len);
108
109 if (!(sclp_conf_register.sclp_receive_mask & EVTYP_CONFMGMDATA_MASK))
110 pr_warn("SCLP receiver did not register to receive "
111 "Configuration Management Data Events.\n");
112
113 mutex_lock(&send_mutex);
114 rc = sclp_sync_request(SCLP_CMDW_WRITE_EVENT_DATA, sccb);
115 mutex_unlock(&send_mutex);
116 if (rc)
117 goto out;
118 response = sccb->header.response_code;
119 if (response != 0x0020) {
120 pr_err("Open for Business request failed with response code "
121 "0x%04x\n", response);
122 rc = -EIO;
123 }
124out:
125 free_page((unsigned long)sccb);
126 return rc;
127}
128
129static ssize_t sysfs_ofb_data_write(struct file *filp, struct kobject *kobj,
130 struct bin_attribute *bin_attr,
131 char *buf, loff_t off, size_t count)
132{
133 int rc;
134
135 rc = sclp_ofb_send_req(buf, count);
136 return rc ?: count;
137}
138
Bhumika Goyalc7e85ae2017-08-02 21:37:22 +0530139static const struct bin_attribute ofb_bin_attr = {
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +0100140 .attr = {
141 .name = "event_data",
142 .mode = S_IWUSR,
143 },
144 .write = sysfs_ofb_data_write,
145};
146#endif
147
148static int __init sclp_ofb_setup(void)
149{
150#ifdef CONFIG_SCLP_OFB
151 struct kset *ofb_kset;
152 int rc;
153
154 ofb_kset = kset_create_and_add("ofb", NULL, firmware_kobj);
155 if (!ofb_kset)
156 return -ENOMEM;
157 rc = sysfs_create_bin_file(&ofb_kset->kobj, &ofb_bin_attr);
158 if (rc) {
159 kset_unregister(ofb_kset);
160 return rc;
161 }
162#endif
163 return 0;
164}
165
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200166static int __init sclp_conf_init(void)
167{
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +0100168 int rc;
169
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200170 INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
Heiko Carstens1e489512008-04-30 13:38:37 +0200171 INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
Jochen Schweflinghausc6f70d32015-11-26 19:13:01 +0100172 rc = sclp_register(&sclp_conf_register);
173 if (rc)
174 return rc;
175 return sclp_ofb_setup();
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200176}
177
178__initcall(sclp_conf_init);