gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / s390 / crypto / ap_card.c
blob0a39dfdb6a1dd1d1cd016a2db09d20368cee565c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright IBM Corp. 2016
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Adjunct processor bus, card related code.
7 */
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>
16 #include "ap_bus.h"
19 * AP card related attributes.
21 static ssize_t hwtype_show(struct device *dev,
22 struct device_attribute *attr, char *buf)
24 struct ap_card *ac = to_ap_card(dev);
26 return scnprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type);
29 static DEVICE_ATTR_RO(hwtype);
31 static ssize_t raw_hwtype_show(struct device *dev,
32 struct device_attribute *attr, char *buf)
34 struct ap_card *ac = to_ap_card(dev);
36 return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
39 static DEVICE_ATTR_RO(raw_hwtype);
41 static ssize_t depth_show(struct device *dev, struct device_attribute *attr,
42 char *buf)
44 struct ap_card *ac = to_ap_card(dev);
46 return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
49 static DEVICE_ATTR_RO(depth);
51 static ssize_t ap_functions_show(struct device *dev,
52 struct device_attribute *attr, char *buf)
54 struct ap_card *ac = to_ap_card(dev);
56 return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
59 static DEVICE_ATTR_RO(ap_functions);
61 static ssize_t request_count_show(struct device *dev,
62 struct device_attribute *attr,
63 char *buf)
65 struct ap_card *ac = to_ap_card(dev);
66 u64 req_cnt;
68 req_cnt = 0;
69 spin_lock_bh(&ap_list_lock);
70 req_cnt = atomic64_read(&ac->total_request_count);
71 spin_unlock_bh(&ap_list_lock);
72 return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt);
75 static ssize_t request_count_store(struct device *dev,
76 struct device_attribute *attr,
77 const char *buf, size_t count)
79 struct ap_card *ac = to_ap_card(dev);
80 struct ap_queue *aq;
82 spin_lock_bh(&ap_list_lock);
83 for_each_ap_queue(aq, ac)
84 aq->total_request_count = 0;
85 spin_unlock_bh(&ap_list_lock);
86 atomic64_set(&ac->total_request_count, 0);
88 return count;
91 static DEVICE_ATTR_RW(request_count);
93 static ssize_t requestq_count_show(struct device *dev,
94 struct device_attribute *attr, char *buf)
96 struct ap_card *ac = to_ap_card(dev);
97 struct ap_queue *aq;
98 unsigned int reqq_cnt;
100 reqq_cnt = 0;
101 spin_lock_bh(&ap_list_lock);
102 for_each_ap_queue(aq, ac)
103 reqq_cnt += aq->requestq_count;
104 spin_unlock_bh(&ap_list_lock);
105 return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
108 static DEVICE_ATTR_RO(requestq_count);
110 static ssize_t pendingq_count_show(struct device *dev,
111 struct device_attribute *attr, char *buf)
113 struct ap_card *ac = to_ap_card(dev);
114 struct ap_queue *aq;
115 unsigned int penq_cnt;
117 penq_cnt = 0;
118 spin_lock_bh(&ap_list_lock);
119 for_each_ap_queue(aq, ac)
120 penq_cnt += aq->pendingq_count;
121 spin_unlock_bh(&ap_list_lock);
122 return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
125 static DEVICE_ATTR_RO(pendingq_count);
127 static ssize_t modalias_show(struct device *dev,
128 struct device_attribute *attr, char *buf)
130 return scnprintf(buf, PAGE_SIZE, "ap:t%02X\n",
131 to_ap_dev(dev)->device_type);
134 static DEVICE_ATTR_RO(modalias);
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,
145 NULL
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,
154 NULL
157 static struct device_type ap_card_type = {
158 .name = "ap_card",
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);
171 kfree(ac);
174 struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
175 int comp_type, unsigned int functions)
177 struct ap_card *ac;
179 ac = kzalloc(sizeof(*ac), GFP_KERNEL);
180 if (!ac)
181 return NULL;
182 INIT_LIST_HEAD(&ac->list);
183 INIT_LIST_HEAD(&ac->queues);
184 ac->ap_dev.device.release = ap_card_device_release;
185 ac->ap_dev.device.type = &ap_card_type;
186 ac->ap_dev.device_type = comp_type;
187 ac->raw_hwtype = raw_type;
188 ac->queue_depth = queue_depth;
189 ac->functions = functions;
190 ac->id = id;
191 return ac;