Ingo Tuchscherer | e28d2af | 2016-08-25 11:16:03 +0200 | [diff] [blame] | 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 | |
| 8 | #define KMSG_COMPONENT "ap" |
| 9 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <asm/facility.h> |
| 14 | |
| 15 | #include "ap_bus.h" |
| 16 | #include "ap_asm.h" |
| 17 | |
| 18 | /* |
| 19 | * AP card related attributes. |
| 20 | */ |
| 21 | static ssize_t ap_hwtype_show(struct device *dev, |
| 22 | struct device_attribute *attr, char *buf) |
| 23 | { |
| 24 | struct ap_card *ac = to_ap_card(dev); |
| 25 | |
| 26 | return snprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type); |
| 27 | } |
| 28 | |
| 29 | static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL); |
| 30 | |
| 31 | static ssize_t ap_raw_hwtype_show(struct device *dev, |
| 32 | struct device_attribute *attr, char *buf) |
| 33 | { |
| 34 | struct ap_card *ac = to_ap_card(dev); |
| 35 | |
| 36 | return snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype); |
| 37 | } |
| 38 | |
| 39 | static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL); |
| 40 | |
| 41 | static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr, |
| 42 | char *buf) |
| 43 | { |
| 44 | struct ap_card *ac = to_ap_card(dev); |
| 45 | |
| 46 | return snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth); |
| 47 | } |
| 48 | |
| 49 | static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL); |
| 50 | |
| 51 | static ssize_t ap_functions_show(struct device *dev, |
| 52 | struct device_attribute *attr, char *buf) |
| 53 | { |
| 54 | struct ap_card *ac = to_ap_card(dev); |
| 55 | |
| 56 | return snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions); |
| 57 | } |
| 58 | |
| 59 | static DEVICE_ATTR(ap_functions, 0444, ap_functions_show, NULL); |
| 60 | |
| 61 | static ssize_t ap_request_count_show(struct device *dev, |
| 62 | struct device_attribute *attr, |
| 63 | char *buf) |
| 64 | { |
| 65 | struct ap_card *ac = to_ap_card(dev); |
Ingo Tuchscherer | e28d2af | 2016-08-25 11:16:03 +0200 | [diff] [blame] | 66 | unsigned int req_cnt; |
| 67 | |
| 68 | req_cnt = 0; |
| 69 | spin_lock_bh(&ap_list_lock); |
Ingo Tuchscherer | e47de21 | 2016-10-14 14:34:51 +0200 | [diff] [blame] | 70 | req_cnt = atomic_read(&ac->total_request_count); |
Ingo Tuchscherer | e28d2af | 2016-08-25 11:16:03 +0200 | [diff] [blame] | 71 | spin_unlock_bh(&ap_list_lock); |
| 72 | return snprintf(buf, PAGE_SIZE, "%d\n", req_cnt); |
| 73 | } |
| 74 | |
| 75 | static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL); |
| 76 | |
| 77 | static ssize_t ap_requestq_count_show(struct device *dev, |
| 78 | struct device_attribute *attr, char *buf) |
| 79 | { |
| 80 | struct ap_card *ac = to_ap_card(dev); |
| 81 | struct ap_queue *aq; |
| 82 | unsigned int reqq_cnt; |
| 83 | |
| 84 | reqq_cnt = 0; |
| 85 | spin_lock_bh(&ap_list_lock); |
| 86 | for_each_ap_queue(aq, ac) |
| 87 | reqq_cnt += aq->requestq_count; |
| 88 | spin_unlock_bh(&ap_list_lock); |
| 89 | return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); |
| 90 | } |
| 91 | |
| 92 | static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL); |
| 93 | |
| 94 | static ssize_t ap_pendingq_count_show(struct device *dev, |
| 95 | struct device_attribute *attr, char *buf) |
| 96 | { |
| 97 | struct ap_card *ac = to_ap_card(dev); |
| 98 | struct ap_queue *aq; |
| 99 | unsigned int penq_cnt; |
| 100 | |
| 101 | penq_cnt = 0; |
| 102 | spin_lock_bh(&ap_list_lock); |
| 103 | for_each_ap_queue(aq, ac) |
| 104 | penq_cnt += aq->pendingq_count; |
| 105 | spin_unlock_bh(&ap_list_lock); |
| 106 | return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); |
| 107 | } |
| 108 | |
| 109 | static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL); |
| 110 | |
| 111 | static ssize_t ap_modalias_show(struct device *dev, |
| 112 | struct device_attribute *attr, char *buf) |
| 113 | { |
| 114 | return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type); |
| 115 | } |
| 116 | |
| 117 | static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL); |
| 118 | |
| 119 | static struct attribute *ap_card_dev_attrs[] = { |
| 120 | &dev_attr_hwtype.attr, |
| 121 | &dev_attr_raw_hwtype.attr, |
| 122 | &dev_attr_depth.attr, |
| 123 | &dev_attr_ap_functions.attr, |
| 124 | &dev_attr_request_count.attr, |
| 125 | &dev_attr_requestq_count.attr, |
| 126 | &dev_attr_pendingq_count.attr, |
| 127 | &dev_attr_modalias.attr, |
| 128 | NULL |
| 129 | }; |
| 130 | |
| 131 | static struct attribute_group ap_card_dev_attr_group = { |
| 132 | .attrs = ap_card_dev_attrs |
| 133 | }; |
| 134 | |
| 135 | static const struct attribute_group *ap_card_dev_attr_groups[] = { |
| 136 | &ap_card_dev_attr_group, |
| 137 | NULL |
| 138 | }; |
| 139 | |
| 140 | struct device_type ap_card_type = { |
| 141 | .name = "ap_card", |
| 142 | .groups = ap_card_dev_attr_groups, |
| 143 | }; |
| 144 | |
| 145 | static void ap_card_device_release(struct device *dev) |
| 146 | { |
| 147 | kfree(to_ap_card(dev)); |
| 148 | } |
| 149 | |
| 150 | struct ap_card *ap_card_create(int id, int queue_depth, int device_type, |
| 151 | unsigned int functions) |
| 152 | { |
| 153 | struct ap_card *ac; |
| 154 | |
| 155 | ac = kzalloc(sizeof(*ac), GFP_KERNEL); |
| 156 | if (!ac) |
| 157 | return NULL; |
| 158 | INIT_LIST_HEAD(&ac->queues); |
| 159 | ac->ap_dev.device.release = ap_card_device_release; |
| 160 | ac->ap_dev.device.type = &ap_card_type; |
| 161 | ac->ap_dev.device_type = device_type; |
| 162 | /* CEX6 toleration: map to CEX5 */ |
| 163 | if (device_type == AP_DEVICE_TYPE_CEX6) |
| 164 | ac->ap_dev.device_type = AP_DEVICE_TYPE_CEX5; |
| 165 | ac->raw_hwtype = device_type; |
| 166 | ac->queue_depth = queue_depth; |
| 167 | ac->functions = functions; |
| 168 | ac->id = id; |
| 169 | return ac; |
| 170 | } |