ap_card.c 5.6 KB

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