ap_card.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "ap_bus.h"
  14. #include "ap_asm.h"
  15. /*
  16. * AP card related attributes.
  17. */
  18. static ssize_t ap_hwtype_show(struct device *dev,
  19. struct device_attribute *attr, char *buf)
  20. {
  21. struct ap_card *ac = to_ap_card(dev);
  22. return snprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type);
  23. }
  24. static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
  25. static ssize_t ap_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 snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
  30. }
  31. static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL);
  32. static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
  33. char *buf)
  34. {
  35. struct ap_card *ac = to_ap_card(dev);
  36. return snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
  37. }
  38. static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
  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 snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
  44. }
  45. static DEVICE_ATTR_RO(ap_functions);
  46. static ssize_t ap_req_count_show(struct device *dev,
  47. struct device_attribute *attr,
  48. char *buf)
  49. {
  50. struct ap_card *ac = to_ap_card(dev);
  51. unsigned int req_cnt;
  52. req_cnt = 0;
  53. spin_lock_bh(&ap_list_lock);
  54. req_cnt = atomic_read(&ac->total_request_count);
  55. spin_unlock_bh(&ap_list_lock);
  56. return snprintf(buf, PAGE_SIZE, "%d\n", req_cnt);
  57. }
  58. static ssize_t ap_req_count_store(struct device *dev,
  59. struct device_attribute *attr,
  60. const char *buf, size_t count)
  61. {
  62. struct ap_card *ac = to_ap_card(dev);
  63. struct ap_queue *aq;
  64. spin_lock_bh(&ap_list_lock);
  65. for_each_ap_queue(aq, ac)
  66. aq->total_request_count = 0;
  67. spin_unlock_bh(&ap_list_lock);
  68. atomic_set(&ac->total_request_count, 0);
  69. return count;
  70. }
  71. static DEVICE_ATTR(request_count, 0644, ap_req_count_show, ap_req_count_store);
  72. static ssize_t ap_requestq_count_show(struct device *dev,
  73. struct device_attribute *attr, char *buf)
  74. {
  75. struct ap_card *ac = to_ap_card(dev);
  76. struct ap_queue *aq;
  77. unsigned int reqq_cnt;
  78. reqq_cnt = 0;
  79. spin_lock_bh(&ap_list_lock);
  80. for_each_ap_queue(aq, ac)
  81. reqq_cnt += aq->requestq_count;
  82. spin_unlock_bh(&ap_list_lock);
  83. return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
  84. }
  85. static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL);
  86. static ssize_t ap_pendingq_count_show(struct device *dev,
  87. struct device_attribute *attr, char *buf)
  88. {
  89. struct ap_card *ac = to_ap_card(dev);
  90. struct ap_queue *aq;
  91. unsigned int penq_cnt;
  92. penq_cnt = 0;
  93. spin_lock_bh(&ap_list_lock);
  94. for_each_ap_queue(aq, ac)
  95. penq_cnt += aq->pendingq_count;
  96. spin_unlock_bh(&ap_list_lock);
  97. return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
  98. }
  99. static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL);
  100. static ssize_t ap_modalias_show(struct device *dev,
  101. struct device_attribute *attr, char *buf)
  102. {
  103. return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
  104. }
  105. static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
  106. static struct attribute *ap_card_dev_attrs[] = {
  107. &dev_attr_hwtype.attr,
  108. &dev_attr_raw_hwtype.attr,
  109. &dev_attr_depth.attr,
  110. &dev_attr_ap_functions.attr,
  111. &dev_attr_request_count.attr,
  112. &dev_attr_requestq_count.attr,
  113. &dev_attr_pendingq_count.attr,
  114. &dev_attr_modalias.attr,
  115. NULL
  116. };
  117. static struct attribute_group ap_card_dev_attr_group = {
  118. .attrs = ap_card_dev_attrs
  119. };
  120. static const struct attribute_group *ap_card_dev_attr_groups[] = {
  121. &ap_card_dev_attr_group,
  122. NULL
  123. };
  124. static struct device_type ap_card_type = {
  125. .name = "ap_card",
  126. .groups = ap_card_dev_attr_groups,
  127. };
  128. static void ap_card_device_release(struct device *dev)
  129. {
  130. struct ap_card *ac = to_ap_card(dev);
  131. if (!list_empty(&ac->list)) {
  132. spin_lock_bh(&ap_list_lock);
  133. list_del_init(&ac->list);
  134. spin_unlock_bh(&ap_list_lock);
  135. }
  136. kfree(ac);
  137. }
  138. struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
  139. int comp_type, unsigned int functions)
  140. {
  141. struct ap_card *ac;
  142. ac = kzalloc(sizeof(*ac), GFP_KERNEL);
  143. if (!ac)
  144. return NULL;
  145. INIT_LIST_HEAD(&ac->list);
  146. INIT_LIST_HEAD(&ac->queues);
  147. ac->ap_dev.device.release = ap_card_device_release;
  148. ac->ap_dev.device.type = &ap_card_type;
  149. ac->ap_dev.device_type = comp_type;
  150. ac->raw_hwtype = raw_type;
  151. ac->queue_depth = queue_depth;
  152. ac->functions = functions;
  153. ac->id = id;
  154. return ac;
  155. }