Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 2 | * driver for channel subsystem |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2002, 2010 |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 5 | * |
| 6 | * Author(s): 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 | */ |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 9 | |
| 10 | #define KMSG_COMPONENT "cio" |
| 11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/list.h> |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 19 | #include <linux/reboot.h> |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 20 | #include <linux/suspend.h> |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 21 | #include <linux/proc_fs.h> |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 22 | #include <asm/isc.h> |
Heiko Carstens | f5daba1 | 2009-03-26 15:24:01 +0100 | [diff] [blame] | 23 | #include <asm/crw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include "css.h" |
| 26 | #include "cio.h" |
| 27 | #include "cio_debug.h" |
| 28 | #include "ioasm.h" |
| 29 | #include "chsc.h" |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 30 | #include "device.h" |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 31 | #include "idset.h" |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 32 | #include "chp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | int css_init_done = 0; |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 35 | int max_ssid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 37 | struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1]; |
Sebastian Ott | 3041b6a | 2011-03-15 17:08:31 +0100 | [diff] [blame] | 38 | static struct bus_type css_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 40 | int |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 41 | for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data) |
| 42 | { |
| 43 | struct subchannel_id schid; |
| 44 | int ret; |
| 45 | |
| 46 | init_subchannel_id(&schid); |
| 47 | ret = -ENODEV; |
| 48 | do { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 49 | do { |
| 50 | ret = fn(schid, data); |
| 51 | if (ret) |
| 52 | break; |
| 53 | } while (schid.sch_no++ < __MAX_SUBCHANNEL); |
| 54 | schid.sch_no = 0; |
| 55 | } while (schid.ssid++ < max_ssid); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 56 | return ret; |
| 57 | } |
| 58 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 59 | struct cb_data { |
| 60 | void *data; |
| 61 | struct idset *set; |
| 62 | int (*fn_known_sch)(struct subchannel *, void *); |
| 63 | int (*fn_unknown_sch)(struct subchannel_id, void *); |
| 64 | }; |
| 65 | |
| 66 | static int call_fn_known_sch(struct device *dev, void *data) |
| 67 | { |
| 68 | struct subchannel *sch = to_subchannel(dev); |
| 69 | struct cb_data *cb = data; |
| 70 | int rc = 0; |
| 71 | |
| 72 | idset_sch_del(cb->set, sch->schid); |
| 73 | if (cb->fn_known_sch) |
| 74 | rc = cb->fn_known_sch(sch, cb->data); |
| 75 | return rc; |
| 76 | } |
| 77 | |
| 78 | static int call_fn_unknown_sch(struct subchannel_id schid, void *data) |
| 79 | { |
| 80 | struct cb_data *cb = data; |
| 81 | int rc = 0; |
| 82 | |
| 83 | if (idset_sch_contains(cb->set, schid)) |
| 84 | rc = cb->fn_unknown_sch(schid, cb->data); |
| 85 | return rc; |
| 86 | } |
| 87 | |
Sebastian Ott | 90ac24a | 2009-03-26 15:24:11 +0100 | [diff] [blame] | 88 | static int call_fn_all_sch(struct subchannel_id schid, void *data) |
| 89 | { |
| 90 | struct cb_data *cb = data; |
| 91 | struct subchannel *sch; |
| 92 | int rc = 0; |
| 93 | |
| 94 | sch = get_subchannel_by_schid(schid); |
| 95 | if (sch) { |
| 96 | if (cb->fn_known_sch) |
| 97 | rc = cb->fn_known_sch(sch, cb->data); |
| 98 | put_device(&sch->dev); |
| 99 | } else { |
| 100 | if (cb->fn_unknown_sch) |
| 101 | rc = cb->fn_unknown_sch(schid, cb->data); |
| 102 | } |
| 103 | |
| 104 | return rc; |
| 105 | } |
| 106 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 107 | int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *), |
| 108 | int (*fn_unknown)(struct subchannel_id, |
| 109 | void *), void *data) |
| 110 | { |
| 111 | struct cb_data cb; |
| 112 | int rc; |
| 113 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 114 | cb.data = data; |
| 115 | cb.fn_known_sch = fn_known; |
| 116 | cb.fn_unknown_sch = fn_unknown; |
Sebastian Ott | 90ac24a | 2009-03-26 15:24:11 +0100 | [diff] [blame] | 117 | |
| 118 | cb.set = idset_sch_new(); |
| 119 | if (!cb.set) |
| 120 | /* fall back to brute force scanning in case of oom */ |
| 121 | return for_each_subchannel(call_fn_all_sch, &cb); |
| 122 | |
| 123 | idset_fill(cb.set); |
| 124 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 125 | /* Process registered subchannels. */ |
| 126 | rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch); |
| 127 | if (rc) |
| 128 | goto out; |
| 129 | /* Process unregistered subchannels. */ |
| 130 | if (fn_unknown) |
| 131 | rc = for_each_subchannel(call_fn_unknown_sch, &cb); |
| 132 | out: |
| 133 | idset_free(cb.set); |
| 134 | |
| 135 | return rc; |
| 136 | } |
| 137 | |
Peter Oberparleiter | 390935a | 2009-12-07 12:51:18 +0100 | [diff] [blame] | 138 | static void css_sch_todo(struct work_struct *work); |
| 139 | |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 140 | static int css_sch_create_locks(struct subchannel *sch) |
| 141 | { |
| 142 | sch->lock = kmalloc(sizeof(*sch->lock), GFP_KERNEL); |
| 143 | if (!sch->lock) |
| 144 | return -ENOMEM; |
| 145 | |
| 146 | spin_lock_init(sch->lock); |
| 147 | mutex_init(&sch->reg_mutex); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 152 | static void css_subchannel_release(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 154 | struct subchannel *sch = to_subchannel(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 156 | sch->config.intparm = 0; |
| 157 | cio_commit_config(sch); |
| 158 | kfree(sch->lock); |
| 159 | kfree(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 162 | struct subchannel *css_alloc_subchannel(struct subchannel_id schid) |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 163 | { |
| 164 | struct subchannel *sch; |
| 165 | int ret; |
| 166 | |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 167 | sch = kzalloc(sizeof(*sch), GFP_KERNEL | GFP_DMA); |
| 168 | if (!sch) |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 169 | return ERR_PTR(-ENOMEM); |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 170 | |
| 171 | ret = cio_validate_subchannel(sch, schid); |
| 172 | if (ret < 0) |
| 173 | goto err; |
| 174 | |
| 175 | ret = css_sch_create_locks(sch); |
| 176 | if (ret) |
| 177 | goto err; |
| 178 | |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 179 | INIT_WORK(&sch->todo_work, css_sch_todo); |
| 180 | sch->dev.release = &css_subchannel_release; |
| 181 | device_initialize(&sch->dev); |
| 182 | return sch; |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 183 | |
| 184 | err: |
| 185 | kfree(sch); |
| 186 | return ERR_PTR(ret); |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Cornelia Huck | 07c6a33 | 2007-07-27 12:29:10 +0200 | [diff] [blame] | 189 | static int css_sch_device_register(struct subchannel *sch) |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 190 | { |
| 191 | int ret; |
| 192 | |
| 193 | mutex_lock(&sch->reg_mutex); |
Sebastian Ott | 6ee4fec | 2009-09-11 10:28:25 +0200 | [diff] [blame] | 194 | dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid, |
| 195 | sch->schid.sch_no); |
Sebastian Ott | c135ad1 | 2013-04-13 12:58:55 +0200 | [diff] [blame] | 196 | ret = device_add(&sch->dev); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 197 | mutex_unlock(&sch->reg_mutex); |
| 198 | return ret; |
| 199 | } |
| 200 | |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 201 | /** |
| 202 | * css_sch_device_unregister - unregister a subchannel |
| 203 | * @sch: subchannel to be unregistered |
| 204 | */ |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 205 | void css_sch_device_unregister(struct subchannel *sch) |
| 206 | { |
| 207 | mutex_lock(&sch->reg_mutex); |
Sebastian Ott | ef60cd1 | 2008-07-14 09:59:20 +0200 | [diff] [blame] | 208 | if (device_is_registered(&sch->dev)) |
| 209 | device_unregister(&sch->dev); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 210 | mutex_unlock(&sch->reg_mutex); |
| 211 | } |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 212 | EXPORT_SYMBOL_GPL(css_sch_device_unregister); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 213 | |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 214 | static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw) |
| 215 | { |
| 216 | int i; |
| 217 | int mask; |
| 218 | |
| 219 | memset(ssd, 0, sizeof(struct chsc_ssd_info)); |
| 220 | ssd->path_mask = pmcw->pim; |
| 221 | for (i = 0; i < 8; i++) { |
| 222 | mask = 0x80 >> i; |
| 223 | if (pmcw->pim & mask) { |
| 224 | chp_id_init(&ssd->chpid[i]); |
| 225 | ssd->chpid[i].id = pmcw->chpid[i]; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static void ssd_register_chpids(struct chsc_ssd_info *ssd) |
| 231 | { |
| 232 | int i; |
| 233 | int mask; |
| 234 | |
| 235 | for (i = 0; i < 8; i++) { |
| 236 | mask = 0x80 >> i; |
| 237 | if (ssd->path_mask & mask) |
| 238 | if (!chp_is_registered(ssd->chpid[i])) |
| 239 | chp_new(ssd->chpid[i]); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | void css_update_ssd_info(struct subchannel *sch) |
| 244 | { |
| 245 | int ret; |
| 246 | |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 247 | ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info); |
| 248 | if (ret) |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 249 | ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw); |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 250 | |
| 251 | ssd_register_chpids(&sch->ssd_info); |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 254 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
| 255 | char *buf) |
| 256 | { |
| 257 | struct subchannel *sch = to_subchannel(dev); |
| 258 | |
| 259 | return sprintf(buf, "%01x\n", sch->st); |
| 260 | } |
| 261 | |
| 262 | static DEVICE_ATTR(type, 0444, type_show, NULL); |
| 263 | |
| 264 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 265 | char *buf) |
| 266 | { |
| 267 | struct subchannel *sch = to_subchannel(dev); |
| 268 | |
| 269 | return sprintf(buf, "css:t%01X\n", sch->st); |
| 270 | } |
| 271 | |
| 272 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); |
| 273 | |
| 274 | static struct attribute *subch_attrs[] = { |
| 275 | &dev_attr_type.attr, |
| 276 | &dev_attr_modalias.attr, |
| 277 | NULL, |
| 278 | }; |
| 279 | |
| 280 | static struct attribute_group subch_attr_group = { |
| 281 | .attrs = subch_attrs, |
| 282 | }; |
| 283 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 284 | static const struct attribute_group *default_subch_attr_groups[] = { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 285 | &subch_attr_group, |
| 286 | NULL, |
| 287 | }; |
| 288 | |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 289 | int css_register_subchannel(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | int ret; |
| 292 | |
| 293 | /* Initialize the subchannel structure */ |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 294 | sch->dev.parent = &channel_subsystems[0]->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | sch->dev.bus = &css_bus_type; |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 296 | sch->dev.groups = default_subch_attr_groups; |
Cornelia Huck | 5bf04b2 | 2007-10-22 12:52:41 +0200 | [diff] [blame] | 297 | /* |
| 298 | * We don't want to generate uevents for I/O subchannels that don't |
| 299 | * have a working ccw device behind them since they will be |
| 300 | * unregistered before they can be used anyway, so we delay the add |
| 301 | * uevent until after device recognition was successful. |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 302 | * Note that we suppress the uevent for all subchannel types; |
| 303 | * the subchannel driver can decide itself when it wants to inform |
| 304 | * userspace of its existence. |
Cornelia Huck | 5bf04b2 | 2007-10-22 12:52:41 +0200 | [diff] [blame] | 305 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 306 | dev_set_uevent_suppress(&sch->dev, 1); |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 307 | css_update_ssd_info(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /* make it known to the system */ |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 309 | ret = css_sch_device_register(sch); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 310 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 311 | CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n", |
| 312 | sch->schid.ssid, sch->schid.sch_no, ret); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 313 | return ret; |
| 314 | } |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 315 | if (!sch->driver) { |
| 316 | /* |
| 317 | * No driver matched. Generate the uevent now so that |
| 318 | * a fitting driver module may be loaded based on the |
| 319 | * modalias. |
| 320 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 321 | dev_set_uevent_suppress(&sch->dev, 0); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 322 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
| 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return ret; |
| 325 | } |
| 326 | |
Sebastian Ott | 4e5ebd5 | 2013-04-13 13:04:49 +0200 | [diff] [blame] | 327 | static int css_probe_device(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | struct subchannel *sch; |
Sebastian Ott | 4e5ebd5 | 2013-04-13 13:04:49 +0200 | [diff] [blame] | 330 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 332 | sch = css_alloc_subchannel(schid); |
| 333 | if (IS_ERR(sch)) |
| 334 | return PTR_ERR(sch); |
| 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | ret = css_register_subchannel(sch); |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 337 | if (ret) |
| 338 | put_device(&sch->dev); |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return ret; |
| 341 | } |
| 342 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 343 | static int |
| 344 | check_subchannel(struct device * dev, void * data) |
| 345 | { |
| 346 | struct subchannel *sch; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 347 | struct subchannel_id *schid = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 348 | |
| 349 | sch = to_subchannel(dev); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 350 | return schid_equal(&sch->schid, schid); |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | struct subchannel * |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 354 | get_subchannel_by_schid(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | struct device *dev; |
| 357 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 358 | dev = bus_find_device(&css_bus_type, NULL, |
Cornelia Huck | 12975ae | 2006-10-11 15:31:47 +0200 | [diff] [blame] | 359 | &schid, check_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 361 | return dev ? to_subchannel(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 364 | /** |
| 365 | * css_sch_is_valid() - check if a subchannel is valid |
| 366 | * @schib: subchannel information block for the subchannel |
| 367 | */ |
| 368 | int css_sch_is_valid(struct schib *schib) |
| 369 | { |
| 370 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv) |
| 371 | return 0; |
Cornelia Huck | b3a686f | 2008-07-14 09:58:48 +0200 | [diff] [blame] | 372 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w) |
| 373 | return 0; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 374 | return 1; |
| 375 | } |
| 376 | EXPORT_SYMBOL_GPL(css_sch_is_valid); |
| 377 | |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 378 | static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow) |
| 379 | { |
| 380 | struct schib schib; |
| 381 | |
| 382 | if (!slow) { |
| 383 | /* Will be done on the slow path. */ |
| 384 | return -EAGAIN; |
| 385 | } |
Sebastian Ott | cec8546 | 2012-10-15 12:24:56 +0200 | [diff] [blame] | 386 | if (stsch_err(schid, &schib)) { |
| 387 | /* Subchannel is not provided. */ |
| 388 | return -ENXIO; |
| 389 | } |
| 390 | if (!css_sch_is_valid(&schib)) { |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 391 | /* Unusable - ignore. */ |
| 392 | return 0; |
| 393 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 394 | CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid.ssid, |
| 395 | schid.sch_no); |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 396 | |
| 397 | return css_probe_device(schid); |
| 398 | } |
| 399 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 400 | static int css_evaluate_known_subchannel(struct subchannel *sch, int slow) |
| 401 | { |
| 402 | int ret = 0; |
| 403 | |
| 404 | if (sch->driver) { |
| 405 | if (sch->driver->sch_event) |
| 406 | ret = sch->driver->sch_event(sch, slow); |
| 407 | else |
| 408 | dev_dbg(&sch->dev, |
| 409 | "Got subchannel machine check but " |
| 410 | "no sch_event handler provided.\n"); |
| 411 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 412 | if (ret != 0 && ret != -EAGAIN) { |
| 413 | CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n", |
| 414 | sch->schid.ssid, sch->schid.sch_no, ret); |
| 415 | } |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 416 | return ret; |
| 417 | } |
| 418 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 419 | static void css_evaluate_subchannel(struct subchannel_id schid, int slow) |
Peter Oberparleiter | 564337f | 2006-09-20 16:00:01 +0200 | [diff] [blame] | 420 | { |
| 421 | struct subchannel *sch; |
| 422 | int ret; |
| 423 | |
| 424 | sch = get_subchannel_by_schid(schid); |
| 425 | if (sch) { |
| 426 | ret = css_evaluate_known_subchannel(sch, slow); |
| 427 | put_device(&sch->dev); |
| 428 | } else |
| 429 | ret = css_evaluate_new_subchannel(schid, slow); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 430 | if (ret == -EAGAIN) |
| 431 | css_schedule_eval(schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Sebastian Ott | 817e500 | 2011-12-01 13:32:19 +0100 | [diff] [blame] | 434 | /** |
| 435 | * css_sched_sch_todo - schedule a subchannel operation |
| 436 | * @sch: subchannel |
| 437 | * @todo: todo |
| 438 | * |
| 439 | * Schedule the operation identified by @todo to be performed on the slow path |
| 440 | * workqueue. Do nothing if another operation with higher priority is already |
| 441 | * scheduled. Needs to be called with subchannel lock held. |
| 442 | */ |
| 443 | void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo) |
| 444 | { |
| 445 | CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n", |
| 446 | sch->schid.ssid, sch->schid.sch_no, todo); |
| 447 | if (sch->todo >= todo) |
| 448 | return; |
| 449 | /* Get workqueue ref. */ |
| 450 | if (!get_device(&sch->dev)) |
| 451 | return; |
| 452 | sch->todo = todo; |
| 453 | if (!queue_work(cio_work_q, &sch->todo_work)) { |
| 454 | /* Already queued, release workqueue ref. */ |
| 455 | put_device(&sch->dev); |
| 456 | } |
| 457 | } |
Sebastian Ott | 01c5e6d | 2012-08-28 16:42:37 +0200 | [diff] [blame] | 458 | EXPORT_SYMBOL_GPL(css_sched_sch_todo); |
Sebastian Ott | 817e500 | 2011-12-01 13:32:19 +0100 | [diff] [blame] | 459 | |
| 460 | static void css_sch_todo(struct work_struct *work) |
| 461 | { |
| 462 | struct subchannel *sch; |
| 463 | enum sch_todo todo; |
| 464 | int ret; |
| 465 | |
| 466 | sch = container_of(work, struct subchannel, todo_work); |
| 467 | /* Find out todo. */ |
| 468 | spin_lock_irq(sch->lock); |
| 469 | todo = sch->todo; |
| 470 | CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch->schid.ssid, |
| 471 | sch->schid.sch_no, todo); |
| 472 | sch->todo = SCH_TODO_NOTHING; |
| 473 | spin_unlock_irq(sch->lock); |
| 474 | /* Perform todo. */ |
| 475 | switch (todo) { |
| 476 | case SCH_TODO_NOTHING: |
| 477 | break; |
| 478 | case SCH_TODO_EVAL: |
| 479 | ret = css_evaluate_known_subchannel(sch, 1); |
| 480 | if (ret == -EAGAIN) { |
| 481 | spin_lock_irq(sch->lock); |
| 482 | css_sched_sch_todo(sch, todo); |
| 483 | spin_unlock_irq(sch->lock); |
| 484 | } |
| 485 | break; |
| 486 | case SCH_TODO_UNREG: |
| 487 | css_sch_device_unregister(sch); |
| 488 | break; |
| 489 | } |
| 490 | /* Release workqueue ref. */ |
| 491 | put_device(&sch->dev); |
| 492 | } |
| 493 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 494 | static struct idset *slow_subchannel_set; |
| 495 | static spinlock_t slow_subchannel_lock; |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 496 | static wait_queue_head_t css_eval_wq; |
| 497 | static atomic_t css_eval_scheduled; |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 498 | |
| 499 | static int __init slow_subchannel_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 501 | spin_lock_init(&slow_subchannel_lock); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 502 | atomic_set(&css_eval_scheduled, 0); |
| 503 | init_waitqueue_head(&css_eval_wq); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 504 | slow_subchannel_set = idset_sch_new(); |
| 505 | if (!slow_subchannel_set) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 506 | CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n"); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 507 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 509 | return 0; |
| 510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 512 | static int slow_eval_known_fn(struct subchannel *sch, void *data) |
| 513 | { |
| 514 | int eval; |
| 515 | int rc; |
| 516 | |
| 517 | spin_lock_irq(&slow_subchannel_lock); |
| 518 | eval = idset_sch_contains(slow_subchannel_set, sch->schid); |
| 519 | idset_sch_del(slow_subchannel_set, sch->schid); |
| 520 | spin_unlock_irq(&slow_subchannel_lock); |
| 521 | if (eval) { |
| 522 | rc = css_evaluate_known_subchannel(sch, 1); |
| 523 | if (rc == -EAGAIN) |
| 524 | css_schedule_eval(sch->schid); |
| 525 | } |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | static int slow_eval_unknown_fn(struct subchannel_id schid, void *data) |
| 530 | { |
| 531 | int eval; |
| 532 | int rc = 0; |
| 533 | |
| 534 | spin_lock_irq(&slow_subchannel_lock); |
| 535 | eval = idset_sch_contains(slow_subchannel_set, schid); |
| 536 | idset_sch_del(slow_subchannel_set, schid); |
| 537 | spin_unlock_irq(&slow_subchannel_lock); |
| 538 | if (eval) { |
| 539 | rc = css_evaluate_new_subchannel(schid, 1); |
| 540 | switch (rc) { |
| 541 | case -EAGAIN: |
| 542 | css_schedule_eval(schid); |
| 543 | rc = 0; |
| 544 | break; |
| 545 | case -ENXIO: |
| 546 | case -ENOMEM: |
| 547 | case -EIO: |
| 548 | /* These should abort looping */ |
Sebastian Ott | eb072a7 | 2013-08-29 20:31:06 +0200 | [diff] [blame] | 549 | spin_lock_irq(&slow_subchannel_lock); |
Sebastian Ott | cec8546 | 2012-10-15 12:24:56 +0200 | [diff] [blame] | 550 | idset_sch_del_subseq(slow_subchannel_set, schid); |
Sebastian Ott | eb072a7 | 2013-08-29 20:31:06 +0200 | [diff] [blame] | 551 | spin_unlock_irq(&slow_subchannel_lock); |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 552 | break; |
| 553 | default: |
| 554 | rc = 0; |
| 555 | } |
| 556 | } |
| 557 | return rc; |
| 558 | } |
| 559 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 560 | static void css_slow_path_func(struct work_struct *unused) |
| 561 | { |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 562 | unsigned long flags; |
| 563 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 564 | CIO_TRACE_EVENT(4, "slowpath"); |
Peter Oberparleiter | e82a156 | 2008-01-26 14:10:48 +0100 | [diff] [blame] | 565 | for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn, |
| 566 | NULL); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 567 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 568 | if (idset_is_empty(slow_subchannel_set)) { |
| 569 | atomic_set(&css_eval_scheduled, 0); |
| 570 | wake_up(&css_eval_wq); |
| 571 | } |
| 572 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 575 | static DECLARE_WORK(slow_path_work, css_slow_path_func); |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 576 | struct workqueue_struct *cio_work_q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 578 | void css_schedule_eval(struct subchannel_id schid) |
| 579 | { |
| 580 | unsigned long flags; |
| 581 | |
| 582 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 583 | idset_sch_add(slow_subchannel_set, schid); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 584 | atomic_set(&css_eval_scheduled, 1); |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 585 | queue_work(cio_work_q, &slow_path_work); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 586 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 587 | } |
| 588 | |
| 589 | void css_schedule_eval_all(void) |
| 590 | { |
| 591 | unsigned long flags; |
| 592 | |
| 593 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 594 | idset_fill(slow_subchannel_set); |
Sebastian Ott | 2553055 | 2009-09-22 22:58:34 +0200 | [diff] [blame] | 595 | atomic_set(&css_eval_scheduled, 1); |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 596 | queue_work(cio_work_q, &slow_path_work); |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 597 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 598 | } |
| 599 | |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 600 | static int __unset_registered(struct device *dev, void *data) |
| 601 | { |
| 602 | struct idset *set = data; |
| 603 | struct subchannel *sch = to_subchannel(dev); |
| 604 | |
| 605 | idset_sch_del(set, sch->schid); |
| 606 | return 0; |
| 607 | } |
| 608 | |
Sebastian Ott | a8481c2 | 2010-10-25 16:10:23 +0200 | [diff] [blame] | 609 | static void css_schedule_eval_all_unreg(void) |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 610 | { |
| 611 | unsigned long flags; |
| 612 | struct idset *unreg_set; |
| 613 | |
| 614 | /* Find unregistered subchannels. */ |
| 615 | unreg_set = idset_sch_new(); |
| 616 | if (!unreg_set) { |
| 617 | /* Fallback. */ |
| 618 | css_schedule_eval_all(); |
| 619 | return; |
| 620 | } |
| 621 | idset_fill(unreg_set); |
| 622 | bus_for_each_dev(&css_bus_type, NULL, unreg_set, __unset_registered); |
| 623 | /* Apply to slow_subchannel_set. */ |
| 624 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 625 | idset_add_set(slow_subchannel_set, unreg_set); |
| 626 | atomic_set(&css_eval_scheduled, 1); |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 627 | queue_work(cio_work_q, &slow_path_work); |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 628 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 629 | idset_free(unreg_set); |
| 630 | } |
| 631 | |
Cornelia Huck | 22806dc | 2008-04-17 07:45:59 +0200 | [diff] [blame] | 632 | void css_wait_for_slow_path(void) |
| 633 | { |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 634 | flush_workqueue(cio_work_q); |
Cornelia Huck | 22806dc | 2008-04-17 07:45:59 +0200 | [diff] [blame] | 635 | } |
| 636 | |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 637 | /* Schedule reprobing of all unregistered subchannels. */ |
| 638 | void css_schedule_reprobe(void) |
| 639 | { |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 640 | css_schedule_eval_all_unreg(); |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 641 | } |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 642 | EXPORT_SYMBOL_GPL(css_schedule_reprobe); |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | * Called from the machine check handler for subchannel report words. |
| 646 | */ |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 647 | static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 649 | struct subchannel_id mchk_schid; |
Sebastian Ott | 4bc4e96 | 2011-01-05 12:47:58 +0100 | [diff] [blame] | 650 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 652 | if (overflow) { |
| 653 | css_schedule_eval_all(); |
| 654 | return; |
| 655 | } |
| 656 | CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, " |
| 657 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", |
| 658 | crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc, |
| 659 | crw0->erc, crw0->rsid); |
| 660 | if (crw1) |
| 661 | CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, " |
| 662 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", |
| 663 | crw1->slct, crw1->oflw, crw1->chn, crw1->rsc, |
| 664 | crw1->anc, crw1->erc, crw1->rsid); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 665 | init_subchannel_id(&mchk_schid); |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 666 | mchk_schid.sch_no = crw0->rsid; |
| 667 | if (crw1) |
Sebastian Ott | 8d7bfb4 | 2010-12-01 10:08:02 +0100 | [diff] [blame] | 668 | mchk_schid.ssid = (crw1->rsid >> 4) & 3; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 669 | |
Sebastian Ott | 4bc4e96 | 2011-01-05 12:47:58 +0100 | [diff] [blame] | 670 | if (crw0->erc == CRW_ERC_PMOD) { |
| 671 | sch = get_subchannel_by_schid(mchk_schid); |
| 672 | if (sch) { |
| 673 | css_update_ssd_info(sch); |
| 674 | put_device(&sch->dev); |
| 675 | } |
| 676 | } |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 677 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | * Since we are always presented with IPI in the CRW, we have to |
| 679 | * use stsch() to find out if the subchannel in question has come |
| 680 | * or gone. |
| 681 | */ |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 682 | css_evaluate_subchannel(mchk_schid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static void __init |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 686 | css_generate_pgid(struct channel_subsystem *css, u32 tod_high) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | { |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 688 | struct cpuid cpu_id; |
| 689 | |
Cornelia Huck | 75784c0 | 2008-07-14 09:58:57 +0200 | [diff] [blame] | 690 | if (css_general_characteristics.mcss) { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 691 | css->global_pgid.pgid_high.ext_cssid.version = 0x80; |
| 692 | css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid; |
| 693 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | #ifdef CONFIG_SMP |
Martin Schwidefsky | 7b46848 | 2009-03-26 15:24:42 +0100 | [diff] [blame] | 695 | css->global_pgid.pgid_high.cpu_addr = stap(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | #else |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 697 | css->global_pgid.pgid_high.cpu_addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | #endif |
| 699 | } |
Martin Schwidefsky | 94038a9 | 2010-05-17 10:00:00 +0200 | [diff] [blame] | 700 | get_cpu_id(&cpu_id); |
| 701 | css->global_pgid.cpu_id = cpu_id.ident; |
| 702 | css->global_pgid.cpu_model = cpu_id.machine; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 703 | css->global_pgid.tod_high = tod_high; |
| 704 | |
| 705 | } |
| 706 | |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 707 | static void |
| 708 | channel_subsystem_release(struct device *dev) |
| 709 | { |
| 710 | struct channel_subsystem *css; |
| 711 | |
| 712 | css = to_css(dev); |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 713 | mutex_destroy(&css->mutex); |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 714 | if (css->pseudo_subchannel) { |
| 715 | /* Implies that it has been generated but never registered. */ |
| 716 | css_subchannel_release(&css->pseudo_subchannel->dev); |
| 717 | css->pseudo_subchannel = NULL; |
| 718 | } |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 719 | kfree(css); |
| 720 | } |
| 721 | |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 722 | static ssize_t |
| 723 | css_cm_enable_show(struct device *dev, struct device_attribute *attr, |
| 724 | char *buf) |
| 725 | { |
| 726 | struct channel_subsystem *css = to_css(dev); |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 727 | int ret; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 728 | |
| 729 | if (!css) |
| 730 | return 0; |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 731 | mutex_lock(&css->mutex); |
| 732 | ret = sprintf(buf, "%x\n", css->cm_enabled); |
| 733 | mutex_unlock(&css->mutex); |
| 734 | return ret; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | static ssize_t |
| 738 | css_cm_enable_store(struct device *dev, struct device_attribute *attr, |
| 739 | const char *buf, size_t count) |
| 740 | { |
| 741 | struct channel_subsystem *css = to_css(dev); |
| 742 | int ret; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 743 | unsigned long val; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 744 | |
Jingoo Han | 0178722 | 2013-07-22 10:18:15 +0900 | [diff] [blame] | 745 | ret = kstrtoul(buf, 16, &val); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 746 | if (ret) |
| 747 | return ret; |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 748 | mutex_lock(&css->mutex); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 749 | switch (val) { |
| 750 | case 0: |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 751 | ret = css->cm_enabled ? chsc_secm(css, 0) : 0; |
| 752 | break; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 753 | case 1: |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 754 | ret = css->cm_enabled ? 0 : chsc_secm(css, 1); |
| 755 | break; |
| 756 | default: |
| 757 | ret = -EINVAL; |
| 758 | } |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 759 | mutex_unlock(&css->mutex); |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 760 | return ret < 0 ? ret : count; |
| 761 | } |
| 762 | |
| 763 | static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store); |
| 764 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 765 | static int __init setup_css(int nr) |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 766 | { |
| 767 | u32 tod_high; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 768 | int ret; |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 769 | struct channel_subsystem *css; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 770 | |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 771 | css = channel_subsystems[nr]; |
| 772 | memset(css, 0, sizeof(struct channel_subsystem)); |
| 773 | css->pseudo_subchannel = |
| 774 | kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL); |
| 775 | if (!css->pseudo_subchannel) |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 776 | return -ENOMEM; |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 777 | css->pseudo_subchannel->dev.parent = &css->device; |
| 778 | css->pseudo_subchannel->dev.release = css_subchannel_release; |
Cornelia Huck | 1bf5b28 | 2008-10-10 21:33:10 +0200 | [diff] [blame] | 779 | dev_set_name(&css->pseudo_subchannel->dev, "defunct"); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 780 | mutex_init(&css->pseudo_subchannel->reg_mutex); |
Sebastian Ott | e5dcf00 | 2013-04-13 13:08:01 +0200 | [diff] [blame] | 781 | ret = css_sch_create_locks(css->pseudo_subchannel); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 782 | if (ret) { |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 783 | kfree(css->pseudo_subchannel); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 784 | return ret; |
| 785 | } |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 786 | mutex_init(&css->mutex); |
| 787 | css->valid = 1; |
| 788 | css->cssid = nr; |
Cornelia Huck | 1bf5b28 | 2008-10-10 21:33:10 +0200 | [diff] [blame] | 789 | dev_set_name(&css->device, "css%x", nr); |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 790 | css->device.release = channel_subsystem_release; |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 791 | tod_high = (u32) (get_tod_clock() >> 32); |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 792 | css_generate_pgid(css, tod_high); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 793 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 796 | static int css_reboot_event(struct notifier_block *this, |
| 797 | unsigned long event, |
| 798 | void *ptr) |
| 799 | { |
| 800 | int ret, i; |
| 801 | |
| 802 | ret = NOTIFY_DONE; |
| 803 | for (i = 0; i <= __MAX_CSSID; i++) { |
| 804 | struct channel_subsystem *css; |
| 805 | |
| 806 | css = channel_subsystems[i]; |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 807 | mutex_lock(&css->mutex); |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 808 | if (css->cm_enabled) |
| 809 | if (chsc_secm(css, 0)) |
| 810 | ret = NOTIFY_BAD; |
Michael Ernst | 8284fb19 | 2008-04-17 07:46:01 +0200 | [diff] [blame] | 811 | mutex_unlock(&css->mutex); |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | return ret; |
| 815 | } |
| 816 | |
| 817 | static struct notifier_block css_reboot_notifier = { |
| 818 | .notifier_call = css_reboot_event, |
| 819 | }; |
| 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | /* |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 822 | * Since the css devices are neither on a bus nor have a class |
| 823 | * nor have a special device type, we cannot stop/restart channel |
| 824 | * path measurements via the normal suspend/resume callbacks, but have |
| 825 | * to use notifiers. |
| 826 | */ |
| 827 | static int css_power_event(struct notifier_block *this, unsigned long event, |
| 828 | void *ptr) |
| 829 | { |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 830 | int ret, i; |
| 831 | |
| 832 | switch (event) { |
| 833 | case PM_HIBERNATION_PREPARE: |
| 834 | case PM_SUSPEND_PREPARE: |
| 835 | ret = NOTIFY_DONE; |
| 836 | for (i = 0; i <= __MAX_CSSID; i++) { |
| 837 | struct channel_subsystem *css; |
| 838 | |
| 839 | css = channel_subsystems[i]; |
| 840 | mutex_lock(&css->mutex); |
| 841 | if (!css->cm_enabled) { |
| 842 | mutex_unlock(&css->mutex); |
| 843 | continue; |
| 844 | } |
Akinobu Mita | f0c077a | 2011-07-08 20:53:36 +0200 | [diff] [blame] | 845 | ret = __chsc_do_secm(css, 0); |
| 846 | ret = notifier_from_errno(ret); |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 847 | mutex_unlock(&css->mutex); |
| 848 | } |
| 849 | break; |
| 850 | case PM_POST_HIBERNATION: |
| 851 | case PM_POST_SUSPEND: |
| 852 | ret = NOTIFY_DONE; |
| 853 | for (i = 0; i <= __MAX_CSSID; i++) { |
| 854 | struct channel_subsystem *css; |
| 855 | |
| 856 | css = channel_subsystems[i]; |
| 857 | mutex_lock(&css->mutex); |
| 858 | if (!css->cm_enabled) { |
| 859 | mutex_unlock(&css->mutex); |
| 860 | continue; |
| 861 | } |
Akinobu Mita | f0c077a | 2011-07-08 20:53:36 +0200 | [diff] [blame] | 862 | ret = __chsc_do_secm(css, 1); |
| 863 | ret = notifier_from_errno(ret); |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 864 | mutex_unlock(&css->mutex); |
| 865 | } |
| 866 | /* search for subchannels, which appeared during hibernation */ |
| 867 | css_schedule_reprobe(); |
| 868 | break; |
| 869 | default: |
| 870 | ret = NOTIFY_DONE; |
| 871 | } |
| 872 | return ret; |
| 873 | |
| 874 | } |
| 875 | static struct notifier_block css_power_notifier = { |
| 876 | .notifier_call = css_power_event, |
| 877 | }; |
| 878 | |
| 879 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | * Now that the driver core is running, we can setup our channel subsystem. |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 881 | * The struct subchannel's are created during probing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | */ |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 883 | static int __init css_bus_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 885 | int ret, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 887 | ret = chsc_init(); |
| 888 | if (ret) |
| 889 | return ret; |
| 890 | |
Sebastian Ott | 34196f8 | 2010-10-25 16:10:29 +0200 | [diff] [blame] | 891 | chsc_determine_css_characteristics(); |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 892 | /* Try to enable MSS. */ |
| 893 | ret = chsc_enable_facility(CHSC_SDA_OC_MSS); |
Sebastian Ott | 818c272 | 2010-04-22 17:17:03 +0200 | [diff] [blame] | 894 | if (ret) |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 895 | max_ssid = 0; |
Sebastian Ott | 818c272 | 2010-04-22 17:17:03 +0200 | [diff] [blame] | 896 | else /* Success. */ |
| 897 | max_ssid = __MAX_SSID; |
Sebastian Ott | b0a285d | 2009-09-22 22:58:37 +0200 | [diff] [blame] | 898 | |
Cornelia Huck | 4434a38 | 2007-07-27 12:29:21 +0200 | [diff] [blame] | 899 | ret = slow_subchannel_init(); |
| 900 | if (ret) |
| 901 | goto out; |
| 902 | |
Heiko Carstens | f5daba1 | 2009-03-26 15:24:01 +0100 | [diff] [blame] | 903 | ret = crw_register_handler(CRW_RSC_SCH, css_process_crw); |
Cornelia Huck | c115618 | 2008-07-14 09:58:46 +0200 | [diff] [blame] | 904 | if (ret) |
| 905 | goto out; |
| 906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | if ((ret = bus_register(&css_bus_type))) |
| 908 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 910 | /* Setup css structure. */ |
| 911 | for (i = 0; i <= __MAX_CSSID; i++) { |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 912 | struct channel_subsystem *css; |
| 913 | |
| 914 | css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL); |
| 915 | if (!css) { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 916 | ret = -ENOMEM; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 917 | goto out_unregister; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 918 | } |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 919 | channel_subsystems[i] = css; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 920 | ret = setup_css(i); |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 921 | if (ret) { |
| 922 | kfree(channel_subsystems[i]); |
| 923 | goto out_unregister; |
| 924 | } |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 925 | ret = device_register(&css->device); |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 926 | if (ret) { |
| 927 | put_device(&css->device); |
| 928 | goto out_unregister; |
| 929 | } |
Cornelia Huck | 75784c0 | 2008-07-14 09:58:57 +0200 | [diff] [blame] | 930 | if (css_chsc_characteristics.secm) { |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 931 | ret = device_create_file(&css->device, |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 932 | &dev_attr_cm_enable); |
| 933 | if (ret) |
| 934 | goto out_device; |
| 935 | } |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 936 | ret = device_register(&css->pseudo_subchannel->dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 937 | if (ret) { |
| 938 | put_device(&css->pseudo_subchannel->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 939 | goto out_file; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 940 | } |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 941 | } |
Cornelia Huck | a55360d | 2007-10-12 16:11:20 +0200 | [diff] [blame] | 942 | ret = register_reboot_notifier(&css_reboot_notifier); |
| 943 | if (ret) |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 944 | goto out_unregister; |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 945 | ret = register_pm_notifier(&css_power_notifier); |
| 946 | if (ret) { |
| 947 | unregister_reboot_notifier(&css_reboot_notifier); |
| 948 | goto out_unregister; |
| 949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | css_init_done = 1; |
| 951 | |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 952 | /* Enable default isc for I/O subchannels. */ |
Cornelia Huck | 6ef556cc | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 953 | isc_register(IO_SCH_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | return 0; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 956 | out_file: |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 957 | if (css_chsc_characteristics.secm) |
| 958 | device_remove_file(&channel_subsystems[i]->device, |
| 959 | &dev_attr_cm_enable); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 960 | out_device: |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 961 | device_unregister(&channel_subsystems[i]->device); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 962 | out_unregister: |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 963 | while (i > 0) { |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 964 | struct channel_subsystem *css; |
| 965 | |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 966 | i--; |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 967 | css = channel_subsystems[i]; |
| 968 | device_unregister(&css->pseudo_subchannel->dev); |
Cornelia Huck | a2164b8 | 2008-09-09 12:38:57 +0200 | [diff] [blame] | 969 | css->pseudo_subchannel = NULL; |
Cornelia Huck | 75784c0 | 2008-07-14 09:58:57 +0200 | [diff] [blame] | 970 | if (css_chsc_characteristics.secm) |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 971 | device_remove_file(&css->device, |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 972 | &dev_attr_cm_enable); |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 973 | device_unregister(&css->device); |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | bus_unregister(&css_bus_type); |
| 976 | out: |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 977 | crw_unregister_handler(CRW_RSC_SCH); |
Sebastian Ott | b827d1c8 | 2009-09-22 22:58:36 +0200 | [diff] [blame] | 978 | idset_free(slow_subchannel_set); |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 979 | chsc_init_cleanup(); |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 980 | pr_alert("The CSS device driver initialization failed with " |
| 981 | "errno=%d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return ret; |
| 983 | } |
| 984 | |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 985 | static void __init css_bus_cleanup(void) |
| 986 | { |
| 987 | struct channel_subsystem *css; |
| 988 | int i; |
| 989 | |
| 990 | for (i = 0; i <= __MAX_CSSID; i++) { |
| 991 | css = channel_subsystems[i]; |
| 992 | device_unregister(&css->pseudo_subchannel->dev); |
| 993 | css->pseudo_subchannel = NULL; |
| 994 | if (css_chsc_characteristics.secm) |
| 995 | device_remove_file(&css->device, &dev_attr_cm_enable); |
| 996 | device_unregister(&css->device); |
| 997 | } |
| 998 | bus_unregister(&css_bus_type); |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 999 | crw_unregister_handler(CRW_RSC_SCH); |
Sebastian Ott | b827d1c8 | 2009-09-22 22:58:36 +0200 | [diff] [blame] | 1000 | idset_free(slow_subchannel_set); |
Sebastian Ott | 34aec07 | 2010-10-25 16:10:28 +0200 | [diff] [blame] | 1001 | chsc_init_cleanup(); |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1002 | isc_unregister(IO_SCH_ISC); |
| 1003 | } |
| 1004 | |
| 1005 | static int __init channel_subsystem_init(void) |
| 1006 | { |
| 1007 | int ret; |
| 1008 | |
| 1009 | ret = css_bus_init(); |
| 1010 | if (ret) |
| 1011 | return ret; |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 1012 | cio_work_q = create_singlethread_workqueue("cio"); |
| 1013 | if (!cio_work_q) { |
| 1014 | ret = -ENOMEM; |
| 1015 | goto out_bus; |
| 1016 | } |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1017 | ret = io_subchannel_init(); |
| 1018 | if (ret) |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 1019 | goto out_wq; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1020 | |
| 1021 | return ret; |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 1022 | out_wq: |
| 1023 | destroy_workqueue(cio_work_q); |
| 1024 | out_bus: |
| 1025 | css_bus_cleanup(); |
| 1026 | return ret; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1027 | } |
| 1028 | subsys_initcall(channel_subsystem_init); |
| 1029 | |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 1030 | static int css_settle(struct device_driver *drv, void *unused) |
| 1031 | { |
| 1032 | struct css_driver *cssdrv = to_cssdriver(drv); |
| 1033 | |
| 1034 | if (cssdrv->settle) |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1035 | return cssdrv->settle(); |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1039 | int css_complete_work(void) |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1040 | { |
| 1041 | int ret; |
| 1042 | |
| 1043 | /* Wait for the evaluation of subchannels to finish. */ |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1044 | ret = wait_event_interruptible(css_eval_wq, |
| 1045 | atomic_read(&css_eval_scheduled) == 0); |
| 1046 | if (ret) |
| 1047 | return -EINTR; |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1048 | flush_workqueue(cio_work_q); |
| 1049 | /* Wait for the subchannel type specific initialization to finish */ |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1050 | return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1054 | /* |
| 1055 | * Wait for the initialization of devices to finish, to make sure we are |
| 1056 | * done with our setup if the search for the root device starts. |
| 1057 | */ |
| 1058 | static int __init channel_subsystem_init_sync(void) |
| 1059 | { |
Sebastian Ott | 14556b3 | 2013-04-13 13:03:54 +0200 | [diff] [blame] | 1060 | /* Register subchannels which are already in use. */ |
| 1061 | cio_register_early_subchannels(); |
Sebastian Ott | 703e5c9 | 2009-09-22 22:58:38 +0200 | [diff] [blame] | 1062 | /* Start initial subchannel evaluation. */ |
| 1063 | css_schedule_eval_all(); |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1064 | css_complete_work(); |
| 1065 | return 0; |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 1066 | } |
| 1067 | subsys_initcall_sync(channel_subsystem_init_sync); |
| 1068 | |
Sebastian Ott | 889ee95 | 2010-04-22 17:17:04 +0200 | [diff] [blame] | 1069 | void channel_subsystem_reinit(void) |
| 1070 | { |
Sebastian Ott | 62da177 | 2010-10-25 16:10:32 +0200 | [diff] [blame] | 1071 | struct channel_path *chp; |
| 1072 | struct chp_id chpid; |
| 1073 | |
Sebastian Ott | 889ee95 | 2010-04-22 17:17:04 +0200 | [diff] [blame] | 1074 | chsc_enable_facility(CHSC_SDA_OC_MSS); |
Sebastian Ott | 62da177 | 2010-10-25 16:10:32 +0200 | [diff] [blame] | 1075 | chp_id_for_each(&chpid) { |
| 1076 | chp = chpid_to_chp(chpid); |
Peter Oberparleiter | cce0eac | 2013-03-11 12:58:18 +0100 | [diff] [blame] | 1077 | if (chp) |
| 1078 | chp_update_desc(chp); |
Sebastian Ott | 62da177 | 2010-10-25 16:10:32 +0200 | [diff] [blame] | 1079 | } |
Sebastian Ott | 889ee95 | 2010-04-22 17:17:04 +0200 | [diff] [blame] | 1080 | } |
| 1081 | |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1082 | #ifdef CONFIG_PROC_FS |
| 1083 | static ssize_t cio_settle_write(struct file *file, const char __user *buf, |
| 1084 | size_t count, loff_t *ppos) |
| 1085 | { |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1086 | int ret; |
| 1087 | |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1088 | /* Handle pending CRW's. */ |
| 1089 | crw_wait_for_channel_report(); |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 1090 | ret = css_complete_work(); |
| 1091 | |
| 1092 | return ret ? ret : count; |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static const struct file_operations cio_settle_proc_fops = { |
Martin Schwidefsky | 58ea91c | 2010-05-17 10:00:07 +0200 | [diff] [blame] | 1096 | .open = nonseekable_open, |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1097 | .write = cio_settle_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1098 | .llseek = no_llseek, |
Sebastian Ott | 879acca5 | 2010-02-26 22:37:25 +0100 | [diff] [blame] | 1099 | }; |
| 1100 | |
| 1101 | static int __init cio_settle_init(void) |
| 1102 | { |
| 1103 | struct proc_dir_entry *entry; |
| 1104 | |
| 1105 | entry = proc_create("cio_settle", S_IWUSR, NULL, |
| 1106 | &cio_settle_proc_fops); |
| 1107 | if (!entry) |
| 1108 | return -ENOMEM; |
| 1109 | return 0; |
| 1110 | } |
| 1111 | device_initcall(cio_settle_init); |
| 1112 | #endif /*CONFIG_PROC_FS*/ |
| 1113 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1114 | int sch_is_pseudo_sch(struct subchannel *sch) |
| 1115 | { |
| 1116 | return sch == to_css(sch->dev.parent)->pseudo_subchannel; |
| 1117 | } |
| 1118 | |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 1119 | static int css_bus_match(struct device *dev, struct device_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | { |
Cornelia Huck | 084325d | 2008-01-26 14:10:38 +0100 | [diff] [blame] | 1121 | struct subchannel *sch = to_subchannel(dev); |
| 1122 | struct css_driver *driver = to_cssdriver(drv); |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 1123 | struct css_device_id *id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 1125 | for (id = driver->subchannel_type; id->match_flags; id++) { |
| 1126 | if (sch->st == id->type) |
| 1127 | return 1; |
| 1128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1133 | static int css_probe(struct device *dev) |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1134 | { |
| 1135 | struct subchannel *sch; |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1136 | int ret; |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1137 | |
| 1138 | sch = to_subchannel(dev); |
Cornelia Huck | 084325d | 2008-01-26 14:10:38 +0100 | [diff] [blame] | 1139 | sch->driver = to_cssdriver(dev->driver); |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1140 | ret = sch->driver->probe ? sch->driver->probe(sch) : 0; |
| 1141 | if (ret) |
| 1142 | sch->driver = NULL; |
| 1143 | return ret; |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1146 | static int css_remove(struct device *dev) |
| 1147 | { |
| 1148 | struct subchannel *sch; |
| 1149 | int ret; |
| 1150 | |
| 1151 | sch = to_subchannel(dev); |
| 1152 | ret = sch->driver->remove ? sch->driver->remove(sch) : 0; |
| 1153 | sch->driver = NULL; |
| 1154 | return ret; |
| 1155 | } |
| 1156 | |
| 1157 | static void css_shutdown(struct device *dev) |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1158 | { |
| 1159 | struct subchannel *sch; |
| 1160 | |
| 1161 | sch = to_subchannel(dev); |
Cornelia Huck | 98c13c2 | 2008-01-26 14:10:40 +0100 | [diff] [blame] | 1162 | if (sch->driver && sch->driver->shutdown) |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1163 | sch->driver->shutdown(sch); |
| 1164 | } |
| 1165 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1166 | static int css_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 1167 | { |
| 1168 | struct subchannel *sch = to_subchannel(dev); |
| 1169 | int ret; |
| 1170 | |
| 1171 | ret = add_uevent_var(env, "ST=%01X", sch->st); |
| 1172 | if (ret) |
| 1173 | return ret; |
| 1174 | ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st); |
| 1175 | return ret; |
| 1176 | } |
| 1177 | |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1178 | static int css_pm_prepare(struct device *dev) |
| 1179 | { |
| 1180 | struct subchannel *sch = to_subchannel(dev); |
| 1181 | struct css_driver *drv; |
| 1182 | |
| 1183 | if (mutex_is_locked(&sch->reg_mutex)) |
| 1184 | return -EAGAIN; |
| 1185 | if (!sch->dev.driver) |
| 1186 | return 0; |
| 1187 | drv = to_cssdriver(sch->dev.driver); |
| 1188 | /* Notify drivers that they may not register children. */ |
| 1189 | return drv->prepare ? drv->prepare(sch) : 0; |
| 1190 | } |
| 1191 | |
| 1192 | static void css_pm_complete(struct device *dev) |
| 1193 | { |
| 1194 | struct subchannel *sch = to_subchannel(dev); |
| 1195 | struct css_driver *drv; |
| 1196 | |
| 1197 | if (!sch->dev.driver) |
| 1198 | return; |
| 1199 | drv = to_cssdriver(sch->dev.driver); |
| 1200 | if (drv->complete) |
| 1201 | drv->complete(sch); |
| 1202 | } |
| 1203 | |
| 1204 | static int css_pm_freeze(struct device *dev) |
| 1205 | { |
| 1206 | struct subchannel *sch = to_subchannel(dev); |
| 1207 | struct css_driver *drv; |
| 1208 | |
| 1209 | if (!sch->dev.driver) |
| 1210 | return 0; |
| 1211 | drv = to_cssdriver(sch->dev.driver); |
| 1212 | return drv->freeze ? drv->freeze(sch) : 0; |
| 1213 | } |
| 1214 | |
| 1215 | static int css_pm_thaw(struct device *dev) |
| 1216 | { |
| 1217 | struct subchannel *sch = to_subchannel(dev); |
| 1218 | struct css_driver *drv; |
| 1219 | |
| 1220 | if (!sch->dev.driver) |
| 1221 | return 0; |
| 1222 | drv = to_cssdriver(sch->dev.driver); |
| 1223 | return drv->thaw ? drv->thaw(sch) : 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int css_pm_restore(struct device *dev) |
| 1227 | { |
| 1228 | struct subchannel *sch = to_subchannel(dev); |
| 1229 | struct css_driver *drv; |
| 1230 | |
Sebastian Ott | eb4f5d9 | 2010-10-25 16:10:33 +0200 | [diff] [blame] | 1231 | css_update_ssd_info(sch); |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1232 | if (!sch->dev.driver) |
| 1233 | return 0; |
| 1234 | drv = to_cssdriver(sch->dev.driver); |
| 1235 | return drv->restore ? drv->restore(sch) : 0; |
| 1236 | } |
| 1237 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1238 | static const struct dev_pm_ops css_pm_ops = { |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1239 | .prepare = css_pm_prepare, |
| 1240 | .complete = css_pm_complete, |
| 1241 | .freeze = css_pm_freeze, |
| 1242 | .thaw = css_pm_thaw, |
| 1243 | .restore = css_pm_restore, |
| 1244 | }; |
| 1245 | |
Sebastian Ott | 3041b6a | 2011-03-15 17:08:31 +0100 | [diff] [blame] | 1246 | static struct bus_type css_bus_type = { |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1247 | .name = "css", |
| 1248 | .match = css_bus_match, |
| 1249 | .probe = css_probe, |
| 1250 | .remove = css_remove, |
| 1251 | .shutdown = css_shutdown, |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1252 | .uevent = css_uevent, |
Sebastian Ott | dcbd16d | 2009-06-16 10:30:22 +0200 | [diff] [blame] | 1253 | .pm = &css_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | }; |
| 1255 | |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 1256 | /** |
| 1257 | * css_driver_register - register a css driver |
| 1258 | * @cdrv: css driver to register |
| 1259 | * |
| 1260 | * This is mainly a wrapper around driver_register that sets name |
| 1261 | * and bus_type in the embedded struct device_driver correctly. |
| 1262 | */ |
| 1263 | int css_driver_register(struct css_driver *cdrv) |
| 1264 | { |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 1265 | cdrv->drv.bus = &css_bus_type; |
| 1266 | return driver_register(&cdrv->drv); |
| 1267 | } |
| 1268 | EXPORT_SYMBOL_GPL(css_driver_register); |
| 1269 | |
| 1270 | /** |
| 1271 | * css_driver_unregister - unregister a css driver |
| 1272 | * @cdrv: css driver to unregister |
| 1273 | * |
| 1274 | * This is a wrapper around driver_unregister. |
| 1275 | */ |
| 1276 | void css_driver_unregister(struct css_driver *cdrv) |
| 1277 | { |
| 1278 | driver_unregister(&cdrv->drv); |
| 1279 | } |
| 1280 | EXPORT_SYMBOL_GPL(css_driver_unregister); |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | MODULE_LICENSE("GPL"); |