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