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