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