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