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