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> |
| 16 | |
| 17 | #include "css.h" |
| 18 | #include "cio.h" |
| 19 | #include "cio_debug.h" |
| 20 | #include "ioasm.h" |
| 21 | #include "chsc.h" |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 22 | #include "device.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | int need_rescan = 0; |
| 25 | int css_init_done = 0; |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 26 | static int need_reprobe = 0; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 27 | static int max_ssid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 29 | struct channel_subsystem *css[__MAX_CSSID + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 31 | int css_characteristics_avail = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 33 | inline int |
| 34 | for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data) |
| 35 | { |
| 36 | struct subchannel_id schid; |
| 37 | int ret; |
| 38 | |
| 39 | init_subchannel_id(&schid); |
| 40 | ret = -ENODEV; |
| 41 | do { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 42 | do { |
| 43 | ret = fn(schid, data); |
| 44 | if (ret) |
| 45 | break; |
| 46 | } while (schid.sch_no++ < __MAX_SUBCHANNEL); |
| 47 | schid.sch_no = 0; |
| 48 | } while (schid.ssid++ < max_ssid); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 49 | return ret; |
| 50 | } |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static struct subchannel * |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 53 | css_alloc_subchannel(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | struct subchannel *sch; |
| 56 | int ret; |
| 57 | |
| 58 | sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA); |
| 59 | if (sch == NULL) |
| 60 | return ERR_PTR(-ENOMEM); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 61 | ret = cio_validate_subchannel (sch, schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | if (ret < 0) { |
| 63 | kfree(sch); |
| 64 | return ERR_PTR(ret); |
| 65 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | if (sch->st != SUBCHANNEL_TYPE_IO) { |
| 68 | /* For now we ignore all non-io subchannels. */ |
| 69 | kfree(sch); |
| 70 | return ERR_PTR(-EINVAL); |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Set intparm to subchannel address. |
| 75 | * This is fine even on 64bit since the subchannel is always located |
| 76 | * under 2G. |
| 77 | */ |
| 78 | sch->schib.pmcw.intparm = (__u32)(unsigned long)sch; |
| 79 | ret = cio_modify(sch); |
| 80 | if (ret) { |
| 81 | kfree(sch); |
| 82 | return ERR_PTR(ret); |
| 83 | } |
| 84 | return sch; |
| 85 | } |
| 86 | |
| 87 | static void |
| 88 | css_free_subchannel(struct subchannel *sch) |
| 89 | { |
| 90 | if (sch) { |
| 91 | /* Reset intparm to zeroes. */ |
| 92 | sch->schib.pmcw.intparm = 0; |
| 93 | cio_modify(sch); |
| 94 | kfree(sch); |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |
| 99 | static void |
| 100 | css_subchannel_release(struct device *dev) |
| 101 | { |
| 102 | struct subchannel *sch; |
| 103 | |
| 104 | sch = to_subchannel(dev); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 105 | if (!cio_is_console(sch->schid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | kfree(sch); |
| 107 | } |
| 108 | |
| 109 | extern int css_get_ssd_info(struct subchannel *sch); |
| 110 | |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 111 | |
| 112 | int css_sch_device_register(struct subchannel *sch) |
| 113 | { |
| 114 | int ret; |
| 115 | |
| 116 | mutex_lock(&sch->reg_mutex); |
| 117 | ret = device_register(&sch->dev); |
| 118 | mutex_unlock(&sch->reg_mutex); |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | void css_sch_device_unregister(struct subchannel *sch) |
| 123 | { |
| 124 | mutex_lock(&sch->reg_mutex); |
| 125 | device_unregister(&sch->dev); |
| 126 | mutex_unlock(&sch->reg_mutex); |
| 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | static int |
| 130 | css_register_subchannel(struct subchannel *sch) |
| 131 | { |
| 132 | int ret; |
| 133 | |
| 134 | /* Initialize the subchannel structure */ |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 135 | sch->dev.parent = &css[0]->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | sch->dev.bus = &css_bus_type; |
| 137 | sch->dev.release = &css_subchannel_release; |
| 138 | |
| 139 | /* make it known to the system */ |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 140 | ret = css_sch_device_register(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (ret) |
| 142 | printk (KERN_WARNING "%s: could not register %s\n", |
| 143 | __func__, sch->dev.bus_id); |
| 144 | else |
| 145 | css_get_ssd_info(sch); |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 150 | css_probe_device(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
| 152 | int ret; |
| 153 | struct subchannel *sch; |
| 154 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 155 | sch = css_alloc_subchannel(schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | if (IS_ERR(sch)) |
| 157 | return PTR_ERR(sch); |
| 158 | ret = css_register_subchannel(sch); |
| 159 | if (ret) |
| 160 | css_free_subchannel(sch); |
| 161 | return ret; |
| 162 | } |
| 163 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 164 | static int |
| 165 | check_subchannel(struct device * dev, void * data) |
| 166 | { |
| 167 | struct subchannel *sch; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 168 | struct subchannel_id *schid = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 169 | |
| 170 | sch = to_subchannel(dev); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 171 | return schid_equal(&sch->schid, schid); |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | struct subchannel * |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 175 | get_subchannel_by_schid(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | struct device *dev; |
| 178 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 179 | dev = bus_find_device(&css_bus_type, NULL, |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 180 | (void *)&schid, check_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 182 | return dev ? to_subchannel(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static inline int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 187 | css_get_subchannel_status(struct subchannel *sch, struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
| 189 | struct schib schib; |
| 190 | int cc; |
| 191 | |
| 192 | cc = stsch(schid, &schib); |
| 193 | if (cc) |
| 194 | return CIO_GONE; |
| 195 | if (!schib.pmcw.dnv) |
| 196 | return CIO_GONE; |
| 197 | if (sch && sch->schib.pmcw.dnv && |
| 198 | (schib.pmcw.dev != sch->schib.pmcw.dev)) |
| 199 | return CIO_REVALIDATE; |
| 200 | if (sch && !sch->lpm) |
| 201 | return CIO_NO_PATH; |
| 202 | return CIO_OPER; |
| 203 | } |
| 204 | |
| 205 | static int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 206 | css_evaluate_subchannel(struct subchannel_id schid, int slow) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | int event, ret, disc; |
| 209 | struct subchannel *sch; |
| 210 | unsigned long flags; |
| 211 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 212 | sch = get_subchannel_by_schid(schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | disc = sch ? device_is_disconnected(sch) : 0; |
| 214 | if (disc && slow) { |
| 215 | if (sch) |
| 216 | put_device(&sch->dev); |
| 217 | return 0; /* Already processed. */ |
| 218 | } |
| 219 | /* |
| 220 | * We've got a machine check, so running I/O won't get an interrupt. |
| 221 | * Kill any pending timers. |
| 222 | */ |
| 223 | if (sch) |
| 224 | device_kill_pending_timer(sch); |
| 225 | if (!disc && !slow) { |
| 226 | if (sch) |
| 227 | put_device(&sch->dev); |
| 228 | return -EAGAIN; /* Will be done on the slow path. */ |
| 229 | } |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 230 | event = css_get_subchannel_status(sch, schid); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 231 | CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n", |
| 232 | schid.ssid, schid.sch_no, event, |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 233 | sch?(disc?"disconnected":"normal"):"unknown", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | slow?"slow":"fast"); |
| 235 | switch (event) { |
| 236 | case CIO_NO_PATH: |
| 237 | case CIO_GONE: |
| 238 | if (!sch) { |
| 239 | /* Never used this subchannel. Ignore. */ |
| 240 | ret = 0; |
| 241 | break; |
| 242 | } |
| 243 | if (disc && (event == CIO_NO_PATH)) { |
| 244 | /* |
| 245 | * Uargh, hack again. Because we don't get a machine |
| 246 | * check on configure on, our path bookkeeping can |
| 247 | * be out of date here (it's fine while we only do |
| 248 | * logical varying or get chsc machine checks). We |
| 249 | * need to force reprobing or we might miss devices |
| 250 | * coming operational again. It won't do harm in real |
| 251 | * no path situations. |
| 252 | */ |
| 253 | spin_lock_irqsave(&sch->lock, flags); |
| 254 | device_trigger_reprobe(sch); |
| 255 | spin_unlock_irqrestore(&sch->lock, flags); |
| 256 | ret = 0; |
| 257 | break; |
| 258 | } |
| 259 | if (sch->driver && sch->driver->notify && |
| 260 | sch->driver->notify(&sch->dev, event)) { |
| 261 | cio_disable_subchannel(sch); |
| 262 | device_set_disconnected(sch); |
| 263 | ret = 0; |
| 264 | break; |
| 265 | } |
| 266 | /* |
| 267 | * Unregister subchannel. |
| 268 | * The device will be killed automatically. |
| 269 | */ |
| 270 | cio_disable_subchannel(sch); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 271 | css_sch_device_unregister(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /* Reset intparm to zeroes. */ |
| 273 | sch->schib.pmcw.intparm = 0; |
| 274 | cio_modify(sch); |
| 275 | put_device(&sch->dev); |
| 276 | ret = 0; |
| 277 | break; |
| 278 | case CIO_REVALIDATE: |
| 279 | /* |
| 280 | * Revalidation machine check. Sick. |
| 281 | * We don't notify the driver since we have to throw the device |
| 282 | * away in any case. |
| 283 | */ |
| 284 | if (!disc) { |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 285 | css_sch_device_unregister(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | /* Reset intparm to zeroes. */ |
| 287 | sch->schib.pmcw.intparm = 0; |
| 288 | cio_modify(sch); |
| 289 | put_device(&sch->dev); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 290 | ret = css_probe_device(schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } else { |
| 292 | /* |
| 293 | * We can't immediately deregister the disconnected |
| 294 | * device since it might block. |
| 295 | */ |
| 296 | spin_lock_irqsave(&sch->lock, flags); |
| 297 | device_trigger_reprobe(sch); |
| 298 | spin_unlock_irqrestore(&sch->lock, flags); |
| 299 | ret = 0; |
| 300 | } |
| 301 | break; |
| 302 | case CIO_OPER: |
| 303 | if (disc) { |
| 304 | spin_lock_irqsave(&sch->lock, flags); |
| 305 | /* Get device operational again. */ |
| 306 | device_trigger_reprobe(sch); |
| 307 | spin_unlock_irqrestore(&sch->lock, flags); |
| 308 | } |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 309 | ret = sch ? 0 : css_probe_device(schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | break; |
| 311 | default: |
| 312 | BUG(); |
| 313 | ret = 0; |
| 314 | } |
| 315 | return ret; |
| 316 | } |
| 317 | |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 318 | static int |
| 319 | css_rescan_devices(struct subchannel_id schid, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 321 | return css_evaluate_subchannel(schid, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | struct slow_subchannel { |
| 325 | struct list_head slow_list; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 326 | struct subchannel_id schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | static LIST_HEAD(slow_subchannels_head); |
| 330 | static DEFINE_SPINLOCK(slow_subchannel_lock); |
| 331 | |
| 332 | static void |
| 333 | css_trigger_slow_path(void) |
| 334 | { |
| 335 | CIO_TRACE_EVENT(4, "slowpath"); |
| 336 | |
| 337 | if (need_rescan) { |
| 338 | need_rescan = 0; |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 339 | for_each_subchannel(css_rescan_devices, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return; |
| 341 | } |
| 342 | |
| 343 | spin_lock_irq(&slow_subchannel_lock); |
| 344 | while (!list_empty(&slow_subchannels_head)) { |
| 345 | struct slow_subchannel *slow_sch = |
| 346 | list_entry(slow_subchannels_head.next, |
| 347 | struct slow_subchannel, slow_list); |
| 348 | |
| 349 | list_del_init(slow_subchannels_head.next); |
| 350 | spin_unlock_irq(&slow_subchannel_lock); |
| 351 | css_evaluate_subchannel(slow_sch->schid, 1); |
| 352 | spin_lock_irq(&slow_subchannel_lock); |
| 353 | kfree(slow_sch); |
| 354 | } |
| 355 | spin_unlock_irq(&slow_subchannel_lock); |
| 356 | } |
| 357 | |
| 358 | typedef void (*workfunc)(void *); |
| 359 | DECLARE_WORK(slow_path_work, (workfunc)css_trigger_slow_path, NULL); |
| 360 | struct workqueue_struct *slow_path_wq; |
| 361 | |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 362 | /* Reprobe subchannel if unregistered. */ |
| 363 | static int reprobe_subchannel(struct subchannel_id schid, void *data) |
| 364 | { |
| 365 | struct subchannel *sch; |
| 366 | int ret; |
| 367 | |
| 368 | CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n", |
| 369 | schid.ssid, schid.sch_no); |
| 370 | if (need_reprobe) |
| 371 | return -EAGAIN; |
| 372 | |
| 373 | sch = get_subchannel_by_schid(schid); |
| 374 | if (sch) { |
| 375 | /* Already known. */ |
| 376 | put_device(&sch->dev); |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | ret = css_probe_device(schid); |
| 381 | switch (ret) { |
| 382 | case 0: |
| 383 | break; |
| 384 | case -ENXIO: |
| 385 | case -ENOMEM: |
| 386 | /* These should abort looping */ |
| 387 | break; |
| 388 | default: |
| 389 | ret = 0; |
| 390 | } |
| 391 | |
| 392 | return ret; |
| 393 | } |
| 394 | |
| 395 | /* Work function used to reprobe all unregistered subchannels. */ |
| 396 | static void reprobe_all(void *data) |
| 397 | { |
| 398 | int ret; |
| 399 | |
| 400 | CIO_MSG_EVENT(2, "reprobe start\n"); |
| 401 | |
| 402 | need_reprobe = 0; |
| 403 | /* Make sure initial subchannel scan is done. */ |
| 404 | wait_event(ccw_device_init_wq, |
| 405 | atomic_read(&ccw_device_init_count) == 0); |
| 406 | ret = for_each_subchannel(reprobe_subchannel, NULL); |
| 407 | |
| 408 | CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret, |
| 409 | need_reprobe); |
| 410 | } |
| 411 | |
| 412 | DECLARE_WORK(css_reprobe_work, reprobe_all, NULL); |
| 413 | |
| 414 | /* Schedule reprobing of all unregistered subchannels. */ |
| 415 | void css_schedule_reprobe(void) |
| 416 | { |
| 417 | need_reprobe = 1; |
| 418 | queue_work(ccw_device_work, &css_reprobe_work); |
| 419 | } |
| 420 | |
| 421 | EXPORT_SYMBOL_GPL(css_schedule_reprobe); |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* |
| 424 | * Rescan for new devices. FIXME: This is slow. |
| 425 | * This function is called when we have lost CRWs due to overflows and we have |
| 426 | * to do subchannel housekeeping. |
| 427 | */ |
| 428 | void |
| 429 | css_reiterate_subchannels(void) |
| 430 | { |
| 431 | css_clear_subchannel_slow_list(); |
| 432 | need_rescan = 1; |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Called from the machine check handler for subchannel report words. |
| 437 | */ |
| 438 | int |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 439 | css_process_crw(int rsid1, int rsid2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
| 441 | int ret; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 442 | struct subchannel_id mchk_schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 444 | CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n", |
| 445 | rsid1, rsid2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
| 447 | if (need_rescan) |
| 448 | /* We need to iterate all subchannels anyway. */ |
| 449 | return -EAGAIN; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 450 | |
| 451 | init_subchannel_id(&mchk_schid); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 452 | mchk_schid.sch_no = rsid1; |
| 453 | if (rsid2 != 0) |
| 454 | mchk_schid.ssid = (rsid2 >> 8) & 3; |
| 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* |
| 457 | * Since we are always presented with IPI in the CRW, we have to |
| 458 | * use stsch() to find out if the subchannel in question has come |
| 459 | * or gone. |
| 460 | */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 461 | ret = css_evaluate_subchannel(mchk_schid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | if (ret == -EAGAIN) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 463 | if (css_enqueue_subchannel_slow(mchk_schid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | css_clear_subchannel_slow_list(); |
| 465 | need_rescan = 1; |
| 466 | } |
| 467 | } |
| 468 | return ret; |
| 469 | } |
| 470 | |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 471 | static int __init |
| 472 | __init_channel_subsystem(struct subchannel_id schid, void *data) |
| 473 | { |
| 474 | struct subchannel *sch; |
| 475 | int ret; |
| 476 | |
| 477 | if (cio_is_console(schid)) |
| 478 | sch = cio_get_console_subchannel(); |
| 479 | else { |
| 480 | sch = css_alloc_subchannel(schid); |
| 481 | if (IS_ERR(sch)) |
| 482 | ret = PTR_ERR(sch); |
| 483 | else |
| 484 | ret = 0; |
| 485 | switch (ret) { |
| 486 | case 0: |
| 487 | break; |
| 488 | case -ENOMEM: |
| 489 | panic("Out of memory in init_channel_subsystem\n"); |
| 490 | /* -ENXIO: no more subchannels. */ |
| 491 | case -ENXIO: |
| 492 | return ret; |
Greg Smith | e843e28 | 2006-03-14 19:50:17 -0800 | [diff] [blame] | 493 | /* -EIO: this subchannel set not supported. */ |
| 494 | case -EIO: |
| 495 | return ret; |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 496 | default: |
| 497 | return 0; |
| 498 | } |
| 499 | } |
| 500 | /* |
| 501 | * We register ALL valid subchannels in ioinfo, even those |
| 502 | * that have been present before init_channel_subsystem. |
| 503 | * These subchannels can't have been registered yet (kmalloc |
| 504 | * not working) so we do it now. This is true e.g. for the |
| 505 | * console subchannel. |
| 506 | */ |
| 507 | css_register_subchannel(sch); |
| 508 | return 0; |
| 509 | } |
| 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | static void __init |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 512 | css_generate_pgid(struct channel_subsystem *css, u32 tod_high) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 514 | if (css_characteristics_avail && css_general_characteristics.mcss) { |
| 515 | css->global_pgid.pgid_high.ext_cssid.version = 0x80; |
| 516 | css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid; |
| 517 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | #ifdef CONFIG_SMP |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 519 | css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | #else |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 521 | css->global_pgid.pgid_high.cpu_addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | #endif |
| 523 | } |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 524 | css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident; |
| 525 | css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine; |
| 526 | css->global_pgid.tod_high = tod_high; |
| 527 | |
| 528 | } |
| 529 | |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 530 | static void |
| 531 | channel_subsystem_release(struct device *dev) |
| 532 | { |
| 533 | struct channel_subsystem *css; |
| 534 | |
| 535 | css = to_css(dev); |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 536 | mutex_destroy(&css->mutex); |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 537 | kfree(css); |
| 538 | } |
| 539 | |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 540 | static ssize_t |
| 541 | css_cm_enable_show(struct device *dev, struct device_attribute *attr, |
| 542 | char *buf) |
| 543 | { |
| 544 | struct channel_subsystem *css = to_css(dev); |
| 545 | |
| 546 | if (!css) |
| 547 | return 0; |
| 548 | return sprintf(buf, "%x\n", css->cm_enabled); |
| 549 | } |
| 550 | |
| 551 | static ssize_t |
| 552 | css_cm_enable_store(struct device *dev, struct device_attribute *attr, |
| 553 | const char *buf, size_t count) |
| 554 | { |
| 555 | struct channel_subsystem *css = to_css(dev); |
| 556 | int ret; |
| 557 | |
| 558 | switch (buf[0]) { |
| 559 | case '0': |
| 560 | ret = css->cm_enabled ? chsc_secm(css, 0) : 0; |
| 561 | break; |
| 562 | case '1': |
| 563 | ret = css->cm_enabled ? 0 : chsc_secm(css, 1); |
| 564 | break; |
| 565 | default: |
| 566 | ret = -EINVAL; |
| 567 | } |
| 568 | return ret < 0 ? ret : count; |
| 569 | } |
| 570 | |
| 571 | static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store); |
| 572 | |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 573 | static inline void __init |
| 574 | setup_css(int nr) |
| 575 | { |
| 576 | u32 tod_high; |
| 577 | |
| 578 | memset(css[nr], 0, sizeof(struct channel_subsystem)); |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 579 | mutex_init(&css[nr]->mutex); |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 580 | css[nr]->valid = 1; |
| 581 | css[nr]->cssid = nr; |
| 582 | sprintf(css[nr]->device.bus_id, "css%x", nr); |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 583 | css[nr]->device.release = channel_subsystem_release; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 584 | tod_high = (u32) (get_clock() >> 32); |
| 585 | css_generate_pgid(css[nr], tod_high); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Now that the driver core is running, we can setup our channel subsystem. |
| 590 | * The struct subchannel's are created during probing (except for the |
| 591 | * static console subchannel). |
| 592 | */ |
| 593 | static int __init |
| 594 | init_channel_subsystem (void) |
| 595 | { |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 596 | int ret, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | if (chsc_determine_css_characteristics() == 0) |
| 599 | css_characteristics_avail = 1; |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | if ((ret = bus_register(&css_bus_type))) |
| 602 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 604 | /* Try to enable MSS. */ |
| 605 | ret = chsc_enable_facility(CHSC_SDA_OC_MSS); |
| 606 | switch (ret) { |
| 607 | case 0: /* Success. */ |
| 608 | max_ssid = __MAX_SSID; |
| 609 | break; |
| 610 | case -ENOMEM: |
| 611 | goto out_bus; |
| 612 | default: |
| 613 | max_ssid = 0; |
| 614 | } |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 615 | /* Setup css structure. */ |
| 616 | for (i = 0; i <= __MAX_CSSID; i++) { |
| 617 | css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL); |
| 618 | if (!css[i]) { |
| 619 | ret = -ENOMEM; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 620 | goto out_unregister; |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 621 | } |
| 622 | setup_css(i); |
| 623 | ret = device_register(&css[i]->device); |
| 624 | if (ret) |
| 625 | goto out_free; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame^] | 626 | if (css_characteristics_avail && |
| 627 | css_chsc_characteristics.secm) { |
| 628 | ret = device_create_file(&css[i]->device, |
| 629 | &dev_attr_cm_enable); |
| 630 | if (ret) |
| 631 | goto out_device; |
| 632 | } |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | css_init_done = 1; |
| 635 | |
| 636 | ctl_set_bit(6, 28); |
| 637 | |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 638 | for_each_subchannel(__init_channel_subsystem, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return 0; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame^] | 640 | out_device: |
| 641 | device_unregister(&css[i]->device); |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 642 | out_free: |
| 643 | kfree(css[i]); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 644 | out_unregister: |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 645 | while (i > 0) { |
| 646 | i--; |
Cornelia Huck | 495a5b4 | 2006-03-24 03:15:14 -0800 | [diff] [blame] | 647 | if (css_characteristics_avail && css_chsc_characteristics.secm) |
| 648 | device_remove_file(&css[i]->device, |
| 649 | &dev_attr_cm_enable); |
Cornelia Huck | a28c694 | 2006-01-06 00:19:23 -0800 | [diff] [blame] | 650 | device_unregister(&css[i]->device); |
| 651 | } |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 652 | out_bus: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | bus_unregister(&css_bus_type); |
| 654 | out: |
| 655 | return ret; |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * find a driver for a subchannel. They identify by the subchannel |
| 660 | * type with the exception that the console subchannel driver has its own |
| 661 | * subchannel type although the device is an i/o subchannel |
| 662 | */ |
| 663 | static int |
| 664 | css_bus_match (struct device *dev, struct device_driver *drv) |
| 665 | { |
| 666 | struct subchannel *sch = container_of (dev, struct subchannel, dev); |
| 667 | struct css_driver *driver = container_of (drv, struct css_driver, drv); |
| 668 | |
| 669 | if (sch->st == driver->subchannel_type) |
| 670 | return 1; |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 675 | static int |
| 676 | css_probe (struct device *dev) |
| 677 | { |
| 678 | struct subchannel *sch; |
| 679 | |
| 680 | sch = to_subchannel(dev); |
| 681 | sch->driver = container_of (dev->driver, struct css_driver, drv); |
| 682 | return (sch->driver->probe ? sch->driver->probe(sch) : 0); |
| 683 | } |
| 684 | |
| 685 | static int |
| 686 | css_remove (struct device *dev) |
| 687 | { |
| 688 | struct subchannel *sch; |
| 689 | |
| 690 | sch = to_subchannel(dev); |
| 691 | return (sch->driver->remove ? sch->driver->remove(sch) : 0); |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | css_shutdown (struct device *dev) |
| 696 | { |
| 697 | struct subchannel *sch; |
| 698 | |
| 699 | sch = to_subchannel(dev); |
| 700 | if (sch->driver->shutdown) |
| 701 | sch->driver->shutdown(sch); |
| 702 | } |
| 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | struct bus_type css_bus_type = { |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 705 | .name = "css", |
| 706 | .match = css_bus_match, |
| 707 | .probe = css_probe, |
| 708 | .remove = css_remove, |
| 709 | .shutdown = css_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | }; |
| 711 | |
| 712 | subsys_initcall(init_channel_subsystem); |
| 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 715 | css_enqueue_subchannel_slow(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | { |
| 717 | struct slow_subchannel *new_slow_sch; |
| 718 | unsigned long flags; |
| 719 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 720 | new_slow_sch = kzalloc(sizeof(struct slow_subchannel), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | if (!new_slow_sch) |
| 722 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | new_slow_sch->schid = schid; |
| 724 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 725 | list_add_tail(&new_slow_sch->slow_list, &slow_subchannels_head); |
| 726 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | void |
| 731 | css_clear_subchannel_slow_list(void) |
| 732 | { |
| 733 | unsigned long flags; |
| 734 | |
| 735 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
| 736 | while (!list_empty(&slow_subchannels_head)) { |
| 737 | struct slow_subchannel *slow_sch = |
| 738 | list_entry(slow_subchannels_head.next, |
| 739 | struct slow_subchannel, slow_list); |
| 740 | |
| 741 | list_del_init(slow_subchannels_head.next); |
| 742 | kfree(slow_sch); |
| 743 | } |
| 744 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
| 745 | } |
| 746 | |
| 747 | |
| 748 | |
| 749 | int |
| 750 | css_slow_subchannels_exist(void) |
| 751 | { |
| 752 | return (!list_empty(&slow_subchannels_head)); |
| 753 | } |
| 754 | |
| 755 | MODULE_LICENSE("GPL"); |
| 756 | EXPORT_SYMBOL(css_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | EXPORT_SYMBOL_GPL(css_characteristics_avail); |