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
hwtype_show(struct device
*dev
,
23 struct device_attribute
*attr
, char *buf
)
25 struct ap_card
*ac
= to_ap_card(dev
);
27 return sysfs_emit(buf
, "%d\n", ac
->ap_dev
.device_type
);
30 static DEVICE_ATTR_RO(hwtype
);
32 static ssize_t
raw_hwtype_show(struct device
*dev
,
33 struct device_attribute
*attr
, char *buf
)
35 struct ap_card
*ac
= to_ap_card(dev
);
37 return sysfs_emit(buf
, "%d\n", ac
->hwinfo
.at
);
40 static DEVICE_ATTR_RO(raw_hwtype
);
42 static ssize_t
depth_show(struct device
*dev
, struct device_attribute
*attr
,
45 struct ap_card
*ac
= to_ap_card(dev
);
47 return sysfs_emit(buf
, "%d\n", ac
->hwinfo
.qd
);
50 static DEVICE_ATTR_RO(depth
);
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 sysfs_emit(buf
, "0x%08X\n", ac
->hwinfo
.fac
);
60 static DEVICE_ATTR_RO(ap_functions
);
62 static ssize_t
request_count_show(struct device
*dev
,
63 struct device_attribute
*attr
,
66 struct ap_card
*ac
= to_ap_card(dev
);
70 spin_lock_bh(&ap_queues_lock
);
71 req_cnt
= atomic64_read(&ac
->total_request_count
);
72 spin_unlock_bh(&ap_queues_lock
);
73 return sysfs_emit(buf
, "%llu\n", req_cnt
);
76 static ssize_t
request_count_store(struct device
*dev
,
77 struct device_attribute
*attr
,
78 const char *buf
, size_t count
)
82 struct ap_card
*ac
= to_ap_card(dev
);
84 spin_lock_bh(&ap_queues_lock
);
85 hash_for_each(ap_queues
, bkt
, aq
, hnode
)
87 aq
->total_request_count
= 0;
88 spin_unlock_bh(&ap_queues_lock
);
89 atomic64_set(&ac
->total_request_count
, 0);
94 static DEVICE_ATTR_RW(request_count
);
96 static ssize_t
requestq_count_show(struct device
*dev
,
97 struct device_attribute
*attr
, char *buf
)
101 unsigned int reqq_cnt
;
102 struct ap_card
*ac
= to_ap_card(dev
);
105 spin_lock_bh(&ap_queues_lock
);
106 hash_for_each(ap_queues
, bkt
, aq
, hnode
)
108 reqq_cnt
+= aq
->requestq_count
;
109 spin_unlock_bh(&ap_queues_lock
);
110 return sysfs_emit(buf
, "%d\n", reqq_cnt
);
113 static DEVICE_ATTR_RO(requestq_count
);
115 static ssize_t
pendingq_count_show(struct device
*dev
,
116 struct device_attribute
*attr
, char *buf
)
120 unsigned int penq_cnt
;
121 struct ap_card
*ac
= to_ap_card(dev
);
124 spin_lock_bh(&ap_queues_lock
);
125 hash_for_each(ap_queues
, bkt
, aq
, hnode
)
127 penq_cnt
+= aq
->pendingq_count
;
128 spin_unlock_bh(&ap_queues_lock
);
129 return sysfs_emit(buf
, "%d\n", penq_cnt
);
132 static DEVICE_ATTR_RO(pendingq_count
);
134 static ssize_t
modalias_show(struct device
*dev
,
135 struct device_attribute
*attr
, char *buf
)
137 return sysfs_emit(buf
, "ap:t%02X\n", to_ap_dev(dev
)->device_type
);
140 static DEVICE_ATTR_RO(modalias
);
142 static ssize_t
config_show(struct device
*dev
,
143 struct device_attribute
*attr
, char *buf
)
145 struct ap_card
*ac
= to_ap_card(dev
);
147 return sysfs_emit(buf
, "%d\n", ac
->config
? 1 : 0);
150 static ssize_t
config_store(struct device
*dev
,
151 struct device_attribute
*attr
,
152 const char *buf
, size_t count
)
155 struct ap_card
*ac
= to_ap_card(dev
);
157 if (sscanf(buf
, "%d\n", &cfg
) != 1 || cfg
< 0 || cfg
> 1)
160 if (cfg
&& !ac
->config
)
161 rc
= sclp_ap_configure(ac
->id
);
162 else if (!cfg
&& ac
->config
)
163 rc
= sclp_ap_deconfigure(ac
->id
);
167 ac
->config
= cfg
? true : false;
169 ap_send_config_uevent(&ac
->ap_dev
, ac
->config
);
174 static DEVICE_ATTR_RW(config
);
176 static ssize_t
chkstop_show(struct device
*dev
,
177 struct device_attribute
*attr
, char *buf
)
179 struct ap_card
*ac
= to_ap_card(dev
);
181 return sysfs_emit(buf
, "%d\n", ac
->chkstop
? 1 : 0);
184 static DEVICE_ATTR_RO(chkstop
);
186 static ssize_t
max_msg_size_show(struct device
*dev
,
187 struct device_attribute
*attr
, char *buf
)
189 struct ap_card
*ac
= to_ap_card(dev
);
191 return sysfs_emit(buf
, "%u\n", ac
->maxmsgsize
);
194 static DEVICE_ATTR_RO(max_msg_size
);
196 static struct attribute
*ap_card_dev_attrs
[] = {
197 &dev_attr_hwtype
.attr
,
198 &dev_attr_raw_hwtype
.attr
,
199 &dev_attr_depth
.attr
,
200 &dev_attr_ap_functions
.attr
,
201 &dev_attr_request_count
.attr
,
202 &dev_attr_requestq_count
.attr
,
203 &dev_attr_pendingq_count
.attr
,
204 &dev_attr_modalias
.attr
,
205 &dev_attr_config
.attr
,
206 &dev_attr_chkstop
.attr
,
207 &dev_attr_max_msg_size
.attr
,
211 static struct attribute_group ap_card_dev_attr_group
= {
212 .attrs
= ap_card_dev_attrs
215 static const struct attribute_group
*ap_card_dev_attr_groups
[] = {
216 &ap_card_dev_attr_group
,
220 static struct device_type ap_card_type
= {
222 .groups
= ap_card_dev_attr_groups
,
225 static void ap_card_device_release(struct device
*dev
)
227 struct ap_card
*ac
= to_ap_card(dev
);
232 struct ap_card
*ap_card_create(int id
, struct ap_tapq_hwinfo hwinfo
,
237 ac
= kzalloc(sizeof(*ac
), GFP_KERNEL
);
240 ac
->ap_dev
.device
.release
= ap_card_device_release
;
241 ac
->ap_dev
.device
.type
= &ap_card_type
;
242 ac
->ap_dev
.device_type
= comp_type
;
245 ac
->maxmsgsize
= hwinfo
.ml
> 0 ?
246 hwinfo
.ml
* AP_TAPQ_ML_FIELD_CHUNK_SIZE
: AP_DEFAULT_MAX_MSG_SIZE
;