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