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