sclp_config.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2007
  4. * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
  5. */
  6. #define KMSG_COMPONENT "sclp_config"
  7. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  8. #include <linux/init.h>
  9. #include <linux/errno.h>
  10. #include <linux/cpu.h>
  11. #include <linux/device.h>
  12. #include <linux/workqueue.h>
  13. #include <linux/slab.h>
  14. #include <linux/sysfs.h>
  15. #include <asm/smp.h>
  16. #include "sclp.h"
  17. struct conf_mgm_data {
  18. u8 reserved;
  19. u8 ev_qualifier;
  20. } __attribute__((packed));
  21. #define OFB_DATA_MAX 64
  22. struct sclp_ofb_evbuf {
  23. struct evbuf_header header;
  24. struct conf_mgm_data cm_data;
  25. char ev_data[OFB_DATA_MAX];
  26. } __packed;
  27. struct sclp_ofb_sccb {
  28. struct sccb_header header;
  29. struct sclp_ofb_evbuf ofb_evbuf;
  30. } __packed;
  31. #define EV_QUAL_CPU_CHANGE 1
  32. #define EV_QUAL_CAP_CHANGE 3
  33. #define EV_QUAL_OPEN4BUSINESS 5
  34. static struct work_struct sclp_cpu_capability_work;
  35. static struct work_struct sclp_cpu_change_work;
  36. static void sclp_cpu_capability_notify(struct work_struct *work)
  37. {
  38. int cpu;
  39. struct device *dev;
  40. s390_update_cpu_mhz();
  41. pr_info("CPU capability may have changed\n");
  42. get_online_cpus();
  43. for_each_online_cpu(cpu) {
  44. dev = get_cpu_device(cpu);
  45. kobject_uevent(&dev->kobj, KOBJ_CHANGE);
  46. }
  47. put_online_cpus();
  48. }
  49. static void __ref sclp_cpu_change_notify(struct work_struct *work)
  50. {
  51. lock_device_hotplug();
  52. smp_rescan_cpus();
  53. unlock_device_hotplug();
  54. }
  55. static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
  56. {
  57. struct conf_mgm_data *cdata;
  58. cdata = (struct conf_mgm_data *)(evbuf + 1);
  59. switch (cdata->ev_qualifier) {
  60. case EV_QUAL_CPU_CHANGE:
  61. schedule_work(&sclp_cpu_change_work);
  62. break;
  63. case EV_QUAL_CAP_CHANGE:
  64. schedule_work(&sclp_cpu_capability_work);
  65. break;
  66. }
  67. }
  68. static struct sclp_register sclp_conf_register =
  69. {
  70. #ifdef CONFIG_SCLP_OFB
  71. .send_mask = EVTYP_CONFMGMDATA_MASK,
  72. #endif
  73. .receive_mask = EVTYP_CONFMGMDATA_MASK,
  74. .receiver_fn = sclp_conf_receiver_fn,
  75. };
  76. #ifdef CONFIG_SCLP_OFB
  77. static int sclp_ofb_send_req(char *ev_data, size_t len)
  78. {
  79. static DEFINE_MUTEX(send_mutex);
  80. struct sclp_ofb_sccb *sccb;
  81. int rc, response;
  82. if (len > OFB_DATA_MAX)
  83. return -EINVAL;
  84. sccb = (struct sclp_ofb_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  85. if (!sccb)
  86. return -ENOMEM;
  87. /* Setup SCCB for Control-Program Identification */
  88. sccb->header.length = sizeof(struct sclp_ofb_sccb);
  89. sccb->ofb_evbuf.header.length = sizeof(struct sclp_ofb_evbuf);
  90. sccb->ofb_evbuf.header.type = EVTYP_CONFMGMDATA;
  91. sccb->ofb_evbuf.cm_data.ev_qualifier = EV_QUAL_OPEN4BUSINESS;
  92. memcpy(sccb->ofb_evbuf.ev_data, ev_data, len);
  93. if (!(sclp_conf_register.sclp_receive_mask & EVTYP_CONFMGMDATA_MASK))
  94. pr_warn("SCLP receiver did not register to receive "
  95. "Configuration Management Data Events.\n");
  96. mutex_lock(&send_mutex);
  97. rc = sclp_sync_request(SCLP_CMDW_WRITE_EVENT_DATA, sccb);
  98. mutex_unlock(&send_mutex);
  99. if (rc)
  100. goto out;
  101. response = sccb->header.response_code;
  102. if (response != 0x0020) {
  103. pr_err("Open for Business request failed with response code "
  104. "0x%04x\n", response);
  105. rc = -EIO;
  106. }
  107. out:
  108. free_page((unsigned long)sccb);
  109. return rc;
  110. }
  111. static ssize_t sysfs_ofb_data_write(struct file *filp, struct kobject *kobj,
  112. struct bin_attribute *bin_attr,
  113. char *buf, loff_t off, size_t count)
  114. {
  115. int rc;
  116. rc = sclp_ofb_send_req(buf, count);
  117. return rc ?: count;
  118. }
  119. static const struct bin_attribute ofb_bin_attr = {
  120. .attr = {
  121. .name = "event_data",
  122. .mode = S_IWUSR,
  123. },
  124. .write = sysfs_ofb_data_write,
  125. };
  126. #endif
  127. static int __init sclp_ofb_setup(void)
  128. {
  129. #ifdef CONFIG_SCLP_OFB
  130. struct kset *ofb_kset;
  131. int rc;
  132. ofb_kset = kset_create_and_add("ofb", NULL, firmware_kobj);
  133. if (!ofb_kset)
  134. return -ENOMEM;
  135. rc = sysfs_create_bin_file(&ofb_kset->kobj, &ofb_bin_attr);
  136. if (rc) {
  137. kset_unregister(ofb_kset);
  138. return rc;
  139. }
  140. #endif
  141. return 0;
  142. }
  143. static int __init sclp_conf_init(void)
  144. {
  145. int rc;
  146. INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
  147. INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
  148. rc = sclp_register(&sclp_conf_register);
  149. if (rc)
  150. return rc;
  151. return sclp_ofb_setup();
  152. }
  153. __initcall(sclp_conf_init);