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