ap_card.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright IBM Corp. 2016
  3. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  4. *
  5. * Adjunct processor bus, card related code.
  6. */
  7. #define KMSG_COMPONENT "ap"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <asm/facility.h>
  12. #include "ap_bus.h"
  13. #include "ap_asm.h"
  14. /*
  15. * AP card related attributes.
  16. */
  17. static ssize_t ap_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(hwtype, 0444, ap_hwtype_show, NULL);
  24. static ssize_t ap_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(raw_hwtype, 0444, ap_raw_hwtype_show, NULL);
  31. static ssize_t ap_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(depth, 0444, ap_depth_show, NULL);
  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(ap_functions, 0444, ap_functions_show, NULL);
  45. static ssize_t ap_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. unsigned int req_cnt;
  51. req_cnt = 0;
  52. spin_lock_bh(&ap_list_lock);
  53. req_cnt = atomic_read(&ac->total_request_count);
  54. spin_unlock_bh(&ap_list_lock);
  55. return snprintf(buf, PAGE_SIZE, "%d\n", req_cnt);
  56. }
  57. static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);
  58. static ssize_t ap_requestq_count_show(struct device *dev,
  59. struct device_attribute *attr, char *buf)
  60. {
  61. struct ap_card *ac = to_ap_card(dev);
  62. struct ap_queue *aq;
  63. unsigned int reqq_cnt;
  64. reqq_cnt = 0;
  65. spin_lock_bh(&ap_list_lock);
  66. for_each_ap_queue(aq, ac)
  67. reqq_cnt += aq->requestq_count;
  68. spin_unlock_bh(&ap_list_lock);
  69. return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
  70. }
  71. static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL);
  72. static ssize_t ap_pendingq_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 penq_cnt;
  78. penq_cnt = 0;
  79. spin_lock_bh(&ap_list_lock);
  80. for_each_ap_queue(aq, ac)
  81. penq_cnt += aq->pendingq_count;
  82. spin_unlock_bh(&ap_list_lock);
  83. return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
  84. }
  85. static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL);
  86. static ssize_t ap_modalias_show(struct device *dev,
  87. struct device_attribute *attr, char *buf)
  88. {
  89. return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
  90. }
  91. static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
  92. static struct attribute *ap_card_dev_attrs[] = {
  93. &dev_attr_hwtype.attr,
  94. &dev_attr_raw_hwtype.attr,
  95. &dev_attr_depth.attr,
  96. &dev_attr_ap_functions.attr,
  97. &dev_attr_request_count.attr,
  98. &dev_attr_requestq_count.attr,
  99. &dev_attr_pendingq_count.attr,
  100. &dev_attr_modalias.attr,
  101. NULL
  102. };
  103. static struct attribute_group ap_card_dev_attr_group = {
  104. .attrs = ap_card_dev_attrs
  105. };
  106. static const struct attribute_group *ap_card_dev_attr_groups[] = {
  107. &ap_card_dev_attr_group,
  108. NULL
  109. };
  110. struct device_type ap_card_type = {
  111. .name = "ap_card",
  112. .groups = ap_card_dev_attr_groups,
  113. };
  114. static void ap_card_device_release(struct device *dev)
  115. {
  116. kfree(to_ap_card(dev));
  117. }
  118. struct ap_card *ap_card_create(int id, int queue_depth, int device_type,
  119. unsigned int functions)
  120. {
  121. struct ap_card *ac;
  122. ac = kzalloc(sizeof(*ac), GFP_KERNEL);
  123. if (!ac)
  124. return NULL;
  125. INIT_LIST_HEAD(&ac->queues);
  126. ac->ap_dev.device.release = ap_card_device_release;
  127. ac->ap_dev.device.type = &ap_card_type;
  128. ac->ap_dev.device_type = device_type;
  129. /* CEX6 toleration: map to CEX5 */
  130. if (device_type == AP_DEVICE_TYPE_CEX6)
  131. ac->ap_dev.device_type = AP_DEVICE_TYPE_CEX5;
  132. ac->raw_hwtype = device_type;
  133. ac->queue_depth = queue_depth;
  134. ac->functions = functions;
  135. ac->id = id;
  136. return ac;
  137. }