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