sclp_ocf.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * drivers/s390/char/sclp_ocf.c
  3. * SCLP OCF communication parameters sysfs interface
  4. *
  5. * Copyright IBM Corp. 2011
  6. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. */
  8. #define KMSG_COMPONENT "sclp_ocf"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/stat.h>
  13. #include <linux/device.h>
  14. #include <linux/string.h>
  15. #include <linux/ctype.h>
  16. #include <linux/kmod.h>
  17. #include <linux/timer.h>
  18. #include <linux/err.h>
  19. #include <asm/ebcdic.h>
  20. #include <asm/sclp.h>
  21. #include "sclp.h"
  22. #define OCF_LENGTH_HMC_NETWORK 8UL
  23. #define OCF_LENGTH_CPC_NAME 8UL
  24. static char hmc_network[OCF_LENGTH_HMC_NETWORK + 1];
  25. static char cpc_name[OCF_LENGTH_CPC_NAME + 1];
  26. static DEFINE_SPINLOCK(sclp_ocf_lock);
  27. static struct work_struct sclp_ocf_change_work;
  28. static struct kset *ocf_kset;
  29. static void sclp_ocf_change_notify(struct work_struct *work)
  30. {
  31. kobject_uevent(&ocf_kset->kobj, KOBJ_CHANGE);
  32. }
  33. /* Handler for OCF event. Look for the CPC image name. */
  34. static void sclp_ocf_handler(struct evbuf_header *evbuf)
  35. {
  36. struct gds_vector *v;
  37. struct gds_subvector *sv, *netid, *cpc;
  38. size_t size;
  39. /* Find the 0x9f00 block. */
  40. v = sclp_find_gds_vector(evbuf + 1, (void *) evbuf + evbuf->length,
  41. 0x9f00);
  42. if (!v)
  43. return;
  44. /* Find the 0x9f22 block inside the 0x9f00 block. */
  45. v = sclp_find_gds_vector(v + 1, (void *) v + v->length, 0x9f22);
  46. if (!v)
  47. return;
  48. /* Find the 0x81 block inside the 0x9f22 block. */
  49. sv = sclp_find_gds_subvector(v + 1, (void *) v + v->length, 0x81);
  50. if (!sv)
  51. return;
  52. /* Find the 0x01 block inside the 0x81 block. */
  53. netid = sclp_find_gds_subvector(sv + 1, (void *) sv + sv->length, 1);
  54. /* Find the 0x02 block inside the 0x81 block. */
  55. cpc = sclp_find_gds_subvector(sv + 1, (void *) sv + sv->length, 2);
  56. /* Copy network name and cpc name. */
  57. spin_lock(&sclp_ocf_lock);
  58. if (netid) {
  59. size = min(OCF_LENGTH_HMC_NETWORK, (size_t) netid->length);
  60. memcpy(hmc_network, netid + 1, size);
  61. EBCASC(hmc_network, size);
  62. hmc_network[size] = 0;
  63. }
  64. if (cpc) {
  65. size = min(OCF_LENGTH_CPC_NAME, (size_t) cpc->length);
  66. memcpy(cpc_name, cpc + 1, size);
  67. EBCASC(cpc_name, size);
  68. cpc_name[size] = 0;
  69. }
  70. spin_unlock(&sclp_ocf_lock);
  71. schedule_work(&sclp_ocf_change_work);
  72. }
  73. static struct sclp_register sclp_ocf_event = {
  74. .receive_mask = EVTYP_OCF_MASK,
  75. .receiver_fn = sclp_ocf_handler,
  76. };
  77. static ssize_t cpc_name_show(struct kobject *kobj,
  78. struct kobj_attribute *attr, char *page)
  79. {
  80. int rc;
  81. spin_lock_irq(&sclp_ocf_lock);
  82. rc = snprintf(page, PAGE_SIZE, "%s\n", cpc_name);
  83. spin_unlock_irq(&sclp_ocf_lock);
  84. return rc;
  85. }
  86. static struct kobj_attribute cpc_name_attr =
  87. __ATTR(cpc_name, 0444, cpc_name_show, NULL);
  88. static ssize_t hmc_network_show(struct kobject *kobj,
  89. struct kobj_attribute *attr, char *page)
  90. {
  91. int rc;
  92. spin_lock_irq(&sclp_ocf_lock);
  93. rc = snprintf(page, PAGE_SIZE, "%s\n", hmc_network);
  94. spin_unlock_irq(&sclp_ocf_lock);
  95. return rc;
  96. }
  97. static struct kobj_attribute hmc_network_attr =
  98. __ATTR(hmc_network, 0444, hmc_network_show, NULL);
  99. static struct attribute *ocf_attrs[] = {
  100. &cpc_name_attr.attr,
  101. &hmc_network_attr.attr,
  102. NULL,
  103. };
  104. static struct attribute_group ocf_attr_group = {
  105. .attrs = ocf_attrs,
  106. };
  107. static int __init ocf_init(void)
  108. {
  109. int rc;
  110. INIT_WORK(&sclp_ocf_change_work, sclp_ocf_change_notify);
  111. ocf_kset = kset_create_and_add("ocf", NULL, firmware_kobj);
  112. if (!ocf_kset)
  113. return -ENOMEM;
  114. rc = sysfs_create_group(&ocf_kset->kobj, &ocf_attr_group);
  115. if (rc) {
  116. kset_unregister(ocf_kset);
  117. return rc;
  118. }
  119. return sclp_register(&sclp_ocf_event);
  120. }
  121. device_initcall(ocf_init);