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