sclp_config.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. smp_rescan_cpus();
  52. }
  53. static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
  54. {
  55. struct conf_mgm_data *cdata;
  56. cdata = (struct conf_mgm_data *)(evbuf + 1);
  57. switch (cdata->ev_qualifier) {
  58. case EV_QUAL_CPU_CHANGE:
  59. schedule_work(&sclp_cpu_change_work);
  60. break;
  61. case EV_QUAL_CAP_CHANGE:
  62. schedule_work(&sclp_cpu_capability_work);
  63. break;
  64. }
  65. }
  66. static struct sclp_register sclp_conf_register =
  67. {
  68. #ifdef CONFIG_SCLP_OFB
  69. .send_mask = EVTYP_CONFMGMDATA_MASK,
  70. #endif
  71. .receive_mask = EVTYP_CONFMGMDATA_MASK,
  72. .receiver_fn = sclp_conf_receiver_fn,
  73. };
  74. #ifdef CONFIG_SCLP_OFB
  75. static int sclp_ofb_send_req(char *ev_data, size_t len)
  76. {
  77. static DEFINE_MUTEX(send_mutex);
  78. struct sclp_ofb_sccb *sccb;
  79. int rc, response;
  80. if (len > OFB_DATA_MAX)
  81. return -EINVAL;
  82. sccb = (struct sclp_ofb_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  83. if (!sccb)
  84. return -ENOMEM;
  85. /* Setup SCCB for Control-Program Identification */
  86. sccb->header.length = sizeof(struct sclp_ofb_sccb);
  87. sccb->ofb_evbuf.header.length = sizeof(struct sclp_ofb_evbuf);
  88. sccb->ofb_evbuf.header.type = EVTYP_CONFMGMDATA;
  89. sccb->ofb_evbuf.cm_data.ev_qualifier = EV_QUAL_OPEN4BUSINESS;
  90. memcpy(sccb->ofb_evbuf.ev_data, ev_data, len);
  91. if (!(sclp_conf_register.sclp_receive_mask & EVTYP_CONFMGMDATA_MASK))
  92. pr_warn("SCLP receiver did not register to receive "
  93. "Configuration Management Data Events.\n");
  94. mutex_lock(&send_mutex);
  95. rc = sclp_sync_request(SCLP_CMDW_WRITE_EVENT_DATA, sccb);
  96. mutex_unlock(&send_mutex);
  97. if (rc)
  98. goto out;
  99. response = sccb->header.response_code;
  100. if (response != 0x0020) {
  101. pr_err("Open for Business request failed with response code "
  102. "0x%04x\n", response);
  103. rc = -EIO;
  104. }
  105. out:
  106. free_page((unsigned long)sccb);
  107. return rc;
  108. }
  109. static ssize_t sysfs_ofb_data_write(struct file *filp, struct kobject *kobj,
  110. struct bin_attribute *bin_attr,
  111. char *buf, loff_t off, size_t count)
  112. {
  113. int rc;
  114. rc = sclp_ofb_send_req(buf, count);
  115. return rc ?: count;
  116. }
  117. static const struct bin_attribute ofb_bin_attr = {
  118. .attr = {
  119. .name = "event_data",
  120. .mode = S_IWUSR,
  121. },
  122. .write = sysfs_ofb_data_write,
  123. };
  124. #endif
  125. static int __init sclp_ofb_setup(void)
  126. {
  127. #ifdef CONFIG_SCLP_OFB
  128. struct kset *ofb_kset;
  129. int rc;
  130. ofb_kset = kset_create_and_add("ofb", NULL, firmware_kobj);
  131. if (!ofb_kset)
  132. return -ENOMEM;
  133. rc = sysfs_create_bin_file(&ofb_kset->kobj, &ofb_bin_attr);
  134. if (rc) {
  135. kset_unregister(ofb_kset);
  136. return rc;
  137. }
  138. #endif
  139. return 0;
  140. }
  141. static int __init sclp_conf_init(void)
  142. {
  143. int rc;
  144. INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
  145. INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
  146. rc = sclp_register(&sclp_conf_register);
  147. if (rc)
  148. return rc;
  149. return sclp_ofb_setup();
  150. }
  151. __initcall(sclp_conf_init);