ap_card.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2016
  4. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  5. *
  6. * Adjunct processor bus, card related code.
  7. */
  8. #define pr_fmt(fmt) "ap: " fmt
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <asm/facility.h>
  12. #include <asm/sclp.h>
  13. #include "ap_bus.h"
  14. /*
  15. * AP card related attributes.
  16. */
  17. static ssize_t hwtype_show(struct device *dev,
  18. struct device_attribute *attr, char *buf)
  19. {
  20. struct ap_card *ac = to_ap_card(dev);
  21. return sysfs_emit(buf, "%d\n", ac->ap_dev.device_type);
  22. }
  23. static DEVICE_ATTR_RO(hwtype);
  24. static ssize_t raw_hwtype_show(struct device *dev,
  25. struct device_attribute *attr, char *buf)
  26. {
  27. struct ap_card *ac = to_ap_card(dev);
  28. return sysfs_emit(buf, "%d\n", ac->hwinfo.at);
  29. }
  30. static DEVICE_ATTR_RO(raw_hwtype);
  31. static ssize_t depth_show(struct device *dev, struct device_attribute *attr,
  32. char *buf)
  33. {
  34. struct ap_card *ac = to_ap_card(dev);
  35. return sysfs_emit(buf, "%d\n", ac->hwinfo.qd + 1);
  36. }
  37. static DEVICE_ATTR_RO(depth);
  38. static ssize_t ap_functions_show(struct device *dev,
  39. struct device_attribute *attr, char *buf)
  40. {
  41. struct ap_card *ac = to_ap_card(dev);
  42. return sysfs_emit(buf, "0x%08X\n", ac->hwinfo.fac);
  43. }
  44. static DEVICE_ATTR_RO(ap_functions);
  45. static ssize_t request_count_show(struct device *dev,
  46. struct device_attribute *attr,
  47. char *buf)
  48. {
  49. struct ap_card *ac = to_ap_card(dev);
  50. u64 req_cnt;
  51. req_cnt = 0;
  52. spin_lock_bh(&ap_queues_lock);
  53. req_cnt = atomic64_read(&ac->total_request_count);
  54. spin_unlock_bh(&ap_queues_lock);
  55. return sysfs_emit(buf, "%llu\n", req_cnt);
  56. }
  57. static ssize_t request_count_store(struct device *dev,
  58. struct device_attribute *attr,
  59. const char *buf, size_t count)
  60. {
  61. int bkt;
  62. struct ap_queue *aq;
  63. struct ap_card *ac = to_ap_card(dev);
  64. spin_lock_bh(&ap_queues_lock);
  65. hash_for_each(ap_queues, bkt, aq, hnode)
  66. if (ac == aq->card)
  67. aq->total_request_count = 0;
  68. spin_unlock_bh(&ap_queues_lock);
  69. atomic64_set(&ac->total_request_count, 0);
  70. return count;
  71. }
  72. static DEVICE_ATTR_RW(request_count);
  73. static ssize_t requestq_count_show(struct device *dev,
  74. struct device_attribute *attr, char *buf)
  75. {
  76. int bkt;
  77. struct ap_queue *aq;
  78. unsigned int reqq_cnt;
  79. struct ap_card *ac = to_ap_card(dev);
  80. reqq_cnt = 0;
  81. spin_lock_bh(&ap_queues_lock);
  82. hash_for_each(ap_queues, bkt, aq, hnode)
  83. if (ac == aq->card)
  84. reqq_cnt += aq->requestq_count;
  85. spin_unlock_bh(&ap_queues_lock);
  86. return sysfs_emit(buf, "%d\n", reqq_cnt);
  87. }
  88. static DEVICE_ATTR_RO(requestq_count);
  89. static ssize_t pendingq_count_show(struct device *dev,
  90. struct device_attribute *attr, char *buf)
  91. {
  92. int bkt;
  93. struct ap_queue *aq;
  94. unsigned int penq_cnt;
  95. struct ap_card *ac = to_ap_card(dev);
  96. penq_cnt = 0;
  97. spin_lock_bh(&ap_queues_lock);
  98. hash_for_each(ap_queues, bkt, aq, hnode)
  99. if (ac == aq->card)
  100. penq_cnt += aq->pendingq_count;
  101. spin_unlock_bh(&ap_queues_lock);
  102. return sysfs_emit(buf, "%d\n", penq_cnt);
  103. }
  104. static DEVICE_ATTR_RO(pendingq_count);
  105. static ssize_t modalias_show(struct device *dev,
  106. struct device_attribute *attr, char *buf)
  107. {
  108. return sysfs_emit(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
  109. }
  110. static DEVICE_ATTR_RO(modalias);
  111. static ssize_t config_show(struct device *dev,
  112. struct device_attribute *attr, char *buf)
  113. {
  114. struct ap_card *ac = to_ap_card(dev);
  115. return sysfs_emit(buf, "%d\n", ac->config ? 1 : 0);
  116. }
  117. static ssize_t config_store(struct device *dev,
  118. struct device_attribute *attr,
  119. const char *buf, size_t count)
  120. {
  121. int rc = 0, cfg;
  122. struct ap_card *ac = to_ap_card(dev);
  123. if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1)
  124. return -EINVAL;
  125. if (cfg && !ac->config)
  126. rc = sclp_ap_configure(ac->id);
  127. else if (!cfg && ac->config)
  128. rc = sclp_ap_deconfigure(ac->id);
  129. if (rc)
  130. return rc;
  131. ac->config = cfg ? true : false;
  132. ap_send_config_uevent(&ac->ap_dev, ac->config);
  133. return count;
  134. }
  135. static DEVICE_ATTR_RW(config);
  136. static ssize_t chkstop_show(struct device *dev,
  137. struct device_attribute *attr, char *buf)
  138. {
  139. struct ap_card *ac = to_ap_card(dev);
  140. return sysfs_emit(buf, "%d\n", ac->chkstop ? 1 : 0);
  141. }
  142. static DEVICE_ATTR_RO(chkstop);
  143. static ssize_t max_msg_size_show(struct device *dev,
  144. struct device_attribute *attr, char *buf)
  145. {
  146. struct ap_card *ac = to_ap_card(dev);
  147. return sysfs_emit(buf, "%u\n", ac->maxmsgsize);
  148. }
  149. static DEVICE_ATTR_RO(max_msg_size);
  150. static struct attribute *ap_card_dev_attrs[] = {
  151. &dev_attr_hwtype.attr,
  152. &dev_attr_raw_hwtype.attr,
  153. &dev_attr_depth.attr,
  154. &dev_attr_ap_functions.attr,
  155. &dev_attr_request_count.attr,
  156. &dev_attr_requestq_count.attr,
  157. &dev_attr_pendingq_count.attr,
  158. &dev_attr_modalias.attr,
  159. &dev_attr_config.attr,
  160. &dev_attr_chkstop.attr,
  161. &dev_attr_max_msg_size.attr,
  162. NULL
  163. };
  164. static struct attribute_group ap_card_dev_attr_group = {
  165. .attrs = ap_card_dev_attrs
  166. };
  167. static const struct attribute_group *ap_card_dev_attr_groups[] = {
  168. &ap_card_dev_attr_group,
  169. NULL
  170. };
  171. static struct device_type ap_card_type = {
  172. .name = "ap_card",
  173. .groups = ap_card_dev_attr_groups,
  174. };
  175. static void ap_card_device_release(struct device *dev)
  176. {
  177. struct ap_card *ac = to_ap_card(dev);
  178. kfree(ac);
  179. }
  180. struct ap_card *ap_card_create(int id, struct ap_tapq_hwinfo hwinfo,
  181. int comp_type)
  182. {
  183. struct ap_card *ac;
  184. ac = kzalloc_obj(*ac);
  185. if (!ac)
  186. return NULL;
  187. ac->ap_dev.device.release = ap_card_device_release;
  188. ac->ap_dev.device.type = &ap_card_type;
  189. ac->ap_dev.device_type = comp_type;
  190. ac->hwinfo = hwinfo;
  191. ac->id = id;
  192. ac->maxmsgsize = hwinfo.ml > 0 ?
  193. hwinfo.ml * AP_TAPQ_ML_FIELD_CHUNK_SIZE : AP_DEFAULT_MAX_MSG_SIZE;
  194. return ac;
  195. }