ap_card.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 scnprintf(buf, PAGE_SIZE, "%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 scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
  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 scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
  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 scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
  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 scnprintf(buf, PAGE_SIZE, "%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 scnprintf(buf, PAGE_SIZE, "%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 scnprintf(buf, PAGE_SIZE, "%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 scnprintf(buf, PAGE_SIZE, "ap:t%02X\n",
  110. to_ap_dev(dev)->device_type);
  111. }
  112. static DEVICE_ATTR_RO(modalias);
  113. static ssize_t config_show(struct device *dev,
  114. struct device_attribute *attr, char *buf)
  115. {
  116. struct ap_card *ac = to_ap_card(dev);
  117. return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0);
  118. }
  119. static ssize_t config_store(struct device *dev,
  120. struct device_attribute *attr,
  121. const char *buf, size_t count)
  122. {
  123. int rc = 0, cfg;
  124. struct ap_card *ac = to_ap_card(dev);
  125. if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1)
  126. return -EINVAL;
  127. if (cfg && !ac->config)
  128. rc = sclp_ap_configure(ac->id);
  129. else if (!cfg && ac->config)
  130. rc = sclp_ap_deconfigure(ac->id);
  131. if (rc)
  132. return rc;
  133. ac->config = cfg ? true : false;
  134. return count;
  135. }
  136. static DEVICE_ATTR_RW(config);
  137. static struct attribute *ap_card_dev_attrs[] = {
  138. &dev_attr_hwtype.attr,
  139. &dev_attr_raw_hwtype.attr,
  140. &dev_attr_depth.attr,
  141. &dev_attr_ap_functions.attr,
  142. &dev_attr_request_count.attr,
  143. &dev_attr_requestq_count.attr,
  144. &dev_attr_pendingq_count.attr,
  145. &dev_attr_modalias.attr,
  146. &dev_attr_config.attr,
  147. NULL
  148. };
  149. static struct attribute_group ap_card_dev_attr_group = {
  150. .attrs = ap_card_dev_attrs
  151. };
  152. static const struct attribute_group *ap_card_dev_attr_groups[] = {
  153. &ap_card_dev_attr_group,
  154. NULL
  155. };
  156. static struct device_type ap_card_type = {
  157. .name = "ap_card",
  158. .groups = ap_card_dev_attr_groups,
  159. };
  160. static void ap_card_device_release(struct device *dev)
  161. {
  162. struct ap_card *ac = to_ap_card(dev);
  163. kfree(ac);
  164. }
  165. struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
  166. int comp_type, unsigned int functions)
  167. {
  168. struct ap_card *ac;
  169. ac = kzalloc(sizeof(*ac), GFP_KERNEL);
  170. if (!ac)
  171. return NULL;
  172. ac->ap_dev.device.release = ap_card_device_release;
  173. ac->ap_dev.device.type = &ap_card_type;
  174. ac->ap_dev.device_type = comp_type;
  175. ac->raw_hwtype = raw_type;
  176. ac->queue_depth = queue_depth;
  177. ac->functions = functions;
  178. ac->id = id;
  179. return ac;
  180. }