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