FILE
ap_card.c
File preview with syntax highlighting.
linux-6.19.14/drivers/s390/crypto/ap_card.c
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright IBM Corp. 2016 4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 5 * 6 * Adjunct processor bus, card related code. 7 */ 8 9#define pr_fmt(fmt) "ap: " fmt 10 11#include <linux/init.h> 12#include <linux/slab.h> 13#include <asm/facility.h> 14#include <asm/sclp.h> 15 16#include "ap_bus.h" 17 18/* 19 * AP card related attributes. 20 */ 21static ssize_t 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 sysfs_emit(buf, "%d\n", ac->ap_dev.device_type); 27} 28 29static DEVICE_ATTR_RO(hwtype); 30 31static ssize_t 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 sysfs_emit(buf, "%d\n", ac->hwinfo.at); 37} 38 39static DEVICE_ATTR_RO(raw_hwtype); 40 41static ssize_t 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 sysfs_emit(buf, "%d\n", ac->hwinfo.qd + 1); 47} 48 49static DEVICE_ATTR_RO(depth); 50 51static 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 sysfs_emit(buf, "0x%08X\n", ac->hwinfo.fac); 57} 58 59static DEVICE_ATTR_RO(ap_functions); 60 61static ssize_t request_count_show(struct device *dev, 62 struct device_attribute *attr, 63 char *buf) 64{ 65 struct ap_card *ac = to_ap_card(dev); 66 u64 req_cnt; 67 68 req_cnt = 0; 69 spin_lock_bh(&ap_queues_lock); 70 req_cnt = atomic64_read(&ac->total_request_count); 71 spin_unlock_bh(&ap_queues_lock); 72 return sysfs_emit(buf, "%llu\n", req_cnt); 73} 74 75static ssize_t request_count_store(struct device *dev, 76 struct device_attribute *attr, 77 const char *buf, size_t count) 78{ 79 int bkt; 80 struct ap_queue *aq; 81 struct ap_card *ac = to_ap_card(dev); 82 83 spin_lock_bh(&ap_queues_lock); 84 hash_for_each(ap_queues, bkt, aq, hnode) 85 if (ac == aq->card) 86 aq->total_request_count = 0; 87 spin_unlock_bh(&ap_queues_lock); 88 atomic64_set(&ac->total_request_count, 0); 89 90 return count; 91} 92 93static DEVICE_ATTR_RW(request_count); 94 95static ssize_t requestq_count_show(struct device *dev, 96 struct device_attribute *attr, char *buf) 97{ 98 int bkt; 99 struct ap_queue *aq; 100 unsigned int reqq_cnt; 101 struct ap_card *ac = to_ap_card(dev); 102 103 reqq_cnt = 0; 104 spin_lock_bh(&ap_queues_lock); 105 hash_for_each(ap_queues, bkt, aq, hnode) 106 if (ac == aq->card) 107 reqq_cnt += aq->requestq_count; 108 spin_unlock_bh(&ap_queues_lock); 109 return sysfs_emit(buf, "%d\n", reqq_cnt); 110} 111 112static DEVICE_ATTR_RO(requestq_count); 113 114static ssize_t pendingq_count_show(struct device *dev, 115 struct device_attribute *attr, char *buf) 116{ 117 int bkt; 118 struct ap_queue *aq; 119 unsigned int penq_cnt; 120 struct ap_card *ac = to_ap_card(dev); 121 122 penq_cnt = 0; 123 spin_lock_bh(&ap_queues_lock); 124 hash_for_each(ap_queues, bkt, aq, hnode) 125 if (ac == aq->card) 126 penq_cnt += aq->pendingq_count; 127 spin_unlock_bh(&ap_queues_lock); 128 return sysfs_emit(buf, "%d\n", penq_cnt); 129} 130 131static DEVICE_ATTR_RO(pendingq_count); 132 133static ssize_t modalias_show(struct device *dev, 134 struct device_attribute *attr, char *buf) 135{ 136 return sysfs_emit(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type); 137} 138 139static DEVICE_ATTR_RO(modalias); 140 141static ssize_t config_show(struct device *dev, 142 struct device_attribute *attr, char *buf) 143{ 144 struct ap_card *ac = to_ap_card(dev); 145 146 return sysfs_emit(buf, "%d\n", ac->config ? 1 : 0); 147} 148 149static ssize_t config_store(struct device *dev, 150 struct device_attribute *attr, 151 const char *buf, size_t count) 152{ 153 int rc = 0, cfg; 154 struct ap_card *ac = to_ap_card(dev); 155 156 if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1) 157 return -EINVAL; 158 159 if (cfg && !ac->config) 160 rc = sclp_ap_configure(ac->id); 161 else if (!cfg && ac->config) 162 rc = sclp_ap_deconfigure(ac->id); 163 if (rc) 164 return rc; 165 166 ac->config = cfg ? true : false; 167 168 ap_send_config_uevent(&ac->ap_dev, ac->config); 169 170 return count; 171} 172 173static DEVICE_ATTR_RW(config); 174 175static ssize_t chkstop_show(struct device *dev, 176 struct device_attribute *attr, char *buf) 177{ 178 struct ap_card *ac = to_ap_card(dev); 179 180 return sysfs_emit(buf, "%d\n", ac->chkstop ? 1 : 0); 181} 182 183static DEVICE_ATTR_RO(chkstop); 184 185static ssize_t max_msg_size_show(struct device *dev, 186 struct device_attribute *attr, char *buf) 187{ 188 struct ap_card *ac = to_ap_card(dev); 189 190 return sysfs_emit(buf, "%u\n", ac->maxmsgsize); 191} 192 193static DEVICE_ATTR_RO(max_msg_size); 194 195static struct attribute *ap_card_dev_attrs[] = { 196 &dev_attr_hwtype.attr, 197 &dev_attr_raw_hwtype.attr, 198 &dev_attr_depth.attr, 199 &dev_attr_ap_functions.attr, 200 &dev_attr_request_count.attr, 201 &dev_attr_requestq_count.attr, 202 &dev_attr_pendingq_count.attr, 203 &dev_attr_modalias.attr, 204 &dev_attr_config.attr, 205 &dev_attr_chkstop.attr, 206 &dev_attr_max_msg_size.attr, 207 NULL 208}; 209 210static struct attribute_group ap_card_dev_attr_group = { 211 .attrs = ap_card_dev_attrs 212}; 213 214static const struct attribute_group *ap_card_dev_attr_groups[] = { 215 &ap_card_dev_attr_group, 216 NULL 217}; 218 219static struct device_type ap_card_type = { 220 .name = "ap_card", 221 .groups = ap_card_dev_attr_groups, 222}; 223 224static void ap_card_device_release(struct device *dev) 225{ 226 struct ap_card *ac = to_ap_card(dev); 227 228 kfree(ac); 229} 230 231struct ap_card *ap_card_create(int id, struct ap_tapq_hwinfo hwinfo, 232 int comp_type) 233{ 234 struct ap_card *ac; 235 236 ac = kzalloc(sizeof(*ac), GFP_KERNEL); 237 if (!ac) 238 return NULL; 239 ac->ap_dev.device.release = ap_card_device_release; 240 ac->ap_dev.device.type = &ap_card_type; 241 ac->ap_dev.device_type = comp_type; 242 ac->hwinfo = hwinfo; 243 ac->id = id; 244 ac->maxmsgsize = hwinfo.ml > 0 ? 245 hwinfo.ml * AP_TAPQ_ML_FIELD_CHUNK_SIZE : AP_DEFAULT_MAX_MSG_SIZE; 246 247 return ac; 248}
~/
Read-only file preview.