^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright IBM Corp. 2016
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Adjunct processor bus, card related code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define KMSG_COMPONENT "ap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "ap_bus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * AP card related attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static ssize_t hwtype_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return scnprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static DEVICE_ATTR_RO(hwtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static ssize_t raw_hwtype_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static DEVICE_ATTR_RO(raw_hwtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static ssize_t depth_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static DEVICE_ATTR_RO(depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static ssize_t ap_functions_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static DEVICE_ATTR_RO(ap_functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static ssize_t request_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u64 req_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) req_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) req_cnt = atomic64_read(&ac->total_request_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static ssize_t request_count_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) hash_for_each(ap_queues, bkt, aq, hnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (ac == aq->card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) aq->total_request_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) atomic64_set(&ac->total_request_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static DEVICE_ATTR_RW(request_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static ssize_t requestq_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int reqq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) reqq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) hash_for_each(ap_queues, bkt, aq, hnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ac == aq->card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) reqq_cnt += aq->requestq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static DEVICE_ATTR_RO(requestq_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static ssize_t pendingq_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) unsigned int penq_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) penq_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) hash_for_each(ap_queues, bkt, aq, hnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (ac == aq->card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) penq_cnt += aq->pendingq_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static DEVICE_ATTR_RO(pendingq_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static ssize_t modalias_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return scnprintf(buf, PAGE_SIZE, "ap:t%02X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) to_ap_dev(dev)->device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static ssize_t config_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static ssize_t config_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int rc = 0, cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (cfg && !ac->config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) rc = sclp_ap_configure(ac->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) else if (!cfg && ac->config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) rc = sclp_ap_deconfigure(ac->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ac->config = cfg ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static DEVICE_ATTR_RW(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static struct attribute *ap_card_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) &dev_attr_hwtype.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) &dev_attr_raw_hwtype.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) &dev_attr_depth.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) &dev_attr_ap_functions.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) &dev_attr_request_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) &dev_attr_requestq_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) &dev_attr_pendingq_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) &dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) &dev_attr_config.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static struct attribute_group ap_card_dev_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .attrs = ap_card_dev_attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static const struct attribute_group *ap_card_dev_attr_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) &ap_card_dev_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static struct device_type ap_card_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .name = "ap_card",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .groups = ap_card_dev_attr_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void ap_card_device_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct ap_card *ac = to_ap_card(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) kfree(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct ap_card *ap_card_create(int id, int queue_depth, int raw_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int comp_type, unsigned int functions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct ap_card *ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ac = kzalloc(sizeof(*ac), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (!ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ac->ap_dev.device.release = ap_card_device_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ac->ap_dev.device.type = &ap_card_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ac->ap_dev.device_type = comp_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ac->raw_hwtype = raw_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ac->queue_depth = queue_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ac->functions = functions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ac->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }