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