Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/device.c |
| 3 | * bus driver for ccw devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 2002,2008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 7 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/workqueue.h> |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 19 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/ccwdev.h> |
| 22 | #include <asm/cio.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 23 | #include <asm/param.h> /* HZ */ |
Cornelia Huck | 1842f2b | 2007-10-12 16:11:22 +0200 | [diff] [blame] | 24 | #include <asm/cmb.h> |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 25 | #include <asm/isc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 27 | #include "chp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "cio.h" |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 29 | #include "cio_debug.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "css.h" |
| 31 | #include "device.h" |
| 32 | #include "ioasm.h" |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 33 | #include "io_sch.h" |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 34 | #include "blacklist.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 36 | static struct timer_list recovery_timer; |
Cornelia Huck | 486d0a0 | 2008-02-19 15:29:23 +0100 | [diff] [blame] | 37 | static DEFINE_SPINLOCK(recovery_lock); |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 38 | static int recovery_phase; |
| 39 | static const unsigned long recovery_delay[] = { 3, 30, 300 }; |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /******************* bus type handling ***********************/ |
| 42 | |
| 43 | /* The Linux driver model distinguishes between a bus type and |
| 44 | * the bus itself. Of course we only have one channel |
| 45 | * subsystem driver and one channel system per machine, but |
| 46 | * we still use the abstraction. T.R. says it's a good idea. */ |
| 47 | static int |
| 48 | ccw_bus_match (struct device * dev, struct device_driver * drv) |
| 49 | { |
| 50 | struct ccw_device *cdev = to_ccwdev(dev); |
| 51 | struct ccw_driver *cdrv = to_ccwdrv(drv); |
| 52 | const struct ccw_device_id *ids = cdrv->ids, *found; |
| 53 | |
| 54 | if (!ids) |
| 55 | return 0; |
| 56 | |
| 57 | found = ccw_device_id_match(ids, &cdev->id); |
| 58 | if (!found) |
| 59 | return 0; |
| 60 | |
| 61 | cdev->id.driver_info = found->driver_info; |
| 62 | |
| 63 | return 1; |
| 64 | } |
| 65 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 66 | /* Store modalias string delimited by prefix/suffix string into buffer with |
| 67 | * specified size. Return length of resulting string (excluding trailing '\0') |
| 68 | * even if string doesn't fit buffer (snprintf semantics). */ |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 69 | static int snprint_alias(char *buf, size_t size, |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 70 | struct ccw_device_id *id, const char *suffix) |
| 71 | { |
| 72 | int len; |
| 73 | |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 74 | len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 75 | if (len > size) |
| 76 | return len; |
| 77 | buf += len; |
| 78 | size -= len; |
| 79 | |
| 80 | if (id->dev_type != 0) |
| 81 | len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type, |
| 82 | id->dev_model, suffix); |
| 83 | else |
| 84 | len += snprintf(buf, size, "dtdm%s", suffix); |
| 85 | |
| 86 | return len; |
| 87 | } |
| 88 | |
| 89 | /* Set up environment variables for ccw device uevent. Return 0 on success, |
| 90 | * non-zero otherwise. */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 91 | static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
| 93 | struct ccw_device *cdev = to_ccwdev(dev); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 94 | struct ccw_device_id *id = &(cdev->id); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 95 | int ret; |
| 96 | char modalias_buf[30]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 98 | /* CU_TYPE= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 99 | ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 100 | if (ret) |
| 101 | return ret; |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 102 | |
| 103 | /* CU_MODEL= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 104 | ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 105 | if (ret) |
| 106 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | /* The next two can be zero, that's ok for us */ |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 109 | /* DEV_TYPE= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 110 | ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 111 | if (ret) |
| 112 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 114 | /* DEV_MODEL= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 115 | ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 116 | if (ret) |
| 117 | return ret; |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 118 | |
| 119 | /* MODALIAS= */ |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 120 | snprint_alias(modalias_buf, sizeof(modalias_buf), id, ""); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 121 | ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf); |
| 122 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 125 | struct bus_type ccw_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 127 | static void io_subchannel_irq(struct subchannel *); |
| 128 | static int io_subchannel_probe(struct subchannel *); |
| 129 | static int io_subchannel_remove(struct subchannel *); |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 130 | static void io_subchannel_shutdown(struct subchannel *); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 131 | static int io_subchannel_sch_event(struct subchannel *, int); |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 132 | static int io_subchannel_chp_event(struct subchannel *, struct chp_link *, |
| 133 | int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 135 | static struct css_device_id io_subchannel_ids[] = { |
| 136 | { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, }, |
| 137 | { /* end of list */ }, |
| 138 | }; |
| 139 | MODULE_DEVICE_TABLE(css, io_subchannel_ids); |
| 140 | |
Cornelia Huck | f7e5d67 | 2007-05-10 15:45:43 +0200 | [diff] [blame] | 141 | static struct css_driver io_subchannel_driver = { |
Cornelia Huck | 4beee64 | 2008-01-26 14:10:47 +0100 | [diff] [blame] | 142 | .owner = THIS_MODULE, |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 143 | .subchannel_type = io_subchannel_ids, |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 144 | .name = "io_subchannel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | .irq = io_subchannel_irq, |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 146 | .sch_event = io_subchannel_sch_event, |
| 147 | .chp_event = io_subchannel_chp_event, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 148 | .probe = io_subchannel_probe, |
| 149 | .remove = io_subchannel_remove, |
| 150 | .shutdown = io_subchannel_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | struct workqueue_struct *ccw_device_work; |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 154 | wait_queue_head_t ccw_device_init_wq; |
| 155 | atomic_t ccw_device_init_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 157 | static void recovery_func(unsigned long data); |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static int __init |
| 160 | init_ccw_bus_type (void) |
| 161 | { |
| 162 | int ret; |
| 163 | |
| 164 | init_waitqueue_head(&ccw_device_init_wq); |
| 165 | atomic_set(&ccw_device_init_count, 0); |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 166 | setup_timer(&recovery_timer, recovery_func, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | ccw_device_work = create_singlethread_workqueue("cio"); |
| 169 | if (!ccw_device_work) |
| 170 | return -ENOMEM; /* FIXME: better errno ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | slow_path_wq = create_singlethread_workqueue("kslowcrw"); |
| 172 | if (!slow_path_wq) { |
| 173 | ret = -ENOMEM; /* FIXME: better errno ? */ |
| 174 | goto out_err; |
| 175 | } |
| 176 | if ((ret = bus_register (&ccw_bus_type))) |
| 177 | goto out_err; |
| 178 | |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 179 | ret = css_driver_register(&io_subchannel_driver); |
| 180 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | goto out_err; |
| 182 | |
| 183 | wait_event(ccw_device_init_wq, |
| 184 | atomic_read(&ccw_device_init_count) == 0); |
| 185 | flush_workqueue(ccw_device_work); |
| 186 | return 0; |
| 187 | out_err: |
| 188 | if (ccw_device_work) |
| 189 | destroy_workqueue(ccw_device_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | if (slow_path_wq) |
| 191 | destroy_workqueue(slow_path_wq); |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | static void __exit |
| 196 | cleanup_ccw_bus_type (void) |
| 197 | { |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 198 | css_driver_unregister(&io_subchannel_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | bus_unregister(&ccw_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | destroy_workqueue(ccw_device_work); |
| 201 | } |
| 202 | |
| 203 | subsys_initcall(init_ccw_bus_type); |
| 204 | module_exit(cleanup_ccw_bus_type); |
| 205 | |
| 206 | /************************ device handling **************************/ |
| 207 | |
| 208 | /* |
| 209 | * A ccw_device has some interfaces in sysfs in addition to the |
| 210 | * standard ones. |
| 211 | * The following entries are designed to export the information which |
| 212 | * resided in 2.4 in /proc/subchannels. Subchannel and device number |
| 213 | * are obvious, so they don't have an entry :) |
| 214 | * TODO: Split chpids and pimpampom up? Where is "in use" in the tree? |
| 215 | */ |
| 216 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 217 | chpids_show (struct device * dev, struct device_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
| 219 | struct subchannel *sch = to_subchannel(dev); |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 220 | struct chsc_ssd_info *ssd = &sch->ssd_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | ssize_t ret = 0; |
| 222 | int chp; |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 223 | int mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 225 | for (chp = 0; chp < 8; chp++) { |
| 226 | mask = 0x80 >> chp; |
| 227 | if (ssd->path_mask & mask) |
| 228 | ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id); |
| 229 | else |
| 230 | ret += sprintf(buf + ret, "00 "); |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | ret += sprintf (buf+ret, "\n"); |
| 233 | return min((ssize_t)PAGE_SIZE, ret); |
| 234 | } |
| 235 | |
| 236 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 237 | pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | struct subchannel *sch = to_subchannel(dev); |
| 240 | struct pmcw *pmcw = &sch->schib.pmcw; |
| 241 | |
| 242 | return sprintf (buf, "%02x %02x %02x\n", |
| 243 | pmcw->pim, pmcw->pam, pmcw->pom); |
| 244 | } |
| 245 | |
| 246 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 247 | devtype_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | struct ccw_device *cdev = to_ccwdev(dev); |
| 250 | struct ccw_device_id *id = &(cdev->id); |
| 251 | |
| 252 | if (id->dev_type != 0) |
| 253 | return sprintf(buf, "%04x/%02x\n", |
| 254 | id->dev_type, id->dev_model); |
| 255 | else |
| 256 | return sprintf(buf, "n/a\n"); |
| 257 | } |
| 258 | |
| 259 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 260 | cutype_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
| 262 | struct ccw_device *cdev = to_ccwdev(dev); |
| 263 | struct ccw_device_id *id = &(cdev->id); |
| 264 | |
| 265 | return sprintf(buf, "%04x/%02x\n", |
| 266 | id->cu_type, id->cu_model); |
| 267 | } |
| 268 | |
| 269 | static ssize_t |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 270 | modalias_show (struct device *dev, struct device_attribute *attr, char *buf) |
| 271 | { |
| 272 | struct ccw_device *cdev = to_ccwdev(dev); |
| 273 | struct ccw_device_id *id = &(cdev->id); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 274 | int len; |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 275 | |
Cornelia Huck | 086a6c6 | 2007-07-17 13:36:08 +0200 | [diff] [blame] | 276 | len = snprint_alias(buf, PAGE_SIZE, id, "\n"); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 277 | |
| 278 | return len > PAGE_SIZE ? PAGE_SIZE : len; |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 282 | online_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | struct ccw_device *cdev = to_ccwdev(dev); |
| 285 | |
| 286 | return sprintf(buf, cdev->online ? "1\n" : "0\n"); |
| 287 | } |
| 288 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 289 | int ccw_device_is_orphan(struct ccw_device *cdev) |
| 290 | { |
| 291 | return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent)); |
| 292 | } |
| 293 | |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 294 | static void ccw_device_unregister(struct ccw_device *cdev) |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 295 | { |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 296 | if (test_and_clear_bit(1, &cdev->private->registered)) |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 297 | device_del(&cdev->dev); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 300 | static void ccw_device_remove_orphan_cb(struct work_struct *work) |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 301 | { |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 302 | struct ccw_device_private *priv; |
| 303 | struct ccw_device *cdev; |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 304 | |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 305 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 306 | cdev = priv->cdev; |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 307 | ccw_device_unregister(cdev); |
| 308 | put_device(&cdev->dev); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 309 | /* Release cdev reference for workqueue processing. */ |
| 310 | put_device(&cdev->dev); |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 313 | static void ccw_device_call_sch_unregister(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 315 | static void |
| 316 | ccw_device_remove_disconnected(struct ccw_device *cdev) |
| 317 | { |
| 318 | unsigned long flags; |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 319 | |
| 320 | /* |
| 321 | * Forced offline in disconnected state means |
| 322 | * 'throw away device'. |
| 323 | */ |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 324 | /* Get cdev reference for workqueue processing. */ |
| 325 | if (!get_device(&cdev->dev)) |
| 326 | return; |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 327 | if (ccw_device_is_orphan(cdev)) { |
| 328 | /* |
| 329 | * Deregister ccw device. |
| 330 | * Unfortunately, we cannot do this directly from the |
| 331 | * attribute method. |
| 332 | */ |
| 333 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 334 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 335 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 336 | PREPARE_WORK(&cdev->private->kick_work, |
| 337 | ccw_device_remove_orphan_cb); |
| 338 | } else |
| 339 | /* Deregister subchannel, which will kill the ccw device. */ |
| 340 | PREPARE_WORK(&cdev->private->kick_work, |
| 341 | ccw_device_call_sch_unregister); |
| 342 | queue_work(slow_path_wq, &cdev->private->kick_work); |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 345 | /** |
| 346 | * ccw_device_set_offline() - disable a ccw device for I/O |
| 347 | * @cdev: target ccw device |
| 348 | * |
| 349 | * This function calls the driver's set_offline() function for @cdev, if |
| 350 | * given, and then disables @cdev. |
| 351 | * Returns: |
| 352 | * %0 on success and a negative error value on failure. |
| 353 | * Context: |
| 354 | * enabled, ccw device lock not held |
| 355 | */ |
| 356 | int ccw_device_set_offline(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
| 358 | int ret; |
| 359 | |
| 360 | if (!cdev) |
| 361 | return -ENODEV; |
| 362 | if (!cdev->online || !cdev->drv) |
| 363 | return -EINVAL; |
| 364 | |
| 365 | if (cdev->drv->set_offline) { |
| 366 | ret = cdev->drv->set_offline(cdev); |
| 367 | if (ret != 0) |
| 368 | return ret; |
| 369 | } |
| 370 | cdev->online = 0; |
| 371 | spin_lock_irq(cdev->ccwlock); |
| 372 | ret = ccw_device_offline(cdev); |
| 373 | if (ret == -ENODEV) { |
| 374 | if (cdev->private->state != DEV_STATE_NOT_OPER) { |
| 375 | cdev->private->state = DEV_STATE_OFFLINE; |
| 376 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 377 | } |
| 378 | spin_unlock_irq(cdev->ccwlock); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 379 | /* Give up reference from ccw_device_set_online(). */ |
| 380 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return ret; |
| 382 | } |
| 383 | spin_unlock_irq(cdev->ccwlock); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 384 | if (ret == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 386 | /* Give up reference from ccw_device_set_online(). */ |
| 387 | put_device(&cdev->dev); |
| 388 | } else { |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 389 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 390 | "device 0.%x.%04x\n", |
| 391 | ret, cdev->private->dev_id.ssid, |
| 392 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | cdev->online = 1; |
| 394 | } |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 395 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 398 | /** |
| 399 | * ccw_device_set_online() - enable a ccw device for I/O |
| 400 | * @cdev: target ccw device |
| 401 | * |
| 402 | * This function first enables @cdev and then calls the driver's set_online() |
| 403 | * function for @cdev, if given. If set_online() returns an error, @cdev is |
| 404 | * disabled again. |
| 405 | * Returns: |
| 406 | * %0 on success and a negative error value on failure. |
| 407 | * Context: |
| 408 | * enabled, ccw device lock not held |
| 409 | */ |
| 410 | int ccw_device_set_online(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
| 412 | int ret; |
| 413 | |
| 414 | if (!cdev) |
| 415 | return -ENODEV; |
| 416 | if (cdev->online || !cdev->drv) |
| 417 | return -EINVAL; |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 418 | /* Hold on to an extra reference while device is online. */ |
| 419 | if (!get_device(&cdev->dev)) |
| 420 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | spin_lock_irq(cdev->ccwlock); |
| 423 | ret = ccw_device_online(cdev); |
| 424 | spin_unlock_irq(cdev->ccwlock); |
| 425 | if (ret == 0) |
| 426 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 427 | else { |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 428 | CIO_MSG_EVENT(0, "ccw_device_online returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 429 | "device 0.%x.%04x\n", |
| 430 | ret, cdev->private->dev_id.ssid, |
| 431 | cdev->private->dev_id.devno); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 432 | /* Give up online reference since onlining failed. */ |
| 433 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return ret; |
| 435 | } |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 436 | if (cdev->private->state != DEV_STATE_ONLINE) { |
| 437 | /* Give up online reference since onlining failed. */ |
| 438 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | return -ENODEV; |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) { |
| 442 | cdev->online = 1; |
| 443 | return 0; |
| 444 | } |
| 445 | spin_lock_irq(cdev->ccwlock); |
| 446 | ret = ccw_device_offline(cdev); |
| 447 | spin_unlock_irq(cdev->ccwlock); |
| 448 | if (ret == 0) |
| 449 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 450 | else |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 451 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 452 | "device 0.%x.%04x\n", |
| 453 | ret, cdev->private->dev_id.ssid, |
| 454 | cdev->private->dev_id.devno); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 455 | /* Give up online reference since onlining failed. */ |
| 456 | put_device(&cdev->dev); |
Cornelia Huck | 6cadb78 | 2006-02-17 13:52:49 -0800 | [diff] [blame] | 457 | return (ret == 0) ? -ENODEV : ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 460 | static void online_store_handle_offline(struct ccw_device *cdev) |
| 461 | { |
| 462 | if (cdev->private->state == DEV_STATE_DISCONNECTED) |
| 463 | ccw_device_remove_disconnected(cdev); |
| 464 | else if (cdev->drv && cdev->drv->set_offline) |
| 465 | ccw_device_set_offline(cdev); |
| 466 | } |
| 467 | |
| 468 | static int online_store_recog_and_online(struct ccw_device *cdev) |
| 469 | { |
| 470 | int ret; |
| 471 | |
| 472 | /* Do device recognition, if needed. */ |
| 473 | if (cdev->id.cu_type == 0) { |
| 474 | ret = ccw_device_recognition(cdev); |
| 475 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 476 | CIO_MSG_EVENT(0, "Couldn't start recognition " |
| 477 | "for device 0.%x.%04x (ret=%d)\n", |
| 478 | cdev->private->dev_id.ssid, |
| 479 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 480 | return ret; |
| 481 | } |
| 482 | wait_event(cdev->private->wait_q, |
| 483 | cdev->private->flags.recog_done); |
| 484 | } |
| 485 | if (cdev->drv && cdev->drv->set_online) |
| 486 | ccw_device_set_online(cdev); |
| 487 | return 0; |
| 488 | } |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 489 | static int online_store_handle_online(struct ccw_device *cdev, int force) |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 490 | { |
| 491 | int ret; |
| 492 | |
| 493 | ret = online_store_recog_and_online(cdev); |
| 494 | if (ret) |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 495 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 496 | if (force && cdev->private->state == DEV_STATE_BOXED) { |
| 497 | ret = ccw_device_stlck(cdev); |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 498 | if (ret) |
| 499 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 500 | if (cdev->id.cu_type == 0) |
| 501 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 502 | online_store_recog_and_online(cdev); |
| 503 | } |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 504 | return 0; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static ssize_t online_store (struct device *dev, struct device_attribute *attr, |
| 508 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | struct ccw_device *cdev = to_ccwdev(dev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 511 | int force, ret; |
| 512 | unsigned long i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 514 | if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | return -EAGAIN; |
| 516 | |
| 517 | if (cdev->drv && !try_module_get(cdev->drv->owner)) { |
| 518 | atomic_set(&cdev->private->onoff, 0); |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | if (!strncmp(buf, "force\n", count)) { |
| 522 | force = 1; |
| 523 | i = 1; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 524 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } else { |
| 526 | force = 0; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 527 | ret = strict_strtoul(buf, 16, &i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 529 | if (ret) |
| 530 | goto out; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 531 | switch (i) { |
| 532 | case 0: |
| 533 | online_store_handle_offline(cdev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 534 | ret = count; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 535 | break; |
| 536 | case 1: |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 537 | ret = online_store_handle_online(cdev, force); |
| 538 | if (!ret) |
| 539 | ret = count; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 540 | break; |
| 541 | default: |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 542 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 544 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (cdev->drv) |
| 546 | module_put(cdev->drv->owner); |
| 547 | atomic_set(&cdev->private->onoff, 0); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 548 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 552 | available_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
| 554 | struct ccw_device *cdev = to_ccwdev(dev); |
| 555 | struct subchannel *sch; |
| 556 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 557 | if (ccw_device_is_orphan(cdev)) |
| 558 | return sprintf(buf, "no device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | switch (cdev->private->state) { |
| 560 | case DEV_STATE_BOXED: |
| 561 | return sprintf(buf, "boxed\n"); |
| 562 | case DEV_STATE_DISCONNECTED: |
| 563 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 564 | case DEV_STATE_NOT_OPER: |
| 565 | sch = to_subchannel(dev->parent); |
| 566 | if (!sch->lpm) |
| 567 | return sprintf(buf, "no path\n"); |
| 568 | else |
| 569 | return sprintf(buf, "no device\n"); |
| 570 | default: |
| 571 | /* All other states considered fine. */ |
| 572 | return sprintf(buf, "good\n"); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | static DEVICE_ATTR(chpids, 0444, chpids_show, NULL); |
| 577 | static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); |
| 578 | static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); |
| 579 | static DEVICE_ATTR(cutype, 0444, cutype_show, NULL); |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 580 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | static DEVICE_ATTR(online, 0644, online_show, online_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | static DEVICE_ATTR(availability, 0444, available_show, NULL); |
| 583 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 584 | static struct attribute *io_subchannel_attrs[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | &dev_attr_chpids.attr, |
| 586 | &dev_attr_pimpampom.attr, |
| 587 | NULL, |
| 588 | }; |
| 589 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 590 | static struct attribute_group io_subchannel_attr_group = { |
| 591 | .attrs = io_subchannel_attrs, |
Cornelia Huck | 529192f | 2006-12-08 15:55:57 +0100 | [diff] [blame] | 592 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | static struct attribute * ccwdev_attrs[] = { |
| 595 | &dev_attr_devtype.attr, |
| 596 | &dev_attr_cutype.attr, |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 597 | &dev_attr_modalias.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | &dev_attr_online.attr, |
| 599 | &dev_attr_cmb_enable.attr, |
| 600 | &dev_attr_availability.attr, |
| 601 | NULL, |
| 602 | }; |
| 603 | |
| 604 | static struct attribute_group ccwdev_attr_group = { |
| 605 | .attrs = ccwdev_attrs, |
| 606 | }; |
| 607 | |
Cornelia Huck | f7e5d67 | 2007-05-10 15:45:43 +0200 | [diff] [blame] | 608 | static struct attribute_group *ccwdev_attr_groups[] = { |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 609 | &ccwdev_attr_group, |
| 610 | NULL, |
| 611 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | /* this is a simple abstraction for device_register that sets the |
| 614 | * correct bus type and adds the bus specific files */ |
Cornelia Huck | 3c9da7b | 2006-10-27 12:39:33 +0200 | [diff] [blame] | 615 | static int ccw_device_register(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
| 617 | struct device *dev = &cdev->dev; |
| 618 | int ret; |
| 619 | |
| 620 | dev->bus = &ccw_bus_type; |
| 621 | |
| 622 | if ((ret = device_add(dev))) |
| 623 | return ret; |
| 624 | |
| 625 | set_bit(1, &cdev->private->registered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return ret; |
| 627 | } |
| 628 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 629 | struct match_data { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 630 | struct ccw_dev_id dev_id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 631 | struct ccw_device * sibling; |
| 632 | }; |
| 633 | |
| 634 | static int |
| 635 | match_devno(struct device * dev, void * data) |
| 636 | { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 637 | struct match_data * d = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 638 | struct ccw_device * cdev; |
| 639 | |
| 640 | cdev = to_ccwdev(dev); |
| 641 | if ((cdev->private->state == DEV_STATE_DISCONNECTED) && |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 642 | !ccw_device_is_orphan(cdev) && |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 643 | ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) && |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 644 | (cdev != d->sibling)) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 645 | return 1; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 649 | static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id, |
| 650 | struct ccw_device *sibling) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | struct device *dev; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 653 | struct match_data data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 655 | data.dev_id = *dev_id; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 656 | data.sibling = sibling; |
Cornelia Huck | e5945b4 | 2005-10-11 08:28:59 -0700 | [diff] [blame] | 657 | dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 659 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 662 | static int match_orphan(struct device *dev, void *data) |
| 663 | { |
| 664 | struct ccw_dev_id *dev_id; |
| 665 | struct ccw_device *cdev; |
| 666 | |
| 667 | dev_id = data; |
| 668 | cdev = to_ccwdev(dev); |
| 669 | return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); |
| 670 | } |
| 671 | |
| 672 | static struct ccw_device * |
| 673 | get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css, |
| 674 | struct ccw_dev_id *dev_id) |
| 675 | { |
| 676 | struct device *dev; |
| 677 | |
| 678 | dev = device_find_child(&css->pseudo_subchannel->dev, dev_id, |
| 679 | match_orphan); |
| 680 | |
| 681 | return dev ? to_ccwdev(dev) : NULL; |
| 682 | } |
| 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 685 | ccw_device_add_changed(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 687 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | struct ccw_device *cdev; |
| 689 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 690 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 691 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | if (device_add(&cdev->dev)) { |
| 693 | put_device(&cdev->dev); |
| 694 | return; |
| 695 | } |
| 696 | set_bit(1, &cdev->private->registered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 699 | void ccw_device_do_unreg_rereg(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 701 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | struct ccw_device *cdev; |
| 703 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 705 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 706 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | sch = to_subchannel(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 709 | ccw_device_unregister(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 711 | ccw_device_add_changed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | queue_work(ccw_device_work, &cdev->private->kick_work); |
| 713 | } |
| 714 | |
| 715 | static void |
| 716 | ccw_device_release(struct device *dev) |
| 717 | { |
| 718 | struct ccw_device *cdev; |
| 719 | |
| 720 | cdev = to_ccwdev(dev); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 721 | /* Release reference of parent subchannel. */ |
| 722 | put_device(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | kfree(cdev->private); |
| 724 | kfree(cdev); |
| 725 | } |
| 726 | |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 727 | static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) |
| 728 | { |
| 729 | struct ccw_device *cdev; |
| 730 | |
| 731 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 732 | if (cdev) { |
| 733 | cdev->private = kzalloc(sizeof(struct ccw_device_private), |
| 734 | GFP_KERNEL | GFP_DMA); |
| 735 | if (cdev->private) |
| 736 | return cdev; |
| 737 | } |
| 738 | kfree(cdev); |
| 739 | return ERR_PTR(-ENOMEM); |
| 740 | } |
| 741 | |
| 742 | static int io_subchannel_initialize_dev(struct subchannel *sch, |
| 743 | struct ccw_device *cdev) |
| 744 | { |
| 745 | cdev->private->cdev = cdev; |
| 746 | atomic_set(&cdev->private->onoff, 0); |
| 747 | cdev->dev.parent = &sch->dev; |
| 748 | cdev->dev.release = ccw_device_release; |
Heiko Carstens | 33583c3 | 2007-11-05 11:10:07 +0100 | [diff] [blame] | 749 | INIT_WORK(&cdev->private->kick_work, NULL); |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 750 | cdev->dev.groups = ccwdev_attr_groups; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 751 | /* Do first half of device_register. */ |
| 752 | device_initialize(&cdev->dev); |
| 753 | if (!get_device(&sch->dev)) { |
Cornelia Huck | 283fdd0 | 2008-12-25 13:39:10 +0100 | [diff] [blame] | 754 | /* Release reference from device_initialize(). */ |
| 755 | put_device(&cdev->dev); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 756 | return -ENODEV; |
| 757 | } |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch) |
| 762 | { |
| 763 | struct ccw_device *cdev; |
| 764 | int ret; |
| 765 | |
| 766 | cdev = io_subchannel_allocate_dev(sch); |
| 767 | if (!IS_ERR(cdev)) { |
| 768 | ret = io_subchannel_initialize_dev(sch, cdev); |
| 769 | if (ret) { |
| 770 | kfree(cdev); |
| 771 | cdev = ERR_PTR(ret); |
| 772 | } |
| 773 | } |
| 774 | return cdev; |
| 775 | } |
| 776 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 777 | static int io_subchannel_recog(struct ccw_device *, struct subchannel *); |
| 778 | |
| 779 | static void sch_attach_device(struct subchannel *sch, |
| 780 | struct ccw_device *cdev) |
| 781 | { |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 782 | css_update_ssd_info(sch); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 783 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 784 | sch_set_cdev(sch, cdev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 785 | cdev->private->schid = sch->schid; |
| 786 | cdev->ccwlock = sch->lock; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 787 | ccw_device_trigger_reprobe(cdev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 788 | spin_unlock_irq(sch->lock); |
| 789 | } |
| 790 | |
| 791 | static void sch_attach_disconnected_device(struct subchannel *sch, |
| 792 | struct ccw_device *cdev) |
| 793 | { |
| 794 | struct subchannel *other_sch; |
| 795 | int ret; |
| 796 | |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 797 | /* Get reference for new parent. */ |
| 798 | if (!get_device(&sch->dev)) |
| 799 | return; |
| 800 | other_sch = to_subchannel(cdev->dev.parent); |
| 801 | /* Note: device_move() changes cdev->dev.parent */ |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame^] | 802 | ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 803 | if (ret) { |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 804 | CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed " |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 805 | "(ret=%d)!\n", cdev->private->dev_id.ssid, |
| 806 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 807 | /* Put reference for new parent. */ |
| 808 | put_device(&sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 809 | return; |
| 810 | } |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 811 | sch_set_cdev(other_sch, NULL); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 812 | /* No need to keep a subchannel without ccw device around. */ |
| 813 | css_sch_device_unregister(other_sch); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 814 | sch_attach_device(sch, cdev); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 815 | /* Put reference for old parent. */ |
| 816 | put_device(&other_sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | static void sch_attach_orphaned_device(struct subchannel *sch, |
| 820 | struct ccw_device *cdev) |
| 821 | { |
| 822 | int ret; |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 823 | struct subchannel *pseudo_sch; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 824 | |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 825 | /* Get reference for new parent. */ |
| 826 | if (!get_device(&sch->dev)) |
| 827 | return; |
| 828 | pseudo_sch = to_subchannel(cdev->dev.parent); |
| 829 | /* |
| 830 | * Try to move the ccw device to its new subchannel. |
| 831 | * Note: device_move() changes cdev->dev.parent |
| 832 | */ |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame^] | 833 | ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 834 | if (ret) { |
| 835 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " |
| 836 | "failed (ret=%d)!\n", |
| 837 | cdev->private->dev_id.ssid, |
| 838 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 839 | /* Put reference for new parent. */ |
| 840 | put_device(&sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | sch_attach_device(sch, cdev); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 844 | /* Put reference on pseudo subchannel. */ |
| 845 | put_device(&pseudo_sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static void sch_create_and_recog_new_device(struct subchannel *sch) |
| 849 | { |
| 850 | struct ccw_device *cdev; |
| 851 | |
| 852 | /* Need to allocate a new ccw device. */ |
| 853 | cdev = io_subchannel_create_ccwdev(sch); |
| 854 | if (IS_ERR(cdev)) { |
| 855 | /* OK, we did everything we could... */ |
| 856 | css_sch_device_unregister(sch); |
| 857 | return; |
| 858 | } |
| 859 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 860 | sch_set_cdev(sch, cdev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 861 | spin_unlock_irq(sch->lock); |
| 862 | /* Start recognition for the new ccw device. */ |
| 863 | if (io_subchannel_recog(cdev, sch)) { |
| 864 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 865 | sch_set_cdev(sch, NULL); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 866 | spin_unlock_irq(sch->lock); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 867 | css_sch_device_unregister(sch); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 868 | /* Put reference from io_subchannel_create_ccwdev(). */ |
| 869 | put_device(&sch->dev); |
| 870 | /* Give up initial reference. */ |
| 871 | put_device(&cdev->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
| 875 | |
| 876 | void ccw_device_move_to_orphanage(struct work_struct *work) |
| 877 | { |
| 878 | struct ccw_device_private *priv; |
| 879 | struct ccw_device *cdev; |
| 880 | struct ccw_device *replacing_cdev; |
| 881 | struct subchannel *sch; |
| 882 | int ret; |
| 883 | struct channel_subsystem *css; |
| 884 | struct ccw_dev_id dev_id; |
| 885 | |
| 886 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 887 | cdev = priv->cdev; |
| 888 | sch = to_subchannel(cdev->dev.parent); |
| 889 | css = to_css(sch->dev.parent); |
| 890 | dev_id.devno = sch->schib.pmcw.dev; |
| 891 | dev_id.ssid = sch->schid.ssid; |
| 892 | |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 893 | /* Increase refcount for pseudo subchannel. */ |
| 894 | get_device(&css->pseudo_subchannel->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 895 | /* |
| 896 | * Move the orphaned ccw device to the orphanage so the replacing |
| 897 | * ccw device can take its place on the subchannel. |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 898 | * Note: device_move() changes cdev->dev.parent |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 899 | */ |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame^] | 900 | ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev, |
| 901 | DPM_ORDER_NONE); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 902 | if (ret) { |
| 903 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " |
| 904 | "(ret=%d)!\n", cdev->private->dev_id.ssid, |
| 905 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 906 | /* Decrease refcount for pseudo subchannel again. */ |
| 907 | put_device(&css->pseudo_subchannel->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 908 | return; |
| 909 | } |
| 910 | cdev->ccwlock = css->pseudo_subchannel->lock; |
| 911 | /* |
| 912 | * Search for the replacing ccw device |
| 913 | * - among the disconnected devices |
| 914 | * - in the orphanage |
| 915 | */ |
| 916 | replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev); |
| 917 | if (replacing_cdev) { |
| 918 | sch_attach_disconnected_device(sch, replacing_cdev); |
Cornelia Huck | 85acc40 | 2008-11-14 18:18:06 +0100 | [diff] [blame] | 919 | /* Release reference from get_disc_ccwdev_by_dev_id() */ |
Cornelia Huck | 97166f5 | 2008-12-25 13:39:05 +0100 | [diff] [blame] | 920 | put_device(&replacing_cdev->dev); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 921 | /* Release reference of subchannel from old cdev. */ |
| 922 | put_device(&sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 923 | return; |
| 924 | } |
| 925 | replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id); |
| 926 | if (replacing_cdev) { |
| 927 | sch_attach_orphaned_device(sch, replacing_cdev); |
Cornelia Huck | 85acc40 | 2008-11-14 18:18:06 +0100 | [diff] [blame] | 928 | /* Release reference from get_orphaned_ccwdev_by_dev_id() */ |
Cornelia Huck | 97166f5 | 2008-12-25 13:39:05 +0100 | [diff] [blame] | 929 | put_device(&replacing_cdev->dev); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 930 | /* Release reference of subchannel from old cdev. */ |
| 931 | put_device(&sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 932 | return; |
| 933 | } |
| 934 | sch_create_and_recog_new_device(sch); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 935 | /* Release reference of subchannel from old cdev. */ |
| 936 | put_device(&sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | /* |
| 940 | * Register recognized device. |
| 941 | */ |
| 942 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 943 | io_subchannel_register(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 945 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | struct ccw_device *cdev; |
| 947 | struct subchannel *sch; |
| 948 | int ret; |
| 949 | unsigned long flags; |
| 950 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 951 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 952 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 5fb6b85 | 2008-12-25 13:39:08 +0100 | [diff] [blame] | 954 | /* |
| 955 | * Check if subchannel is still registered. It may have become |
| 956 | * unregistered if a machine check hit us after finishing |
| 957 | * device recognition but before the register work could be |
| 958 | * queued. |
| 959 | */ |
| 960 | if (!device_is_registered(&sch->dev)) |
| 961 | goto out_err; |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 962 | css_update_ssd_info(sch); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 963 | /* |
| 964 | * io_subchannel_register() will also be called after device |
| 965 | * recognition has been done for a boxed device (which will already |
| 966 | * be registered). We need to reprobe since we may now have sense id |
| 967 | * information. |
| 968 | */ |
Cornelia Huck | d6a3076 | 2008-12-25 13:39:11 +0100 | [diff] [blame] | 969 | if (device_is_registered(&cdev->dev)) { |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 970 | if (!cdev->drv) { |
| 971 | ret = device_reprobe(&cdev->dev); |
| 972 | if (ret) |
| 973 | /* We can't do much here. */ |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 974 | CIO_MSG_EVENT(0, "device_reprobe() returned" |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 975 | " %d for 0.%x.%04x\n", ret, |
| 976 | cdev->private->dev_id.ssid, |
| 977 | cdev->private->dev_id.devno); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | goto out; |
| 980 | } |
Cornelia Huck | fa1a8c2 | 2007-04-26 00:12:03 -0700 | [diff] [blame] | 981 | /* |
| 982 | * Now we know this subchannel will stay, we can throw |
| 983 | * our delayed uevent. |
| 984 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 985 | dev_set_uevent_suppress(&sch->dev, 0); |
Cornelia Huck | fa1a8c2 | 2007-04-26 00:12:03 -0700 | [diff] [blame] | 986 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | /* make it known to the system */ |
| 988 | ret = ccw_device_register(cdev); |
| 989 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 990 | CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n", |
| 991 | cdev->private->dev_id.ssid, |
| 992 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 993 | spin_lock_irqsave(sch->lock, flags); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 994 | sch_set_cdev(sch, NULL); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 995 | spin_unlock_irqrestore(sch->lock, flags); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 996 | /* Release initial device reference. */ |
| 997 | put_device(&cdev->dev); |
Cornelia Huck | 5fb6b85 | 2008-12-25 13:39:08 +0100 | [diff] [blame] | 998 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | out: |
| 1001 | cdev->private->flags.recog_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | wake_up(&cdev->private->wait_q); |
Cornelia Huck | 5fb6b85 | 2008-12-25 13:39:08 +0100 | [diff] [blame] | 1003 | out_err: |
| 1004 | /* Release reference for workqueue processing. */ |
| 1005 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1007 | wake_up(&ccw_device_init_wq); |
| 1008 | } |
| 1009 | |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1010 | static void ccw_device_call_sch_unregister(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1012 | struct ccw_device_private *priv; |
| 1013 | struct ccw_device *cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | struct subchannel *sch; |
| 1015 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1016 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 1017 | cdev = priv->cdev; |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 1018 | /* Get subchannel reference for local processing. */ |
| 1019 | if (!get_device(cdev->dev.parent)) |
| 1020 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 1022 | css_sch_device_unregister(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | /* Reset intparm to zeroes. */ |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1024 | sch->config.intparm = 0; |
| 1025 | cio_commit_config(sch); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 1026 | /* Release cdev reference for workqueue processing.*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | put_device(&cdev->dev); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 1028 | /* Release subchannel reference for local processing. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | put_device(&sch->dev); |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | * subchannel recognition done. Called from the state machine. |
| 1034 | */ |
| 1035 | void |
| 1036 | io_subchannel_recog_done(struct ccw_device *cdev) |
| 1037 | { |
| 1038 | struct subchannel *sch; |
| 1039 | |
| 1040 | if (css_init_done == 0) { |
| 1041 | cdev->private->flags.recog_done = 1; |
| 1042 | return; |
| 1043 | } |
| 1044 | switch (cdev->private->state) { |
| 1045 | case DEV_STATE_NOT_OPER: |
| 1046 | cdev->private->flags.recog_done = 1; |
| 1047 | /* Remove device found not operational. */ |
| 1048 | if (!get_device(&cdev->dev)) |
| 1049 | break; |
| 1050 | sch = to_subchannel(cdev->dev.parent); |
| 1051 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1052 | ccw_device_call_sch_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1054 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1055 | wake_up(&ccw_device_init_wq); |
| 1056 | break; |
| 1057 | case DEV_STATE_BOXED: |
| 1058 | /* Device did not respond in time. */ |
| 1059 | case DEV_STATE_OFFLINE: |
| 1060 | /* |
| 1061 | * We can't register the device in interrupt context so |
| 1062 | * we schedule a work item. |
| 1063 | */ |
| 1064 | if (!get_device(&cdev->dev)) |
| 1065 | break; |
| 1066 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1067 | io_subchannel_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1069 | break; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | static int |
| 1074 | io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) |
| 1075 | { |
| 1076 | int rc; |
| 1077 | struct ccw_device_private *priv; |
| 1078 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1079 | sch_set_cdev(sch, cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1080 | cdev->ccwlock = sch->lock; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | /* Init private data. */ |
| 1083 | priv = cdev->private; |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 1084 | priv->dev_id.devno = sch->schib.pmcw.dev; |
| 1085 | priv->dev_id.ssid = sch->schid.ssid; |
| 1086 | priv->schid = sch->schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | priv->state = DEV_STATE_NOT_OPER; |
| 1088 | INIT_LIST_HEAD(&priv->cmb_list); |
| 1089 | init_waitqueue_head(&priv->wait_q); |
| 1090 | init_timer(&priv->timer); |
| 1091 | |
| 1092 | /* Set an initial name for the device. */ |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1093 | if (cio_is_console(sch->schid)) |
| 1094 | cdev->dev.init_name = cio_get_console_cdev_name(sch); |
| 1095 | else |
| 1096 | dev_set_name(&cdev->dev, "0.%x.%04x", |
| 1097 | sch->schid.ssid, sch->schib.pmcw.dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | /* Increase counter of devices currently in recognition. */ |
| 1100 | atomic_inc(&ccw_device_init_count); |
| 1101 | |
| 1102 | /* Start async. device sensing. */ |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1103 | spin_lock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | rc = ccw_device_recognition(cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1105 | spin_unlock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | if (rc) { |
| 1107 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1108 | wake_up(&ccw_device_init_wq); |
| 1109 | } |
| 1110 | return rc; |
| 1111 | } |
| 1112 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1113 | static void ccw_device_move_to_sch(struct work_struct *work) |
| 1114 | { |
| 1115 | struct ccw_device_private *priv; |
| 1116 | int rc; |
| 1117 | struct subchannel *sch; |
| 1118 | struct ccw_device *cdev; |
| 1119 | struct subchannel *former_parent; |
| 1120 | |
| 1121 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 1122 | sch = priv->sch; |
| 1123 | cdev = priv->cdev; |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 1124 | former_parent = to_subchannel(cdev->dev.parent); |
| 1125 | /* Get reference for new parent. */ |
| 1126 | if (!get_device(&sch->dev)) |
| 1127 | return; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1128 | mutex_lock(&sch->reg_mutex); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 1129 | /* |
| 1130 | * Try to move the ccw device to its new subchannel. |
| 1131 | * Note: device_move() changes cdev->dev.parent |
| 1132 | */ |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame^] | 1133 | rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1134 | mutex_unlock(&sch->reg_mutex); |
| 1135 | if (rc) { |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 1136 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel " |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1137 | "0.%x.%04x failed (ret=%d)!\n", |
| 1138 | cdev->private->dev_id.ssid, |
| 1139 | cdev->private->dev_id.devno, sch->schid.ssid, |
| 1140 | sch->schid.sch_no, rc); |
| 1141 | css_sch_device_unregister(sch); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 1142 | /* Put reference for new parent again. */ |
| 1143 | put_device(&sch->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1144 | goto out; |
| 1145 | } |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 1146 | if (!sch_is_pseudo_sch(former_parent)) { |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1147 | spin_lock_irq(former_parent->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1148 | sch_set_cdev(former_parent, NULL); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1149 | spin_unlock_irq(former_parent->lock); |
| 1150 | css_sch_device_unregister(former_parent); |
| 1151 | /* Reset intparm to zeroes. */ |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1152 | former_parent->config.intparm = 0; |
| 1153 | cio_commit_config(former_parent); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1154 | } |
| 1155 | sch_attach_device(sch, cdev); |
| 1156 | out: |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 1157 | /* Put reference for old parent. */ |
| 1158 | put_device(&former_parent->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1159 | put_device(&cdev->dev); |
| 1160 | } |
| 1161 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1162 | static void io_subchannel_irq(struct subchannel *sch) |
| 1163 | { |
| 1164 | struct ccw_device *cdev; |
| 1165 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1166 | cdev = sch_get_cdev(sch); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1167 | |
| 1168 | CIO_TRACE_EVENT(3, "IRQ"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1169 | CIO_TRACE_EVENT(3, dev_name(&sch->dev)); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1170 | if (cdev) |
| 1171 | dev_fsm_event(cdev, DEV_EVENT_INTERRUPT); |
| 1172 | } |
| 1173 | |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1174 | void io_subchannel_init_config(struct subchannel *sch) |
| 1175 | { |
| 1176 | memset(&sch->config, 0, sizeof(sch->config)); |
| 1177 | sch->config.csense = 1; |
Sebastian Ott | d36f0c6 | 2008-12-25 13:39:15 +0100 | [diff] [blame] | 1178 | /* Use subchannel mp mode when there is more than 1 installed CHPID. */ |
| 1179 | if ((sch->schib.pmcw.pim & (sch->schib.pmcw.pim - 1)) != 0) |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1180 | sch->config.mp = 1; |
| 1181 | } |
| 1182 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1183 | static void io_subchannel_init_fields(struct subchannel *sch) |
| 1184 | { |
| 1185 | if (cio_is_console(sch->schid)) |
| 1186 | sch->opm = 0xff; |
| 1187 | else |
| 1188 | sch->opm = chp_get_sch_opm(sch); |
| 1189 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 1190 | sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1191 | |
| 1192 | CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X" |
| 1193 | " - PIM = %02X, PAM = %02X, POM = %02X\n", |
| 1194 | sch->schib.pmcw.dev, sch->schid.ssid, |
| 1195 | sch->schid.sch_no, sch->schib.pmcw.pim, |
| 1196 | sch->schib.pmcw.pam, sch->schib.pmcw.pom); |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1197 | |
| 1198 | io_subchannel_init_config(sch); |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1201 | static void io_subchannel_do_unreg(struct work_struct *work) |
| 1202 | { |
| 1203 | struct subchannel *sch; |
| 1204 | |
| 1205 | sch = container_of(work, struct subchannel, work); |
| 1206 | css_sch_device_unregister(sch); |
| 1207 | /* Reset intparm to zeroes. */ |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1208 | sch->config.intparm = 0; |
| 1209 | cio_commit_config(sch); |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1210 | put_device(&sch->dev); |
| 1211 | } |
| 1212 | |
| 1213 | /* Schedule unregister if we have no cdev. */ |
| 1214 | static void io_subchannel_schedule_removal(struct subchannel *sch) |
| 1215 | { |
| 1216 | get_device(&sch->dev); |
| 1217 | INIT_WORK(&sch->work, io_subchannel_do_unreg); |
| 1218 | queue_work(slow_path_wq, &sch->work); |
| 1219 | } |
| 1220 | |
| 1221 | /* |
| 1222 | * Note: We always return 0 so that we bind to the device even on error. |
| 1223 | * This is needed so that our remove function is called on unregister. |
| 1224 | */ |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1225 | static int io_subchannel_probe(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | struct ccw_device *cdev; |
| 1228 | int rc; |
| 1229 | unsigned long flags; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1230 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1232 | cdev = sch_get_cdev(sch); |
| 1233 | if (cdev) { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1234 | rc = sysfs_create_group(&sch->dev.kobj, |
| 1235 | &io_subchannel_attr_group); |
| 1236 | if (rc) |
| 1237 | CIO_MSG_EVENT(0, "Failed to create io subchannel " |
| 1238 | "attributes for subchannel " |
| 1239 | "0.%x.%04x (rc=%d)\n", |
| 1240 | sch->schid.ssid, sch->schid.sch_no, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | /* |
| 1242 | * This subchannel already has an associated ccw_device. |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1243 | * Throw the delayed uevent for the subchannel, register |
| 1244 | * the ccw_device and exit. This happens for all early |
| 1245 | * devices, e.g. the console. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 1247 | dev_set_uevent_suppress(&sch->dev, 0); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1248 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Cornelia Huck | e103178 | 2007-10-12 16:11:23 +0200 | [diff] [blame] | 1249 | cdev->dev.groups = ccwdev_attr_groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | device_initialize(&cdev->dev); |
| 1251 | ccw_device_register(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | /* |
| 1253 | * Check if the device is already online. If it is |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 1254 | * the reference count needs to be corrected since we |
| 1255 | * didn't obtain a reference in ccw_device_set_online. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | */ |
| 1257 | if (cdev->private->state != DEV_STATE_NOT_OPER && |
| 1258 | cdev->private->state != DEV_STATE_OFFLINE && |
| 1259 | cdev->private->state != DEV_STATE_BOXED) |
| 1260 | get_device(&cdev->dev); |
| 1261 | return 0; |
| 1262 | } |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1263 | io_subchannel_init_fields(sch); |
Sebastian Ott | f444cc0 | 2008-12-25 13:39:14 +0100 | [diff] [blame] | 1264 | rc = cio_commit_config(sch); |
| 1265 | if (rc) |
| 1266 | goto out_schedule; |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1267 | rc = sysfs_create_group(&sch->dev.kobj, |
| 1268 | &io_subchannel_attr_group); |
| 1269 | if (rc) |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1270 | goto out_schedule; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1271 | /* Allocate I/O subchannel private data. */ |
| 1272 | sch->private = kzalloc(sizeof(struct io_subchannel_private), |
| 1273 | GFP_KERNEL | GFP_DMA); |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1274 | if (!sch->private) |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1275 | goto out_err; |
Sebastian Ott | 111e95a | 2008-12-25 13:39:03 +0100 | [diff] [blame] | 1276 | /* |
| 1277 | * First check if a fitting device may be found amongst the |
| 1278 | * disconnected devices or in the orphanage. |
| 1279 | */ |
| 1280 | dev_id.devno = sch->schib.pmcw.dev; |
| 1281 | dev_id.ssid = sch->schid.ssid; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1282 | cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); |
| 1283 | if (!cdev) |
| 1284 | cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), |
| 1285 | &dev_id); |
| 1286 | if (cdev) { |
| 1287 | /* |
| 1288 | * Schedule moving the device until when we have a registered |
| 1289 | * subchannel to move to and succeed the probe. We can |
| 1290 | * unregister later again, when the probe is through. |
| 1291 | */ |
| 1292 | cdev->private->sch = sch; |
| 1293 | PREPARE_WORK(&cdev->private->kick_work, |
| 1294 | ccw_device_move_to_sch); |
| 1295 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1296 | return 0; |
| 1297 | } |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 1298 | cdev = io_subchannel_create_ccwdev(sch); |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1299 | if (IS_ERR(cdev)) |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1300 | goto out_err; |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1301 | rc = io_subchannel_recog(cdev, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | if (rc) { |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1303 | spin_lock_irqsave(sch->lock, flags); |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1304 | io_subchannel_recog_done(cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1305 | spin_unlock_irqrestore(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1307 | return 0; |
| 1308 | out_err: |
| 1309 | kfree(sch->private); |
| 1310 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1311 | out_schedule: |
| 1312 | io_subchannel_schedule_removal(sch); |
| 1313 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | static int |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1317 | io_subchannel_remove (struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | { |
| 1319 | struct ccw_device *cdev; |
| 1320 | unsigned long flags; |
| 1321 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1322 | cdev = sch_get_cdev(sch); |
| 1323 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | /* Set ccw device to not operational and drop reference. */ |
| 1326 | spin_lock_irqsave(cdev->ccwlock, flags); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1327 | sch_set_cdev(sch, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1329 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 1330 | ccw_device_unregister(cdev); |
| 1331 | put_device(&cdev->dev); |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1332 | kfree(sch->private); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1333 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | return 0; |
| 1335 | } |
| 1336 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1337 | static int io_subchannel_notify(struct subchannel *sch, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | { |
| 1339 | struct ccw_device *cdev; |
| 1340 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1341 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | if (!cdev) |
| 1343 | return 0; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1344 | return ccw_device_notify(cdev, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1347 | static void io_subchannel_verify(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
| 1349 | struct ccw_device *cdev; |
| 1350 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1351 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | if (cdev) |
| 1353 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1354 | } |
| 1355 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1356 | static int check_for_io_on_path(struct subchannel *sch, int mask) |
| 1357 | { |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 1358 | if (cio_update_schib(sch)) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1359 | return 0; |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1360 | if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1361 | return 1; |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | static void terminate_internal_io(struct subchannel *sch, |
| 1366 | struct ccw_device *cdev) |
| 1367 | { |
| 1368 | if (cio_clear(sch)) { |
| 1369 | /* Recheck device in case clear failed. */ |
| 1370 | sch->lpm = 0; |
| 1371 | if (cdev->online) |
| 1372 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1373 | else |
| 1374 | css_schedule_eval(sch->schid); |
| 1375 | return; |
| 1376 | } |
| 1377 | cdev->private->state = DEV_STATE_CLEAR_VERIFY; |
| 1378 | /* Request retry of internal operation. */ |
| 1379 | cdev->private->flags.intretry = 1; |
| 1380 | /* Call handler. */ |
| 1381 | if (cdev->handler) |
| 1382 | cdev->handler(cdev, cdev->private->intparm, |
| 1383 | ERR_PTR(-EIO)); |
| 1384 | } |
| 1385 | |
| 1386 | static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | { |
| 1388 | struct ccw_device *cdev; |
| 1389 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1390 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | if (!cdev) |
| 1392 | return; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1393 | if (check_for_io_on_path(sch, mask)) { |
| 1394 | if (cdev->private->state == DEV_STATE_ONLINE) |
| 1395 | ccw_device_kill_io(cdev); |
| 1396 | else { |
| 1397 | terminate_internal_io(sch, cdev); |
| 1398 | /* Re-start path verification. */ |
| 1399 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1400 | } |
| 1401 | } else |
| 1402 | /* trigger path verification. */ |
| 1403 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1404 | |
| 1405 | } |
| 1406 | |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 1407 | static int io_subchannel_chp_event(struct subchannel *sch, |
| 1408 | struct chp_link *link, int event) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1409 | { |
| 1410 | int mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1411 | |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 1412 | mask = chp_ssd_get_mask(&sch->ssd_info, link); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1413 | if (!mask) |
| 1414 | return 0; |
| 1415 | switch (event) { |
| 1416 | case CHP_VARY_OFF: |
| 1417 | sch->opm &= ~mask; |
| 1418 | sch->lpm &= ~mask; |
| 1419 | io_subchannel_terminate_path(sch, mask); |
| 1420 | break; |
| 1421 | case CHP_VARY_ON: |
| 1422 | sch->opm |= mask; |
| 1423 | sch->lpm |= mask; |
| 1424 | io_subchannel_verify(sch); |
| 1425 | break; |
| 1426 | case CHP_OFFLINE: |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 1427 | if (cio_update_schib(sch)) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1428 | return -ENODEV; |
| 1429 | io_subchannel_terminate_path(sch, mask); |
| 1430 | break; |
| 1431 | case CHP_ONLINE: |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 1432 | if (cio_update_schib(sch)) |
| 1433 | return -ENODEV; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1434 | sch->lpm |= mask & sch->opm; |
| 1435 | io_subchannel_verify(sch); |
| 1436 | break; |
| 1437 | } |
| 1438 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | static void |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1442 | io_subchannel_shutdown(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | struct ccw_device *cdev; |
| 1445 | int ret; |
| 1446 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1447 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1449 | if (cio_is_console(sch->schid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | return; |
| 1451 | if (!sch->schib.pmcw.ena) |
| 1452 | /* Nothing to do. */ |
| 1453 | return; |
| 1454 | ret = cio_disable_subchannel(sch); |
| 1455 | if (ret != -EBUSY) |
| 1456 | /* Subchannel is disabled, we're done. */ |
| 1457 | return; |
| 1458 | cdev->private->state = DEV_STATE_QUIESCE; |
| 1459 | if (cdev->handler) |
| 1460 | cdev->handler(cdev, cdev->private->intparm, |
| 1461 | ERR_PTR(-EIO)); |
| 1462 | ret = ccw_device_cancel_halt_clear(cdev); |
| 1463 | if (ret == -EBUSY) { |
| 1464 | ccw_device_set_timeout(cdev, HZ/10); |
| 1465 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 1466 | } |
| 1467 | cio_disable_subchannel(sch); |
| 1468 | } |
| 1469 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1470 | static int io_subchannel_get_status(struct subchannel *sch) |
| 1471 | { |
| 1472 | struct schib schib; |
| 1473 | |
| 1474 | if (stsch(sch->schid, &schib) || !schib.pmcw.dnv) |
| 1475 | return CIO_GONE; |
| 1476 | if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev)) |
| 1477 | return CIO_REVALIDATE; |
| 1478 | if (!sch->lpm) |
| 1479 | return CIO_NO_PATH; |
| 1480 | return CIO_OPER; |
| 1481 | } |
| 1482 | |
| 1483 | static int device_is_disconnected(struct ccw_device *cdev) |
| 1484 | { |
| 1485 | if (!cdev) |
| 1486 | return 0; |
| 1487 | return (cdev->private->state == DEV_STATE_DISCONNECTED || |
| 1488 | cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID); |
| 1489 | } |
| 1490 | |
| 1491 | static int recovery_check(struct device *dev, void *data) |
| 1492 | { |
| 1493 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1494 | int *redo = data; |
| 1495 | |
| 1496 | spin_lock_irq(cdev->ccwlock); |
| 1497 | switch (cdev->private->state) { |
| 1498 | case DEV_STATE_DISCONNECTED: |
| 1499 | CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n", |
| 1500 | cdev->private->dev_id.ssid, |
| 1501 | cdev->private->dev_id.devno); |
| 1502 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1503 | *redo = 1; |
| 1504 | break; |
| 1505 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 1506 | *redo = 1; |
| 1507 | break; |
| 1508 | } |
| 1509 | spin_unlock_irq(cdev->ccwlock); |
| 1510 | |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | static void recovery_work_func(struct work_struct *unused) |
| 1515 | { |
| 1516 | int redo = 0; |
| 1517 | |
| 1518 | bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check); |
| 1519 | if (redo) { |
| 1520 | spin_lock_irq(&recovery_lock); |
| 1521 | if (!timer_pending(&recovery_timer)) { |
| 1522 | if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1) |
| 1523 | recovery_phase++; |
| 1524 | mod_timer(&recovery_timer, jiffies + |
| 1525 | recovery_delay[recovery_phase] * HZ); |
| 1526 | } |
| 1527 | spin_unlock_irq(&recovery_lock); |
| 1528 | } else |
| 1529 | CIO_MSG_EVENT(4, "recovery: end\n"); |
| 1530 | } |
| 1531 | |
| 1532 | static DECLARE_WORK(recovery_work, recovery_work_func); |
| 1533 | |
| 1534 | static void recovery_func(unsigned long data) |
| 1535 | { |
| 1536 | /* |
| 1537 | * We can't do our recovery in softirq context and it's not |
| 1538 | * performance critical, so we schedule it. |
| 1539 | */ |
| 1540 | schedule_work(&recovery_work); |
| 1541 | } |
| 1542 | |
| 1543 | static void ccw_device_schedule_recovery(void) |
| 1544 | { |
| 1545 | unsigned long flags; |
| 1546 | |
| 1547 | CIO_MSG_EVENT(4, "recovery: schedule\n"); |
| 1548 | spin_lock_irqsave(&recovery_lock, flags); |
| 1549 | if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) { |
| 1550 | recovery_phase = 0; |
| 1551 | mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ); |
| 1552 | } |
| 1553 | spin_unlock_irqrestore(&recovery_lock, flags); |
| 1554 | } |
| 1555 | |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 1556 | static int purge_fn(struct device *dev, void *data) |
| 1557 | { |
| 1558 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1559 | struct ccw_device_private *priv = cdev->private; |
| 1560 | int unreg; |
| 1561 | |
| 1562 | spin_lock_irq(cdev->ccwlock); |
| 1563 | unreg = is_blacklisted(priv->dev_id.ssid, priv->dev_id.devno) && |
| 1564 | (priv->state == DEV_STATE_OFFLINE); |
| 1565 | spin_unlock_irq(cdev->ccwlock); |
| 1566 | if (!unreg) |
| 1567 | goto out; |
| 1568 | if (!get_device(&cdev->dev)) |
| 1569 | goto out; |
| 1570 | CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", priv->dev_id.ssid, |
| 1571 | priv->dev_id.devno); |
| 1572 | PREPARE_WORK(&cdev->private->kick_work, ccw_device_call_sch_unregister); |
| 1573 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1574 | |
| 1575 | out: |
| 1576 | /* Abort loop in case of pending signal. */ |
| 1577 | if (signal_pending(current)) |
| 1578 | return -EINTR; |
| 1579 | |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * ccw_purge_blacklisted - purge unused, blacklisted devices |
| 1585 | * |
| 1586 | * Unregister all ccw devices that are offline and on the blacklist. |
| 1587 | */ |
| 1588 | int ccw_purge_blacklisted(void) |
| 1589 | { |
| 1590 | CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n"); |
| 1591 | bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn); |
| 1592 | return 0; |
| 1593 | } |
| 1594 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1595 | static void device_set_disconnected(struct ccw_device *cdev) |
| 1596 | { |
| 1597 | if (!cdev) |
| 1598 | return; |
| 1599 | ccw_device_set_timeout(cdev, 0); |
| 1600 | cdev->private->flags.fake_irb = 0; |
| 1601 | cdev->private->state = DEV_STATE_DISCONNECTED; |
| 1602 | if (cdev->online) |
| 1603 | ccw_device_schedule_recovery(); |
| 1604 | } |
| 1605 | |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1606 | void ccw_device_set_notoper(struct ccw_device *cdev) |
| 1607 | { |
| 1608 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1609 | |
| 1610 | CIO_TRACE_EVENT(2, "notoper"); |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 1611 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1612 | ccw_device_set_timeout(cdev, 0); |
| 1613 | cio_disable_subchannel(sch); |
| 1614 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1615 | } |
| 1616 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1617 | static int io_subchannel_sch_event(struct subchannel *sch, int slow) |
| 1618 | { |
| 1619 | int event, ret, disc; |
| 1620 | unsigned long flags; |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1621 | enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1622 | struct ccw_device *cdev; |
| 1623 | |
| 1624 | spin_lock_irqsave(sch->lock, flags); |
| 1625 | cdev = sch_get_cdev(sch); |
| 1626 | disc = device_is_disconnected(cdev); |
| 1627 | if (disc && slow) { |
| 1628 | /* Disconnected devices are evaluated directly only.*/ |
| 1629 | spin_unlock_irqrestore(sch->lock, flags); |
| 1630 | return 0; |
| 1631 | } |
| 1632 | /* No interrupt after machine check - kill pending timers. */ |
| 1633 | if (cdev) |
| 1634 | ccw_device_set_timeout(cdev, 0); |
| 1635 | if (!disc && !slow) { |
| 1636 | /* Non-disconnected devices are evaluated on the slow path. */ |
| 1637 | spin_unlock_irqrestore(sch->lock, flags); |
| 1638 | return -EAGAIN; |
| 1639 | } |
| 1640 | event = io_subchannel_get_status(sch); |
| 1641 | CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n", |
| 1642 | sch->schid.ssid, sch->schid.sch_no, event, |
| 1643 | disc ? "disconnected" : "normal", |
| 1644 | slow ? "slow" : "fast"); |
| 1645 | /* Analyze subchannel status. */ |
| 1646 | action = NONE; |
| 1647 | switch (event) { |
| 1648 | case CIO_NO_PATH: |
| 1649 | if (disc) { |
| 1650 | /* Check if paths have become available. */ |
| 1651 | action = REPROBE; |
| 1652 | break; |
| 1653 | } |
| 1654 | /* fall through */ |
| 1655 | case CIO_GONE: |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1656 | /* Ask driver what to do with device. */ |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1657 | if (io_subchannel_notify(sch, event)) |
| 1658 | action = DISC; |
| 1659 | else |
| 1660 | action = UNREGISTER; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1661 | break; |
| 1662 | case CIO_REVALIDATE: |
| 1663 | /* Device will be removed, so no notify necessary. */ |
| 1664 | if (disc) |
| 1665 | /* Reprobe because immediate unregister might block. */ |
| 1666 | action = REPROBE; |
| 1667 | else |
| 1668 | action = UNREGISTER_PROBE; |
| 1669 | break; |
| 1670 | case CIO_OPER: |
| 1671 | if (disc) |
| 1672 | /* Get device operational again. */ |
| 1673 | action = REPROBE; |
| 1674 | break; |
| 1675 | } |
| 1676 | /* Perform action. */ |
| 1677 | ret = 0; |
| 1678 | switch (action) { |
| 1679 | case UNREGISTER: |
| 1680 | case UNREGISTER_PROBE: |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1681 | ccw_device_set_notoper(cdev); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1682 | /* Unregister device (will use subchannel lock). */ |
| 1683 | spin_unlock_irqrestore(sch->lock, flags); |
| 1684 | css_sch_device_unregister(sch); |
| 1685 | spin_lock_irqsave(sch->lock, flags); |
| 1686 | |
| 1687 | /* Reset intparm to zeroes. */ |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1688 | sch->config.intparm = 0; |
| 1689 | cio_commit_config(sch); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1690 | break; |
| 1691 | case REPROBE: |
| 1692 | ccw_device_trigger_reprobe(cdev); |
| 1693 | break; |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1694 | case DISC: |
| 1695 | device_set_disconnected(cdev); |
| 1696 | break; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1697 | default: |
| 1698 | break; |
| 1699 | } |
| 1700 | spin_unlock_irqrestore(sch->lock, flags); |
| 1701 | /* Probe if necessary. */ |
| 1702 | if (action == UNREGISTER_PROBE) |
| 1703 | ret = css_probe_device(sch->schid); |
| 1704 | |
| 1705 | return ret; |
| 1706 | } |
| 1707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | #ifdef CONFIG_CCW_CONSOLE |
| 1709 | static struct ccw_device console_cdev; |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1710 | static char console_cdev_name[10] = "0.x.xxxx"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | static struct ccw_device_private console_private; |
| 1712 | static int console_cdev_in_use; |
| 1713 | |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1714 | static DEFINE_SPINLOCK(ccw_console_lock); |
| 1715 | |
| 1716 | spinlock_t * cio_get_console_lock(void) |
| 1717 | { |
| 1718 | return &ccw_console_lock; |
| 1719 | } |
| 1720 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1721 | static int ccw_device_console_enable(struct ccw_device *cdev, |
| 1722 | struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | { |
| 1724 | int rc; |
| 1725 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1726 | /* Attach subchannel private data. */ |
| 1727 | sch->private = cio_get_console_priv(); |
| 1728 | memset(sch->private, 0, sizeof(struct io_subchannel_private)); |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1729 | io_subchannel_init_fields(sch); |
Sebastian Ott | f444cc0 | 2008-12-25 13:39:14 +0100 | [diff] [blame] | 1730 | rc = cio_commit_config(sch); |
| 1731 | if (rc) |
| 1732 | return rc; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1733 | sch->driver = &io_subchannel_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | /* Initialize the ccw_device structure. */ |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 1735 | cdev->dev.parent= &sch->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | rc = io_subchannel_recog(cdev, sch); |
| 1737 | if (rc) |
| 1738 | return rc; |
| 1739 | |
| 1740 | /* Now wait for the async. recognition to come to an end. */ |
| 1741 | spin_lock_irq(cdev->ccwlock); |
| 1742 | while (!dev_fsm_final_state(cdev)) |
| 1743 | wait_cons_dev(); |
| 1744 | rc = -EIO; |
| 1745 | if (cdev->private->state != DEV_STATE_OFFLINE) |
| 1746 | goto out_unlock; |
| 1747 | ccw_device_online(cdev); |
| 1748 | while (!dev_fsm_final_state(cdev)) |
| 1749 | wait_cons_dev(); |
| 1750 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 1751 | goto out_unlock; |
| 1752 | rc = 0; |
| 1753 | out_unlock: |
| 1754 | spin_unlock_irq(cdev->ccwlock); |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | struct ccw_device * |
| 1759 | ccw_device_probe_console(void) |
| 1760 | { |
| 1761 | struct subchannel *sch; |
| 1762 | int ret; |
| 1763 | |
| 1764 | if (xchg(&console_cdev_in_use, 1) != 0) |
Peter Oberparleiter | 600b5d1 | 2006-02-01 03:06:35 -0800 | [diff] [blame] | 1765 | return ERR_PTR(-EBUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | sch = cio_probe_console(); |
| 1767 | if (IS_ERR(sch)) { |
| 1768 | console_cdev_in_use = 0; |
| 1769 | return (void *) sch; |
| 1770 | } |
| 1771 | memset(&console_cdev, 0, sizeof(struct ccw_device)); |
| 1772 | memset(&console_private, 0, sizeof(struct ccw_device_private)); |
| 1773 | console_cdev.private = &console_private; |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1774 | console_private.cdev = &console_cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | ret = ccw_device_console_enable(&console_cdev, sch); |
| 1776 | if (ret) { |
| 1777 | cio_release_console(); |
| 1778 | console_cdev_in_use = 0; |
| 1779 | return ERR_PTR(ret); |
| 1780 | } |
| 1781 | console_cdev.online = 1; |
| 1782 | return &console_cdev; |
| 1783 | } |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1784 | |
| 1785 | |
| 1786 | const char *cio_get_console_cdev_name(struct subchannel *sch) |
| 1787 | { |
| 1788 | snprintf(console_cdev_name, 10, "0.%x.%04x", |
| 1789 | sch->schid.ssid, sch->schib.pmcw.dev); |
| 1790 | return (const char *)console_cdev_name; |
| 1791 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | #endif |
| 1793 | |
| 1794 | /* |
| 1795 | * get ccw_device matching the busid, but only if owned by cdrv |
| 1796 | */ |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1797 | static int |
| 1798 | __ccwdev_check_busid(struct device *dev, void *id) |
| 1799 | { |
| 1800 | char *bus_id; |
| 1801 | |
Cornelia Huck | 12975ae | 2006-10-11 15:31:47 +0200 | [diff] [blame] | 1802 | bus_id = id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1803 | |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 1804 | return (strcmp(bus_id, dev_name(dev)) == 0); |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1808 | /** |
| 1809 | * get_ccwdev_by_busid() - obtain device from a bus id |
| 1810 | * @cdrv: driver the device is owned by |
| 1811 | * @bus_id: bus id of the device to be searched |
| 1812 | * |
| 1813 | * This function searches all devices owned by @cdrv for a device with a bus |
| 1814 | * id matching @bus_id. |
| 1815 | * Returns: |
| 1816 | * If a match is found, its reference count of the found device is increased |
| 1817 | * and it is returned; else %NULL is returned. |
| 1818 | */ |
| 1819 | struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 1820 | const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | { |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1822 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | struct device_driver *drv; |
| 1824 | |
| 1825 | drv = get_driver(&cdrv->driver); |
| 1826 | if (!drv) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1827 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1829 | dev = driver_find_device(drv, NULL, (void *)bus_id, |
| 1830 | __ccwdev_check_busid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | put_driver(drv); |
| 1832 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1833 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | /************************** device driver handling ************************/ |
| 1837 | |
| 1838 | /* This is the implementation of the ccw_driver class. The probe, remove |
| 1839 | * and release methods are initially very similar to the device_driver |
| 1840 | * implementations, with the difference that they have ccw_device |
| 1841 | * arguments. |
| 1842 | * |
| 1843 | * A ccw driver also contains the information that is needed for |
| 1844 | * device matching. |
| 1845 | */ |
| 1846 | static int |
| 1847 | ccw_device_probe (struct device *dev) |
| 1848 | { |
| 1849 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1850 | struct ccw_driver *cdrv = to_ccwdrv(dev->driver); |
| 1851 | int ret; |
| 1852 | |
| 1853 | cdev->drv = cdrv; /* to let the driver call _set_online */ |
| 1854 | |
| 1855 | ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; |
| 1856 | |
| 1857 | if (ret) { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1858 | cdev->drv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | return ret; |
| 1860 | } |
| 1861 | |
| 1862 | return 0; |
| 1863 | } |
| 1864 | |
| 1865 | static int |
| 1866 | ccw_device_remove (struct device *dev) |
| 1867 | { |
| 1868 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1869 | struct ccw_driver *cdrv = cdev->drv; |
| 1870 | int ret; |
| 1871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | if (cdrv->remove) |
| 1873 | cdrv->remove(cdev); |
| 1874 | if (cdev->online) { |
| 1875 | cdev->online = 0; |
| 1876 | spin_lock_irq(cdev->ccwlock); |
| 1877 | ret = ccw_device_offline(cdev); |
| 1878 | spin_unlock_irq(cdev->ccwlock); |
| 1879 | if (ret == 0) |
| 1880 | wait_event(cdev->private->wait_q, |
| 1881 | dev_fsm_final_state(cdev)); |
| 1882 | else |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 1883 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 1884 | "device 0.%x.%04x\n", |
| 1885 | ret, cdev->private->dev_id.ssid, |
| 1886 | cdev->private->dev_id.devno); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 1887 | /* Give up reference obtained in ccw_device_set_online(). */ |
| 1888 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
| 1890 | ccw_device_set_timeout(cdev, 0); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1891 | cdev->drv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | return 0; |
| 1893 | } |
| 1894 | |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1895 | static void ccw_device_shutdown(struct device *dev) |
| 1896 | { |
| 1897 | struct ccw_device *cdev; |
| 1898 | |
| 1899 | cdev = to_ccwdev(dev); |
| 1900 | if (cdev->drv && cdev->drv->shutdown) |
| 1901 | cdev->drv->shutdown(cdev); |
Cornelia Huck | 1842f2b | 2007-10-12 16:11:22 +0200 | [diff] [blame] | 1902 | disable_cmf(cdev); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1903 | } |
| 1904 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1905 | struct bus_type ccw_bus_type = { |
| 1906 | .name = "ccw", |
| 1907 | .match = ccw_bus_match, |
| 1908 | .uevent = ccw_uevent, |
| 1909 | .probe = ccw_device_probe, |
| 1910 | .remove = ccw_device_remove, |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1911 | .shutdown = ccw_device_shutdown, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1912 | }; |
| 1913 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1914 | /** |
| 1915 | * ccw_driver_register() - register a ccw driver |
| 1916 | * @cdriver: driver to be registered |
| 1917 | * |
| 1918 | * This function is mainly a wrapper around driver_register(). |
| 1919 | * Returns: |
| 1920 | * %0 on success and a negative error value on failure. |
| 1921 | */ |
| 1922 | int ccw_driver_register(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | { |
| 1924 | struct device_driver *drv = &cdriver->driver; |
| 1925 | |
| 1926 | drv->bus = &ccw_bus_type; |
| 1927 | drv->name = cdriver->name; |
Cornelia Huck | 4beee64 | 2008-01-26 14:10:47 +0100 | [diff] [blame] | 1928 | drv->owner = cdriver->owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | |
| 1930 | return driver_register(drv); |
| 1931 | } |
| 1932 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1933 | /** |
| 1934 | * ccw_driver_unregister() - deregister a ccw driver |
| 1935 | * @cdriver: driver to be deregistered |
| 1936 | * |
| 1937 | * This function is mainly a wrapper around driver_unregister(). |
| 1938 | */ |
| 1939 | void ccw_driver_unregister(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | { |
| 1941 | driver_unregister(&cdriver->driver); |
| 1942 | } |
| 1943 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1944 | /* Helper func for qdio. */ |
| 1945 | struct subchannel_id |
| 1946 | ccw_device_get_subchannel_id(struct ccw_device *cdev) |
| 1947 | { |
| 1948 | struct subchannel *sch; |
| 1949 | |
| 1950 | sch = to_subchannel(cdev->dev.parent); |
| 1951 | return sch->schid; |
| 1952 | } |
| 1953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | MODULE_LICENSE("GPL"); |
| 1955 | EXPORT_SYMBOL(ccw_device_set_online); |
| 1956 | EXPORT_SYMBOL(ccw_device_set_offline); |
| 1957 | EXPORT_SYMBOL(ccw_driver_register); |
| 1958 | EXPORT_SYMBOL(ccw_driver_unregister); |
| 1959 | EXPORT_SYMBOL(get_ccwdev_by_busid); |
| 1960 | EXPORT_SYMBOL(ccw_bus_type); |
| 1961 | EXPORT_SYMBOL(ccw_device_work); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1962 | EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); |