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