Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Linux on zSeries Channel Measurement Facility support |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2000, 2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 6 | * Authors: Arnd Bergmann <arndb@de.ibm.com> |
| 7 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * original idea from Natarajan Krishnaswami <nkrishna@us.ibm.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 26 | #define KMSG_COMPONENT "cio" |
| 27 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/bootmem.h> |
| 30 | #include <linux/device.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/list.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/moduleparam.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 35 | #include <linux/slab.h> |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 36 | #include <linux/timex.h> /* get_tod_clock() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include <asm/ccwdev.h> |
| 39 | #include <asm/cio.h> |
| 40 | #include <asm/cmb.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 41 | #include <asm/div64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include "cio.h" |
| 44 | #include "css.h" |
| 45 | #include "device.h" |
| 46 | #include "ioasm.h" |
| 47 | #include "chsc.h" |
| 48 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 49 | /* |
| 50 | * parameter to enable cmf during boot, possible uses are: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * "s390cmf" -- enable cmf and allocate 2 MB of ram so measuring can be |
| 52 | * used on any subchannel |
| 53 | * "s390cmf=<num>" -- enable cmf and allocate enough memory to measure |
| 54 | * <num> subchannel, where <num> is an integer |
| 55 | * between 1 and 65535, default is 1024 |
| 56 | */ |
| 57 | #define ARGSTRING "s390cmf" |
| 58 | |
| 59 | /* indices for READCMB */ |
| 60 | enum cmb_index { |
| 61 | /* basic and exended format: */ |
| 62 | cmb_ssch_rsch_count, |
| 63 | cmb_sample_count, |
| 64 | cmb_device_connect_time, |
| 65 | cmb_function_pending_time, |
| 66 | cmb_device_disconnect_time, |
| 67 | cmb_control_unit_queuing_time, |
| 68 | cmb_device_active_only_time, |
| 69 | /* extended format only: */ |
| 70 | cmb_device_busy_time, |
| 71 | cmb_initial_command_response_time, |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * enum cmb_format - types of supported measurement block formats |
| 76 | * |
| 77 | * @CMF_BASIC: traditional channel measurement blocks supported |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 78 | * by all machines that we run on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * @CMF_EXTENDED: improved format that was introduced with the z990 |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 80 | * machine |
| 81 | * @CMF_AUTODETECT: default: use extended format when running on a machine |
| 82 | * supporting extended format, otherwise fall back to |
| 83 | * basic format |
| 84 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | enum cmb_format { |
| 86 | CMF_BASIC, |
| 87 | CMF_EXTENDED, |
| 88 | CMF_AUTODETECT = -1, |
| 89 | }; |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 90 | |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 91 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | * format - actual format for all measurement blocks |
| 93 | * |
| 94 | * The format module parameter can be set to a value of 0 (zero) |
| 95 | * or 1, indicating basic or extended format as described for |
| 96 | * enum cmb_format. |
| 97 | */ |
| 98 | static int format = CMF_AUTODETECT; |
Rusty Russell | 69116f2 | 2012-01-13 09:32:17 +1030 | [diff] [blame] | 99 | module_param(format, bint, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * struct cmb_operations - functions to use depending on cmb_format |
| 103 | * |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 104 | * Most of these functions operate on a struct ccw_device. There is only |
| 105 | * one instance of struct cmb_operations because the format of the measurement |
| 106 | * data is guaranteed to be the same for every ccw_device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | * |
| 108 | * @alloc: allocate memory for a channel measurement block, |
| 109 | * either with the help of a special pool or with kmalloc |
| 110 | * @free: free memory allocated with @alloc |
| 111 | * @set: enable or disable measurement |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 112 | * @read: read a measurement entry at an index |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * @readall: read a measurement block in a common format |
| 114 | * @reset: clear the data in the associated measurement block and |
| 115 | * reset its time stamp |
| 116 | */ |
| 117 | struct cmb_operations { |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 118 | int (*alloc) (struct ccw_device *); |
| 119 | void (*free) (struct ccw_device *); |
| 120 | int (*set) (struct ccw_device *, u32); |
| 121 | u64 (*read) (struct ccw_device *, int); |
| 122 | int (*readall)(struct ccw_device *, struct cmbdata *); |
| 123 | void (*reset) (struct ccw_device *); |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 124 | /* private: */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | struct attribute_group *attr_group; |
| 126 | }; |
| 127 | static struct cmb_operations *cmbops; |
| 128 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 129 | struct cmb_data { |
| 130 | void *hw_block; /* Pointer to block updated by hardware */ |
| 131 | void *last_block; /* Last changed block copied from hardware block */ |
| 132 | int size; /* Size of hw_block and last_block */ |
| 133 | unsigned long long last_update; /* when last_block was updated */ |
| 134 | }; |
| 135 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 136 | /* |
| 137 | * Our user interface is designed in terms of nanoseconds, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | * while the hardware measures total times in its own |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 139 | * unit. |
| 140 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | static inline u64 time_to_nsec(u32 value) |
| 142 | { |
| 143 | return ((u64)value) * 128000ull; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Users are usually interested in average times, |
| 148 | * not accumulated time. |
| 149 | * This also helps us with atomicity problems |
| 150 | * when reading sinlge values. |
| 151 | */ |
| 152 | static inline u64 time_to_avg_nsec(u32 value, u32 count) |
| 153 | { |
| 154 | u64 ret; |
| 155 | |
| 156 | /* no samples yet, avoid division by 0 */ |
| 157 | if (count == 0) |
| 158 | return 0; |
| 159 | |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 160 | /* value comes in units of 128 µsec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | ret = time_to_nsec(value); |
| 162 | do_div(ret, count); |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 167 | /* |
| 168 | * Activate or deactivate the channel monitor. When area is NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | * the monitor is deactivated. The channel monitor needs to |
| 170 | * be active in order to measure subchannels, which also need |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 171 | * to be enabled. |
| 172 | */ |
| 173 | static inline void cmf_activate(void *area, unsigned int onoff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
| 175 | register void * __gpr2 asm("2"); |
| 176 | register long __gpr1 asm("1"); |
| 177 | |
| 178 | __gpr2 = area; |
| 179 | __gpr1 = onoff ? 2 : 0; |
| 180 | /* activate channel measurement */ |
| 181 | asm("schm" : : "d" (__gpr2), "d" (__gpr1) ); |
| 182 | } |
| 183 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 184 | static int set_schib(struct ccw_device *cdev, u32 mme, int mbfc, |
| 185 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
Sebastian Ott | a6ef156 | 2015-09-07 19:51:39 +0200 | [diff] [blame] | 187 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 188 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 190 | sch->config.mme = mme; |
| 191 | sch->config.mbfc = mbfc; |
| 192 | /* address can be either a block address or a block index */ |
| 193 | if (mbfc) |
| 194 | sch->config.mba = address; |
| 195 | else |
| 196 | sch->config.mbi = address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Sebastian Ott | a6ef156 | 2015-09-07 19:51:39 +0200 | [diff] [blame] | 198 | ret = cio_commit_config(sch); |
| 199 | if (!mme && ret == -ENODEV) { |
| 200 | /* |
| 201 | * The task was to disable measurement block updates but |
| 202 | * the subchannel is already gone. Report success. |
| 203 | */ |
| 204 | ret = 0; |
| 205 | } |
| 206 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | struct set_schib_struct { |
| 210 | u32 mme; |
| 211 | int mbfc; |
| 212 | unsigned long address; |
| 213 | wait_queue_head_t wait; |
| 214 | int ret; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 215 | struct kref kref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 218 | static void cmf_set_schib_release(struct kref *kref) |
| 219 | { |
| 220 | struct set_schib_struct *set_data; |
| 221 | |
| 222 | set_data = container_of(kref, struct set_schib_struct, kref); |
| 223 | kfree(set_data); |
| 224 | } |
| 225 | |
| 226 | #define CMF_PENDING 1 |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | static int set_schib_wait(struct ccw_device *cdev, u32 mme, |
| 229 | int mbfc, unsigned long address) |
| 230 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 231 | struct set_schib_struct *set_data; |
| 232 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | spin_lock_irq(cdev->ccwlock); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 235 | if (!cdev->private->cmb) { |
| 236 | ret = -ENODEV; |
| 237 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 239 | set_data = kzalloc(sizeof(struct set_schib_struct), GFP_ATOMIC); |
| 240 | if (!set_data) { |
| 241 | ret = -ENOMEM; |
| 242 | goto out; |
| 243 | } |
| 244 | init_waitqueue_head(&set_data->wait); |
| 245 | kref_init(&set_data->kref); |
| 246 | set_data->mme = mme; |
| 247 | set_data->mbfc = mbfc; |
| 248 | set_data->address = address; |
| 249 | |
| 250 | ret = set_schib(cdev, mme, mbfc, address); |
| 251 | if (ret != -EBUSY) |
| 252 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | if (cdev->private->state != DEV_STATE_ONLINE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* if the device is not online, don't even try again */ |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 256 | ret = -EBUSY; |
| 257 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | cdev->private->state = DEV_STATE_CMFCHANGE; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 261 | set_data->ret = CMF_PENDING; |
| 262 | cdev->private->cmb_wait = set_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | spin_unlock_irq(cdev->ccwlock); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 265 | if (wait_event_interruptible(set_data->wait, |
| 266 | set_data->ret != CMF_PENDING)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | spin_lock_irq(cdev->ccwlock); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 268 | if (set_data->ret == CMF_PENDING) { |
| 269 | set_data->ret = -ERESTARTSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (cdev->private->state == DEV_STATE_CMFCHANGE) |
| 271 | cdev->private->state = DEV_STATE_ONLINE; |
| 272 | } |
| 273 | spin_unlock_irq(cdev->ccwlock); |
| 274 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 275 | spin_lock_irq(cdev->ccwlock); |
| 276 | cdev->private->cmb_wait = NULL; |
| 277 | ret = set_data->ret; |
| 278 | out_put: |
| 279 | kref_put(&set_data->kref, cmf_set_schib_release); |
| 280 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | spin_unlock_irq(cdev->ccwlock); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 282 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void retry_set_schib(struct ccw_device *cdev) |
| 286 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 287 | struct set_schib_struct *set_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 289 | set_data = cdev->private->cmb_wait; |
| 290 | if (!set_data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | WARN_ON(1); |
| 292 | return; |
| 293 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 294 | kref_get(&set_data->kref); |
| 295 | set_data->ret = set_schib(cdev, set_data->mme, set_data->mbfc, |
| 296 | set_data->address); |
| 297 | wake_up(&set_data->wait); |
| 298 | kref_put(&set_data->kref, cmf_set_schib_release); |
| 299 | } |
| 300 | |
| 301 | static int cmf_copy_block(struct ccw_device *cdev) |
| 302 | { |
| 303 | struct subchannel *sch; |
| 304 | void *reference_buf; |
| 305 | void *hw_block; |
| 306 | struct cmb_data *cmb_data; |
| 307 | |
| 308 | sch = to_subchannel(cdev->dev.parent); |
| 309 | |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 310 | if (cio_update_schib(sch)) |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 311 | return -ENODEV; |
| 312 | |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 313 | if (scsw_fctl(&sch->schib.scsw) & SCSW_FCTL_START_FUNC) { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 314 | /* Don't copy if a start function is in progress. */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 315 | if ((!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_SUSPENDED)) && |
| 316 | (scsw_actl(&sch->schib.scsw) & |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 317 | (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) && |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 318 | (!(scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_SEC_STATUS))) |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 319 | return -EBUSY; |
| 320 | } |
| 321 | cmb_data = cdev->private->cmb; |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 322 | hw_block = cmb_data->hw_block; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 323 | if (!memcmp(cmb_data->last_block, hw_block, cmb_data->size)) |
| 324 | /* No need to copy. */ |
| 325 | return 0; |
| 326 | reference_buf = kzalloc(cmb_data->size, GFP_ATOMIC); |
| 327 | if (!reference_buf) |
| 328 | return -ENOMEM; |
| 329 | /* Ensure consistency of block copied from hardware. */ |
| 330 | do { |
| 331 | memcpy(cmb_data->last_block, hw_block, cmb_data->size); |
| 332 | memcpy(reference_buf, hw_block, cmb_data->size); |
| 333 | } while (memcmp(cmb_data->last_block, reference_buf, cmb_data->size)); |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 334 | cmb_data->last_update = get_tod_clock(); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 335 | kfree(reference_buf); |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | struct copy_block_struct { |
| 340 | wait_queue_head_t wait; |
| 341 | int ret; |
| 342 | struct kref kref; |
| 343 | }; |
| 344 | |
| 345 | static void cmf_copy_block_release(struct kref *kref) |
| 346 | { |
| 347 | struct copy_block_struct *copy_block; |
| 348 | |
| 349 | copy_block = container_of(kref, struct copy_block_struct, kref); |
| 350 | kfree(copy_block); |
| 351 | } |
| 352 | |
| 353 | static int cmf_cmb_copy_wait(struct ccw_device *cdev) |
| 354 | { |
| 355 | struct copy_block_struct *copy_block; |
| 356 | int ret; |
| 357 | unsigned long flags; |
| 358 | |
| 359 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 360 | if (!cdev->private->cmb) { |
| 361 | ret = -ENODEV; |
| 362 | goto out; |
| 363 | } |
| 364 | copy_block = kzalloc(sizeof(struct copy_block_struct), GFP_ATOMIC); |
| 365 | if (!copy_block) { |
| 366 | ret = -ENOMEM; |
| 367 | goto out; |
| 368 | } |
| 369 | init_waitqueue_head(©_block->wait); |
| 370 | kref_init(©_block->kref); |
| 371 | |
| 372 | ret = cmf_copy_block(cdev); |
| 373 | if (ret != -EBUSY) |
| 374 | goto out_put; |
| 375 | |
| 376 | if (cdev->private->state != DEV_STATE_ONLINE) { |
| 377 | ret = -EBUSY; |
| 378 | goto out_put; |
| 379 | } |
| 380 | |
| 381 | cdev->private->state = DEV_STATE_CMFUPDATE; |
| 382 | copy_block->ret = CMF_PENDING; |
| 383 | cdev->private->cmb_wait = copy_block; |
| 384 | |
| 385 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 386 | if (wait_event_interruptible(copy_block->wait, |
| 387 | copy_block->ret != CMF_PENDING)) { |
| 388 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 389 | if (copy_block->ret == CMF_PENDING) { |
| 390 | copy_block->ret = -ERESTARTSYS; |
| 391 | if (cdev->private->state == DEV_STATE_CMFUPDATE) |
| 392 | cdev->private->state = DEV_STATE_ONLINE; |
| 393 | } |
| 394 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 395 | } |
| 396 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 397 | cdev->private->cmb_wait = NULL; |
| 398 | ret = copy_block->ret; |
| 399 | out_put: |
| 400 | kref_put(©_block->kref, cmf_copy_block_release); |
| 401 | out: |
| 402 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | void cmf_retry_copy_block(struct ccw_device *cdev) |
| 407 | { |
| 408 | struct copy_block_struct *copy_block; |
| 409 | |
| 410 | copy_block = cdev->private->cmb_wait; |
| 411 | if (!copy_block) { |
| 412 | WARN_ON(1); |
| 413 | return; |
| 414 | } |
| 415 | kref_get(©_block->kref); |
| 416 | copy_block->ret = cmf_copy_block(cdev); |
| 417 | wake_up(©_block->wait); |
| 418 | kref_put(©_block->kref, cmf_copy_block_release); |
| 419 | } |
| 420 | |
| 421 | static void cmf_generic_reset(struct ccw_device *cdev) |
| 422 | { |
| 423 | struct cmb_data *cmb_data; |
| 424 | |
| 425 | spin_lock_irq(cdev->ccwlock); |
| 426 | cmb_data = cdev->private->cmb; |
| 427 | if (cmb_data) { |
| 428 | memset(cmb_data->last_block, 0, cmb_data->size); |
| 429 | /* |
| 430 | * Need to reset hw block as well to make the hardware start |
| 431 | * from 0 again. |
| 432 | */ |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 433 | memset(cmb_data->hw_block, 0, cmb_data->size); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 434 | cmb_data->last_update = 0; |
| 435 | } |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 436 | cdev->private->cmb_start_time = get_tod_clock(); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 437 | spin_unlock_irq(cdev->ccwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
| 441 | * struct cmb_area - container for global cmb data |
| 442 | * |
| 443 | * @mem: pointer to CMBs (only in basic measurement mode) |
| 444 | * @list: contains a linked list of all subchannels |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 445 | * @num_channels: number of channels to be measured |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | * @lock: protect concurrent access to @mem and @list |
| 447 | */ |
| 448 | struct cmb_area { |
| 449 | struct cmb *mem; |
| 450 | struct list_head list; |
| 451 | int num_channels; |
| 452 | spinlock_t lock; |
| 453 | }; |
| 454 | |
| 455 | static struct cmb_area cmb_area = { |
Milind Arun Choudhary | cb629a0 | 2007-04-27 16:02:01 +0200 | [diff] [blame] | 456 | .lock = __SPIN_LOCK_UNLOCKED(cmb_area.lock), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | .list = LIST_HEAD_INIT(cmb_area.list), |
| 458 | .num_channels = 1024, |
| 459 | }; |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | /* ****** old style CMB handling ********/ |
| 462 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 463 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | * Basic channel measurement blocks are allocated in one contiguous |
| 465 | * block of memory, which can not be moved as long as any channel |
| 466 | * is active. Therefore, a maximum number of subchannels needs to |
| 467 | * be defined somewhere. This is a module parameter, defaulting to |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 468 | * a reasonable value of 1024, or 32 kb of memory. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | * Current kernels don't allow kmalloc with more than 128kb, so the |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 470 | * maximum is 4096. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | */ |
| 472 | |
| 473 | module_param_named(maxchannels, cmb_area.num_channels, uint, 0444); |
| 474 | |
| 475 | /** |
| 476 | * struct cmb - basic channel measurement block |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 477 | * @ssch_rsch_count: number of ssch and rsch |
| 478 | * @sample_count: number of samples |
| 479 | * @device_connect_time: time of device connect |
| 480 | * @function_pending_time: time of function pending |
| 481 | * @device_disconnect_time: time of device disconnect |
| 482 | * @control_unit_queuing_time: time of control unit queuing |
| 483 | * @device_active_only_time: time of device active only |
| 484 | * @reserved: unused in basic measurement mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | * |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 486 | * The measurement block as used by the hardware. The fields are described |
| 487 | * further in z/Architecture Principles of Operation, chapter 17. |
| 488 | * |
| 489 | * The cmb area made up from these blocks must be a contiguous array and may |
| 490 | * not be reallocated or freed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | * Only one cmb area can be present in the system. |
| 492 | */ |
| 493 | struct cmb { |
| 494 | u16 ssch_rsch_count; |
| 495 | u16 sample_count; |
| 496 | u32 device_connect_time; |
| 497 | u32 function_pending_time; |
| 498 | u32 device_disconnect_time; |
| 499 | u32 control_unit_queuing_time; |
| 500 | u32 device_active_only_time; |
| 501 | u32 reserved[2]; |
| 502 | }; |
| 503 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 504 | /* |
| 505 | * Insert a single device into the cmb_area list. |
| 506 | * Called with cmb_area.lock held from alloc_cmb. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 508 | static int alloc_cmb_single(struct ccw_device *cdev, |
| 509 | struct cmb_data *cmb_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
| 511 | struct cmb *cmb; |
| 512 | struct ccw_device_private *node; |
| 513 | int ret; |
| 514 | |
| 515 | spin_lock_irq(cdev->ccwlock); |
| 516 | if (!list_empty(&cdev->private->cmb_list)) { |
| 517 | ret = -EBUSY; |
| 518 | goto out; |
| 519 | } |
| 520 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 521 | /* |
| 522 | * Find first unused cmb in cmb_area.mem. |
| 523 | * This is a little tricky: cmb_area.list |
| 524 | * remains sorted by ->cmb->hw_data pointers. |
| 525 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | cmb = cmb_area.mem; |
| 527 | list_for_each_entry(node, &cmb_area.list, cmb_list) { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 528 | struct cmb_data *data; |
| 529 | data = node->cmb; |
| 530 | if ((struct cmb*)data->hw_block > cmb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | break; |
| 532 | cmb++; |
| 533 | } |
| 534 | if (cmb - cmb_area.mem >= cmb_area.num_channels) { |
| 535 | ret = -ENOMEM; |
| 536 | goto out; |
| 537 | } |
| 538 | |
| 539 | /* insert new cmb */ |
| 540 | list_add_tail(&cdev->private->cmb_list, &node->cmb_list); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 541 | cmb_data->hw_block = cmb; |
| 542 | cdev->private->cmb = cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | ret = 0; |
| 544 | out: |
| 545 | spin_unlock_irq(cdev->ccwlock); |
| 546 | return ret; |
| 547 | } |
| 548 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 549 | static int alloc_cmb(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
| 551 | int ret; |
| 552 | struct cmb *mem; |
| 553 | ssize_t size; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 554 | struct cmb_data *cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 556 | /* Allocate private cmb_data. */ |
| 557 | cmb_data = kzalloc(sizeof(struct cmb_data), GFP_KERNEL); |
| 558 | if (!cmb_data) |
| 559 | return -ENOMEM; |
| 560 | |
| 561 | cmb_data->last_block = kzalloc(sizeof(struct cmb), GFP_KERNEL); |
| 562 | if (!cmb_data->last_block) { |
| 563 | kfree(cmb_data); |
| 564 | return -ENOMEM; |
| 565 | } |
| 566 | cmb_data->size = sizeof(struct cmb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | spin_lock(&cmb_area.lock); |
| 568 | |
| 569 | if (!cmb_area.mem) { |
| 570 | /* there is no user yet, so we need a new area */ |
| 571 | size = sizeof(struct cmb) * cmb_area.num_channels; |
| 572 | WARN_ON(!list_empty(&cmb_area.list)); |
| 573 | |
| 574 | spin_unlock(&cmb_area.lock); |
| 575 | mem = (void*)__get_free_pages(GFP_KERNEL | GFP_DMA, |
| 576 | get_order(size)); |
| 577 | spin_lock(&cmb_area.lock); |
| 578 | |
| 579 | if (cmb_area.mem) { |
| 580 | /* ok, another thread was faster */ |
| 581 | free_pages((unsigned long)mem, get_order(size)); |
| 582 | } else if (!mem) { |
| 583 | /* no luck */ |
| 584 | ret = -ENOMEM; |
| 585 | goto out; |
| 586 | } else { |
| 587 | /* everything ok */ |
| 588 | memset(mem, 0, size); |
| 589 | cmb_area.mem = mem; |
| 590 | cmf_activate(cmb_area.mem, 1); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | /* do the actual allocation */ |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 595 | ret = alloc_cmb_single(cdev, cmb_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | out: |
| 597 | spin_unlock(&cmb_area.lock); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 598 | if (ret) { |
| 599 | kfree(cmb_data->last_block); |
| 600 | kfree(cmb_data); |
| 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | return ret; |
| 603 | } |
| 604 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 605 | static void free_cmb(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
| 607 | struct ccw_device_private *priv; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 608 | struct cmb_data *cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | spin_lock(&cmb_area.lock); |
| 611 | spin_lock_irq(cdev->ccwlock); |
| 612 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 613 | priv = cdev->private; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 614 | cmb_data = priv->cmb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | priv->cmb = NULL; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 616 | if (cmb_data) |
| 617 | kfree(cmb_data->last_block); |
| 618 | kfree(cmb_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | list_del_init(&priv->cmb_list); |
| 620 | |
| 621 | if (list_empty(&cmb_area.list)) { |
| 622 | ssize_t size; |
| 623 | size = sizeof(struct cmb) * cmb_area.num_channels; |
| 624 | cmf_activate(NULL, 0); |
| 625 | free_pages((unsigned long)cmb_area.mem, get_order(size)); |
| 626 | cmb_area.mem = NULL; |
| 627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | spin_unlock_irq(cdev->ccwlock); |
| 629 | spin_unlock(&cmb_area.lock); |
| 630 | } |
| 631 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 632 | static int set_cmb(struct ccw_device *cdev, u32 mme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
| 634 | u16 offset; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 635 | struct cmb_data *cmb_data; |
| 636 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 638 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 639 | if (!cdev->private->cmb) { |
| 640 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return -EINVAL; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 642 | } |
| 643 | cmb_data = cdev->private->cmb; |
| 644 | offset = mme ? (struct cmb *)cmb_data->hw_block - cmb_area.mem : 0; |
| 645 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | return set_schib_wait(cdev, mme, 0, offset); |
| 648 | } |
| 649 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 650 | static u64 read_cmb(struct ccw_device *cdev, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 652 | struct cmb *cmb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | u32 val; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 654 | int ret; |
| 655 | unsigned long flags; |
| 656 | |
| 657 | ret = cmf_cmb_copy_wait(cdev); |
| 658 | if (ret < 0) |
| 659 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 662 | if (!cdev->private->cmb) { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 663 | ret = 0; |
| 664 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 666 | cmb = ((struct cmb_data *)cdev->private->cmb)->last_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | switch (index) { |
| 669 | case cmb_ssch_rsch_count: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 670 | ret = cmb->ssch_rsch_count; |
| 671 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | case cmb_sample_count: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 673 | ret = cmb->sample_count; |
| 674 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | case cmb_device_connect_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 676 | val = cmb->device_connect_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | break; |
| 678 | case cmb_function_pending_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 679 | val = cmb->function_pending_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | break; |
| 681 | case cmb_device_disconnect_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 682 | val = cmb->device_disconnect_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | break; |
| 684 | case cmb_control_unit_queuing_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 685 | val = cmb->control_unit_queuing_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | break; |
| 687 | case cmb_device_active_only_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 688 | val = cmb->device_active_only_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | break; |
| 690 | default: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 691 | ret = 0; |
| 692 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 694 | ret = time_to_avg_nsec(val, cmb->sample_count); |
| 695 | out: |
| 696 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 697 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 700 | static int readall_cmb(struct ccw_device *cdev, struct cmbdata *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 702 | struct cmb *cmb; |
| 703 | struct cmb_data *cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | u64 time; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 705 | unsigned long flags; |
| 706 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 708 | ret = cmf_cmb_copy_wait(cdev); |
| 709 | if (ret < 0) |
| 710 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | spin_lock_irqsave(cdev->ccwlock, flags); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 712 | cmb_data = cdev->private->cmb; |
| 713 | if (!cmb_data) { |
| 714 | ret = -ENODEV; |
| 715 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 717 | if (cmb_data->last_update == 0) { |
| 718 | ret = -EAGAIN; |
| 719 | goto out; |
| 720 | } |
| 721 | cmb = cmb_data->last_block; |
| 722 | time = cmb_data->last_update - cdev->private->cmb_start_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | memset(data, 0, sizeof(struct cmbdata)); |
| 725 | |
| 726 | /* we only know values before device_busy_time */ |
| 727 | data->size = offsetof(struct cmbdata, device_busy_time); |
| 728 | |
| 729 | /* convert to nanoseconds */ |
| 730 | data->elapsed_time = (time * 1000) >> 12; |
| 731 | |
| 732 | /* copy data to new structure */ |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 733 | data->ssch_rsch_count = cmb->ssch_rsch_count; |
| 734 | data->sample_count = cmb->sample_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | /* time fields are converted to nanoseconds while copying */ |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 737 | data->device_connect_time = time_to_nsec(cmb->device_connect_time); |
| 738 | data->function_pending_time = time_to_nsec(cmb->function_pending_time); |
| 739 | data->device_disconnect_time = |
| 740 | time_to_nsec(cmb->device_disconnect_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | data->control_unit_queuing_time |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 742 | = time_to_nsec(cmb->control_unit_queuing_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | data->device_active_only_time |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 744 | = time_to_nsec(cmb->device_active_only_time); |
| 745 | ret = 0; |
| 746 | out: |
| 747 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 748 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 751 | static void reset_cmb(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 753 | cmf_generic_reset(cdev); |
| 754 | } |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | static struct attribute_group cmf_attr_group; |
| 757 | |
| 758 | static struct cmb_operations cmbops_basic = { |
| 759 | .alloc = alloc_cmb, |
| 760 | .free = free_cmb, |
| 761 | .set = set_cmb, |
| 762 | .read = read_cmb, |
| 763 | .readall = readall_cmb, |
| 764 | .reset = reset_cmb, |
| 765 | .attr_group = &cmf_attr_group, |
| 766 | }; |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | /* ******** extended cmb handling ********/ |
| 769 | |
| 770 | /** |
| 771 | * struct cmbe - extended channel measurement block |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 772 | * @ssch_rsch_count: number of ssch and rsch |
| 773 | * @sample_count: number of samples |
| 774 | * @device_connect_time: time of device connect |
| 775 | * @function_pending_time: time of function pending |
| 776 | * @device_disconnect_time: time of device disconnect |
| 777 | * @control_unit_queuing_time: time of control unit queuing |
| 778 | * @device_active_only_time: time of device active only |
| 779 | * @device_busy_time: time of device busy |
| 780 | * @initial_command_response_time: initial command response time |
| 781 | * @reserved: unused |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | * |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 783 | * The measurement block as used by the hardware. May be in any 64 bit physical |
| 784 | * location. |
| 785 | * The fields are described further in z/Architecture Principles of Operation, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | * third edition, chapter 17. |
| 787 | */ |
| 788 | struct cmbe { |
| 789 | u32 ssch_rsch_count; |
| 790 | u32 sample_count; |
| 791 | u32 device_connect_time; |
| 792 | u32 function_pending_time; |
| 793 | u32 device_disconnect_time; |
| 794 | u32 control_unit_queuing_time; |
| 795 | u32 device_active_only_time; |
| 796 | u32 device_busy_time; |
| 797 | u32 initial_command_response_time; |
| 798 | u32 reserved[7]; |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 799 | } __packed __aligned(64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 801 | static struct kmem_cache *cmbe_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 803 | static int alloc_cmbe(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 805 | struct cmb_data *cmb_data; |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 806 | struct cmbe *cmbe; |
| 807 | int ret = -ENOMEM; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 808 | |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 809 | cmbe = kmem_cache_zalloc(cmbe_cache, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (!cmbe) |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 811 | return ret; |
| 812 | |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 813 | cmb_data = kzalloc(sizeof(*cmb_data), GFP_KERNEL); |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 814 | if (!cmb_data) |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 815 | goto out_free; |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 816 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 817 | cmb_data->last_block = kzalloc(sizeof(struct cmbe), GFP_KERNEL); |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 818 | if (!cmb_data->last_block) |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 819 | goto out_free; |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 820 | |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 821 | cmb_data->size = sizeof(*cmbe); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 822 | cmb_data->hw_block = cmbe; |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 823 | |
| 824 | spin_lock(&cmb_area.lock); |
| 825 | spin_lock_irq(cdev->ccwlock); |
| 826 | if (cdev->private->cmb) |
| 827 | goto out_unlock; |
| 828 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 829 | cdev->private->cmb = cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
| 831 | /* activate global measurement if this is the first channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (list_empty(&cmb_area.list)) |
| 833 | cmf_activate(NULL, 1); |
| 834 | list_add_tail(&cdev->private->cmb_list, &cmb_area.list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 836 | spin_unlock_irq(cdev->ccwlock); |
| 837 | spin_unlock(&cmb_area.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | return 0; |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 839 | |
| 840 | out_unlock: |
| 841 | spin_unlock_irq(cdev->ccwlock); |
| 842 | spin_unlock(&cmb_area.lock); |
| 843 | ret = -EBUSY; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 844 | out_free: |
| 845 | if (cmb_data) |
| 846 | kfree(cmb_data->last_block); |
| 847 | kfree(cmb_data); |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 848 | kmem_cache_free(cmbe_cache, cmbe); |
| 849 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 850 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 853 | static void free_cmbe(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 855 | struct cmb_data *cmb_data; |
| 856 | |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 857 | spin_lock(&cmb_area.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | spin_lock_irq(cdev->ccwlock); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 859 | cmb_data = cdev->private->cmb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | cdev->private->cmb = NULL; |
Sebastian Ott | a5e9ca5 | 2015-09-07 19:52:31 +0200 | [diff] [blame] | 861 | if (cmb_data) { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 862 | kfree(cmb_data->last_block); |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 863 | kmem_cache_free(cmbe_cache, cmb_data->hw_block); |
Sebastian Ott | a5e9ca5 | 2015-09-07 19:52:31 +0200 | [diff] [blame] | 864 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 865 | kfree(cmb_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
| 867 | /* deactivate global measurement if this is the last channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | list_del_init(&cdev->private->cmb_list); |
| 869 | if (list_empty(&cmb_area.list)) |
| 870 | cmf_activate(NULL, 0); |
Sebastian Ott | 616503d | 2015-09-07 19:52:06 +0200 | [diff] [blame] | 871 | spin_unlock_irq(cdev->ccwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | spin_unlock(&cmb_area.lock); |
| 873 | } |
| 874 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 875 | static int set_cmbe(struct ccw_device *cdev, u32 mme) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | { |
| 877 | unsigned long mba; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 878 | struct cmb_data *cmb_data; |
| 879 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 881 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 882 | if (!cdev->private->cmb) { |
| 883 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | return -EINVAL; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 885 | } |
| 886 | cmb_data = cdev->private->cmb; |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 887 | mba = mme ? (unsigned long) cmb_data->hw_block : 0; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 888 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
| 890 | return set_schib_wait(cdev, mme, 1, mba); |
| 891 | } |
| 892 | |
| 893 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 894 | static u64 read_cmbe(struct ccw_device *cdev, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 896 | struct cmbe *cmb; |
| 897 | struct cmb_data *cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | u32 val; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 899 | int ret; |
| 900 | unsigned long flags; |
| 901 | |
| 902 | ret = cmf_cmb_copy_wait(cdev); |
| 903 | if (ret < 0) |
| 904 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | spin_lock_irqsave(cdev->ccwlock, flags); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 907 | cmb_data = cdev->private->cmb; |
| 908 | if (!cmb_data) { |
| 909 | ret = 0; |
| 910 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 912 | cmb = cmb_data->last_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | switch (index) { |
| 915 | case cmb_ssch_rsch_count: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 916 | ret = cmb->ssch_rsch_count; |
| 917 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | case cmb_sample_count: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 919 | ret = cmb->sample_count; |
| 920 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | case cmb_device_connect_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 922 | val = cmb->device_connect_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | break; |
| 924 | case cmb_function_pending_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 925 | val = cmb->function_pending_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | break; |
| 927 | case cmb_device_disconnect_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 928 | val = cmb->device_disconnect_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | break; |
| 930 | case cmb_control_unit_queuing_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 931 | val = cmb->control_unit_queuing_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | break; |
| 933 | case cmb_device_active_only_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 934 | val = cmb->device_active_only_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | break; |
| 936 | case cmb_device_busy_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 937 | val = cmb->device_busy_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | break; |
| 939 | case cmb_initial_command_response_time: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 940 | val = cmb->initial_command_response_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | break; |
| 942 | default: |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 943 | ret = 0; |
| 944 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 946 | ret = time_to_avg_nsec(val, cmb->sample_count); |
| 947 | out: |
| 948 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 949 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 952 | static int readall_cmbe(struct ccw_device *cdev, struct cmbdata *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 954 | struct cmbe *cmb; |
| 955 | struct cmb_data *cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | u64 time; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 957 | unsigned long flags; |
| 958 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 960 | ret = cmf_cmb_copy_wait(cdev); |
| 961 | if (ret < 0) |
| 962 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | spin_lock_irqsave(cdev->ccwlock, flags); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 964 | cmb_data = cdev->private->cmb; |
| 965 | if (!cmb_data) { |
| 966 | ret = -ENODEV; |
| 967 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | } |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 969 | if (cmb_data->last_update == 0) { |
| 970 | ret = -EAGAIN; |
| 971 | goto out; |
| 972 | } |
| 973 | time = cmb_data->last_update - cdev->private->cmb_start_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | memset (data, 0, sizeof(struct cmbdata)); |
| 976 | |
| 977 | /* we only know values before device_busy_time */ |
| 978 | data->size = offsetof(struct cmbdata, device_busy_time); |
| 979 | |
| 980 | /* conver to nanoseconds */ |
| 981 | data->elapsed_time = (time * 1000) >> 12; |
| 982 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 983 | cmb = cmb_data->last_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | /* copy data to new structure */ |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 985 | data->ssch_rsch_count = cmb->ssch_rsch_count; |
| 986 | data->sample_count = cmb->sample_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
| 988 | /* time fields are converted to nanoseconds while copying */ |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 989 | data->device_connect_time = time_to_nsec(cmb->device_connect_time); |
| 990 | data->function_pending_time = time_to_nsec(cmb->function_pending_time); |
| 991 | data->device_disconnect_time = |
| 992 | time_to_nsec(cmb->device_disconnect_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | data->control_unit_queuing_time |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 994 | = time_to_nsec(cmb->control_unit_queuing_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | data->device_active_only_time |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 996 | = time_to_nsec(cmb->device_active_only_time); |
| 997 | data->device_busy_time = time_to_nsec(cmb->device_busy_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | data->initial_command_response_time |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 999 | = time_to_nsec(cmb->initial_command_response_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1001 | ret = 0; |
| 1002 | out: |
| 1003 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 1004 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1007 | static void reset_cmbe(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1009 | cmf_generic_reset(cdev); |
| 1010 | } |
| 1011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | static struct attribute_group cmf_attr_group_ext; |
| 1013 | |
| 1014 | static struct cmb_operations cmbops_extended = { |
| 1015 | .alloc = alloc_cmbe, |
| 1016 | .free = free_cmbe, |
| 1017 | .set = set_cmbe, |
| 1018 | .read = read_cmbe, |
| 1019 | .readall = readall_cmbe, |
| 1020 | .reset = reset_cmbe, |
| 1021 | .attr_group = &cmf_attr_group_ext, |
| 1022 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1024 | static ssize_t cmb_show_attr(struct device *dev, char *buf, enum cmb_index idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | { |
| 1026 | return sprintf(buf, "%lld\n", |
| 1027 | (unsigned long long) cmf_read(to_ccwdev(dev), idx)); |
| 1028 | } |
| 1029 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1030 | static ssize_t cmb_show_avg_sample_interval(struct device *dev, |
| 1031 | struct device_attribute *attr, |
| 1032 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | { |
| 1034 | struct ccw_device *cdev; |
| 1035 | long interval; |
| 1036 | unsigned long count; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1037 | struct cmb_data *cmb_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
| 1039 | cdev = to_ccwdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | count = cmf_read(cdev, cmb_sample_count); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1041 | spin_lock_irq(cdev->ccwlock); |
| 1042 | cmb_data = cdev->private->cmb; |
| 1043 | if (count) { |
| 1044 | interval = cmb_data->last_update - |
| 1045 | cdev->private->cmb_start_time; |
Cornelia Huck | 13ffa92 | 2006-07-17 16:09:28 +0200 | [diff] [blame] | 1046 | interval = (interval * 1000) >> 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | interval /= count; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1048 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | interval = -1; |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1050 | spin_unlock_irq(cdev->ccwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | return sprintf(buf, "%ld\n", interval); |
| 1052 | } |
| 1053 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1054 | static ssize_t cmb_show_avg_utilization(struct device *dev, |
| 1055 | struct device_attribute *attr, |
| 1056 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | { |
| 1058 | struct cmbdata data; |
| 1059 | u64 utilization; |
| 1060 | unsigned long t, u; |
| 1061 | int ret; |
| 1062 | |
| 1063 | ret = cmf_readall(to_ccwdev(dev), &data); |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1064 | if (ret == -EAGAIN || ret == -ENODEV) |
| 1065 | /* No data (yet/currently) available to use for calculation. */ |
| 1066 | return sprintf(buf, "n/a\n"); |
| 1067 | else if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | return ret; |
| 1069 | |
| 1070 | utilization = data.device_connect_time + |
| 1071 | data.function_pending_time + |
| 1072 | data.device_disconnect_time; |
| 1073 | |
| 1074 | /* shift to avoid long long division */ |
| 1075 | while (-1ul < (data.elapsed_time | utilization)) { |
| 1076 | utilization >>= 8; |
| 1077 | data.elapsed_time >>= 8; |
| 1078 | } |
| 1079 | |
| 1080 | /* calculate value in 0.1 percent units */ |
| 1081 | t = (unsigned long) data.elapsed_time / 1000; |
| 1082 | u = (unsigned long) utilization / t; |
| 1083 | |
| 1084 | return sprintf(buf, "%02ld.%01ld%%\n", u/ 10, u - (u/ 10) * 10); |
| 1085 | } |
| 1086 | |
| 1087 | #define cmf_attr(name) \ |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1088 | static ssize_t show_##name(struct device *dev, \ |
| 1089 | struct device_attribute *attr, char *buf) \ |
| 1090 | { return cmb_show_attr((dev), buf, cmb_##name); } \ |
| 1091 | static DEVICE_ATTR(name, 0444, show_##name, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
| 1093 | #define cmf_attr_avg(name) \ |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1094 | static ssize_t show_avg_##name(struct device *dev, \ |
| 1095 | struct device_attribute *attr, char *buf) \ |
| 1096 | { return cmb_show_attr((dev), buf, cmb_##name); } \ |
| 1097 | static DEVICE_ATTR(avg_##name, 0444, show_avg_##name, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | cmf_attr(ssch_rsch_count); |
| 1100 | cmf_attr(sample_count); |
| 1101 | cmf_attr_avg(device_connect_time); |
| 1102 | cmf_attr_avg(function_pending_time); |
| 1103 | cmf_attr_avg(device_disconnect_time); |
| 1104 | cmf_attr_avg(control_unit_queuing_time); |
| 1105 | cmf_attr_avg(device_active_only_time); |
| 1106 | cmf_attr_avg(device_busy_time); |
| 1107 | cmf_attr_avg(initial_command_response_time); |
| 1108 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1109 | static DEVICE_ATTR(avg_sample_interval, 0444, cmb_show_avg_sample_interval, |
| 1110 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | static DEVICE_ATTR(avg_utilization, 0444, cmb_show_avg_utilization, NULL); |
| 1112 | |
| 1113 | static struct attribute *cmf_attributes[] = { |
| 1114 | &dev_attr_avg_sample_interval.attr, |
| 1115 | &dev_attr_avg_utilization.attr, |
| 1116 | &dev_attr_ssch_rsch_count.attr, |
| 1117 | &dev_attr_sample_count.attr, |
| 1118 | &dev_attr_avg_device_connect_time.attr, |
| 1119 | &dev_attr_avg_function_pending_time.attr, |
| 1120 | &dev_attr_avg_device_disconnect_time.attr, |
| 1121 | &dev_attr_avg_control_unit_queuing_time.attr, |
| 1122 | &dev_attr_avg_device_active_only_time.attr, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1123 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | }; |
| 1125 | |
| 1126 | static struct attribute_group cmf_attr_group = { |
| 1127 | .name = "cmf", |
| 1128 | .attrs = cmf_attributes, |
| 1129 | }; |
| 1130 | |
| 1131 | static struct attribute *cmf_attributes_ext[] = { |
| 1132 | &dev_attr_avg_sample_interval.attr, |
| 1133 | &dev_attr_avg_utilization.attr, |
| 1134 | &dev_attr_ssch_rsch_count.attr, |
| 1135 | &dev_attr_sample_count.attr, |
| 1136 | &dev_attr_avg_device_connect_time.attr, |
| 1137 | &dev_attr_avg_function_pending_time.attr, |
| 1138 | &dev_attr_avg_device_disconnect_time.attr, |
| 1139 | &dev_attr_avg_control_unit_queuing_time.attr, |
| 1140 | &dev_attr_avg_device_active_only_time.attr, |
| 1141 | &dev_attr_avg_device_busy_time.attr, |
| 1142 | &dev_attr_avg_initial_command_response_time.attr, |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1143 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | }; |
| 1145 | |
| 1146 | static struct attribute_group cmf_attr_group_ext = { |
| 1147 | .name = "cmf", |
| 1148 | .attrs = cmf_attributes_ext, |
| 1149 | }; |
| 1150 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1151 | static ssize_t cmb_enable_show(struct device *dev, |
| 1152 | struct device_attribute *attr, |
| 1153 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | { |
Sebastian Ott | 279b8f9 | 2015-09-07 19:50:25 +0200 | [diff] [blame] | 1155 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1156 | int enabled; |
| 1157 | |
| 1158 | spin_lock_irq(cdev->ccwlock); |
| 1159 | enabled = !!cdev->private->cmb; |
| 1160 | spin_unlock_irq(cdev->ccwlock); |
| 1161 | |
| 1162 | return sprintf(buf, "%d\n", enabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1165 | static ssize_t cmb_enable_store(struct device *dev, |
| 1166 | struct device_attribute *attr, const char *buf, |
| 1167 | size_t c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | { |
Sebastian Ott | 279b8f9 | 2015-09-07 19:50:25 +0200 | [diff] [blame] | 1169 | struct ccw_device *cdev = to_ccwdev(dev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 1170 | unsigned long val; |
Sebastian Ott | 279b8f9 | 2015-09-07 19:50:25 +0200 | [diff] [blame] | 1171 | int ret; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 1172 | |
Jingoo Han | 0178722 | 2013-07-22 10:18:15 +0900 | [diff] [blame] | 1173 | ret = kstrtoul(buf, 16, &val); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 1174 | if (ret) |
| 1175 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 1177 | switch (val) { |
| 1178 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | ret = disable_cmf(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | break; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 1181 | case 1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | ret = enable_cmf(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | break; |
Sebastian Ott | 279b8f9 | 2015-09-07 19:50:25 +0200 | [diff] [blame] | 1184 | default: |
| 1185 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
Sebastian Ott | 279b8f9 | 2015-09-07 19:50:25 +0200 | [diff] [blame] | 1188 | return ret ? ret : c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
Sebastian Ott | 279b8f9 | 2015-09-07 19:50:25 +0200 | [diff] [blame] | 1190 | DEVICE_ATTR_RW(cmb_enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1192 | int ccw_set_cmf(struct ccw_device *cdev, int enable) |
| 1193 | { |
| 1194 | return cmbops->set(cdev, enable ? 2 : 0); |
| 1195 | } |
| 1196 | |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 1197 | /** |
| 1198 | * enable_cmf() - switch on the channel measurement for a specific device |
| 1199 | * @cdev: The ccw device to be enabled |
| 1200 | * |
| 1201 | * Returns %0 for success or a negative error value. |
| 1202 | * |
| 1203 | * Context: |
| 1204 | * non-atomic |
| 1205 | */ |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1206 | int enable_cmf(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | { |
| 1208 | int ret; |
| 1209 | |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1210 | device_lock(&cdev->dev); |
Sebastian Ott | a6ef156 | 2015-09-07 19:51:39 +0200 | [diff] [blame] | 1211 | get_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | ret = cmbops->alloc(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | if (ret) |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1214 | goto out; |
| 1215 | cmbops->reset(cdev); |
| 1216 | ret = sysfs_create_group(&cdev->dev.kobj, cmbops->attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | if (ret) { |
| 1218 | cmbops->free(cdev); |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1219 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | } |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1221 | ret = cmbops->set(cdev, 2); |
| 1222 | if (ret) { |
| 1223 | sysfs_remove_group(&cdev->dev.kobj, cmbops->attr_group); |
| 1224 | cmbops->free(cdev); |
| 1225 | } |
| 1226 | out: |
Sebastian Ott | a6ef156 | 2015-09-07 19:51:39 +0200 | [diff] [blame] | 1227 | if (ret) |
| 1228 | put_device(&cdev->dev); |
| 1229 | |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1230 | device_unlock(&cdev->dev); |
| 1231 | return ret; |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * __disable_cmf() - switch off the channel measurement for a specific device |
| 1236 | * @cdev: The ccw device to be disabled |
| 1237 | * |
| 1238 | * Returns %0 for success or a negative error value. |
| 1239 | * |
| 1240 | * Context: |
| 1241 | * non-atomic, device_lock() held. |
| 1242 | */ |
| 1243 | int __disable_cmf(struct ccw_device *cdev) |
| 1244 | { |
| 1245 | int ret; |
| 1246 | |
| 1247 | ret = cmbops->set(cdev, 0); |
| 1248 | if (ret) |
| 1249 | return ret; |
| 1250 | |
| 1251 | sysfs_remove_group(&cdev->dev.kobj, cmbops->attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | cmbops->free(cdev); |
Sebastian Ott | a6ef156 | 2015-09-07 19:51:39 +0200 | [diff] [blame] | 1253 | put_device(&cdev->dev); |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | return ret; |
| 1256 | } |
| 1257 | |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 1258 | /** |
| 1259 | * disable_cmf() - switch off the channel measurement for a specific device |
| 1260 | * @cdev: The ccw device to be disabled |
| 1261 | * |
| 1262 | * Returns %0 for success or a negative error value. |
| 1263 | * |
| 1264 | * Context: |
| 1265 | * non-atomic |
| 1266 | */ |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1267 | int disable_cmf(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | { |
| 1269 | int ret; |
| 1270 | |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1271 | device_lock(&cdev->dev); |
| 1272 | ret = __disable_cmf(cdev); |
| 1273 | device_unlock(&cdev->dev); |
| 1274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return ret; |
| 1276 | } |
| 1277 | |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 1278 | /** |
| 1279 | * cmf_read() - read one value from the current channel measurement block |
| 1280 | * @cdev: the channel to be read |
| 1281 | * @index: the index of the value to be read |
| 1282 | * |
| 1283 | * Returns the value read or %0 if the value cannot be read. |
| 1284 | * |
| 1285 | * Context: |
| 1286 | * any |
| 1287 | */ |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1288 | u64 cmf_read(struct ccw_device *cdev, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | { |
| 1290 | return cmbops->read(cdev, index); |
| 1291 | } |
| 1292 | |
Cornelia Huck | c020871 | 2007-10-12 16:11:16 +0200 | [diff] [blame] | 1293 | /** |
| 1294 | * cmf_readall() - read the current channel measurement block |
| 1295 | * @cdev: the channel to be read |
| 1296 | * @data: a pointer to a data block that will be filled |
| 1297 | * |
| 1298 | * Returns %0 on success, a negative error value otherwise. |
| 1299 | * |
| 1300 | * Context: |
| 1301 | * any |
| 1302 | */ |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1303 | int cmf_readall(struct ccw_device *cdev, struct cmbdata *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | { |
| 1305 | return cmbops->readall(cdev, data); |
| 1306 | } |
| 1307 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1308 | /* Reenable cmf when a disconnected device becomes available again. */ |
| 1309 | int cmf_reenable(struct ccw_device *cdev) |
| 1310 | { |
| 1311 | cmbops->reset(cdev); |
| 1312 | return cmbops->set(cdev, 2); |
| 1313 | } |
| 1314 | |
Sebastian Ott | ab97d21 | 2015-09-09 10:29:59 +0200 | [diff] [blame] | 1315 | /** |
| 1316 | * cmf_reactivate() - reactivate measurement block updates |
| 1317 | * |
| 1318 | * Use this during resume from hibernate. |
| 1319 | */ |
| 1320 | void cmf_reactivate(void) |
| 1321 | { |
| 1322 | spin_lock(&cmb_area.lock); |
| 1323 | if (!list_empty(&cmb_area.list)) |
| 1324 | cmf_activate(cmb_area.mem, 1); |
| 1325 | spin_unlock(&cmb_area.lock); |
| 1326 | } |
| 1327 | |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 1328 | static int __init init_cmbe(void) |
| 1329 | { |
| 1330 | cmbe_cache = kmem_cache_create("cmbe_cache", sizeof(struct cmbe), |
| 1331 | __alignof__(struct cmbe), 0, NULL); |
| 1332 | |
| 1333 | return cmbe_cache ? 0 : -ENOMEM; |
| 1334 | } |
| 1335 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1336 | static int __init init_cmf(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | { |
| 1338 | char *format_string; |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 1339 | char *detect_string; |
| 1340 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1342 | /* |
| 1343 | * If the user did not give a parameter, see if we are running on a |
| 1344 | * machine supporting extended measurement blocks, otherwise fall back |
| 1345 | * to basic mode. |
| 1346 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | if (format == CMF_AUTODETECT) { |
Cornelia Huck | 75784c0 | 2008-07-14 09:58:57 +0200 | [diff] [blame] | 1348 | if (!css_general_characteristics.ext_mb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | format = CMF_BASIC; |
| 1350 | } else { |
| 1351 | format = CMF_EXTENDED; |
| 1352 | } |
| 1353 | detect_string = "autodetected"; |
| 1354 | } else { |
| 1355 | detect_string = "parameter"; |
| 1356 | } |
| 1357 | |
| 1358 | switch (format) { |
| 1359 | case CMF_BASIC: |
| 1360 | format_string = "basic"; |
| 1361 | cmbops = &cmbops_basic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | break; |
| 1363 | case CMF_EXTENDED: |
Cornelia Huck | fc5019c | 2007-10-12 16:11:15 +0200 | [diff] [blame] | 1364 | format_string = "extended"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | cmbops = &cmbops_extended; |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 1366 | |
| 1367 | ret = init_cmbe(); |
| 1368 | if (ret) |
| 1369 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | break; |
| 1371 | default: |
Sebastian Ott | 45bf4b9 | 2015-09-07 19:53:01 +0200 | [diff] [blame] | 1372 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | } |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 1374 | pr_info("Channel measurement facility initialized using format " |
| 1375 | "%s (mode %s)\n", format_string, detect_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | return 0; |
| 1377 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | module_init(init_cmf); |
| 1379 | |
| 1380 | |
| 1381 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); |
| 1382 | MODULE_LICENSE("GPL"); |
| 1383 | MODULE_DESCRIPTION("channel measurement facility base driver\n" |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 1384 | "Copyright IBM Corp. 2003\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
| 1386 | EXPORT_SYMBOL_GPL(enable_cmf); |
| 1387 | EXPORT_SYMBOL_GPL(disable_cmf); |
| 1388 | EXPORT_SYMBOL_GPL(cmf_read); |
| 1389 | EXPORT_SYMBOL_GPL(cmf_readall); |