1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2016
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Adjunct processor bus, card related code.
9 #define KMSG_COMPONENT "ap"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <asm/facility.h>
20 * AP card related attributes.
22 static ssize_t ap_hwtype_show(struct device *dev,
23 struct device_attribute *attr, char *buf)
25 struct ap_card *ac = to_ap_card(dev);
27 return snprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type);
30 static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
32 static ssize_t ap_raw_hwtype_show(struct device *dev,
33 struct device_attribute *attr, char *buf)
35 struct ap_card *ac = to_ap_card(dev);
37 return snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
40 static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL);
42 static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
45 struct ap_card *ac = to_ap_card(dev);
47 return snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
50 static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
52 static ssize_t ap_functions_show(struct device *dev,
53 struct device_attribute *attr, char *buf)
55 struct ap_card *ac = to_ap_card(dev);
57 return snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
60 static DEVICE_ATTR(ap_functions, 0444, ap_functions_show, NULL);
62 static ssize_t ap_req_count_show(struct device *dev,
63 struct device_attribute *attr,
66 struct ap_card *ac = to_ap_card(dev);
70 spin_lock_bh(&ap_list_lock);
71 req_cnt = atomic_read(&ac->total_request_count);
72 spin_unlock_bh(&ap_list_lock);
73 return snprintf(buf, PAGE_SIZE, "%d\n", req_cnt);
76 static ssize_t ap_req_count_store(struct device *dev,
77 struct device_attribute *attr,
78 const char *buf, size_t count)
80 struct ap_card *ac = to_ap_card(dev);
83 spin_lock_bh(&ap_list_lock);
84 for_each_ap_queue(aq, ac)
85 aq->total_request_count = 0;
86 spin_unlock_bh(&ap_list_lock);
87 atomic_set(&ac->total_request_count, 0);
92 static DEVICE_ATTR(request_count, 0644, ap_req_count_show, ap_req_count_store);
94 static ssize_t ap_requestq_count_show(struct device *dev,
95 struct device_attribute *attr, char *buf)
97 struct ap_card *ac = to_ap_card(dev);
99 unsigned int reqq_cnt;
102 spin_lock_bh(&ap_list_lock);
103 for_each_ap_queue(aq, ac)
104 reqq_cnt += aq->requestq_count;
105 spin_unlock_bh(&ap_list_lock);
106 return snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
109 static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL);
111 static ssize_t ap_pendingq_count_show(struct device *dev,
112 struct device_attribute *attr, char *buf)
114 struct ap_card *ac = to_ap_card(dev);
116 unsigned int penq_cnt;
119 spin_lock_bh(&ap_list_lock);
120 for_each_ap_queue(aq, ac)
121 penq_cnt += aq->pendingq_count;
122 spin_unlock_bh(&ap_list_lock);
123 return snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
126 static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL);
128 static ssize_t ap_modalias_show(struct device *dev,
129 struct device_attribute *attr, char *buf)
131 return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
134 static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
136 static struct attribute *ap_card_dev_attrs[] = {
137 &dev_attr_hwtype.attr,
138 &dev_attr_raw_hwtype.attr,
139 &dev_attr_depth.attr,
140 &dev_attr_ap_functions.attr,
141 &dev_attr_request_count.attr,
142 &dev_attr_requestq_count.attr,
143 &dev_attr_pendingq_count.attr,
144 &dev_attr_modalias.attr,
148 static struct attribute_group ap_card_dev_attr_group = {
149 .attrs = ap_card_dev_attrs
152 static const struct attribute_group *ap_card_dev_attr_groups[] = {
153 &ap_card_dev_attr_group,
157 static struct device_type ap_card_type = {
159 .groups = ap_card_dev_attr_groups,
162 static void ap_card_device_release(struct device *dev)
164 struct ap_card *ac = to_ap_card(dev);
166 if (!list_empty(&ac->list)) {
167 spin_lock_bh(&ap_list_lock);
168 list_del_init(&ac->list);
169 spin_unlock_bh(&ap_list_lock);
174 struct ap_card *ap_card_create(int id, int queue_depth, int device_type,
175 unsigned int functions)
179 ac = kzalloc(sizeof(*ac), GFP_KERNEL);
182 INIT_LIST_HEAD(&ac->queues);
183 ac->ap_dev.device.release = ap_card_device_release;
184 ac->ap_dev.device.type = &ap_card_type;
185 ac->ap_dev.device_type = device_type;
186 /* CEX6 toleration: map to CEX5 */
187 if (device_type == AP_DEVICE_TYPE_CEX6)
188 ac->ap_dev.device_type = AP_DEVICE_TYPE_CEX5;
189 ac->raw_hwtype = device_type;
190 ac->queue_depth = queue_depth;
191 ac->functions = functions;