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