| .. | .. |
|---|
| 12 | 12 | #include <linux/init.h> |
|---|
| 13 | 13 | #include <linux/slab.h> |
|---|
| 14 | 14 | #include <asm/facility.h> |
|---|
| 15 | +#include <asm/sclp.h> |
|---|
| 15 | 16 | |
|---|
| 16 | 17 | #include "ap_bus.h" |
|---|
| 17 | 18 | |
|---|
| .. | .. |
|---|
| 23 | 24 | { |
|---|
| 24 | 25 | struct ap_card *ac = to_ap_card(dev); |
|---|
| 25 | 26 | |
|---|
| 26 | | - return snprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type); |
|---|
| 27 | + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->ap_dev.device_type); |
|---|
| 27 | 28 | } |
|---|
| 28 | 29 | |
|---|
| 29 | 30 | static DEVICE_ATTR_RO(hwtype); |
|---|
| .. | .. |
|---|
| 33 | 34 | { |
|---|
| 34 | 35 | struct ap_card *ac = to_ap_card(dev); |
|---|
| 35 | 36 | |
|---|
| 36 | | - return snprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype); |
|---|
| 37 | + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->raw_hwtype); |
|---|
| 37 | 38 | } |
|---|
| 38 | 39 | |
|---|
| 39 | 40 | static DEVICE_ATTR_RO(raw_hwtype); |
|---|
| .. | .. |
|---|
| 43 | 44 | { |
|---|
| 44 | 45 | struct ap_card *ac = to_ap_card(dev); |
|---|
| 45 | 46 | |
|---|
| 46 | | - return snprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth); |
|---|
| 47 | + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->queue_depth); |
|---|
| 47 | 48 | } |
|---|
| 48 | 49 | |
|---|
| 49 | 50 | static DEVICE_ATTR_RO(depth); |
|---|
| .. | .. |
|---|
| 53 | 54 | { |
|---|
| 54 | 55 | struct ap_card *ac = to_ap_card(dev); |
|---|
| 55 | 56 | |
|---|
| 56 | | - return snprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions); |
|---|
| 57 | + return scnprintf(buf, PAGE_SIZE, "0x%08X\n", ac->functions); |
|---|
| 57 | 58 | } |
|---|
| 58 | 59 | |
|---|
| 59 | 60 | static DEVICE_ATTR_RO(ap_functions); |
|---|
| .. | .. |
|---|
| 66 | 67 | u64 req_cnt; |
|---|
| 67 | 68 | |
|---|
| 68 | 69 | req_cnt = 0; |
|---|
| 69 | | - spin_lock_bh(&ap_list_lock); |
|---|
| 70 | + spin_lock_bh(&ap_queues_lock); |
|---|
| 70 | 71 | req_cnt = atomic64_read(&ac->total_request_count); |
|---|
| 71 | | - spin_unlock_bh(&ap_list_lock); |
|---|
| 72 | | - return snprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); |
|---|
| 72 | + spin_unlock_bh(&ap_queues_lock); |
|---|
| 73 | + return scnprintf(buf, PAGE_SIZE, "%llu\n", req_cnt); |
|---|
| 73 | 74 | } |
|---|
| 74 | 75 | |
|---|
| 75 | 76 | static ssize_t request_count_store(struct device *dev, |
|---|
| 76 | 77 | struct device_attribute *attr, |
|---|
| 77 | 78 | const char *buf, size_t count) |
|---|
| 78 | 79 | { |
|---|
| 79 | | - struct ap_card *ac = to_ap_card(dev); |
|---|
| 80 | + int bkt; |
|---|
| 80 | 81 | struct ap_queue *aq; |
|---|
| 82 | + struct ap_card *ac = to_ap_card(dev); |
|---|
| 81 | 83 | |
|---|
| 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); |
|---|
| 84 | + spin_lock_bh(&ap_queues_lock); |
|---|
| 85 | + hash_for_each(ap_queues, bkt, aq, hnode) |
|---|
| 86 | + if (ac == aq->card) |
|---|
| 87 | + aq->total_request_count = 0; |
|---|
| 88 | + spin_unlock_bh(&ap_queues_lock); |
|---|
| 86 | 89 | atomic64_set(&ac->total_request_count, 0); |
|---|
| 87 | 90 | |
|---|
| 88 | 91 | return count; |
|---|
| .. | .. |
|---|
| 93 | 96 | static ssize_t requestq_count_show(struct device *dev, |
|---|
| 94 | 97 | struct device_attribute *attr, char *buf) |
|---|
| 95 | 98 | { |
|---|
| 96 | | - struct ap_card *ac = to_ap_card(dev); |
|---|
| 99 | + int bkt; |
|---|
| 97 | 100 | struct ap_queue *aq; |
|---|
| 98 | 101 | unsigned int reqq_cnt; |
|---|
| 102 | + struct ap_card *ac = to_ap_card(dev); |
|---|
| 99 | 103 | |
|---|
| 100 | 104 | 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 snprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); |
|---|
| 105 | + spin_lock_bh(&ap_queues_lock); |
|---|
| 106 | + hash_for_each(ap_queues, bkt, aq, hnode) |
|---|
| 107 | + if (ac == aq->card) |
|---|
| 108 | + reqq_cnt += aq->requestq_count; |
|---|
| 109 | + spin_unlock_bh(&ap_queues_lock); |
|---|
| 110 | + return scnprintf(buf, PAGE_SIZE, "%d\n", reqq_cnt); |
|---|
| 106 | 111 | } |
|---|
| 107 | 112 | |
|---|
| 108 | 113 | static DEVICE_ATTR_RO(requestq_count); |
|---|
| .. | .. |
|---|
| 110 | 115 | static ssize_t pendingq_count_show(struct device *dev, |
|---|
| 111 | 116 | struct device_attribute *attr, char *buf) |
|---|
| 112 | 117 | { |
|---|
| 113 | | - struct ap_card *ac = to_ap_card(dev); |
|---|
| 118 | + int bkt; |
|---|
| 114 | 119 | struct ap_queue *aq; |
|---|
| 115 | 120 | unsigned int penq_cnt; |
|---|
| 121 | + struct ap_card *ac = to_ap_card(dev); |
|---|
| 116 | 122 | |
|---|
| 117 | 123 | 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 snprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); |
|---|
| 124 | + spin_lock_bh(&ap_queues_lock); |
|---|
| 125 | + hash_for_each(ap_queues, bkt, aq, hnode) |
|---|
| 126 | + if (ac == aq->card) |
|---|
| 127 | + penq_cnt += aq->pendingq_count; |
|---|
| 128 | + spin_unlock_bh(&ap_queues_lock); |
|---|
| 129 | + return scnprintf(buf, PAGE_SIZE, "%d\n", penq_cnt); |
|---|
| 123 | 130 | } |
|---|
| 124 | 131 | |
|---|
| 125 | 132 | static DEVICE_ATTR_RO(pendingq_count); |
|---|
| .. | .. |
|---|
| 127 | 134 | static ssize_t modalias_show(struct device *dev, |
|---|
| 128 | 135 | struct device_attribute *attr, char *buf) |
|---|
| 129 | 136 | { |
|---|
| 130 | | - return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type); |
|---|
| 137 | + return scnprintf(buf, PAGE_SIZE, "ap:t%02X\n", |
|---|
| 138 | + to_ap_dev(dev)->device_type); |
|---|
| 131 | 139 | } |
|---|
| 132 | 140 | |
|---|
| 133 | 141 | static DEVICE_ATTR_RO(modalias); |
|---|
| 142 | + |
|---|
| 143 | +static ssize_t config_show(struct device *dev, |
|---|
| 144 | + struct device_attribute *attr, char *buf) |
|---|
| 145 | +{ |
|---|
| 146 | + struct ap_card *ac = to_ap_card(dev); |
|---|
| 147 | + |
|---|
| 148 | + return scnprintf(buf, PAGE_SIZE, "%d\n", ac->config ? 1 : 0); |
|---|
| 149 | +} |
|---|
| 150 | + |
|---|
| 151 | +static ssize_t config_store(struct device *dev, |
|---|
| 152 | + struct device_attribute *attr, |
|---|
| 153 | + const char *buf, size_t count) |
|---|
| 154 | +{ |
|---|
| 155 | + int rc = 0, cfg; |
|---|
| 156 | + struct ap_card *ac = to_ap_card(dev); |
|---|
| 157 | + |
|---|
| 158 | + if (sscanf(buf, "%d\n", &cfg) != 1 || cfg < 0 || cfg > 1) |
|---|
| 159 | + return -EINVAL; |
|---|
| 160 | + |
|---|
| 161 | + if (cfg && !ac->config) |
|---|
| 162 | + rc = sclp_ap_configure(ac->id); |
|---|
| 163 | + else if (!cfg && ac->config) |
|---|
| 164 | + rc = sclp_ap_deconfigure(ac->id); |
|---|
| 165 | + if (rc) |
|---|
| 166 | + return rc; |
|---|
| 167 | + |
|---|
| 168 | + ac->config = cfg ? true : false; |
|---|
| 169 | + |
|---|
| 170 | + return count; |
|---|
| 171 | +} |
|---|
| 172 | + |
|---|
| 173 | +static DEVICE_ATTR_RW(config); |
|---|
| 134 | 174 | |
|---|
| 135 | 175 | static struct attribute *ap_card_dev_attrs[] = { |
|---|
| 136 | 176 | &dev_attr_hwtype.attr, |
|---|
| .. | .. |
|---|
| 141 | 181 | &dev_attr_requestq_count.attr, |
|---|
| 142 | 182 | &dev_attr_pendingq_count.attr, |
|---|
| 143 | 183 | &dev_attr_modalias.attr, |
|---|
| 184 | + &dev_attr_config.attr, |
|---|
| 144 | 185 | NULL |
|---|
| 145 | 186 | }; |
|---|
| 146 | 187 | |
|---|
| .. | .. |
|---|
| 162 | 203 | { |
|---|
| 163 | 204 | struct ap_card *ac = to_ap_card(dev); |
|---|
| 164 | 205 | |
|---|
| 165 | | - if (!list_empty(&ac->list)) { |
|---|
| 166 | | - spin_lock_bh(&ap_list_lock); |
|---|
| 167 | | - list_del_init(&ac->list); |
|---|
| 168 | | - spin_unlock_bh(&ap_list_lock); |
|---|
| 169 | | - } |
|---|
| 170 | 206 | kfree(ac); |
|---|
| 171 | 207 | } |
|---|
| 172 | 208 | |
|---|
| .. | .. |
|---|
| 178 | 214 | ac = kzalloc(sizeof(*ac), GFP_KERNEL); |
|---|
| 179 | 215 | if (!ac) |
|---|
| 180 | 216 | return NULL; |
|---|
| 181 | | - INIT_LIST_HEAD(&ac->list); |
|---|
| 182 | | - INIT_LIST_HEAD(&ac->queues); |
|---|
| 183 | 217 | ac->ap_dev.device.release = ap_card_device_release; |
|---|
| 184 | 218 | ac->ap_dev.device.type = &ap_card_type; |
|---|
| 185 | 219 | ac->ap_dev.device_type = comp_type; |
|---|