ap_card.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. /*
  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 snprintf(buf, PAGE_SIZE, "%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 snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
  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 snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
  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 snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
  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_list_lock);
  53. req_cnt = atomic64_read(&ac->total_request_count);
  54. spin_unlock_bh(&ap_list_lock);
  55. return snprintf(buf, PAGE_SIZE, "%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. struct ap_card *ac = to_ap_card(dev);
  62. struct ap_queue *aq;
  63. spin_lock_bh(&ap_list_lock);
  64. for_each_ap_queue(aq, ac)
  65. aq->total_request_count = 0;
  66. spin_unlock_bh(&ap_list_lock);
  67. atomic64_set(&ac->total_request_count, 0);
  68. return count;
  69. }
  70. static DEVICE_ATTR_RW(request_count);
  71. static ssize_t requestq_count_show(struct device *dev,
  72. struct device_attribute *attr, char *buf)
  73. {
  74. struct ap_card *ac = to_ap_card(dev);
  75. struct ap_queue *aq;
  76. unsigned int reqq_cnt;
  77. reqq_cnt = 0;
  78. spin_lock_bh(&ap_list_lock);
  79. for_each_ap_queue(aq, ac)
  80. reqq_cnt += aq->requestq_count;
  81. spin_unlock_bh(&ap_list_lock);
  82. return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
  83. }
  84. static DEVICE_ATTR_RO(requestq_count);
  85. static ssize_t pendingq_count_show(struct device *dev,
  86. struct device_attribute *attr, char *buf)
  87. {
  88. struct ap_card *ac = to_ap_card(dev);
  89. struct ap_queue *aq;
  90. unsigned int penq_cnt;
  91. penq_cnt = 0;
  92. spin_lock_bh(&ap_list_lock);
  93. for_each_ap_queue(aq, ac)
  94. penq_cnt += aq->pendingq_count;
  95. spin_unlock_bh(&ap_list_lock);
  96. return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
  97. }
  98. static DEVICE_ATTR_RO(pendingq_count);
  99. static ssize_t modalias_show(struct device *dev,
  100. struct device_attribute *attr, char *buf)
  101. {
  102. return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
  103. }
  104. static DEVICE_ATTR_RO(modalias);
  105. static struct attribute *ap_card_dev_attrs[] = {
  106. &dev_attr_hwtype.attr,
  107. &dev_attr_raw_hwtype.attr,
  108. &dev_attr_depth.attr,
  109. &dev_attr_ap_functions.attr,
  110. &dev_attr_request_count.attr,
  111. &dev_attr_requestq_count.attr,
  112. &dev_attr_pendingq_count.attr,
  113. &dev_attr_modalias.attr,
  114. NULL
  115. };
  116. static struct attribute_group ap_card_dev_attr_group = {
  117. .attrs = ap_card_dev_attrs
  118. };
  119. static const struct attribute_group *ap_card_dev_attr_groups[] = {
  120. &ap_card_dev_attr_group,
  121. NULL
  122. };
  123. static struct device_type ap_card_type = {
  124. .name = "ap_card",
  125. .groups = ap_card_dev_attr_groups,
  126. };
  127. static void ap_card_device_release(struct device *dev)
  128. {
  129. struct ap_card *ac = to_ap_card(dev);
  130. if (!list_empty(&ac->list)) {
  131. spin_lock_bh(&ap_list_lock);
  132. list_del_init(&ac->list);
  133. spin_unlock_bh(&ap_list_lock);
  134. }
  135. kfree(ac);
  136. }
  137. struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
  138. int comp_type, unsigned int functions)
  139. {
  140. struct ap_card *ac;
  141. ac = kzalloc(sizeof(*ac), GFP_KERNEL);
  142. if (!ac)
  143. return NULL;
  144. INIT_LIST_HEAD(&ac->list);
  145. INIT_LIST_HEAD(&ac->queues);
  146. ac->ap_dev.device.release = ap_card_device_release;
  147. ac->ap_dev.device.type = &ap_card_type;
  148. ac->ap_dev.device_type = comp_type;
  149. ac->raw_hwtype = raw_type;
  150. ac->queue_depth = queue_depth;
  151. ac->functions = functions;
  152. ac->id = id;
  153. return ac;
  154. }