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