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