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