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); |
| 379 | return ret; |
| 380 | } |
| 381 | spin_unlock_irq(cdev->ccwlock); |
| 382 | if (ret == 0) |
| 383 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 384 | else { |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 385 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 386 | "device 0.%x.%04x\n", |
| 387 | ret, cdev->private->dev_id.ssid, |
| 388 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | cdev->online = 1; |
| 390 | } |
| 391 | return ret; |
| 392 | } |
| 393 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 394 | /** |
| 395 | * ccw_device_set_online() - enable a ccw device for I/O |
| 396 | * @cdev: target ccw device |
| 397 | * |
| 398 | * This function first enables @cdev and then calls the driver's set_online() |
| 399 | * function for @cdev, if given. If set_online() returns an error, @cdev is |
| 400 | * disabled again. |
| 401 | * Returns: |
| 402 | * %0 on success and a negative error value on failure. |
| 403 | * Context: |
| 404 | * enabled, ccw device lock not held |
| 405 | */ |
| 406 | int ccw_device_set_online(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
| 408 | int ret; |
| 409 | |
| 410 | if (!cdev) |
| 411 | return -ENODEV; |
| 412 | if (cdev->online || !cdev->drv) |
| 413 | return -EINVAL; |
| 414 | |
| 415 | spin_lock_irq(cdev->ccwlock); |
| 416 | ret = ccw_device_online(cdev); |
| 417 | spin_unlock_irq(cdev->ccwlock); |
| 418 | if (ret == 0) |
| 419 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 420 | else { |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 421 | CIO_MSG_EVENT(0, "ccw_device_online returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 422 | "device 0.%x.%04x\n", |
| 423 | ret, cdev->private->dev_id.ssid, |
| 424 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return ret; |
| 426 | } |
| 427 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 428 | return -ENODEV; |
| 429 | if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) { |
| 430 | cdev->online = 1; |
| 431 | return 0; |
| 432 | } |
| 433 | spin_lock_irq(cdev->ccwlock); |
| 434 | ret = ccw_device_offline(cdev); |
| 435 | spin_unlock_irq(cdev->ccwlock); |
| 436 | if (ret == 0) |
| 437 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 438 | else |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 439 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 440 | "device 0.%x.%04x\n", |
| 441 | ret, cdev->private->dev_id.ssid, |
| 442 | cdev->private->dev_id.devno); |
Cornelia Huck | 6cadb78 | 2006-02-17 13:52:49 -0800 | [diff] [blame] | 443 | return (ret == 0) ? -ENODEV : ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 446 | static void online_store_handle_offline(struct ccw_device *cdev) |
| 447 | { |
| 448 | if (cdev->private->state == DEV_STATE_DISCONNECTED) |
| 449 | ccw_device_remove_disconnected(cdev); |
| 450 | else if (cdev->drv && cdev->drv->set_offline) |
| 451 | ccw_device_set_offline(cdev); |
| 452 | } |
| 453 | |
| 454 | static int online_store_recog_and_online(struct ccw_device *cdev) |
| 455 | { |
| 456 | int ret; |
| 457 | |
| 458 | /* Do device recognition, if needed. */ |
| 459 | if (cdev->id.cu_type == 0) { |
| 460 | ret = ccw_device_recognition(cdev); |
| 461 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 462 | CIO_MSG_EVENT(0, "Couldn't start recognition " |
| 463 | "for device 0.%x.%04x (ret=%d)\n", |
| 464 | cdev->private->dev_id.ssid, |
| 465 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 466 | return ret; |
| 467 | } |
| 468 | wait_event(cdev->private->wait_q, |
| 469 | cdev->private->flags.recog_done); |
| 470 | } |
| 471 | if (cdev->drv && cdev->drv->set_online) |
| 472 | ccw_device_set_online(cdev); |
| 473 | return 0; |
| 474 | } |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 475 | static int online_store_handle_online(struct ccw_device *cdev, int force) |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 476 | { |
| 477 | int ret; |
| 478 | |
| 479 | ret = online_store_recog_and_online(cdev); |
| 480 | if (ret) |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 481 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 482 | if (force && cdev->private->state == DEV_STATE_BOXED) { |
| 483 | ret = ccw_device_stlck(cdev); |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 484 | if (ret) |
| 485 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 486 | if (cdev->id.cu_type == 0) |
| 487 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 488 | online_store_recog_and_online(cdev); |
| 489 | } |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 490 | return 0; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static ssize_t online_store (struct device *dev, struct device_attribute *attr, |
| 494 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
| 496 | struct ccw_device *cdev = to_ccwdev(dev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 497 | int force, ret; |
| 498 | unsigned long i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 500 | if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | return -EAGAIN; |
| 502 | |
| 503 | if (cdev->drv && !try_module_get(cdev->drv->owner)) { |
| 504 | atomic_set(&cdev->private->onoff, 0); |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | if (!strncmp(buf, "force\n", count)) { |
| 508 | force = 1; |
| 509 | i = 1; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 510 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } else { |
| 512 | force = 0; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 513 | ret = strict_strtoul(buf, 16, &i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 515 | if (ret) |
| 516 | goto out; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 517 | switch (i) { |
| 518 | case 0: |
| 519 | online_store_handle_offline(cdev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 520 | ret = count; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 521 | break; |
| 522 | case 1: |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 523 | ret = online_store_handle_online(cdev, force); |
| 524 | if (!ret) |
| 525 | ret = count; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 526 | break; |
| 527 | default: |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 528 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 530 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | if (cdev->drv) |
| 532 | module_put(cdev->drv->owner); |
| 533 | atomic_set(&cdev->private->onoff, 0); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 534 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 538 | available_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | { |
| 540 | struct ccw_device *cdev = to_ccwdev(dev); |
| 541 | struct subchannel *sch; |
| 542 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 543 | if (ccw_device_is_orphan(cdev)) |
| 544 | return sprintf(buf, "no device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | switch (cdev->private->state) { |
| 546 | case DEV_STATE_BOXED: |
| 547 | return sprintf(buf, "boxed\n"); |
| 548 | case DEV_STATE_DISCONNECTED: |
| 549 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 550 | case DEV_STATE_NOT_OPER: |
| 551 | sch = to_subchannel(dev->parent); |
| 552 | if (!sch->lpm) |
| 553 | return sprintf(buf, "no path\n"); |
| 554 | else |
| 555 | return sprintf(buf, "no device\n"); |
| 556 | default: |
| 557 | /* All other states considered fine. */ |
| 558 | return sprintf(buf, "good\n"); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | static DEVICE_ATTR(chpids, 0444, chpids_show, NULL); |
| 563 | static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); |
| 564 | static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); |
| 565 | static DEVICE_ATTR(cutype, 0444, cutype_show, NULL); |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 566 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | static DEVICE_ATTR(online, 0644, online_show, online_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | static DEVICE_ATTR(availability, 0444, available_show, NULL); |
| 569 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 570 | static struct attribute *io_subchannel_attrs[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | &dev_attr_chpids.attr, |
| 572 | &dev_attr_pimpampom.attr, |
| 573 | NULL, |
| 574 | }; |
| 575 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 576 | static struct attribute_group io_subchannel_attr_group = { |
| 577 | .attrs = io_subchannel_attrs, |
Cornelia Huck | 529192f | 2006-12-08 15:55:57 +0100 | [diff] [blame] | 578 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | static struct attribute * ccwdev_attrs[] = { |
| 581 | &dev_attr_devtype.attr, |
| 582 | &dev_attr_cutype.attr, |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 583 | &dev_attr_modalias.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | &dev_attr_online.attr, |
| 585 | &dev_attr_cmb_enable.attr, |
| 586 | &dev_attr_availability.attr, |
| 587 | NULL, |
| 588 | }; |
| 589 | |
| 590 | static struct attribute_group ccwdev_attr_group = { |
| 591 | .attrs = ccwdev_attrs, |
| 592 | }; |
| 593 | |
Cornelia Huck | f7e5d67 | 2007-05-10 15:45:43 +0200 | [diff] [blame] | 594 | static struct attribute_group *ccwdev_attr_groups[] = { |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 595 | &ccwdev_attr_group, |
| 596 | NULL, |
| 597 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
| 599 | /* this is a simple abstraction for device_register that sets the |
| 600 | * correct bus type and adds the bus specific files */ |
Cornelia Huck | 3c9da7b | 2006-10-27 12:39:33 +0200 | [diff] [blame] | 601 | static int ccw_device_register(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | struct device *dev = &cdev->dev; |
| 604 | int ret; |
| 605 | |
| 606 | dev->bus = &ccw_bus_type; |
| 607 | |
| 608 | if ((ret = device_add(dev))) |
| 609 | return ret; |
| 610 | |
| 611 | set_bit(1, &cdev->private->registered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | return ret; |
| 613 | } |
| 614 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 615 | struct match_data { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 616 | struct ccw_dev_id dev_id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 617 | struct ccw_device * sibling; |
| 618 | }; |
| 619 | |
| 620 | static int |
| 621 | match_devno(struct device * dev, void * data) |
| 622 | { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 623 | struct match_data * d = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 624 | struct ccw_device * cdev; |
| 625 | |
| 626 | cdev = to_ccwdev(dev); |
| 627 | if ((cdev->private->state == DEV_STATE_DISCONNECTED) && |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 628 | !ccw_device_is_orphan(cdev) && |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 629 | ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) && |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 630 | (cdev != d->sibling)) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 631 | return 1; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 635 | static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id, |
| 636 | struct ccw_device *sibling) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | struct device *dev; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 639 | struct match_data data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 641 | data.dev_id = *dev_id; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 642 | data.sibling = sibling; |
Cornelia Huck | e5945b4 | 2005-10-11 08:28:59 -0700 | [diff] [blame] | 643 | dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 645 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 648 | static int match_orphan(struct device *dev, void *data) |
| 649 | { |
| 650 | struct ccw_dev_id *dev_id; |
| 651 | struct ccw_device *cdev; |
| 652 | |
| 653 | dev_id = data; |
| 654 | cdev = to_ccwdev(dev); |
| 655 | return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); |
| 656 | } |
| 657 | |
| 658 | static struct ccw_device * |
| 659 | get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css, |
| 660 | struct ccw_dev_id *dev_id) |
| 661 | { |
| 662 | struct device *dev; |
| 663 | |
| 664 | dev = device_find_child(&css->pseudo_subchannel->dev, dev_id, |
| 665 | match_orphan); |
| 666 | |
| 667 | return dev ? to_ccwdev(dev) : NULL; |
| 668 | } |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 671 | ccw_device_add_changed(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 673 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | struct ccw_device *cdev; |
| 675 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 676 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 677 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | if (device_add(&cdev->dev)) { |
| 679 | put_device(&cdev->dev); |
| 680 | return; |
| 681 | } |
| 682 | set_bit(1, &cdev->private->registered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 685 | void ccw_device_do_unreg_rereg(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 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 691 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 692 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | sch = to_subchannel(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 695 | ccw_device_unregister(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 697 | ccw_device_add_changed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | queue_work(ccw_device_work, &cdev->private->kick_work); |
| 699 | } |
| 700 | |
| 701 | static void |
| 702 | ccw_device_release(struct device *dev) |
| 703 | { |
| 704 | struct ccw_device *cdev; |
| 705 | |
| 706 | cdev = to_ccwdev(dev); |
| 707 | kfree(cdev->private); |
| 708 | kfree(cdev); |
| 709 | } |
| 710 | |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 711 | static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) |
| 712 | { |
| 713 | struct ccw_device *cdev; |
| 714 | |
| 715 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 716 | if (cdev) { |
| 717 | cdev->private = kzalloc(sizeof(struct ccw_device_private), |
| 718 | GFP_KERNEL | GFP_DMA); |
| 719 | if (cdev->private) |
| 720 | return cdev; |
| 721 | } |
| 722 | kfree(cdev); |
| 723 | return ERR_PTR(-ENOMEM); |
| 724 | } |
| 725 | |
| 726 | static int io_subchannel_initialize_dev(struct subchannel *sch, |
| 727 | struct ccw_device *cdev) |
| 728 | { |
| 729 | cdev->private->cdev = cdev; |
| 730 | atomic_set(&cdev->private->onoff, 0); |
| 731 | cdev->dev.parent = &sch->dev; |
| 732 | cdev->dev.release = ccw_device_release; |
Heiko Carstens | 33583c3 | 2007-11-05 11:10:07 +0100 | [diff] [blame] | 733 | INIT_WORK(&cdev->private->kick_work, NULL); |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 734 | cdev->dev.groups = ccwdev_attr_groups; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 735 | /* Do first half of device_register. */ |
| 736 | device_initialize(&cdev->dev); |
| 737 | if (!get_device(&sch->dev)) { |
| 738 | if (cdev->dev.release) |
| 739 | cdev->dev.release(&cdev->dev); |
| 740 | return -ENODEV; |
| 741 | } |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch) |
| 746 | { |
| 747 | struct ccw_device *cdev; |
| 748 | int ret; |
| 749 | |
| 750 | cdev = io_subchannel_allocate_dev(sch); |
| 751 | if (!IS_ERR(cdev)) { |
| 752 | ret = io_subchannel_initialize_dev(sch, cdev); |
| 753 | if (ret) { |
| 754 | kfree(cdev); |
| 755 | cdev = ERR_PTR(ret); |
| 756 | } |
| 757 | } |
| 758 | return cdev; |
| 759 | } |
| 760 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 761 | static int io_subchannel_recog(struct ccw_device *, struct subchannel *); |
| 762 | |
| 763 | static void sch_attach_device(struct subchannel *sch, |
| 764 | struct ccw_device *cdev) |
| 765 | { |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 766 | css_update_ssd_info(sch); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 767 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 768 | sch_set_cdev(sch, cdev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 769 | cdev->private->schid = sch->schid; |
| 770 | cdev->ccwlock = sch->lock; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 771 | ccw_device_trigger_reprobe(cdev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 772 | spin_unlock_irq(sch->lock); |
| 773 | } |
| 774 | |
| 775 | static void sch_attach_disconnected_device(struct subchannel *sch, |
| 776 | struct ccw_device *cdev) |
| 777 | { |
| 778 | struct subchannel *other_sch; |
| 779 | int ret; |
| 780 | |
| 781 | other_sch = to_subchannel(get_device(cdev->dev.parent)); |
| 782 | ret = device_move(&cdev->dev, &sch->dev); |
| 783 | if (ret) { |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 784 | CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed " |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 785 | "(ret=%d)!\n", cdev->private->dev_id.ssid, |
| 786 | cdev->private->dev_id.devno, ret); |
| 787 | put_device(&other_sch->dev); |
| 788 | return; |
| 789 | } |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 790 | sch_set_cdev(other_sch, NULL); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 791 | /* No need to keep a subchannel without ccw device around. */ |
| 792 | css_sch_device_unregister(other_sch); |
| 793 | put_device(&other_sch->dev); |
| 794 | sch_attach_device(sch, cdev); |
| 795 | } |
| 796 | |
| 797 | static void sch_attach_orphaned_device(struct subchannel *sch, |
| 798 | struct ccw_device *cdev) |
| 799 | { |
| 800 | int ret; |
| 801 | |
| 802 | /* Try to move the ccw device to its new subchannel. */ |
| 803 | ret = device_move(&cdev->dev, &sch->dev); |
| 804 | if (ret) { |
| 805 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " |
| 806 | "failed (ret=%d)!\n", |
| 807 | cdev->private->dev_id.ssid, |
| 808 | cdev->private->dev_id.devno, ret); |
| 809 | return; |
| 810 | } |
| 811 | sch_attach_device(sch, cdev); |
| 812 | } |
| 813 | |
| 814 | static void sch_create_and_recog_new_device(struct subchannel *sch) |
| 815 | { |
| 816 | struct ccw_device *cdev; |
| 817 | |
| 818 | /* Need to allocate a new ccw device. */ |
| 819 | cdev = io_subchannel_create_ccwdev(sch); |
| 820 | if (IS_ERR(cdev)) { |
| 821 | /* OK, we did everything we could... */ |
| 822 | css_sch_device_unregister(sch); |
| 823 | return; |
| 824 | } |
| 825 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 826 | sch_set_cdev(sch, cdev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 827 | spin_unlock_irq(sch->lock); |
| 828 | /* Start recognition for the new ccw device. */ |
| 829 | if (io_subchannel_recog(cdev, sch)) { |
| 830 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 831 | sch_set_cdev(sch, NULL); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 832 | spin_unlock_irq(sch->lock); |
| 833 | if (cdev->dev.release) |
| 834 | cdev->dev.release(&cdev->dev); |
| 835 | css_sch_device_unregister(sch); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | |
| 840 | void ccw_device_move_to_orphanage(struct work_struct *work) |
| 841 | { |
| 842 | struct ccw_device_private *priv; |
| 843 | struct ccw_device *cdev; |
| 844 | struct ccw_device *replacing_cdev; |
| 845 | struct subchannel *sch; |
| 846 | int ret; |
| 847 | struct channel_subsystem *css; |
| 848 | struct ccw_dev_id dev_id; |
| 849 | |
| 850 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 851 | cdev = priv->cdev; |
| 852 | sch = to_subchannel(cdev->dev.parent); |
| 853 | css = to_css(sch->dev.parent); |
| 854 | dev_id.devno = sch->schib.pmcw.dev; |
| 855 | dev_id.ssid = sch->schid.ssid; |
| 856 | |
| 857 | /* |
| 858 | * Move the orphaned ccw device to the orphanage so the replacing |
| 859 | * ccw device can take its place on the subchannel. |
| 860 | */ |
| 861 | ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev); |
| 862 | if (ret) { |
| 863 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " |
| 864 | "(ret=%d)!\n", cdev->private->dev_id.ssid, |
| 865 | cdev->private->dev_id.devno, ret); |
| 866 | return; |
| 867 | } |
| 868 | cdev->ccwlock = css->pseudo_subchannel->lock; |
| 869 | /* |
| 870 | * Search for the replacing ccw device |
| 871 | * - among the disconnected devices |
| 872 | * - in the orphanage |
| 873 | */ |
| 874 | replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev); |
| 875 | if (replacing_cdev) { |
| 876 | sch_attach_disconnected_device(sch, replacing_cdev); |
Cornelia Huck | 85acc40 | 2008-11-14 18:18:06 +0100 | [diff] [blame] | 877 | /* Release reference from get_disc_ccwdev_by_dev_id() */ |
| 878 | put_device(&cdev->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 879 | return; |
| 880 | } |
| 881 | replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id); |
| 882 | if (replacing_cdev) { |
| 883 | sch_attach_orphaned_device(sch, replacing_cdev); |
Cornelia Huck | 85acc40 | 2008-11-14 18:18:06 +0100 | [diff] [blame] | 884 | /* Release reference from get_orphaned_ccwdev_by_dev_id() */ |
| 885 | put_device(&cdev->dev); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 886 | return; |
| 887 | } |
| 888 | sch_create_and_recog_new_device(sch); |
| 889 | } |
| 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | /* |
| 892 | * Register recognized device. |
| 893 | */ |
| 894 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 895 | io_subchannel_register(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 897 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | struct ccw_device *cdev; |
| 899 | struct subchannel *sch; |
| 900 | int ret; |
| 901 | unsigned long flags; |
| 902 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 903 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 904 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 906 | css_update_ssd_info(sch); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 907 | /* |
| 908 | * io_subchannel_register() will also be called after device |
| 909 | * recognition has been done for a boxed device (which will already |
| 910 | * be registered). We need to reprobe since we may now have sense id |
| 911 | * information. |
| 912 | */ |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 913 | if (klist_node_attached(&cdev->dev.knode_parent)) { |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 914 | if (!cdev->drv) { |
| 915 | ret = device_reprobe(&cdev->dev); |
| 916 | if (ret) |
| 917 | /* We can't do much here. */ |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 918 | CIO_MSG_EVENT(0, "device_reprobe() returned" |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 919 | " %d for 0.%x.%04x\n", ret, |
| 920 | cdev->private->dev_id.ssid, |
| 921 | cdev->private->dev_id.devno); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | goto out; |
| 924 | } |
Cornelia Huck | fa1a8c2 | 2007-04-26 00:12:03 -0700 | [diff] [blame] | 925 | /* |
| 926 | * Now we know this subchannel will stay, we can throw |
| 927 | * our delayed uevent. |
| 928 | */ |
| 929 | sch->dev.uevent_suppress = 0; |
| 930 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | /* make it known to the system */ |
| 932 | ret = ccw_device_register(cdev); |
| 933 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 934 | CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n", |
| 935 | cdev->private->dev_id.ssid, |
| 936 | cdev->private->dev_id.devno, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | put_device(&cdev->dev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 938 | spin_lock_irqsave(sch->lock, flags); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 939 | sch_set_cdev(sch, NULL); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 940 | spin_unlock_irqrestore(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | kfree (cdev->private); |
| 942 | kfree (cdev); |
| 943 | put_device(&sch->dev); |
| 944 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 945 | wake_up(&ccw_device_init_wq); |
| 946 | return; |
| 947 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | put_device(&cdev->dev); |
| 949 | out: |
| 950 | cdev->private->flags.recog_done = 1; |
| 951 | put_device(&sch->dev); |
| 952 | wake_up(&cdev->private->wait_q); |
| 953 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 954 | wake_up(&ccw_device_init_wq); |
| 955 | } |
| 956 | |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 957 | static void ccw_device_call_sch_unregister(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 959 | struct ccw_device_private *priv; |
| 960 | struct ccw_device *cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | struct subchannel *sch; |
| 962 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 963 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 964 | cdev = priv->cdev; |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 965 | /* Get subchannel reference for local processing. */ |
| 966 | if (!get_device(cdev->dev.parent)) |
| 967 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 969 | css_sch_device_unregister(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | /* Reset intparm to zeroes. */ |
| 971 | sch->schib.pmcw.intparm = 0; |
| 972 | cio_modify(sch); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 973 | /* Release cdev reference for workqueue processing.*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | put_device(&cdev->dev); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 975 | /* Release subchannel reference for local processing. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | put_device(&sch->dev); |
| 977 | } |
| 978 | |
| 979 | /* |
| 980 | * subchannel recognition done. Called from the state machine. |
| 981 | */ |
| 982 | void |
| 983 | io_subchannel_recog_done(struct ccw_device *cdev) |
| 984 | { |
| 985 | struct subchannel *sch; |
| 986 | |
| 987 | if (css_init_done == 0) { |
| 988 | cdev->private->flags.recog_done = 1; |
| 989 | return; |
| 990 | } |
| 991 | switch (cdev->private->state) { |
| 992 | case DEV_STATE_NOT_OPER: |
| 993 | cdev->private->flags.recog_done = 1; |
| 994 | /* Remove device found not operational. */ |
| 995 | if (!get_device(&cdev->dev)) |
| 996 | break; |
| 997 | sch = to_subchannel(cdev->dev.parent); |
| 998 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 999 | ccw_device_call_sch_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | queue_work(slow_path_wq, &cdev->private->kick_work); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 1001 | /* Release subchannel reference for asynchronous recognition. */ |
| 1002 | put_device(&sch->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1004 | wake_up(&ccw_device_init_wq); |
| 1005 | break; |
| 1006 | case DEV_STATE_BOXED: |
| 1007 | /* Device did not respond in time. */ |
| 1008 | case DEV_STATE_OFFLINE: |
| 1009 | /* |
| 1010 | * We can't register the device in interrupt context so |
| 1011 | * we schedule a work item. |
| 1012 | */ |
| 1013 | if (!get_device(&cdev->dev)) |
| 1014 | break; |
| 1015 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1016 | io_subchannel_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1018 | break; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | static int |
| 1023 | io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) |
| 1024 | { |
| 1025 | int rc; |
| 1026 | struct ccw_device_private *priv; |
| 1027 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1028 | sch_set_cdev(sch, cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1029 | cdev->ccwlock = sch->lock; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 1030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | /* Init private data. */ |
| 1032 | priv = cdev->private; |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 1033 | priv->dev_id.devno = sch->schib.pmcw.dev; |
| 1034 | priv->dev_id.ssid = sch->schid.ssid; |
| 1035 | priv->schid = sch->schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | priv->state = DEV_STATE_NOT_OPER; |
| 1037 | INIT_LIST_HEAD(&priv->cmb_list); |
| 1038 | init_waitqueue_head(&priv->wait_q); |
| 1039 | init_timer(&priv->timer); |
| 1040 | |
| 1041 | /* Set an initial name for the device. */ |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1042 | if (cio_is_console(sch->schid)) |
| 1043 | cdev->dev.init_name = cio_get_console_cdev_name(sch); |
| 1044 | else |
| 1045 | dev_set_name(&cdev->dev, "0.%x.%04x", |
| 1046 | sch->schid.ssid, sch->schib.pmcw.dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | /* Increase counter of devices currently in recognition. */ |
| 1049 | atomic_inc(&ccw_device_init_count); |
| 1050 | |
| 1051 | /* Start async. device sensing. */ |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1052 | spin_lock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | rc = ccw_device_recognition(cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1054 | spin_unlock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | if (rc) { |
| 1056 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1057 | wake_up(&ccw_device_init_wq); |
| 1058 | } |
| 1059 | return rc; |
| 1060 | } |
| 1061 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1062 | static void ccw_device_move_to_sch(struct work_struct *work) |
| 1063 | { |
| 1064 | struct ccw_device_private *priv; |
| 1065 | int rc; |
| 1066 | struct subchannel *sch; |
| 1067 | struct ccw_device *cdev; |
| 1068 | struct subchannel *former_parent; |
| 1069 | |
| 1070 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 1071 | sch = priv->sch; |
| 1072 | cdev = priv->cdev; |
| 1073 | former_parent = ccw_device_is_orphan(cdev) ? |
| 1074 | NULL : to_subchannel(get_device(cdev->dev.parent)); |
| 1075 | mutex_lock(&sch->reg_mutex); |
| 1076 | /* Try to move the ccw device to its new subchannel. */ |
| 1077 | rc = device_move(&cdev->dev, &sch->dev); |
| 1078 | mutex_unlock(&sch->reg_mutex); |
| 1079 | if (rc) { |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 1080 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel " |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1081 | "0.%x.%04x failed (ret=%d)!\n", |
| 1082 | cdev->private->dev_id.ssid, |
| 1083 | cdev->private->dev_id.devno, sch->schid.ssid, |
| 1084 | sch->schid.sch_no, rc); |
| 1085 | css_sch_device_unregister(sch); |
| 1086 | goto out; |
| 1087 | } |
| 1088 | if (former_parent) { |
| 1089 | spin_lock_irq(former_parent->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1090 | sch_set_cdev(former_parent, NULL); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1091 | spin_unlock_irq(former_parent->lock); |
| 1092 | css_sch_device_unregister(former_parent); |
| 1093 | /* Reset intparm to zeroes. */ |
| 1094 | former_parent->schib.pmcw.intparm = 0; |
| 1095 | cio_modify(former_parent); |
| 1096 | } |
| 1097 | sch_attach_device(sch, cdev); |
| 1098 | out: |
| 1099 | if (former_parent) |
| 1100 | put_device(&former_parent->dev); |
| 1101 | put_device(&cdev->dev); |
| 1102 | } |
| 1103 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1104 | static void io_subchannel_irq(struct subchannel *sch) |
| 1105 | { |
| 1106 | struct ccw_device *cdev; |
| 1107 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1108 | cdev = sch_get_cdev(sch); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1109 | |
| 1110 | CIO_TRACE_EVENT(3, "IRQ"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1111 | CIO_TRACE_EVENT(3, dev_name(&sch->dev)); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1112 | if (cdev) |
| 1113 | dev_fsm_event(cdev, DEV_EVENT_INTERRUPT); |
| 1114 | } |
| 1115 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1116 | static void io_subchannel_init_fields(struct subchannel *sch) |
| 1117 | { |
| 1118 | if (cio_is_console(sch->schid)) |
| 1119 | sch->opm = 0xff; |
| 1120 | else |
| 1121 | sch->opm = chp_get_sch_opm(sch); |
| 1122 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 1123 | sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1124 | |
| 1125 | CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X" |
| 1126 | " - PIM = %02X, PAM = %02X, POM = %02X\n", |
| 1127 | sch->schib.pmcw.dev, sch->schid.ssid, |
| 1128 | sch->schid.sch_no, sch->schib.pmcw.pim, |
| 1129 | sch->schib.pmcw.pam, sch->schib.pmcw.pom); |
| 1130 | /* Initially set up some fields in the pmcw. */ |
| 1131 | sch->schib.pmcw.ena = 0; |
| 1132 | sch->schib.pmcw.csense = 1; /* concurrent sense */ |
| 1133 | if ((sch->lpm & (sch->lpm - 1)) != 0) |
| 1134 | sch->schib.pmcw.mp = 1; /* multipath mode */ |
| 1135 | /* clean up possible residual cmf stuff */ |
| 1136 | sch->schib.pmcw.mme = 0; |
| 1137 | sch->schib.pmcw.mbfc = 0; |
| 1138 | sch->schib.pmcw.mbi = 0; |
| 1139 | sch->schib.mba = 0; |
| 1140 | } |
| 1141 | |
| 1142 | static int io_subchannel_probe(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | struct ccw_device *cdev; |
| 1145 | int rc; |
| 1146 | unsigned long flags; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1147 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1149 | cdev = sch_get_cdev(sch); |
| 1150 | if (cdev) { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1151 | rc = sysfs_create_group(&sch->dev.kobj, |
| 1152 | &io_subchannel_attr_group); |
| 1153 | if (rc) |
| 1154 | CIO_MSG_EVENT(0, "Failed to create io subchannel " |
| 1155 | "attributes for subchannel " |
| 1156 | "0.%x.%04x (rc=%d)\n", |
| 1157 | sch->schid.ssid, sch->schid.sch_no, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | /* |
| 1159 | * This subchannel already has an associated ccw_device. |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1160 | * Throw the delayed uevent for the subchannel, register |
| 1161 | * the ccw_device and exit. This happens for all early |
| 1162 | * devices, e.g. the console. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | */ |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1164 | sch->dev.uevent_suppress = 0; |
| 1165 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Cornelia Huck | e103178 | 2007-10-12 16:11:23 +0200 | [diff] [blame] | 1166 | cdev->dev.groups = ccwdev_attr_groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | device_initialize(&cdev->dev); |
| 1168 | ccw_device_register(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | /* |
| 1170 | * Check if the device is already online. If it is |
| 1171 | * the reference count needs to be corrected |
| 1172 | * (see ccw_device_online and css_init_done for the |
| 1173 | * ugly details). |
| 1174 | */ |
| 1175 | if (cdev->private->state != DEV_STATE_NOT_OPER && |
| 1176 | cdev->private->state != DEV_STATE_OFFLINE && |
| 1177 | cdev->private->state != DEV_STATE_BOXED) |
| 1178 | get_device(&cdev->dev); |
| 1179 | return 0; |
| 1180 | } |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1181 | io_subchannel_init_fields(sch); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1182 | rc = sysfs_create_group(&sch->dev.kobj, |
| 1183 | &io_subchannel_attr_group); |
| 1184 | if (rc) |
| 1185 | return rc; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1186 | /* Allocate I/O subchannel private data. */ |
| 1187 | sch->private = kzalloc(sizeof(struct io_subchannel_private), |
| 1188 | GFP_KERNEL | GFP_DMA); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1189 | if (!sch->private) { |
| 1190 | rc = -ENOMEM; |
| 1191 | goto out_err; |
| 1192 | } |
Sebastian Ott | 111e95a | 2008-12-25 13:39:03 +0100 | [diff] [blame] | 1193 | /* |
| 1194 | * First check if a fitting device may be found amongst the |
| 1195 | * disconnected devices or in the orphanage. |
| 1196 | */ |
| 1197 | dev_id.devno = sch->schib.pmcw.dev; |
| 1198 | dev_id.ssid = sch->schid.ssid; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1199 | cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); |
| 1200 | if (!cdev) |
| 1201 | cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), |
| 1202 | &dev_id); |
| 1203 | if (cdev) { |
| 1204 | /* |
| 1205 | * Schedule moving the device until when we have a registered |
| 1206 | * subchannel to move to and succeed the probe. We can |
| 1207 | * unregister later again, when the probe is through. |
| 1208 | */ |
| 1209 | cdev->private->sch = sch; |
| 1210 | PREPARE_WORK(&cdev->private->kick_work, |
| 1211 | ccw_device_move_to_sch); |
| 1212 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1213 | return 0; |
| 1214 | } |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 1215 | cdev = io_subchannel_create_ccwdev(sch); |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1216 | if (IS_ERR(cdev)) { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1217 | rc = PTR_ERR(cdev); |
| 1218 | goto out_err; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1219 | } |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1220 | rc = io_subchannel_recog(cdev, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | if (rc) { |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1222 | spin_lock_irqsave(sch->lock, flags); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1223 | sch_set_cdev(sch, NULL); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1224 | spin_unlock_irqrestore(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | if (cdev->dev.release) |
| 1226 | cdev->dev.release(&cdev->dev); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1227 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1229 | return 0; |
| 1230 | out_err: |
| 1231 | kfree(sch->private); |
| 1232 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | return rc; |
| 1234 | } |
| 1235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | static int |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1237 | io_subchannel_remove (struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | { |
| 1239 | struct ccw_device *cdev; |
| 1240 | unsigned long flags; |
| 1241 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1242 | cdev = sch_get_cdev(sch); |
| 1243 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | /* Set ccw device to not operational and drop reference. */ |
| 1246 | spin_lock_irqsave(cdev->ccwlock, flags); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1247 | sch_set_cdev(sch, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1249 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 1250 | ccw_device_unregister(cdev); |
| 1251 | put_device(&cdev->dev); |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1252 | kfree(sch->private); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1253 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | return 0; |
| 1255 | } |
| 1256 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1257 | static int io_subchannel_notify(struct subchannel *sch, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | { |
| 1259 | struct ccw_device *cdev; |
| 1260 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1261 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | if (!cdev) |
| 1263 | return 0; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1264 | return ccw_device_notify(cdev, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1267 | static void io_subchannel_verify(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | { |
| 1269 | struct ccw_device *cdev; |
| 1270 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1271 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | if (cdev) |
| 1273 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1274 | } |
| 1275 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1276 | static int check_for_io_on_path(struct subchannel *sch, int mask) |
| 1277 | { |
| 1278 | int cc; |
| 1279 | |
| 1280 | cc = stsch(sch->schid, &sch->schib); |
| 1281 | if (cc) |
| 1282 | return 0; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1283 | if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1284 | return 1; |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | static void terminate_internal_io(struct subchannel *sch, |
| 1289 | struct ccw_device *cdev) |
| 1290 | { |
| 1291 | if (cio_clear(sch)) { |
| 1292 | /* Recheck device in case clear failed. */ |
| 1293 | sch->lpm = 0; |
| 1294 | if (cdev->online) |
| 1295 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1296 | else |
| 1297 | css_schedule_eval(sch->schid); |
| 1298 | return; |
| 1299 | } |
| 1300 | cdev->private->state = DEV_STATE_CLEAR_VERIFY; |
| 1301 | /* Request retry of internal operation. */ |
| 1302 | cdev->private->flags.intretry = 1; |
| 1303 | /* Call handler. */ |
| 1304 | if (cdev->handler) |
| 1305 | cdev->handler(cdev, cdev->private->intparm, |
| 1306 | ERR_PTR(-EIO)); |
| 1307 | } |
| 1308 | |
| 1309 | static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | { |
| 1311 | struct ccw_device *cdev; |
| 1312 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1313 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | if (!cdev) |
| 1315 | return; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1316 | if (check_for_io_on_path(sch, mask)) { |
| 1317 | if (cdev->private->state == DEV_STATE_ONLINE) |
| 1318 | ccw_device_kill_io(cdev); |
| 1319 | else { |
| 1320 | terminate_internal_io(sch, cdev); |
| 1321 | /* Re-start path verification. */ |
| 1322 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1323 | } |
| 1324 | } else |
| 1325 | /* trigger path verification. */ |
| 1326 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1327 | |
| 1328 | } |
| 1329 | |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 1330 | static int io_subchannel_chp_event(struct subchannel *sch, |
| 1331 | struct chp_link *link, int event) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1332 | { |
| 1333 | int mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1334 | |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 1335 | mask = chp_ssd_get_mask(&sch->ssd_info, link); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1336 | if (!mask) |
| 1337 | return 0; |
| 1338 | switch (event) { |
| 1339 | case CHP_VARY_OFF: |
| 1340 | sch->opm &= ~mask; |
| 1341 | sch->lpm &= ~mask; |
| 1342 | io_subchannel_terminate_path(sch, mask); |
| 1343 | break; |
| 1344 | case CHP_VARY_ON: |
| 1345 | sch->opm |= mask; |
| 1346 | sch->lpm |= mask; |
| 1347 | io_subchannel_verify(sch); |
| 1348 | break; |
| 1349 | case CHP_OFFLINE: |
| 1350 | if (stsch(sch->schid, &sch->schib)) |
| 1351 | return -ENXIO; |
| 1352 | if (!css_sch_is_valid(&sch->schib)) |
| 1353 | return -ENODEV; |
| 1354 | io_subchannel_terminate_path(sch, mask); |
| 1355 | break; |
| 1356 | case CHP_ONLINE: |
| 1357 | if (stsch(sch->schid, &sch->schib)) |
| 1358 | return -ENXIO; |
| 1359 | sch->lpm |= mask & sch->opm; |
| 1360 | io_subchannel_verify(sch); |
| 1361 | break; |
| 1362 | } |
| 1363 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | static void |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1367 | io_subchannel_shutdown(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | struct ccw_device *cdev; |
| 1370 | int ret; |
| 1371 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1372 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1374 | if (cio_is_console(sch->schid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | return; |
| 1376 | if (!sch->schib.pmcw.ena) |
| 1377 | /* Nothing to do. */ |
| 1378 | return; |
| 1379 | ret = cio_disable_subchannel(sch); |
| 1380 | if (ret != -EBUSY) |
| 1381 | /* Subchannel is disabled, we're done. */ |
| 1382 | return; |
| 1383 | cdev->private->state = DEV_STATE_QUIESCE; |
| 1384 | if (cdev->handler) |
| 1385 | cdev->handler(cdev, cdev->private->intparm, |
| 1386 | ERR_PTR(-EIO)); |
| 1387 | ret = ccw_device_cancel_halt_clear(cdev); |
| 1388 | if (ret == -EBUSY) { |
| 1389 | ccw_device_set_timeout(cdev, HZ/10); |
| 1390 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 1391 | } |
| 1392 | cio_disable_subchannel(sch); |
| 1393 | } |
| 1394 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1395 | static int io_subchannel_get_status(struct subchannel *sch) |
| 1396 | { |
| 1397 | struct schib schib; |
| 1398 | |
| 1399 | if (stsch(sch->schid, &schib) || !schib.pmcw.dnv) |
| 1400 | return CIO_GONE; |
| 1401 | if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev)) |
| 1402 | return CIO_REVALIDATE; |
| 1403 | if (!sch->lpm) |
| 1404 | return CIO_NO_PATH; |
| 1405 | return CIO_OPER; |
| 1406 | } |
| 1407 | |
| 1408 | static int device_is_disconnected(struct ccw_device *cdev) |
| 1409 | { |
| 1410 | if (!cdev) |
| 1411 | return 0; |
| 1412 | return (cdev->private->state == DEV_STATE_DISCONNECTED || |
| 1413 | cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID); |
| 1414 | } |
| 1415 | |
| 1416 | static int recovery_check(struct device *dev, void *data) |
| 1417 | { |
| 1418 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1419 | int *redo = data; |
| 1420 | |
| 1421 | spin_lock_irq(cdev->ccwlock); |
| 1422 | switch (cdev->private->state) { |
| 1423 | case DEV_STATE_DISCONNECTED: |
| 1424 | CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n", |
| 1425 | cdev->private->dev_id.ssid, |
| 1426 | cdev->private->dev_id.devno); |
| 1427 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1428 | *redo = 1; |
| 1429 | break; |
| 1430 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 1431 | *redo = 1; |
| 1432 | break; |
| 1433 | } |
| 1434 | spin_unlock_irq(cdev->ccwlock); |
| 1435 | |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static void recovery_work_func(struct work_struct *unused) |
| 1440 | { |
| 1441 | int redo = 0; |
| 1442 | |
| 1443 | bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check); |
| 1444 | if (redo) { |
| 1445 | spin_lock_irq(&recovery_lock); |
| 1446 | if (!timer_pending(&recovery_timer)) { |
| 1447 | if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1) |
| 1448 | recovery_phase++; |
| 1449 | mod_timer(&recovery_timer, jiffies + |
| 1450 | recovery_delay[recovery_phase] * HZ); |
| 1451 | } |
| 1452 | spin_unlock_irq(&recovery_lock); |
| 1453 | } else |
| 1454 | CIO_MSG_EVENT(4, "recovery: end\n"); |
| 1455 | } |
| 1456 | |
| 1457 | static DECLARE_WORK(recovery_work, recovery_work_func); |
| 1458 | |
| 1459 | static void recovery_func(unsigned long data) |
| 1460 | { |
| 1461 | /* |
| 1462 | * We can't do our recovery in softirq context and it's not |
| 1463 | * performance critical, so we schedule it. |
| 1464 | */ |
| 1465 | schedule_work(&recovery_work); |
| 1466 | } |
| 1467 | |
| 1468 | static void ccw_device_schedule_recovery(void) |
| 1469 | { |
| 1470 | unsigned long flags; |
| 1471 | |
| 1472 | CIO_MSG_EVENT(4, "recovery: schedule\n"); |
| 1473 | spin_lock_irqsave(&recovery_lock, flags); |
| 1474 | if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) { |
| 1475 | recovery_phase = 0; |
| 1476 | mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ); |
| 1477 | } |
| 1478 | spin_unlock_irqrestore(&recovery_lock, flags); |
| 1479 | } |
| 1480 | |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 1481 | static int purge_fn(struct device *dev, void *data) |
| 1482 | { |
| 1483 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1484 | struct ccw_device_private *priv = cdev->private; |
| 1485 | int unreg; |
| 1486 | |
| 1487 | spin_lock_irq(cdev->ccwlock); |
| 1488 | unreg = is_blacklisted(priv->dev_id.ssid, priv->dev_id.devno) && |
| 1489 | (priv->state == DEV_STATE_OFFLINE); |
| 1490 | spin_unlock_irq(cdev->ccwlock); |
| 1491 | if (!unreg) |
| 1492 | goto out; |
| 1493 | if (!get_device(&cdev->dev)) |
| 1494 | goto out; |
| 1495 | CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", priv->dev_id.ssid, |
| 1496 | priv->dev_id.devno); |
| 1497 | PREPARE_WORK(&cdev->private->kick_work, ccw_device_call_sch_unregister); |
| 1498 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1499 | |
| 1500 | out: |
| 1501 | /* Abort loop in case of pending signal. */ |
| 1502 | if (signal_pending(current)) |
| 1503 | return -EINTR; |
| 1504 | |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
| 1509 | * ccw_purge_blacklisted - purge unused, blacklisted devices |
| 1510 | * |
| 1511 | * Unregister all ccw devices that are offline and on the blacklist. |
| 1512 | */ |
| 1513 | int ccw_purge_blacklisted(void) |
| 1514 | { |
| 1515 | CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n"); |
| 1516 | bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn); |
| 1517 | return 0; |
| 1518 | } |
| 1519 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1520 | static void device_set_disconnected(struct ccw_device *cdev) |
| 1521 | { |
| 1522 | if (!cdev) |
| 1523 | return; |
| 1524 | ccw_device_set_timeout(cdev, 0); |
| 1525 | cdev->private->flags.fake_irb = 0; |
| 1526 | cdev->private->state = DEV_STATE_DISCONNECTED; |
| 1527 | if (cdev->online) |
| 1528 | ccw_device_schedule_recovery(); |
| 1529 | } |
| 1530 | |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1531 | void ccw_device_set_notoper(struct ccw_device *cdev) |
| 1532 | { |
| 1533 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1534 | |
| 1535 | CIO_TRACE_EVENT(2, "notoper"); |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 1536 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1537 | ccw_device_set_timeout(cdev, 0); |
| 1538 | cio_disable_subchannel(sch); |
| 1539 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1540 | } |
| 1541 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1542 | static int io_subchannel_sch_event(struct subchannel *sch, int slow) |
| 1543 | { |
| 1544 | int event, ret, disc; |
| 1545 | unsigned long flags; |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1546 | enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1547 | struct ccw_device *cdev; |
| 1548 | |
| 1549 | spin_lock_irqsave(sch->lock, flags); |
| 1550 | cdev = sch_get_cdev(sch); |
| 1551 | disc = device_is_disconnected(cdev); |
| 1552 | if (disc && slow) { |
| 1553 | /* Disconnected devices are evaluated directly only.*/ |
| 1554 | spin_unlock_irqrestore(sch->lock, flags); |
| 1555 | return 0; |
| 1556 | } |
| 1557 | /* No interrupt after machine check - kill pending timers. */ |
| 1558 | if (cdev) |
| 1559 | ccw_device_set_timeout(cdev, 0); |
| 1560 | if (!disc && !slow) { |
| 1561 | /* Non-disconnected devices are evaluated on the slow path. */ |
| 1562 | spin_unlock_irqrestore(sch->lock, flags); |
| 1563 | return -EAGAIN; |
| 1564 | } |
| 1565 | event = io_subchannel_get_status(sch); |
| 1566 | CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n", |
| 1567 | sch->schid.ssid, sch->schid.sch_no, event, |
| 1568 | disc ? "disconnected" : "normal", |
| 1569 | slow ? "slow" : "fast"); |
| 1570 | /* Analyze subchannel status. */ |
| 1571 | action = NONE; |
| 1572 | switch (event) { |
| 1573 | case CIO_NO_PATH: |
| 1574 | if (disc) { |
| 1575 | /* Check if paths have become available. */ |
| 1576 | action = REPROBE; |
| 1577 | break; |
| 1578 | } |
| 1579 | /* fall through */ |
| 1580 | case CIO_GONE: |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1581 | /* Ask driver what to do with device. */ |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1582 | if (io_subchannel_notify(sch, event)) |
| 1583 | action = DISC; |
| 1584 | else |
| 1585 | action = UNREGISTER; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1586 | break; |
| 1587 | case CIO_REVALIDATE: |
| 1588 | /* Device will be removed, so no notify necessary. */ |
| 1589 | if (disc) |
| 1590 | /* Reprobe because immediate unregister might block. */ |
| 1591 | action = REPROBE; |
| 1592 | else |
| 1593 | action = UNREGISTER_PROBE; |
| 1594 | break; |
| 1595 | case CIO_OPER: |
| 1596 | if (disc) |
| 1597 | /* Get device operational again. */ |
| 1598 | action = REPROBE; |
| 1599 | break; |
| 1600 | } |
| 1601 | /* Perform action. */ |
| 1602 | ret = 0; |
| 1603 | switch (action) { |
| 1604 | case UNREGISTER: |
| 1605 | case UNREGISTER_PROBE: |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1606 | ccw_device_set_notoper(cdev); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1607 | /* Unregister device (will use subchannel lock). */ |
| 1608 | spin_unlock_irqrestore(sch->lock, flags); |
| 1609 | css_sch_device_unregister(sch); |
| 1610 | spin_lock_irqsave(sch->lock, flags); |
| 1611 | |
| 1612 | /* Reset intparm to zeroes. */ |
| 1613 | sch->schib.pmcw.intparm = 0; |
| 1614 | cio_modify(sch); |
| 1615 | break; |
| 1616 | case REPROBE: |
| 1617 | ccw_device_trigger_reprobe(cdev); |
| 1618 | break; |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1619 | case DISC: |
| 1620 | device_set_disconnected(cdev); |
| 1621 | break; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1622 | default: |
| 1623 | break; |
| 1624 | } |
| 1625 | spin_unlock_irqrestore(sch->lock, flags); |
| 1626 | /* Probe if necessary. */ |
| 1627 | if (action == UNREGISTER_PROBE) |
| 1628 | ret = css_probe_device(sch->schid); |
| 1629 | |
| 1630 | return ret; |
| 1631 | } |
| 1632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | #ifdef CONFIG_CCW_CONSOLE |
| 1634 | static struct ccw_device console_cdev; |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1635 | static char console_cdev_name[10] = "0.x.xxxx"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | static struct ccw_device_private console_private; |
| 1637 | static int console_cdev_in_use; |
| 1638 | |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1639 | static DEFINE_SPINLOCK(ccw_console_lock); |
| 1640 | |
| 1641 | spinlock_t * cio_get_console_lock(void) |
| 1642 | { |
| 1643 | return &ccw_console_lock; |
| 1644 | } |
| 1645 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1646 | static int ccw_device_console_enable(struct ccw_device *cdev, |
| 1647 | struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | { |
| 1649 | int rc; |
| 1650 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1651 | /* Attach subchannel private data. */ |
| 1652 | sch->private = cio_get_console_priv(); |
| 1653 | memset(sch->private, 0, sizeof(struct io_subchannel_private)); |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1654 | io_subchannel_init_fields(sch); |
| 1655 | sch->driver = &io_subchannel_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | /* Initialize the ccw_device structure. */ |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 1657 | cdev->dev.parent= &sch->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | rc = io_subchannel_recog(cdev, sch); |
| 1659 | if (rc) |
| 1660 | return rc; |
| 1661 | |
| 1662 | /* Now wait for the async. recognition to come to an end. */ |
| 1663 | spin_lock_irq(cdev->ccwlock); |
| 1664 | while (!dev_fsm_final_state(cdev)) |
| 1665 | wait_cons_dev(); |
| 1666 | rc = -EIO; |
| 1667 | if (cdev->private->state != DEV_STATE_OFFLINE) |
| 1668 | goto out_unlock; |
| 1669 | ccw_device_online(cdev); |
| 1670 | while (!dev_fsm_final_state(cdev)) |
| 1671 | wait_cons_dev(); |
| 1672 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 1673 | goto out_unlock; |
| 1674 | rc = 0; |
| 1675 | out_unlock: |
| 1676 | spin_unlock_irq(cdev->ccwlock); |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
| 1680 | struct ccw_device * |
| 1681 | ccw_device_probe_console(void) |
| 1682 | { |
| 1683 | struct subchannel *sch; |
| 1684 | int ret; |
| 1685 | |
| 1686 | if (xchg(&console_cdev_in_use, 1) != 0) |
Peter Oberparleiter | 600b5d1 | 2006-02-01 03:06:35 -0800 | [diff] [blame] | 1687 | return ERR_PTR(-EBUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | sch = cio_probe_console(); |
| 1689 | if (IS_ERR(sch)) { |
| 1690 | console_cdev_in_use = 0; |
| 1691 | return (void *) sch; |
| 1692 | } |
| 1693 | memset(&console_cdev, 0, sizeof(struct ccw_device)); |
| 1694 | memset(&console_private, 0, sizeof(struct ccw_device_private)); |
| 1695 | console_cdev.private = &console_private; |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1696 | console_private.cdev = &console_cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | ret = ccw_device_console_enable(&console_cdev, sch); |
| 1698 | if (ret) { |
| 1699 | cio_release_console(); |
| 1700 | console_cdev_in_use = 0; |
| 1701 | return ERR_PTR(ret); |
| 1702 | } |
| 1703 | console_cdev.online = 1; |
| 1704 | return &console_cdev; |
| 1705 | } |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1706 | |
| 1707 | |
| 1708 | const char *cio_get_console_cdev_name(struct subchannel *sch) |
| 1709 | { |
| 1710 | snprintf(console_cdev_name, 10, "0.%x.%04x", |
| 1711 | sch->schid.ssid, sch->schib.pmcw.dev); |
| 1712 | return (const char *)console_cdev_name; |
| 1713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | #endif |
| 1715 | |
| 1716 | /* |
| 1717 | * get ccw_device matching the busid, but only if owned by cdrv |
| 1718 | */ |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1719 | static int |
| 1720 | __ccwdev_check_busid(struct device *dev, void *id) |
| 1721 | { |
| 1722 | char *bus_id; |
| 1723 | |
Cornelia Huck | 12975ae | 2006-10-11 15:31:47 +0200 | [diff] [blame] | 1724 | bus_id = id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1725 | |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 1726 | return (strcmp(bus_id, dev_name(dev)) == 0); |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1730 | /** |
| 1731 | * get_ccwdev_by_busid() - obtain device from a bus id |
| 1732 | * @cdrv: driver the device is owned by |
| 1733 | * @bus_id: bus id of the device to be searched |
| 1734 | * |
| 1735 | * This function searches all devices owned by @cdrv for a device with a bus |
| 1736 | * id matching @bus_id. |
| 1737 | * Returns: |
| 1738 | * If a match is found, its reference count of the found device is increased |
| 1739 | * and it is returned; else %NULL is returned. |
| 1740 | */ |
| 1741 | struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 1742 | const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | { |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1744 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | struct device_driver *drv; |
| 1746 | |
| 1747 | drv = get_driver(&cdrv->driver); |
| 1748 | if (!drv) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1749 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1751 | dev = driver_find_device(drv, NULL, (void *)bus_id, |
| 1752 | __ccwdev_check_busid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | put_driver(drv); |
| 1754 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1755 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /************************** device driver handling ************************/ |
| 1759 | |
| 1760 | /* This is the implementation of the ccw_driver class. The probe, remove |
| 1761 | * and release methods are initially very similar to the device_driver |
| 1762 | * implementations, with the difference that they have ccw_device |
| 1763 | * arguments. |
| 1764 | * |
| 1765 | * A ccw driver also contains the information that is needed for |
| 1766 | * device matching. |
| 1767 | */ |
| 1768 | static int |
| 1769 | ccw_device_probe (struct device *dev) |
| 1770 | { |
| 1771 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1772 | struct ccw_driver *cdrv = to_ccwdrv(dev->driver); |
| 1773 | int ret; |
| 1774 | |
| 1775 | cdev->drv = cdrv; /* to let the driver call _set_online */ |
| 1776 | |
| 1777 | ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; |
| 1778 | |
| 1779 | if (ret) { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1780 | cdev->drv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | return ret; |
| 1782 | } |
| 1783 | |
| 1784 | return 0; |
| 1785 | } |
| 1786 | |
| 1787 | static int |
| 1788 | ccw_device_remove (struct device *dev) |
| 1789 | { |
| 1790 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1791 | struct ccw_driver *cdrv = cdev->drv; |
| 1792 | int ret; |
| 1793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | if (cdrv->remove) |
| 1795 | cdrv->remove(cdev); |
| 1796 | if (cdev->online) { |
| 1797 | cdev->online = 0; |
| 1798 | spin_lock_irq(cdev->ccwlock); |
| 1799 | ret = ccw_device_offline(cdev); |
| 1800 | spin_unlock_irq(cdev->ccwlock); |
| 1801 | if (ret == 0) |
| 1802 | wait_event(cdev->private->wait_q, |
| 1803 | dev_fsm_final_state(cdev)); |
| 1804 | else |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 1805 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 1806 | "device 0.%x.%04x\n", |
| 1807 | ret, cdev->private->dev_id.ssid, |
| 1808 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | ccw_device_set_timeout(cdev, 0); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1811 | cdev->drv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | return 0; |
| 1813 | } |
| 1814 | |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1815 | static void ccw_device_shutdown(struct device *dev) |
| 1816 | { |
| 1817 | struct ccw_device *cdev; |
| 1818 | |
| 1819 | cdev = to_ccwdev(dev); |
| 1820 | if (cdev->drv && cdev->drv->shutdown) |
| 1821 | cdev->drv->shutdown(cdev); |
Cornelia Huck | 1842f2b | 2007-10-12 16:11:22 +0200 | [diff] [blame] | 1822 | disable_cmf(cdev); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1823 | } |
| 1824 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1825 | struct bus_type ccw_bus_type = { |
| 1826 | .name = "ccw", |
| 1827 | .match = ccw_bus_match, |
| 1828 | .uevent = ccw_uevent, |
| 1829 | .probe = ccw_device_probe, |
| 1830 | .remove = ccw_device_remove, |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1831 | .shutdown = ccw_device_shutdown, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1832 | }; |
| 1833 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1834 | /** |
| 1835 | * ccw_driver_register() - register a ccw driver |
| 1836 | * @cdriver: driver to be registered |
| 1837 | * |
| 1838 | * This function is mainly a wrapper around driver_register(). |
| 1839 | * Returns: |
| 1840 | * %0 on success and a negative error value on failure. |
| 1841 | */ |
| 1842 | int ccw_driver_register(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | { |
| 1844 | struct device_driver *drv = &cdriver->driver; |
| 1845 | |
| 1846 | drv->bus = &ccw_bus_type; |
| 1847 | drv->name = cdriver->name; |
Cornelia Huck | 4beee64 | 2008-01-26 14:10:47 +0100 | [diff] [blame] | 1848 | drv->owner = cdriver->owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
| 1850 | return driver_register(drv); |
| 1851 | } |
| 1852 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1853 | /** |
| 1854 | * ccw_driver_unregister() - deregister a ccw driver |
| 1855 | * @cdriver: driver to be deregistered |
| 1856 | * |
| 1857 | * This function is mainly a wrapper around driver_unregister(). |
| 1858 | */ |
| 1859 | void ccw_driver_unregister(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | { |
| 1861 | driver_unregister(&cdriver->driver); |
| 1862 | } |
| 1863 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1864 | /* Helper func for qdio. */ |
| 1865 | struct subchannel_id |
| 1866 | ccw_device_get_subchannel_id(struct ccw_device *cdev) |
| 1867 | { |
| 1868 | struct subchannel *sch; |
| 1869 | |
| 1870 | sch = to_subchannel(cdev->dev.parent); |
| 1871 | return sch->schid; |
| 1872 | } |
| 1873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | MODULE_LICENSE("GPL"); |
| 1875 | EXPORT_SYMBOL(ccw_device_set_online); |
| 1876 | EXPORT_SYMBOL(ccw_device_set_offline); |
| 1877 | EXPORT_SYMBOL(ccw_driver_register); |
| 1878 | EXPORT_SYMBOL(ccw_driver_unregister); |
| 1879 | EXPORT_SYMBOL(get_ccwdev_by_busid); |
| 1880 | EXPORT_SYMBOL(ccw_bus_type); |
| 1881 | EXPORT_SYMBOL(ccw_device_work); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1882 | EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); |