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