ap_card.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2016
  4. * Author(s): Martin Schwidefsky <[email protected]>
  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. ap_send_config_uevent(&ac->ap_dev, ac->config);
  135. return count;
  136. }
  137. static DEVICE_ATTR_RW(config);
  138. static ssize_t chkstop_show(struct device *dev,
  139. struct device_attribute *attr, char *buf)
  140. {
  141. struct ap_card *ac = to_ap_card(dev);
  142. return scnprintf(buf, PAGE_SIZE, "%d\n", ac->chkstop ? 1 : 0);
  143. }
  144. static DEVICE_ATTR_RO(chkstop);
  145. static ssize_t max_msg_size_show(struct device *dev,
  146. struct device_attribute *attr, char *buf)
  147. {
  148. struct ap_card *ac = to_ap_card(dev);
  149. return scnprintf(buf, PAGE_SIZE, "%u\n", ac->maxmsgsize);
  150. }
  151. static DEVICE_ATTR_RO(max_msg_size);
  152. static struct attribute *ap_card_dev_attrs[] = {
  153. &dev_attr_hwtype.attr,
  154. &dev_attr_raw_hwtype.attr,
  155. &dev_attr_depth.attr,
  156. &dev_attr_ap_functions.attr,
  157. &dev_attr_request_count.attr,
  158. &dev_attr_requestq_count.attr,
  159. &dev_attr_pendingq_count.attr,
  160. &dev_attr_modalias.attr,
  161. &dev_attr_config.attr,
  162. &dev_attr_chkstop.attr,
  163. &dev_attr_max_msg_size.attr,
  164. NULL
  165. };
  166. static struct attribute_group ap_card_dev_attr_group = {
  167. .attrs = ap_card_dev_attrs
  168. };
  169. static const struct attribute_group *ap_card_dev_attr_groups[] = {
  170. &ap_card_dev_attr_group,
  171. NULL
  172. };
  173. static struct device_type ap_card_type = {
  174. .name = "ap_card",
  175. .groups = ap_card_dev_attr_groups,
  176. };
  177. static void ap_card_device_release(struct device *dev)
  178. {
  179. struct ap_card *ac = to_ap_card(dev);
  180. kfree(ac);
  181. }
  182. struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
  183. int comp_type, unsigned int functions, int ml)
  184. {
  185. struct ap_card *ac;
  186. ac = kzalloc(sizeof(*ac), GFP_KERNEL);
  187. if (!ac)
  188. return NULL;
  189. ac->ap_dev.device.release = ap_card_device_release;
  190. ac->ap_dev.device.type = &ap_card_type;
  191. ac->ap_dev.device_type = comp_type;
  192. ac->raw_hwtype = raw_type;
  193. ac->queue_depth = queue_depth;
  194. ac->functions = functions;
  195. ac->id = id;
  196. ac->maxmsgsize = ml > 0 ?
  197. ml * AP_TAPQ_ML_FIELD_CHUNK_SIZE : AP_DEFAULT_MAX_MSG_SIZE;
  198. return ac;
  199. }