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