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