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