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