blob: c6767f5a58b23f3202a52113bc67ee295ab174f6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * bus driver for ccw devices
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 2002, 2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08006 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 */
Peter Oberparleitera7ae2c022009-12-07 12:51:20 +01009
10#define KMSG_COMPONENT "cio"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/spinlock.h>
16#include <linux/errno.h>
17#include <linux/err.h>
18#include <linux/slab.h>
19#include <linux/list.h>
20#include <linux/device.h>
21#include <linux/workqueue.h>
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010022#include <linux/timer.h>
Peter Oberparleiterde400d62011-10-30 15:16:04 +010023#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include <asm/ccwdev.h>
26#include <asm/cio.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080027#include <asm/param.h> /* HZ */
Cornelia Huck1842f2b2007-10-12 16:11:22 +020028#include <asm/cmb.h>
Cornelia Huck3a3fc292008-07-14 09:58:58 +020029#include <asm/isc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +020031#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "cio.h"
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +010033#include "cio_debug.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "css.h"
35#include "device.h"
36#include "ioasm.h"
Cornelia Huckcd6b4f22008-01-26 14:10:43 +010037#include "io_sch.h"
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +020038#include "blacklist.h"
Michael Ernstfd0457a2010-08-09 18:12:50 +020039#include "chsc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010041static struct timer_list recovery_timer;
Cornelia Huck486d0a02008-02-19 15:29:23 +010042static DEFINE_SPINLOCK(recovery_lock);
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010043static int recovery_phase;
44static const unsigned long recovery_delay[] = { 3, 30, 300 };
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/******************* bus type handling ***********************/
47
48/* The Linux driver model distinguishes between a bus type and
49 * the bus itself. Of course we only have one channel
50 * subsystem driver and one channel system per machine, but
51 * we still use the abstraction. T.R. says it's a good idea. */
52static int
53ccw_bus_match (struct device * dev, struct device_driver * drv)
54{
55 struct ccw_device *cdev = to_ccwdev(dev);
56 struct ccw_driver *cdrv = to_ccwdrv(drv);
57 const struct ccw_device_id *ids = cdrv->ids, *found;
58
59 if (!ids)
60 return 0;
61
62 found = ccw_device_id_match(ids, &cdev->id);
63 if (!found)
64 return 0;
65
66 cdev->id.driver_info = found->driver_info;
67
68 return 1;
69}
70
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020071/* Store modalias string delimited by prefix/suffix string into buffer with
72 * specified size. Return length of resulting string (excluding trailing '\0')
73 * even if string doesn't fit buffer (snprintf semantics). */
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020074static int snprint_alias(char *buf, size_t size,
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020075 struct ccw_device_id *id, const char *suffix)
76{
77 int len;
78
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020079 len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020080 if (len > size)
81 return len;
82 buf += len;
83 size -= len;
84
85 if (id->dev_type != 0)
86 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
87 id->dev_model, suffix);
88 else
89 len += snprintf(buf, size, "dtdm%s", suffix);
90
91 return len;
92}
93
94/* Set up environment variables for ccw device uevent. Return 0 on success,
95 * non-zero otherwise. */
Kay Sievers7eff2e72007-08-14 15:15:12 +020096static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020099 struct ccw_device_id *id = &(cdev->id);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200100 int ret;
101 char modalias_buf[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200103 /* CU_TYPE= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200104 ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200105 if (ret)
106 return ret;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200107
108 /* CU_MODEL= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200109 ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200110 if (ret)
111 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 /* The next two can be zero, that's ok for us */
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200114 /* DEV_TYPE= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200115 ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200116 if (ret)
117 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200119 /* DEV_MODEL= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200120 ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200121 if (ret)
122 return ret;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200123
124 /* MODALIAS= */
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200125 snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
Kay Sievers7eff2e72007-08-14 15:15:12 +0200126 ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf);
127 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Sebastian Ottd5ab5272011-03-23 10:16:03 +0100130static struct bus_type ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Cornelia Huck602b20f2008-01-26 14:10:39 +0100132static void io_subchannel_irq(struct subchannel *);
133static int io_subchannel_probe(struct subchannel *);
134static int io_subchannel_remove(struct subchannel *);
Cornelia Huck8bbace72006-01-11 10:56:22 +0100135static void io_subchannel_shutdown(struct subchannel *);
Cornelia Huckc820de32008-07-14 09:58:45 +0200136static int io_subchannel_sch_event(struct subchannel *, int);
Cornelia Huck99611f82008-07-14 09:59:02 +0200137static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
138 int);
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200139static void recovery_func(unsigned long data);
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200140wait_queue_head_t ccw_device_init_wq;
141atomic_t ccw_device_init_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Cornelia Huckf08adc02008-07-14 09:59:03 +0200143static struct css_device_id io_subchannel_ids[] = {
144 { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, },
145 { /* end of list */ },
146};
147MODULE_DEVICE_TABLE(css, io_subchannel_ids);
148
Cornelia Huck93a27592009-06-16 10:30:23 +0200149static int io_subchannel_prepare(struct subchannel *sch)
150{
151 struct ccw_device *cdev;
152 /*
153 * Don't allow suspend while a ccw device registration
154 * is still outstanding.
155 */
156 cdev = sch_get_cdev(sch);
157 if (cdev && !device_is_registered(&cdev->dev))
158 return -EAGAIN;
159 return 0;
160}
161
Sebastian Ottb4c70722010-02-26 22:37:27 +0100162static int io_subchannel_settle(void)
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200163{
Sebastian Ottb4c70722010-02-26 22:37:27 +0100164 int ret;
165
166 ret = wait_event_interruptible(ccw_device_init_wq,
167 atomic_read(&ccw_device_init_count) == 0);
168 if (ret)
169 return -EINTR;
Sebastian Ottbe5d3822010-02-26 22:37:24 +0100170 flush_workqueue(cio_work_q);
Sebastian Ottb4c70722010-02-26 22:37:27 +0100171 return 0;
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200172}
173
Cornelia Huckf7e5d672007-05-10 15:45:43 +0200174static struct css_driver io_subchannel_driver = {
Sebastian Otte6aed122011-03-15 17:08:30 +0100175 .drv = {
176 .owner = THIS_MODULE,
177 .name = "io_subchannel",
178 },
Cornelia Huckf08adc02008-07-14 09:59:03 +0200179 .subchannel_type = io_subchannel_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .irq = io_subchannel_irq,
Cornelia Huckc820de32008-07-14 09:58:45 +0200181 .sch_event = io_subchannel_sch_event,
182 .chp_event = io_subchannel_chp_event,
Cornelia Huck8bbace72006-01-11 10:56:22 +0100183 .probe = io_subchannel_probe,
184 .remove = io_subchannel_remove,
185 .shutdown = io_subchannel_shutdown,
Cornelia Huck93a27592009-06-16 10:30:23 +0200186 .prepare = io_subchannel_prepare,
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200187 .settle = io_subchannel_settle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Sebastian Ott2f176442009-09-22 22:58:33 +0200190int __init io_subchannel_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 int ret;
193
194 init_waitqueue_head(&ccw_device_init_wq);
195 atomic_set(&ccw_device_init_count, 0);
Peter Oberparleiter90ab1332008-01-26 14:10:52 +0100196 setup_timer(&recovery_timer, recovery_func, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Sebastian Ottbe5d3822010-02-26 22:37:24 +0100198 ret = bus_register(&ccw_bus_type);
199 if (ret)
200 return ret;
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100201 ret = css_driver_register(&io_subchannel_driver);
202 if (ret)
Sebastian Ottbe5d3822010-02-26 22:37:24 +0100203 bus_unregister(&ccw_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return ret;
206}
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209/************************ device handling **************************/
210
211/*
212 * A ccw_device has some interfaces in sysfs in addition to the
213 * standard ones.
214 * The following entries are designed to export the information which
215 * resided in 2.4 in /proc/subchannels. Subchannel and device number
216 * are obvious, so they don't have an entry :)
217 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
218 */
219static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400220chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 struct subchannel *sch = to_subchannel(dev);
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200223 struct chsc_ssd_info *ssd = &sch->ssd_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 ssize_t ret = 0;
225 int chp;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200226 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200228 for (chp = 0; chp < 8; chp++) {
229 mask = 0x80 >> chp;
230 if (ssd->path_mask & mask)
231 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
232 else
233 ret += sprintf(buf + ret, "00 ");
234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 ret += sprintf (buf+ret, "\n");
236 return min((ssize_t)PAGE_SIZE, ret);
237}
238
239static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400240pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 struct subchannel *sch = to_subchannel(dev);
243 struct pmcw *pmcw = &sch->schib.pmcw;
244
245 return sprintf (buf, "%02x %02x %02x\n",
246 pmcw->pim, pmcw->pam, pmcw->pom);
247}
248
249static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400250devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 struct ccw_device *cdev = to_ccwdev(dev);
253 struct ccw_device_id *id = &(cdev->id);
254
255 if (id->dev_type != 0)
256 return sprintf(buf, "%04x/%02x\n",
257 id->dev_type, id->dev_model);
258 else
259 return sprintf(buf, "n/a\n");
260}
261
262static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400263cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 struct ccw_device *cdev = to_ccwdev(dev);
266 struct ccw_device_id *id = &(cdev->id);
267
268 return sprintf(buf, "%04x/%02x\n",
269 id->cu_type, id->cu_model);
270}
271
272static ssize_t
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800273modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
274{
275 struct ccw_device *cdev = to_ccwdev(dev);
276 struct ccw_device_id *id = &(cdev->id);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200277 int len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800278
Cornelia Huck086a6c62007-07-17 13:36:08 +0200279 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200280
281 return len > PAGE_SIZE ? PAGE_SIZE : len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800282}
283
284static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400285online_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct ccw_device *cdev = to_ccwdev(dev);
288
289 return sprintf(buf, cdev->online ? "1\n" : "0\n");
290}
291
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100292int ccw_device_is_orphan(struct ccw_device *cdev)
293{
294 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
295}
296
Cornelia Huckef995162007-04-27 16:01:39 +0200297static void ccw_device_unregister(struct ccw_device *cdev)
Cornelia Huck7674da72006-12-08 15:54:21 +0100298{
Sebastian Ott7d253b92009-12-07 12:51:33 +0100299 if (device_is_registered(&cdev->dev)) {
Sebastian Ott24a18722009-12-07 12:51:34 +0100300 /* Undo device_add(). */
Cornelia Huckef995162007-04-27 16:01:39 +0200301 device_del(&cdev->dev);
Sebastian Ott24a18722009-12-07 12:51:34 +0100302 }
303 if (cdev->private->flags.initialized) {
304 cdev->private->flags.initialized = 0;
Sebastian Ott3b554a12009-09-11 10:28:26 +0200305 /* Release reference from device_initialize(). */
306 put_device(&cdev->dev);
307 }
Cornelia Huck7674da72006-12-08 15:54:21 +0100308}
309
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100310static void io_subchannel_quiesce(struct subchannel *);
311
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200312/**
313 * ccw_device_set_offline() - disable a ccw device for I/O
314 * @cdev: target ccw device
315 *
316 * This function calls the driver's set_offline() function for @cdev, if
317 * given, and then disables @cdev.
318 * Returns:
319 * %0 on success and a negative error value on failure.
320 * Context:
321 * enabled, ccw device lock not held
322 */
323int ccw_device_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100325 struct subchannel *sch;
326 int ret, state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 if (!cdev)
329 return -ENODEV;
330 if (!cdev->online || !cdev->drv)
331 return -EINVAL;
332
333 if (cdev->drv->set_offline) {
334 ret = cdev->drv->set_offline(cdev);
335 if (ret != 0)
336 return ret;
337 }
338 cdev->online = 0;
339 spin_lock_irq(cdev->ccwlock);
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100340 sch = to_subchannel(cdev->dev.parent);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200341 /* Wait until a final state or DISCONNECTED is reached */
342 while (!dev_fsm_final_state(cdev) &&
343 cdev->private->state != DEV_STATE_DISCONNECTED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 spin_unlock_irq(cdev->ccwlock);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200345 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
346 cdev->private->state == DEV_STATE_DISCONNECTED));
347 spin_lock_irq(cdev->ccwlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100349 do {
350 ret = ccw_device_offline(cdev);
351 if (!ret)
352 break;
353 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device "
354 "0.%x.%04x\n", ret, cdev->private->dev_id.ssid,
355 cdev->private->dev_id.devno);
356 if (ret != -EBUSY)
357 goto error;
358 state = cdev->private->state;
359 spin_unlock_irq(cdev->ccwlock);
360 io_subchannel_quiesce(sch);
361 spin_lock_irq(cdev->ccwlock);
362 cdev->private->state = state;
363 } while (ret == -EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 spin_unlock_irq(cdev->ccwlock);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200365 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
366 cdev->private->state == DEV_STATE_DISCONNECTED));
Peter Oberparleitera7ae2c022009-12-07 12:51:20 +0100367 /* Inform the user if set offline failed. */
368 if (cdev->private->state == DEV_STATE_BOXED) {
369 pr_warning("%s: The device entered boxed state while "
370 "being set offline\n", dev_name(&cdev->dev));
371 } else if (cdev->private->state == DEV_STATE_NOT_OPER) {
372 pr_warning("%s: The device stopped operating while "
373 "being set offline\n", dev_name(&cdev->dev));
374 }
Michael Ernst217ee6c2009-09-11 10:28:21 +0200375 /* Give up reference from ccw_device_set_online(). */
376 put_device(&cdev->dev);
377 return 0;
378
379error:
Michael Ernst217ee6c2009-09-11 10:28:21 +0200380 cdev->private->state = DEV_STATE_OFFLINE;
381 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
382 spin_unlock_irq(cdev->ccwlock);
383 /* Give up reference from ccw_device_set_online(). */
384 put_device(&cdev->dev);
385 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200388/**
389 * ccw_device_set_online() - enable a ccw device for I/O
390 * @cdev: target ccw device
391 *
392 * This function first enables @cdev and then calls the driver's set_online()
393 * function for @cdev, if given. If set_online() returns an error, @cdev is
394 * disabled again.
395 * Returns:
396 * %0 on success and a negative error value on failure.
397 * Context:
398 * enabled, ccw device lock not held
399 */
400int ccw_device_set_online(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 int ret;
Michael Ernst217ee6c2009-09-11 10:28:21 +0200403 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 if (!cdev)
406 return -ENODEV;
407 if (cdev->online || !cdev->drv)
408 return -EINVAL;
Cornelia Huck9cd67422008-12-25 13:39:06 +0100409 /* Hold on to an extra reference while device is online. */
410 if (!get_device(&cdev->dev))
411 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 spin_lock_irq(cdev->ccwlock);
414 ret = ccw_device_online(cdev);
415 spin_unlock_irq(cdev->ccwlock);
416 if (ret == 0)
417 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
418 else {
Michael Ernst139b83d2008-05-07 09:22:54 +0200419 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200420 "device 0.%x.%04x\n",
421 ret, cdev->private->dev_id.ssid,
422 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +0100423 /* Give up online reference since onlining failed. */
424 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return ret;
426 }
Michael Ernst217ee6c2009-09-11 10:28:21 +0200427 spin_lock_irq(cdev->ccwlock);
428 /* Check if online processing was successful */
429 if ((cdev->private->state != DEV_STATE_ONLINE) &&
430 (cdev->private->state != DEV_STATE_W4SENSE)) {
431 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleitera7ae2c022009-12-07 12:51:20 +0100432 /* Inform the user that set online failed. */
433 if (cdev->private->state == DEV_STATE_BOXED) {
434 pr_warning("%s: Setting the device online failed "
435 "because it is boxed\n",
436 dev_name(&cdev->dev));
437 } else if (cdev->private->state == DEV_STATE_NOT_OPER) {
438 pr_warning("%s: Setting the device online failed "
439 "because it is not operational\n",
440 dev_name(&cdev->dev));
441 }
Cornelia Huck9cd67422008-12-25 13:39:06 +0100442 /* Give up online reference since onlining failed. */
443 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return -ENODEV;
Cornelia Huck9cd67422008-12-25 13:39:06 +0100445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 spin_unlock_irq(cdev->ccwlock);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200447 if (cdev->drv->set_online)
448 ret = cdev->drv->set_online(cdev);
449 if (ret)
450 goto rollback;
451 cdev->online = 1;
452 return 0;
453
454rollback:
455 spin_lock_irq(cdev->ccwlock);
456 /* Wait until a final state or DISCONNECTED is reached */
457 while (!dev_fsm_final_state(cdev) &&
458 cdev->private->state != DEV_STATE_DISCONNECTED) {
459 spin_unlock_irq(cdev->ccwlock);
460 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
461 cdev->private->state == DEV_STATE_DISCONNECTED));
462 spin_lock_irq(cdev->ccwlock);
463 }
464 ret2 = ccw_device_offline(cdev);
465 if (ret2)
466 goto error;
467 spin_unlock_irq(cdev->ccwlock);
468 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
469 cdev->private->state == DEV_STATE_DISCONNECTED));
Cornelia Huck9cd67422008-12-25 13:39:06 +0100470 /* Give up online reference since onlining failed. */
471 put_device(&cdev->dev);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200472 return ret;
473
474error:
475 CIO_MSG_EVENT(0, "rollback ccw_device_offline returned %d, "
476 "device 0.%x.%04x\n",
477 ret2, cdev->private->dev_id.ssid,
478 cdev->private->dev_id.devno);
479 cdev->private->state = DEV_STATE_OFFLINE;
480 spin_unlock_irq(cdev->ccwlock);
481 /* Give up online reference since onlining failed. */
482 put_device(&cdev->dev);
483 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100486static int online_store_handle_offline(struct ccw_device *cdev)
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200487{
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100488 if (cdev->private->state == DEV_STATE_DISCONNECTED) {
489 spin_lock_irq(cdev->ccwlock);
490 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL);
491 spin_unlock_irq(cdev->ccwlock);
Sebastian Ott7cd40312010-08-09 18:12:52 +0200492 return 0;
493 }
494 if (cdev->drv && cdev->drv->set_offline)
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100495 return ccw_device_set_offline(cdev);
Sebastian Ott7cd40312010-08-09 18:12:52 +0200496 return -EINVAL;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200497}
498
499static int online_store_recog_and_online(struct ccw_device *cdev)
500{
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200501 /* Do device recognition, if needed. */
Sebastian Ott99f6a5702009-03-31 19:16:07 +0200502 if (cdev->private->state == DEV_STATE_BOXED) {
Peter Oberparleiter1f5bd382009-12-07 12:51:23 +0100503 spin_lock_irq(cdev->ccwlock);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100504 ccw_device_recognition(cdev);
Peter Oberparleiter1f5bd382009-12-07 12:51:23 +0100505 spin_unlock_irq(cdev->ccwlock);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200506 wait_event(cdev->private->wait_q,
507 cdev->private->flags.recog_done);
Sebastian Ott156013f2009-03-31 19:16:03 +0200508 if (cdev->private->state != DEV_STATE_OFFLINE)
509 /* recognition failed */
510 return -EAGAIN;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200511 }
512 if (cdev->drv && cdev->drv->set_online)
Sebastian Ott7cd40312010-08-09 18:12:52 +0200513 return ccw_device_set_online(cdev);
514 return -EINVAL;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200515}
Sebastian Ott156013f2009-03-31 19:16:03 +0200516
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200517static int online_store_handle_online(struct ccw_device *cdev, int force)
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200518{
519 int ret;
520
521 ret = online_store_recog_and_online(cdev);
Sebastian Ott156013f2009-03-31 19:16:03 +0200522 if (ret && !force)
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200523 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200524 if (force && cdev->private->state == DEV_STATE_BOXED) {
525 ret = ccw_device_stlck(cdev);
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200526 if (ret)
527 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200528 if (cdev->id.cu_type == 0)
529 cdev->private->state = DEV_STATE_NOT_OPER;
Sebastian Ott156013f2009-03-31 19:16:03 +0200530 ret = online_store_recog_and_online(cdev);
531 if (ret)
532 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200533 }
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200534 return 0;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200535}
536
537static ssize_t online_store (struct device *dev, struct device_attribute *attr,
538 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 struct ccw_device *cdev = to_ccwdev(dev);
Cornelia Huck2f972202008-04-30 13:38:33 +0200541 int force, ret;
542 unsigned long i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200544 /* Prevent conflict between multiple on-/offline processing requests. */
Peter Oberparleiter350e9122009-12-07 12:51:28 +0100545 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return -EAGAIN;
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200547 /* Prevent conflict between internal I/Os and on-/offline processing. */
548 if (!dev_fsm_final_state(cdev) &&
549 cdev->private->state != DEV_STATE_DISCONNECTED) {
550 ret = -EAGAIN;
551 goto out_onoff;
552 }
553 /* Prevent conflict between pending work and on-/offline processing.*/
554 if (work_pending(&cdev->private->todo_work)) {
555 ret = -EAGAIN;
556 goto out_onoff;
557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Sebastian Ott3bda0582011-03-23 10:16:02 +0100559 if (cdev->drv && !try_module_get(cdev->drv->driver.owner)) {
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200560 ret = -EINVAL;
561 goto out_onoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563 if (!strncmp(buf, "force\n", count)) {
564 force = 1;
565 i = 1;
Cornelia Huck2f972202008-04-30 13:38:33 +0200566 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 } else {
568 force = 0;
Cornelia Huck2f972202008-04-30 13:38:33 +0200569 ret = strict_strtoul(buf, 16, &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 }
Cornelia Huck2f972202008-04-30 13:38:33 +0200571 if (ret)
572 goto out;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200573 switch (i) {
574 case 0:
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100575 ret = online_store_handle_offline(cdev);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200576 break;
577 case 1:
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200578 ret = online_store_handle_online(cdev, force);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200579 break;
580 default:
Cornelia Huck2f972202008-04-30 13:38:33 +0200581 ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
Cornelia Huck2f972202008-04-30 13:38:33 +0200583out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (cdev->drv)
Sebastian Ott3bda0582011-03-23 10:16:02 +0100585 module_put(cdev->drv->driver.owner);
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200586out_onoff:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 atomic_set(&cdev->private->onoff, 0);
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100588 return (ret < 0) ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400592available_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
594 struct ccw_device *cdev = to_ccwdev(dev);
595 struct subchannel *sch;
596
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100597 if (ccw_device_is_orphan(cdev))
598 return sprintf(buf, "no device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 switch (cdev->private->state) {
600 case DEV_STATE_BOXED:
601 return sprintf(buf, "boxed\n");
602 case DEV_STATE_DISCONNECTED:
603 case DEV_STATE_DISCONNECTED_SENSE_ID:
604 case DEV_STATE_NOT_OPER:
605 sch = to_subchannel(dev->parent);
606 if (!sch->lpm)
607 return sprintf(buf, "no path\n");
608 else
609 return sprintf(buf, "no device\n");
610 default:
611 /* All other states considered fine. */
612 return sprintf(buf, "good\n");
613 }
614}
615
Michael Ernstfd0457a2010-08-09 18:12:50 +0200616static ssize_t
617initiate_logging(struct device *dev, struct device_attribute *attr,
618 const char *buf, size_t count)
619{
620 struct subchannel *sch = to_subchannel(dev);
621 int rc;
622
623 rc = chsc_siosl(sch->schid);
624 if (rc < 0) {
625 pr_warning("Logging for subchannel 0.%x.%04x failed with "
626 "errno=%d\n",
627 sch->schid.ssid, sch->schid.sch_no, rc);
628 return rc;
629 }
630 pr_notice("Logging for subchannel 0.%x.%04x was triggered\n",
631 sch->schid.ssid, sch->schid.sch_no);
632 return count;
633}
634
Sebastian Ott84c57ad2013-01-28 19:32:27 +0100635static ssize_t vpm_show(struct device *dev, struct device_attribute *attr,
636 char *buf)
637{
638 struct subchannel *sch = to_subchannel(dev);
639
640 return sprintf(buf, "%02x\n", sch->vpm);
641}
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
644static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
645static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
646static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800647static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648static DEVICE_ATTR(online, 0644, online_show, online_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649static DEVICE_ATTR(availability, 0444, available_show, NULL);
Michael Ernstfd0457a2010-08-09 18:12:50 +0200650static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
Sebastian Ott84c57ad2013-01-28 19:32:27 +0100651static DEVICE_ATTR(vpm, 0444, vpm_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200653static struct attribute *io_subchannel_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 &dev_attr_chpids.attr,
655 &dev_attr_pimpampom.attr,
Michael Ernstfd0457a2010-08-09 18:12:50 +0200656 &dev_attr_logging.attr,
Sebastian Ott84c57ad2013-01-28 19:32:27 +0100657 &dev_attr_vpm.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 NULL,
659};
660
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200661static struct attribute_group io_subchannel_attr_group = {
662 .attrs = io_subchannel_attrs,
Cornelia Huck529192f2006-12-08 15:55:57 +0100663};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665static struct attribute * ccwdev_attrs[] = {
666 &dev_attr_devtype.attr,
667 &dev_attr_cutype.attr,
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800668 &dev_attr_modalias.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 &dev_attr_online.attr,
670 &dev_attr_cmb_enable.attr,
671 &dev_attr_availability.attr,
672 NULL,
673};
674
675static struct attribute_group ccwdev_attr_group = {
676 .attrs = ccwdev_attrs,
677};
678
David Brownella4dbd672009-06-24 10:06:31 -0700679static const struct attribute_group *ccwdev_attr_groups[] = {
Cornelia Huckef995162007-04-27 16:01:39 +0200680 &ccwdev_attr_group,
681 NULL,
682};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
684/* this is a simple abstraction for device_register that sets the
685 * correct bus type and adds the bus specific files */
Cornelia Huck3c9da7b2006-10-27 12:39:33 +0200686static int ccw_device_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 struct device *dev = &cdev->dev;
689 int ret;
690
691 dev->bus = &ccw_bus_type;
Sebastian Ott3ac276f2009-09-11 10:28:27 +0200692 ret = dev_set_name(&cdev->dev, "0.%x.%04x", cdev->private->dev_id.ssid,
693 cdev->private->dev_id.devno);
694 if (ret)
695 return ret;
Sebastian Ott7d253b92009-12-07 12:51:33 +0100696 return device_add(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697}
698
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100699static int match_dev_id(struct device *dev, void *data)
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700700{
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100701 struct ccw_device *cdev = to_ccwdev(dev);
702 struct ccw_dev_id *dev_id = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700703
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100704 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
705}
706
Sebastian Ottb7a610f2012-05-15 17:52:07 +0200707/**
708 * get_ccwdev_by_dev_id() - obtain device from a ccw device id
709 * @dev_id: id of the device to be searched
710 *
711 * This function searches all devices attached to the ccw bus for a device
712 * matching @dev_id.
713 * Returns:
714 * If a device is found its reference count is increased and returned;
715 * else %NULL is returned.
716 */
717struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id)
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100718{
719 struct device *dev;
720
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100721 dev = bus_find_device(&ccw_bus_type, NULL, dev_id, match_dev_id);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100722
723 return dev ? to_ccwdev(dev) : NULL;
724}
Sebastian Ottb7a610f2012-05-15 17:52:07 +0200725EXPORT_SYMBOL_GPL(get_ccwdev_by_dev_id);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100726
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100727static void ccw_device_do_unbind_bind(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728{
Cornelia Huckeb32ae82009-03-26 15:24:05 +0100729 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Sebastian Ott7d253b92009-12-07 12:51:33 +0100731 if (device_is_registered(&cdev->dev)) {
Cornelia Huckeb32ae82009-03-26 15:24:05 +0100732 device_release_driver(&cdev->dev);
733 ret = device_attach(&cdev->dev);
734 WARN_ON(ret == -ENODEV);
735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736}
737
738static void
739ccw_device_release(struct device *dev)
740{
741 struct ccw_device *cdev;
742
743 cdev = to_ccwdev(dev);
Cornelia Huck6eff2082008-12-25 13:39:07 +0100744 /* Release reference of parent subchannel. */
745 put_device(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 kfree(cdev->private);
747 kfree(cdev);
748}
749
Cornelia Huck7674da72006-12-08 15:54:21 +0100750static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
751{
752 struct ccw_device *cdev;
753
754 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
755 if (cdev) {
756 cdev->private = kzalloc(sizeof(struct ccw_device_private),
757 GFP_KERNEL | GFP_DMA);
758 if (cdev->private)
759 return cdev;
760 }
761 kfree(cdev);
762 return ERR_PTR(-ENOMEM);
763}
764
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100765static void ccw_device_todo(struct work_struct *work);
766
Cornelia Huck7674da72006-12-08 15:54:21 +0100767static int io_subchannel_initialize_dev(struct subchannel *sch,
768 struct ccw_device *cdev)
769{
770 cdev->private->cdev = cdev;
Heiko Carstens420f42e2013-01-02 15:18:18 +0100771 cdev->private->int_class = IRQIO_CIO;
Cornelia Huck7674da72006-12-08 15:54:21 +0100772 atomic_set(&cdev->private->onoff, 0);
773 cdev->dev.parent = &sch->dev;
774 cdev->dev.release = ccw_device_release;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100775 INIT_WORK(&cdev->private->todo_work, ccw_device_todo);
Cornelia Huckef995162007-04-27 16:01:39 +0200776 cdev->dev.groups = ccwdev_attr_groups;
Cornelia Huck7674da72006-12-08 15:54:21 +0100777 /* Do first half of device_register. */
778 device_initialize(&cdev->dev);
779 if (!get_device(&sch->dev)) {
Cornelia Huck283fdd02008-12-25 13:39:10 +0100780 /* Release reference from device_initialize(). */
781 put_device(&cdev->dev);
Cornelia Huck7674da72006-12-08 15:54:21 +0100782 return -ENODEV;
783 }
Sebastian Ott24a18722009-12-07 12:51:34 +0100784 cdev->private->flags.initialized = 1;
Cornelia Huck7674da72006-12-08 15:54:21 +0100785 return 0;
786}
787
788static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
789{
790 struct ccw_device *cdev;
791 int ret;
792
793 cdev = io_subchannel_allocate_dev(sch);
794 if (!IS_ERR(cdev)) {
795 ret = io_subchannel_initialize_dev(sch, cdev);
Sebastian Ott06739a82009-08-23 18:09:04 +0200796 if (ret)
Cornelia Huck7674da72006-12-08 15:54:21 +0100797 cdev = ERR_PTR(ret);
Cornelia Huck7674da72006-12-08 15:54:21 +0100798 }
799 return cdev;
800}
801
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100802static void io_subchannel_recog(struct ccw_device *, struct subchannel *);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100803
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100804static void sch_create_and_recog_new_device(struct subchannel *sch)
805{
806 struct ccw_device *cdev;
807
808 /* Need to allocate a new ccw device. */
809 cdev = io_subchannel_create_ccwdev(sch);
810 if (IS_ERR(cdev)) {
811 /* OK, we did everything we could... */
812 css_sch_device_unregister(sch);
813 return;
814 }
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100815 /* Start recognition for the new ccw device. */
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100816 io_subchannel_recog(cdev, sch);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100817}
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819/*
820 * Register recognized device.
821 */
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100822static void io_subchannel_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 struct subchannel *sch;
Sebastian Otta2901562010-03-08 12:25:17 +0100825 int ret, adjust_init_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 unsigned long flags;
827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100829 /*
830 * Check if subchannel is still registered. It may have become
831 * unregistered if a machine check hit us after finishing
832 * device recognition but before the register work could be
833 * queued.
834 */
835 if (!device_is_registered(&sch->dev))
836 goto out_err;
Cornelia Huck82b7ac02007-04-27 16:01:36 +0200837 css_update_ssd_info(sch);
Cornelia Huck47af5512006-12-04 15:41:07 +0100838 /*
839 * io_subchannel_register() will also be called after device
840 * recognition has been done for a boxed device (which will already
841 * be registered). We need to reprobe since we may now have sense id
842 * information.
843 */
Cornelia Huckd6a30762008-12-25 13:39:11 +0100844 if (device_is_registered(&cdev->dev)) {
Cornelia Huck47af5512006-12-04 15:41:07 +0100845 if (!cdev->drv) {
846 ret = device_reprobe(&cdev->dev);
847 if (ret)
848 /* We can't do much here. */
Michael Ernst139b83d2008-05-07 09:22:54 +0200849 CIO_MSG_EVENT(0, "device_reprobe() returned"
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200850 " %d for 0.%x.%04x\n", ret,
851 cdev->private->dev_id.ssid,
852 cdev->private->dev_id.devno);
Cornelia Huck47af5512006-12-04 15:41:07 +0100853 }
Sebastian Otta2901562010-03-08 12:25:17 +0100854 adjust_init_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 goto out;
856 }
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700857 /*
858 * Now we know this subchannel will stay, we can throw
859 * our delayed uevent.
860 */
Ming Leif67f1292009-03-01 21:10:49 +0800861 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700862 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 /* make it known to the system */
864 ret = ccw_device_register(cdev);
865 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200866 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
867 cdev->private->dev_id.ssid,
868 cdev->private->dev_id.devno, ret);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100869 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100870 sch_set_cdev(sch, NULL);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100871 spin_unlock_irqrestore(sch->lock, flags);
Cornelia Huck6eff2082008-12-25 13:39:07 +0100872 /* Release initial device reference. */
873 put_device(&cdev->dev);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100874 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876out:
877 cdev->private->flags.recog_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 wake_up(&cdev->private->wait_q);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100879out_err:
Sebastian Otta2901562010-03-08 12:25:17 +0100880 if (adjust_init_count && atomic_dec_and_test(&ccw_device_init_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 wake_up(&ccw_device_init_wq);
882}
883
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100884static void ccw_device_call_sch_unregister(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 struct subchannel *sch;
887
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200888 /* Get subchannel reference for local processing. */
889 if (!get_device(cdev->dev.parent))
890 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200892 css_sch_device_unregister(sch);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200893 /* Release subchannel reference for local processing. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 put_device(&sch->dev);
895}
896
897/*
898 * subchannel recognition done. Called from the state machine.
899 */
900void
901io_subchannel_recog_done(struct ccw_device *cdev)
902{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 if (css_init_done == 0) {
904 cdev->private->flags.recog_done = 1;
905 return;
906 }
907 switch (cdev->private->state) {
Sebastian Ott47593bf2009-03-31 19:16:05 +0200908 case DEV_STATE_BOXED:
909 /* Device did not respond in time. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 case DEV_STATE_NOT_OPER:
911 cdev->private->flags.recog_done = 1;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100912 /* Remove device found not operational. */
913 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 if (atomic_dec_and_test(&ccw_device_init_count))
915 wake_up(&ccw_device_init_wq);
916 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 case DEV_STATE_OFFLINE:
918 /*
919 * We can't register the device in interrupt context so
920 * we schedule a work item.
921 */
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100922 ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 break;
924 }
925}
926
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100927static void io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 struct ccw_device_private *priv;
930
Cornelia Huck2ec22982006-12-08 15:54:26 +0100931 cdev->ccwlock = sch->lock;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 /* Init private data. */
934 priv = cdev->private;
Cornelia Huck78964262006-10-11 15:31:38 +0200935 priv->dev_id.devno = sch->schib.pmcw.dev;
936 priv->dev_id.ssid = sch->schid.ssid;
937 priv->schid = sch->schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 priv->state = DEV_STATE_NOT_OPER;
939 INIT_LIST_HEAD(&priv->cmb_list);
940 init_waitqueue_head(&priv->wait_q);
941 init_timer(&priv->timer);
942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 /* Increase counter of devices currently in recognition. */
944 atomic_inc(&ccw_device_init_count);
945
946 /* Start async. device sensing. */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100947 spin_lock_irq(sch->lock);
Peter Oberparleiter60e4dac2009-12-07 12:51:16 +0100948 sch_set_cdev(sch, cdev);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100949 ccw_device_recognition(cdev);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100950 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100953static int ccw_device_move_to_sch(struct ccw_device *cdev,
954 struct subchannel *sch)
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100955{
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100956 struct subchannel *old_sch;
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100957 int rc, old_enabled = 0;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100958
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100959 old_sch = to_subchannel(cdev->dev.parent);
960 /* Obtain child reference for new parent. */
Cornelia Huck6eff2082008-12-25 13:39:07 +0100961 if (!get_device(&sch->dev))
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100962 return -ENODEV;
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100963
964 if (!sch_is_pseudo_sch(old_sch)) {
965 spin_lock_irq(old_sch->lock);
966 old_enabled = old_sch->schib.pmcw.ena;
967 rc = 0;
968 if (old_enabled)
969 rc = cio_disable_subchannel(old_sch);
970 spin_unlock_irq(old_sch->lock);
971 if (rc == -EBUSY) {
972 /* Release child reference for new parent. */
973 put_device(&sch->dev);
974 return rc;
975 }
976 }
977
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100978 mutex_lock(&sch->reg_mutex);
Cornelia Huckffa6a702009-03-04 12:44:00 +0100979 rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100980 mutex_unlock(&sch->reg_mutex);
981 if (rc) {
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100982 CIO_MSG_EVENT(0, "device_move(0.%x.%04x,0.%x.%04x)=%d\n",
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100983 cdev->private->dev_id.ssid,
984 cdev->private->dev_id.devno, sch->schid.ssid,
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100985 sch->schib.pmcw.dev, rc);
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100986 if (old_enabled) {
987 /* Try to reenable the old subchannel. */
988 spin_lock_irq(old_sch->lock);
989 cio_enable_subchannel(old_sch, (u32)(addr_t)old_sch);
990 spin_unlock_irq(old_sch->lock);
991 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100992 /* Release child reference for new parent. */
Cornelia Huck6eff2082008-12-25 13:39:07 +0100993 put_device(&sch->dev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100994 return rc;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100995 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100996 /* Clean up old subchannel. */
997 if (!sch_is_pseudo_sch(old_sch)) {
998 spin_lock_irq(old_sch->lock);
999 sch_set_cdev(old_sch, NULL);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001000 spin_unlock_irq(old_sch->lock);
1001 css_schedule_eval(old_sch->schid);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +01001002 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001003 /* Release child reference for old parent. */
1004 put_device(&old_sch->dev);
1005 /* Initialize new subchannel. */
1006 spin_lock_irq(sch->lock);
1007 cdev->private->schid = sch->schid;
1008 cdev->ccwlock = sch->lock;
1009 if (!sch_is_pseudo_sch(sch))
1010 sch_set_cdev(sch, cdev);
1011 spin_unlock_irq(sch->lock);
1012 if (!sch_is_pseudo_sch(sch))
1013 css_update_ssd_info(sch);
1014 return 0;
1015}
1016
1017static int ccw_device_move_to_orph(struct ccw_device *cdev)
1018{
1019 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1020 struct channel_subsystem *css = to_css(sch->dev.parent);
1021
1022 return ccw_device_move_to_sch(cdev, css->pseudo_subchannel);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +01001023}
1024
Cornelia Huck602b20f2008-01-26 14:10:39 +01001025static void io_subchannel_irq(struct subchannel *sch)
1026{
1027 struct ccw_device *cdev;
1028
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001029 cdev = sch_get_cdev(sch);
Cornelia Huck602b20f2008-01-26 14:10:39 +01001030
Sebastian Ottefd986d2009-09-11 10:28:18 +02001031 CIO_TRACE_EVENT(6, "IRQ");
1032 CIO_TRACE_EVENT(6, dev_name(&sch->dev));
Cornelia Huck602b20f2008-01-26 14:10:39 +01001033 if (cdev)
1034 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001035 else
Heiko Carstens420f42e2013-01-02 15:18:18 +01001036 inc_irq_stat(IRQIO_CIO);
Cornelia Huck602b20f2008-01-26 14:10:39 +01001037}
1038
Sebastian Ott13952ec2008-12-25 13:39:13 +01001039void io_subchannel_init_config(struct subchannel *sch)
1040{
1041 memset(&sch->config, 0, sizeof(sch->config));
1042 sch->config.csense = 1;
Sebastian Ott13952ec2008-12-25 13:39:13 +01001043}
1044
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001045static void io_subchannel_init_fields(struct subchannel *sch)
1046{
1047 if (cio_is_console(sch->schid))
1048 sch->opm = 0xff;
1049 else
1050 sch->opm = chp_get_sch_opm(sch);
1051 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Cornelia Huck3a3fc292008-07-14 09:58:58 +02001052 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001053
1054 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1055 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1056 sch->schib.pmcw.dev, sch->schid.ssid,
1057 sch->schid.sch_no, sch->schib.pmcw.pim,
1058 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
Sebastian Ott13952ec2008-12-25 13:39:13 +01001059
1060 io_subchannel_init_config(sch);
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001061}
1062
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001063/*
1064 * Note: We always return 0 so that we bind to the device even on error.
1065 * This is needed so that our remove function is called on unregister.
1066 */
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001067static int io_subchannel_probe(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001069 struct io_subchannel_private *io_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 struct ccw_device *cdev;
1071 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001073 if (cio_is_console(sch->schid)) {
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001074 rc = sysfs_create_group(&sch->dev.kobj,
1075 &io_subchannel_attr_group);
1076 if (rc)
1077 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1078 "attributes for subchannel "
1079 "0.%x.%04x (rc=%d)\n",
1080 sch->schid.ssid, sch->schid.sch_no, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 /*
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001082 * The console subchannel already has an associated ccw_device.
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001083 * Throw the delayed uevent for the subchannel, register
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001084 * the ccw_device and exit.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 */
Ming Leif67f1292009-03-01 21:10:49 +08001086 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001087 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001088 cdev = sch_get_cdev(sch);
Cornelia Hucke1031782007-10-12 16:11:23 +02001089 cdev->dev.groups = ccwdev_attr_groups;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 device_initialize(&cdev->dev);
Sebastian Ott24a18722009-12-07 12:51:34 +01001091 cdev->private->flags.initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 ccw_device_register(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 /*
1094 * Check if the device is already online. If it is
Cornelia Huck9cd67422008-12-25 13:39:06 +01001095 * the reference count needs to be corrected since we
1096 * didn't obtain a reference in ccw_device_set_online.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 */
1098 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1099 cdev->private->state != DEV_STATE_OFFLINE &&
1100 cdev->private->state != DEV_STATE_BOXED)
1101 get_device(&cdev->dev);
1102 return 0;
1103 }
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001104 io_subchannel_init_fields(sch);
Sebastian Ottf444cc02008-12-25 13:39:14 +01001105 rc = cio_commit_config(sch);
1106 if (rc)
1107 goto out_schedule;
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001108 rc = sysfs_create_group(&sch->dev.kobj,
1109 &io_subchannel_attr_group);
1110 if (rc)
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001111 goto out_schedule;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001112 /* Allocate I/O subchannel private data. */
Sebastian Ottf92519e2011-03-15 17:08:27 +01001113 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA);
1114 if (!io_priv)
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001115 goto out_schedule;
Sebastian Ottf92519e2011-03-15 17:08:27 +01001116
1117 set_io_private(sch, io_priv);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001118 css_schedule_eval(sch->schid);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001119 return 0;
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001120
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001121out_schedule:
Peter Oberparleiter390935a2009-12-07 12:51:18 +01001122 spin_lock_irq(sch->lock);
1123 css_sched_sch_todo(sch, SCH_TODO_UNREG);
1124 spin_unlock_irq(sch->lock);
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128static int
Cornelia Huck8bbace72006-01-11 10:56:22 +01001129io_subchannel_remove (struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001131 struct io_subchannel_private *io_priv = to_io_private(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 struct ccw_device *cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001134 cdev = sch_get_cdev(sch);
1135 if (!cdev)
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001136 goto out_free;
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001137 io_subchannel_quiesce(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 /* Set ccw device to not operational and drop reference. */
Sebastian Ott7a8ad102009-12-07 12:51:39 +01001139 spin_lock_irq(cdev->ccwlock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001140 sch_set_cdev(sch, NULL);
Sebastian Ottf92519e2011-03-15 17:08:27 +01001141 set_io_private(sch, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 cdev->private->state = DEV_STATE_NOT_OPER;
Sebastian Ott7a8ad102009-12-07 12:51:39 +01001143 spin_unlock_irq(cdev->ccwlock);
Cornelia Huckef995162007-04-27 16:01:39 +02001144 ccw_device_unregister(cdev);
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001145out_free:
Sebastian Ottf92519e2011-03-15 17:08:27 +01001146 kfree(io_priv);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001147 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 return 0;
1149}
1150
Cornelia Huck602b20f2008-01-26 14:10:39 +01001151static void io_subchannel_verify(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
1153 struct ccw_device *cdev;
1154
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001155 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 if (cdev)
1157 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1158}
1159
Cornelia Huckc820de32008-07-14 09:58:45 +02001160static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{
1162 struct ccw_device *cdev;
1163
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001164 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if (!cdev)
1166 return;
Peter Oberparleiter4257aae2009-12-07 12:51:29 +01001167 if (cio_update_schib(sch))
1168 goto err;
1169 /* Check for I/O on path. */
1170 if (scsw_actl(&sch->schib.scsw) == 0 || sch->schib.pmcw.lpum != mask)
1171 goto out;
1172 if (cdev->private->state == DEV_STATE_ONLINE) {
1173 ccw_device_kill_io(cdev);
1174 goto out;
1175 }
1176 if (cio_clear(sch))
1177 goto err;
1178out:
1179 /* Trigger path verification. */
1180 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1181 return;
Cornelia Huckc820de32008-07-14 09:58:45 +02001182
Peter Oberparleiter4257aae2009-12-07 12:51:29 +01001183err:
1184 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
Cornelia Huckc820de32008-07-14 09:58:45 +02001185}
1186
Cornelia Huck99611f82008-07-14 09:59:02 +02001187static int io_subchannel_chp_event(struct subchannel *sch,
1188 struct chp_link *link, int event)
Cornelia Huckc820de32008-07-14 09:58:45 +02001189{
Sebastian Ott585b9542010-10-25 16:10:34 +02001190 struct ccw_device *cdev = sch_get_cdev(sch);
Cornelia Huckc820de32008-07-14 09:58:45 +02001191 int mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001192
Cornelia Huck99611f82008-07-14 09:59:02 +02001193 mask = chp_ssd_get_mask(&sch->ssd_info, link);
Cornelia Huckc820de32008-07-14 09:58:45 +02001194 if (!mask)
1195 return 0;
1196 switch (event) {
1197 case CHP_VARY_OFF:
1198 sch->opm &= ~mask;
1199 sch->lpm &= ~mask;
Sebastian Ott585b9542010-10-25 16:10:34 +02001200 if (cdev)
1201 cdev->private->path_gone_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001202 io_subchannel_terminate_path(sch, mask);
1203 break;
1204 case CHP_VARY_ON:
1205 sch->opm |= mask;
1206 sch->lpm |= mask;
Sebastian Ott585b9542010-10-25 16:10:34 +02001207 if (cdev)
1208 cdev->private->path_new_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001209 io_subchannel_verify(sch);
1210 break;
1211 case CHP_OFFLINE:
Sebastian Ottcdb912a2008-12-25 13:39:12 +01001212 if (cio_update_schib(sch))
Cornelia Huckc820de32008-07-14 09:58:45 +02001213 return -ENODEV;
Sebastian Ott585b9542010-10-25 16:10:34 +02001214 if (cdev)
1215 cdev->private->path_gone_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001216 io_subchannel_terminate_path(sch, mask);
1217 break;
1218 case CHP_ONLINE:
Sebastian Ottcdb912a2008-12-25 13:39:12 +01001219 if (cio_update_schib(sch))
1220 return -ENODEV;
Cornelia Huckc820de32008-07-14 09:58:45 +02001221 sch->lpm |= mask & sch->opm;
Sebastian Ott585b9542010-10-25 16:10:34 +02001222 if (cdev)
1223 cdev->private->path_new_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001224 io_subchannel_verify(sch);
1225 break;
1226 }
1227 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001230static void io_subchannel_quiesce(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 struct ccw_device *cdev;
1233 int ret;
1234
Sebastian Ott56e6b792009-12-07 12:51:35 +01001235 spin_lock_irq(sch->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001236 cdev = sch_get_cdev(sch);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001237 if (cio_is_console(sch->schid))
Sebastian Ott56e6b792009-12-07 12:51:35 +01001238 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 if (!sch->schib.pmcw.ena)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001240 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 ret = cio_disable_subchannel(sch);
1242 if (ret != -EBUSY)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001243 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 if (cdev->handler)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001245 cdev->handler(cdev, cdev->private->intparm, ERR_PTR(-EIO));
1246 while (ret == -EBUSY) {
1247 cdev->private->state = DEV_STATE_QUIESCE;
Peter Oberparleiter376ae472010-10-25 16:10:44 +02001248 cdev->private->iretry = 255;
Sebastian Ott56e6b792009-12-07 12:51:35 +01001249 ret = ccw_device_cancel_halt_clear(cdev);
1250 if (ret == -EBUSY) {
1251 ccw_device_set_timeout(cdev, HZ/10);
1252 spin_unlock_irq(sch->lock);
1253 wait_event(cdev->private->wait_q,
1254 cdev->private->state != DEV_STATE_QUIESCE);
1255 spin_lock_irq(sch->lock);
1256 }
1257 ret = cio_disable_subchannel(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
Sebastian Ott56e6b792009-12-07 12:51:35 +01001259out_unlock:
1260 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001263static void io_subchannel_shutdown(struct subchannel *sch)
1264{
1265 io_subchannel_quiesce(sch);
1266}
1267
Cornelia Huckc820de32008-07-14 09:58:45 +02001268static int device_is_disconnected(struct ccw_device *cdev)
1269{
1270 if (!cdev)
1271 return 0;
1272 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1273 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1274}
1275
1276static int recovery_check(struct device *dev, void *data)
1277{
1278 struct ccw_device *cdev = to_ccwdev(dev);
1279 int *redo = data;
1280
1281 spin_lock_irq(cdev->ccwlock);
1282 switch (cdev->private->state) {
1283 case DEV_STATE_DISCONNECTED:
1284 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1285 cdev->private->dev_id.ssid,
1286 cdev->private->dev_id.devno);
1287 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1288 *redo = 1;
1289 break;
1290 case DEV_STATE_DISCONNECTED_SENSE_ID:
1291 *redo = 1;
1292 break;
1293 }
1294 spin_unlock_irq(cdev->ccwlock);
1295
1296 return 0;
1297}
1298
1299static void recovery_work_func(struct work_struct *unused)
1300{
1301 int redo = 0;
1302
1303 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1304 if (redo) {
1305 spin_lock_irq(&recovery_lock);
1306 if (!timer_pending(&recovery_timer)) {
1307 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1308 recovery_phase++;
1309 mod_timer(&recovery_timer, jiffies +
1310 recovery_delay[recovery_phase] * HZ);
1311 }
1312 spin_unlock_irq(&recovery_lock);
1313 } else
1314 CIO_MSG_EVENT(4, "recovery: end\n");
1315}
1316
1317static DECLARE_WORK(recovery_work, recovery_work_func);
1318
1319static void recovery_func(unsigned long data)
1320{
1321 /*
1322 * We can't do our recovery in softirq context and it's not
1323 * performance critical, so we schedule it.
1324 */
1325 schedule_work(&recovery_work);
1326}
1327
1328static void ccw_device_schedule_recovery(void)
1329{
1330 unsigned long flags;
1331
1332 CIO_MSG_EVENT(4, "recovery: schedule\n");
1333 spin_lock_irqsave(&recovery_lock, flags);
1334 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1335 recovery_phase = 0;
1336 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1337 }
1338 spin_unlock_irqrestore(&recovery_lock, flags);
1339}
1340
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001341static int purge_fn(struct device *dev, void *data)
1342{
1343 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001344 struct ccw_dev_id *id = &cdev->private->dev_id;
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001345
1346 spin_lock_irq(cdev->ccwlock);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001347 if (is_blacklisted(id->ssid, id->devno) &&
Peter Oberparleitera2fc8482011-04-04 09:43:32 +02001348 (cdev->private->state == DEV_STATE_OFFLINE) &&
1349 (atomic_cmpxchg(&cdev->private->onoff, 0, 1) == 0)) {
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001350 CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", id->ssid,
1351 id->devno);
1352 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Peter Oberparleitera2fc8482011-04-04 09:43:32 +02001353 atomic_set(&cdev->private->onoff, 0);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001354 }
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001355 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001356 /* Abort loop in case of pending signal. */
1357 if (signal_pending(current))
1358 return -EINTR;
1359
1360 return 0;
1361}
1362
1363/**
1364 * ccw_purge_blacklisted - purge unused, blacklisted devices
1365 *
1366 * Unregister all ccw devices that are offline and on the blacklist.
1367 */
1368int ccw_purge_blacklisted(void)
1369{
1370 CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n");
1371 bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn);
1372 return 0;
1373}
1374
Peter Oberparleiter6afcc772009-10-06 10:34:02 +02001375void ccw_device_set_disconnected(struct ccw_device *cdev)
Cornelia Huckc820de32008-07-14 09:58:45 +02001376{
1377 if (!cdev)
1378 return;
1379 ccw_device_set_timeout(cdev, 0);
1380 cdev->private->flags.fake_irb = 0;
1381 cdev->private->state = DEV_STATE_DISCONNECTED;
1382 if (cdev->online)
1383 ccw_device_schedule_recovery();
1384}
1385
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001386void ccw_device_set_notoper(struct ccw_device *cdev)
1387{
1388 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1389
1390 CIO_TRACE_EVENT(2, "notoper");
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001391 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001392 ccw_device_set_timeout(cdev, 0);
1393 cio_disable_subchannel(sch);
1394 cdev->private->state = DEV_STATE_NOT_OPER;
1395}
1396
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001397enum io_sch_action {
1398 IO_SCH_UNREG,
1399 IO_SCH_ORPH_UNREG,
1400 IO_SCH_ATTACH,
1401 IO_SCH_UNREG_ATTACH,
1402 IO_SCH_ORPH_ATTACH,
1403 IO_SCH_REPROBE,
1404 IO_SCH_VERIFY,
1405 IO_SCH_DISC,
1406 IO_SCH_NOP,
1407};
1408
1409static enum io_sch_action sch_get_action(struct subchannel *sch)
Cornelia Huckc820de32008-07-14 09:58:45 +02001410{
Cornelia Huckc820de32008-07-14 09:58:45 +02001411 struct ccw_device *cdev;
1412
Cornelia Huckc820de32008-07-14 09:58:45 +02001413 cdev = sch_get_cdev(sch);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001414 if (cio_update_schib(sch)) {
1415 /* Not operational. */
1416 if (!cdev)
1417 return IO_SCH_UNREG;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001418 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001419 return IO_SCH_UNREG;
1420 return IO_SCH_ORPH_UNREG;
Cornelia Huckc820de32008-07-14 09:58:45 +02001421 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001422 /* Operational. */
1423 if (!cdev)
1424 return IO_SCH_ATTACH;
1425 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001426 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001427 return IO_SCH_UNREG_ATTACH;
1428 return IO_SCH_ORPH_ATTACH;
Cornelia Huckc820de32008-07-14 09:58:45 +02001429 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001430 if ((sch->schib.pmcw.pam & sch->opm) == 0) {
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001431 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001432 return IO_SCH_UNREG;
1433 return IO_SCH_DISC;
Cornelia Huckc820de32008-07-14 09:58:45 +02001434 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001435 if (device_is_disconnected(cdev))
1436 return IO_SCH_REPROBE;
Sebastian Ott31370f752012-10-24 11:22:52 +02001437 if (cdev->online && !cdev->private->flags.resuming)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001438 return IO_SCH_VERIFY;
Sebastian Ott43d0be72012-09-05 14:19:42 +02001439 if (cdev->private->state == DEV_STATE_NOT_OPER)
1440 return IO_SCH_UNREG_ATTACH;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001441 return IO_SCH_NOP;
1442}
1443
1444/**
1445 * io_subchannel_sch_event - process subchannel event
1446 * @sch: subchannel
1447 * @process: non-zero if function is called in process context
1448 *
1449 * An unspecified event occurred for this subchannel. Adjust data according
1450 * to the current operational state of the subchannel and device. Return
1451 * zero when the event has been handled sufficiently or -EAGAIN when this
1452 * function should be called again in process context.
1453 */
1454static int io_subchannel_sch_event(struct subchannel *sch, int process)
1455{
1456 unsigned long flags;
1457 struct ccw_device *cdev;
1458 struct ccw_dev_id dev_id;
1459 enum io_sch_action action;
1460 int rc = -EAGAIN;
1461
1462 spin_lock_irqsave(sch->lock, flags);
1463 if (!device_is_registered(&sch->dev))
1464 goto out_unlock;
Peter Oberparleiter390935a2009-12-07 12:51:18 +01001465 if (work_pending(&sch->todo_work))
1466 goto out_unlock;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001467 cdev = sch_get_cdev(sch);
1468 if (cdev && work_pending(&cdev->private->todo_work))
1469 goto out_unlock;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001470 action = sch_get_action(sch);
1471 CIO_MSG_EVENT(2, "event: sch 0.%x.%04x, process=%d, action=%d\n",
1472 sch->schid.ssid, sch->schid.sch_no, process,
1473 action);
1474 /* Perform immediate actions while holding the lock. */
Cornelia Huckc820de32008-07-14 09:58:45 +02001475 switch (action) {
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001476 case IO_SCH_REPROBE:
1477 /* Trigger device recognition. */
Cornelia Huckc820de32008-07-14 09:58:45 +02001478 ccw_device_trigger_reprobe(cdev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001479 rc = 0;
1480 goto out_unlock;
1481 case IO_SCH_VERIFY:
1482 /* Trigger path verification. */
1483 io_subchannel_verify(sch);
1484 rc = 0;
1485 goto out_unlock;
1486 case IO_SCH_DISC:
1487 ccw_device_set_disconnected(cdev);
1488 rc = 0;
1489 goto out_unlock;
1490 case IO_SCH_ORPH_UNREG:
1491 case IO_SCH_ORPH_ATTACH:
Peter Oberparleiter6afcc772009-10-06 10:34:02 +02001492 ccw_device_set_disconnected(cdev);
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001493 break;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001494 case IO_SCH_UNREG_ATTACH:
1495 case IO_SCH_UNREG:
Sebastian Ott16d2ce22010-11-10 10:05:53 +01001496 if (!cdev)
1497 break;
1498 if (cdev->private->state == DEV_STATE_SENSE_ID) {
1499 /*
1500 * Note: delayed work triggered by this event
1501 * and repeated calls to sch_event are synchronized
1502 * by the above check for work_pending(cdev).
1503 */
1504 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1505 } else
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001506 ccw_device_set_notoper(cdev);
1507 break;
1508 case IO_SCH_NOP:
1509 rc = 0;
1510 goto out_unlock;
Cornelia Huckc820de32008-07-14 09:58:45 +02001511 default:
1512 break;
1513 }
1514 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001515 /* All other actions require process context. */
1516 if (!process)
1517 goto out;
1518 /* Handle attached ccw device. */
1519 switch (action) {
1520 case IO_SCH_ORPH_UNREG:
1521 case IO_SCH_ORPH_ATTACH:
1522 /* Move ccw device to orphanage. */
1523 rc = ccw_device_move_to_orph(cdev);
1524 if (rc)
1525 goto out;
1526 break;
1527 case IO_SCH_UNREG_ATTACH:
Sebastian Ott3368ba22012-09-05 14:20:41 +02001528 spin_lock_irqsave(sch->lock, flags);
Sebastian Ott74b61272010-10-25 16:10:26 +02001529 if (cdev->private->flags.resuming) {
1530 /* Device will be handled later. */
1531 rc = 0;
Sebastian Ott3368ba22012-09-05 14:20:41 +02001532 goto out_unlock;
Sebastian Ott74b61272010-10-25 16:10:26 +02001533 }
Sebastian Ott3368ba22012-09-05 14:20:41 +02001534 sch_set_cdev(sch, NULL);
1535 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001536 /* Unregister ccw device. */
Sebastian Ott74b61272010-10-25 16:10:26 +02001537 ccw_device_unregister(cdev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001538 break;
1539 default:
1540 break;
1541 }
1542 /* Handle subchannel. */
1543 switch (action) {
1544 case IO_SCH_ORPH_UNREG:
1545 case IO_SCH_UNREG:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001546 if (!cdev || !cdev->private->flags.resuming)
1547 css_sch_device_unregister(sch);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001548 break;
1549 case IO_SCH_ORPH_ATTACH:
1550 case IO_SCH_UNREG_ATTACH:
1551 case IO_SCH_ATTACH:
1552 dev_id.ssid = sch->schid.ssid;
1553 dev_id.devno = sch->schib.pmcw.dev;
1554 cdev = get_ccwdev_by_dev_id(&dev_id);
1555 if (!cdev) {
1556 sch_create_and_recog_new_device(sch);
1557 break;
1558 }
1559 rc = ccw_device_move_to_sch(cdev, sch);
1560 if (rc) {
1561 /* Release reference from get_ccwdev_by_dev_id() */
1562 put_device(&cdev->dev);
1563 goto out;
1564 }
1565 spin_lock_irqsave(sch->lock, flags);
1566 ccw_device_trigger_reprobe(cdev);
1567 spin_unlock_irqrestore(sch->lock, flags);
1568 /* Release reference from get_ccwdev_by_dev_id() */
1569 put_device(&cdev->dev);
1570 break;
1571 default:
1572 break;
1573 }
1574 return 0;
Cornelia Huckc820de32008-07-14 09:58:45 +02001575
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001576out_unlock:
1577 spin_unlock_irqrestore(sch->lock, flags);
1578out:
1579 return rc;
Cornelia Huckc820de32008-07-14 09:58:45 +02001580}
1581
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582#ifdef CONFIG_CCW_CONSOLE
1583static struct ccw_device console_cdev;
1584static struct ccw_device_private console_private;
1585static int console_cdev_in_use;
1586
Cornelia Huck2ec22982006-12-08 15:54:26 +01001587static DEFINE_SPINLOCK(ccw_console_lock);
1588
1589spinlock_t * cio_get_console_lock(void)
1590{
1591 return &ccw_console_lock;
1592}
1593
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001594static int ccw_device_console_enable(struct ccw_device *cdev,
1595 struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001597 struct io_subchannel_private *io_priv = cio_get_console_priv();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 int rc;
1599
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001600 /* Attach subchannel private data. */
Sebastian Ottf92519e2011-03-15 17:08:27 +01001601 memset(io_priv, 0, sizeof(*io_priv));
1602 set_io_private(sch, io_priv);
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001603 io_subchannel_init_fields(sch);
Sebastian Ottf444cc02008-12-25 13:39:14 +01001604 rc = cio_commit_config(sch);
1605 if (rc)
1606 return rc;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001607 sch->driver = &io_subchannel_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 /* Initialize the ccw_device structure. */
Heiko Carstens292888c2006-08-30 14:33:35 +02001609 cdev->dev.parent= &sch->dev;
Sebastian Ottffa8d2a2009-12-18 17:43:15 +01001610 sch_set_cdev(sch, cdev);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001611 io_subchannel_recog(cdev, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 /* Now wait for the async. recognition to come to an end. */
1613 spin_lock_irq(cdev->ccwlock);
1614 while (!dev_fsm_final_state(cdev))
1615 wait_cons_dev();
1616 rc = -EIO;
1617 if (cdev->private->state != DEV_STATE_OFFLINE)
1618 goto out_unlock;
1619 ccw_device_online(cdev);
1620 while (!dev_fsm_final_state(cdev))
1621 wait_cons_dev();
1622 if (cdev->private->state != DEV_STATE_ONLINE)
1623 goto out_unlock;
1624 rc = 0;
1625out_unlock:
1626 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001627 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
1630struct ccw_device *
1631ccw_device_probe_console(void)
1632{
1633 struct subchannel *sch;
1634 int ret;
1635
1636 if (xchg(&console_cdev_in_use, 1) != 0)
Peter Oberparleiter600b5d12006-02-01 03:06:35 -08001637 return ERR_PTR(-EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 sch = cio_probe_console();
1639 if (IS_ERR(sch)) {
1640 console_cdev_in_use = 0;
1641 return (void *) sch;
1642 }
1643 memset(&console_cdev, 0, sizeof(struct ccw_device));
1644 memset(&console_private, 0, sizeof(struct ccw_device_private));
1645 console_cdev.private = &console_private;
Martin Schwidefskyc1637532006-12-08 15:53:57 +01001646 console_private.cdev = &console_cdev;
Heiko Carstens420f42e2013-01-02 15:18:18 +01001647 console_private.int_class = IRQIO_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 ret = ccw_device_console_enable(&console_cdev, sch);
1649 if (ret) {
1650 cio_release_console();
1651 console_cdev_in_use = 0;
1652 return ERR_PTR(ret);
1653 }
1654 console_cdev.online = 1;
1655 return &console_cdev;
1656}
Cornelia Huck1f4e7ed2008-10-10 21:33:14 +02001657
Martin Schwidefsky66648452009-06-16 10:30:28 +02001658static int ccw_device_pm_restore(struct device *dev);
1659
1660int ccw_device_force_console(void)
1661{
1662 if (!console_cdev_in_use)
1663 return -ENODEV;
1664 return ccw_device_pm_restore(&console_cdev.dev);
1665}
1666EXPORT_SYMBOL_GPL(ccw_device_force_console);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667#endif
1668
1669/*
1670 * get ccw_device matching the busid, but only if owned by cdrv
1671 */
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001672static int
1673__ccwdev_check_busid(struct device *dev, void *id)
1674{
1675 char *bus_id;
1676
Cornelia Huck12975ae2006-10-11 15:31:47 +02001677 bus_id = id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001678
Kay Sievers98df67b2008-12-25 13:38:55 +01001679 return (strcmp(bus_id, dev_name(dev)) == 0);
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001680}
1681
1682
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02001683/**
1684 * get_ccwdev_by_busid() - obtain device from a bus id
1685 * @cdrv: driver the device is owned by
1686 * @bus_id: bus id of the device to be searched
1687 *
1688 * This function searches all devices owned by @cdrv for a device with a bus
1689 * id matching @bus_id.
1690 * Returns:
1691 * If a match is found, its reference count of the found device is increased
1692 * and it is returned; else %NULL is returned.
1693 */
1694struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1695 const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001697 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Sebastian Ott9f30ea92012-01-24 13:35:02 -05001699 dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001700 __ccwdev_check_busid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001702 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
1705/************************** device driver handling ************************/
1706
1707/* This is the implementation of the ccw_driver class. The probe, remove
1708 * and release methods are initially very similar to the device_driver
1709 * implementations, with the difference that they have ccw_device
1710 * arguments.
1711 *
1712 * A ccw driver also contains the information that is needed for
1713 * device matching.
1714 */
1715static int
1716ccw_device_probe (struct device *dev)
1717{
1718 struct ccw_device *cdev = to_ccwdev(dev);
1719 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1720 int ret;
1721
1722 cdev->drv = cdrv; /* to let the driver call _set_online */
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001723 /* Note: we interpret class 0 in this context as an uninitialized
1724 * field since it translates to a non-I/O interrupt class. */
1725 if (cdrv->int_class != 0)
1726 cdev->private->int_class = cdrv->int_class;
1727 else
Heiko Carstens420f42e2013-01-02 15:18:18 +01001728 cdev->private->int_class = IRQIO_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1731
1732 if (ret) {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001733 cdev->drv = NULL;
Heiko Carstens420f42e2013-01-02 15:18:18 +01001734 cdev->private->int_class = IRQIO_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 return ret;
1736 }
1737
1738 return 0;
1739}
1740
1741static int
1742ccw_device_remove (struct device *dev)
1743{
1744 struct ccw_device *cdev = to_ccwdev(dev);
1745 struct ccw_driver *cdrv = cdev->drv;
1746 int ret;
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 if (cdrv->remove)
1749 cdrv->remove(cdev);
1750 if (cdev->online) {
1751 cdev->online = 0;
1752 spin_lock_irq(cdev->ccwlock);
1753 ret = ccw_device_offline(cdev);
1754 spin_unlock_irq(cdev->ccwlock);
1755 if (ret == 0)
1756 wait_event(cdev->private->wait_q,
1757 dev_fsm_final_state(cdev));
1758 else
Michael Ernst139b83d2008-05-07 09:22:54 +02001759 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +02001760 "device 0.%x.%04x\n",
1761 ret, cdev->private->dev_id.ssid,
1762 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +01001763 /* Give up reference obtained in ccw_device_set_online(). */
1764 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 }
1766 ccw_device_set_timeout(cdev, 0);
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001767 cdev->drv = NULL;
Heiko Carstens420f42e2013-01-02 15:18:18 +01001768 cdev->private->int_class = IRQIO_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return 0;
1770}
1771
Cornelia Huck958974fb2007-10-12 16:11:21 +02001772static void ccw_device_shutdown(struct device *dev)
1773{
1774 struct ccw_device *cdev;
1775
1776 cdev = to_ccwdev(dev);
1777 if (cdev->drv && cdev->drv->shutdown)
1778 cdev->drv->shutdown(cdev);
Cornelia Huck1842f2b2007-10-12 16:11:22 +02001779 disable_cmf(cdev);
Cornelia Huck958974fb2007-10-12 16:11:21 +02001780}
1781
Sebastian Ott823d4942009-06-16 10:30:20 +02001782static int ccw_device_pm_prepare(struct device *dev)
1783{
1784 struct ccw_device *cdev = to_ccwdev(dev);
1785
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001786 if (work_pending(&cdev->private->todo_work))
Sebastian Ott823d4942009-06-16 10:30:20 +02001787 return -EAGAIN;
1788 /* Fail while device is being set online/offline. */
1789 if (atomic_read(&cdev->private->onoff))
1790 return -EAGAIN;
1791
1792 if (cdev->online && cdev->drv && cdev->drv->prepare)
1793 return cdev->drv->prepare(cdev);
1794
1795 return 0;
1796}
1797
1798static void ccw_device_pm_complete(struct device *dev)
1799{
1800 struct ccw_device *cdev = to_ccwdev(dev);
1801
1802 if (cdev->online && cdev->drv && cdev->drv->complete)
1803 cdev->drv->complete(cdev);
1804}
1805
1806static int ccw_device_pm_freeze(struct device *dev)
1807{
1808 struct ccw_device *cdev = to_ccwdev(dev);
1809 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1810 int ret, cm_enabled;
1811
1812 /* Fail suspend while device is in transistional state. */
1813 if (!dev_fsm_final_state(cdev))
1814 return -EAGAIN;
1815 if (!cdev->online)
1816 return 0;
1817 if (cdev->drv && cdev->drv->freeze) {
1818 ret = cdev->drv->freeze(cdev);
1819 if (ret)
1820 return ret;
1821 }
1822
1823 spin_lock_irq(sch->lock);
1824 cm_enabled = cdev->private->cmb != NULL;
1825 spin_unlock_irq(sch->lock);
1826 if (cm_enabled) {
1827 /* Don't have the css write on memory. */
1828 ret = ccw_set_cmf(cdev, 0);
1829 if (ret)
1830 return ret;
1831 }
1832 /* From here on, disallow device driver I/O. */
1833 spin_lock_irq(sch->lock);
1834 ret = cio_disable_subchannel(sch);
1835 spin_unlock_irq(sch->lock);
1836
1837 return ret;
1838}
1839
1840static int ccw_device_pm_thaw(struct device *dev)
1841{
1842 struct ccw_device *cdev = to_ccwdev(dev);
1843 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1844 int ret, cm_enabled;
1845
1846 if (!cdev->online)
1847 return 0;
1848
1849 spin_lock_irq(sch->lock);
1850 /* Allow device driver I/O again. */
1851 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
1852 cm_enabled = cdev->private->cmb != NULL;
1853 spin_unlock_irq(sch->lock);
1854 if (ret)
1855 return ret;
1856
1857 if (cm_enabled) {
1858 ret = ccw_set_cmf(cdev, 1);
1859 if (ret)
1860 return ret;
1861 }
1862
1863 if (cdev->drv && cdev->drv->thaw)
1864 ret = cdev->drv->thaw(cdev);
1865
1866 return ret;
1867}
1868
1869static void __ccw_device_pm_restore(struct ccw_device *cdev)
1870{
1871 struct subchannel *sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +02001872
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001873 spin_lock_irq(sch->lock);
1874 if (cio_is_console(sch->schid)) {
1875 cio_enable_subchannel(sch, (u32)(addr_t)sch);
1876 goto out_unlock;
1877 }
Sebastian Ott823d4942009-06-16 10:30:20 +02001878 /*
1879 * While we were sleeping, devices may have gone or become
1880 * available again. Kick re-detection.
1881 */
Sebastian Ott823d4942009-06-16 10:30:20 +02001882 cdev->private->flags.resuming = 1;
Sebastian Ottb17295e2011-01-12 09:55:10 +01001883 cdev->private->path_new_mask = LPM_ANYPATH;
Sebastian Ott817e5002011-12-01 13:32:19 +01001884 css_sched_sch_todo(sch, SCH_TODO_EVAL);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001885 spin_unlock_irq(sch->lock);
Sebastian Ott817e5002011-12-01 13:32:19 +01001886 css_wait_for_slow_path();
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001887
1888 /* cdev may have been moved to a different subchannel. */
1889 sch = to_subchannel(cdev->dev.parent);
1890 spin_lock_irq(sch->lock);
1891 if (cdev->private->state != DEV_STATE_ONLINE &&
1892 cdev->private->state != DEV_STATE_OFFLINE)
1893 goto out_unlock;
1894
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001895 ccw_device_recognition(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001896 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001897 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) ||
1898 cdev->private->state == DEV_STATE_DISCONNECTED);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001899 spin_lock_irq(sch->lock);
1900
1901out_unlock:
Sebastian Ott823d4942009-06-16 10:30:20 +02001902 cdev->private->flags.resuming = 0;
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001903 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001904}
1905
1906static int resume_handle_boxed(struct ccw_device *cdev)
1907{
1908 cdev->private->state = DEV_STATE_BOXED;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001909 if (ccw_device_notify(cdev, CIO_BOXED) == NOTIFY_OK)
Sebastian Ott823d4942009-06-16 10:30:20 +02001910 return 0;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001911 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Sebastian Ott823d4942009-06-16 10:30:20 +02001912 return -ENODEV;
1913}
1914
1915static int resume_handle_disc(struct ccw_device *cdev)
1916{
1917 cdev->private->state = DEV_STATE_DISCONNECTED;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001918 if (ccw_device_notify(cdev, CIO_GONE) == NOTIFY_OK)
Sebastian Ott823d4942009-06-16 10:30:20 +02001919 return 0;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001920 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Sebastian Ott823d4942009-06-16 10:30:20 +02001921 return -ENODEV;
1922}
1923
1924static int ccw_device_pm_restore(struct device *dev)
1925{
1926 struct ccw_device *cdev = to_ccwdev(dev);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001927 struct subchannel *sch;
1928 int ret = 0;
Sebastian Ott823d4942009-06-16 10:30:20 +02001929
1930 __ccw_device_pm_restore(cdev);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001931 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +02001932 spin_lock_irq(sch->lock);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001933 if (cio_is_console(sch->schid))
Sebastian Ott823d4942009-06-16 10:30:20 +02001934 goto out_restore;
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001935
Sebastian Ott823d4942009-06-16 10:30:20 +02001936 /* check recognition results */
1937 switch (cdev->private->state) {
1938 case DEV_STATE_OFFLINE:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001939 case DEV_STATE_ONLINE:
1940 cdev->private->flags.donotify = 0;
Sebastian Ott823d4942009-06-16 10:30:20 +02001941 break;
1942 case DEV_STATE_BOXED:
1943 ret = resume_handle_boxed(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001944 if (ret)
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001945 goto out_unlock;
Sebastian Ott823d4942009-06-16 10:30:20 +02001946 goto out_restore;
Sebastian Ott823d4942009-06-16 10:30:20 +02001947 default:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001948 ret = resume_handle_disc(cdev);
1949 if (ret)
1950 goto out_unlock;
1951 goto out_restore;
Sebastian Ott823d4942009-06-16 10:30:20 +02001952 }
1953 /* check if the device type has changed */
1954 if (!ccw_device_test_sense_data(cdev)) {
1955 ccw_device_update_sense_data(cdev);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001956 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
Sebastian Ott823d4942009-06-16 10:30:20 +02001957 ret = -ENODEV;
1958 goto out_unlock;
1959 }
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001960 if (!cdev->online)
1961 goto out_unlock;
1962
1963 if (ccw_device_online(cdev)) {
1964 ret = resume_handle_disc(cdev);
1965 if (ret)
1966 goto out_unlock;
1967 goto out_restore;
1968 }
1969 spin_unlock_irq(sch->lock);
1970 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1971 spin_lock_irq(sch->lock);
1972
1973 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) {
1974 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
1975 ret = -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +02001976 goto out_unlock;
1977 }
Sebastian Ott823d4942009-06-16 10:30:20 +02001978
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001979 /* reenable cmf, if needed */
1980 if (cdev->private->cmb) {
1981 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001982 ret = ccw_set_cmf(cdev, 1);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001983 spin_lock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001984 if (ret) {
Sebastian Ottf0148242009-09-11 10:28:23 +02001985 CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed "
1986 "(rc=%d)\n", cdev->private->dev_id.ssid,
1987 cdev->private->dev_id.devno, ret);
Sebastian Ott823d4942009-06-16 10:30:20 +02001988 ret = 0;
1989 }
1990 }
1991
1992out_restore:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001993 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001994 if (cdev->online && cdev->drv && cdev->drv->restore)
1995 ret = cdev->drv->restore(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001996 return ret;
1997
Sebastian Ott823d4942009-06-16 10:30:20 +02001998out_unlock:
1999 spin_unlock_irq(sch->lock);
2000 return ret;
2001}
2002
Alexey Dobriyan47145212009-12-14 18:00:08 -08002003static const struct dev_pm_ops ccw_pm_ops = {
Sebastian Ott823d4942009-06-16 10:30:20 +02002004 .prepare = ccw_device_pm_prepare,
2005 .complete = ccw_device_pm_complete,
2006 .freeze = ccw_device_pm_freeze,
2007 .thaw = ccw_device_pm_thaw,
2008 .restore = ccw_device_pm_restore,
2009};
2010
Sebastian Ottd5ab5272011-03-23 10:16:03 +01002011static struct bus_type ccw_bus_type = {
Cornelia Huck8bbace72006-01-11 10:56:22 +01002012 .name = "ccw",
2013 .match = ccw_bus_match,
2014 .uevent = ccw_uevent,
2015 .probe = ccw_device_probe,
2016 .remove = ccw_device_remove,
Cornelia Huck958974fb2007-10-12 16:11:21 +02002017 .shutdown = ccw_device_shutdown,
Sebastian Ott823d4942009-06-16 10:30:20 +02002018 .pm = &ccw_pm_ops,
Cornelia Huck8bbace72006-01-11 10:56:22 +01002019};
2020
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02002021/**
2022 * ccw_driver_register() - register a ccw driver
2023 * @cdriver: driver to be registered
2024 *
2025 * This function is mainly a wrapper around driver_register().
2026 * Returns:
2027 * %0 on success and a negative error value on failure.
2028 */
2029int ccw_driver_register(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030{
2031 struct device_driver *drv = &cdriver->driver;
2032
2033 drv->bus = &ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 return driver_register(drv);
2036}
2037
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02002038/**
2039 * ccw_driver_unregister() - deregister a ccw driver
2040 * @cdriver: driver to be deregistered
2041 *
2042 * This function is mainly a wrapper around driver_unregister().
2043 */
2044void ccw_driver_unregister(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
2046 driver_unregister(&cdriver->driver);
2047}
2048
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01002049static void ccw_device_todo(struct work_struct *work)
2050{
2051 struct ccw_device_private *priv;
2052 struct ccw_device *cdev;
2053 struct subchannel *sch;
2054 enum cdev_todo todo;
2055
2056 priv = container_of(work, struct ccw_device_private, todo_work);
2057 cdev = priv->cdev;
2058 sch = to_subchannel(cdev->dev.parent);
2059 /* Find out todo. */
2060 spin_lock_irq(cdev->ccwlock);
2061 todo = priv->todo;
2062 priv->todo = CDEV_TODO_NOTHING;
2063 CIO_MSG_EVENT(4, "cdev_todo: cdev=0.%x.%04x todo=%d\n",
2064 priv->dev_id.ssid, priv->dev_id.devno, todo);
2065 spin_unlock_irq(cdev->ccwlock);
2066 /* Perform todo. */
2067 switch (todo) {
2068 case CDEV_TODO_ENABLE_CMF:
2069 cmf_reenable(cdev);
2070 break;
2071 case CDEV_TODO_REBIND:
2072 ccw_device_do_unbind_bind(cdev);
2073 break;
2074 case CDEV_TODO_REGISTER:
2075 io_subchannel_register(cdev);
2076 break;
2077 case CDEV_TODO_UNREG_EVAL:
2078 if (!sch_is_pseudo_sch(sch))
2079 css_schedule_eval(sch->schid);
2080 /* fall-through */
2081 case CDEV_TODO_UNREG:
2082 if (sch_is_pseudo_sch(sch))
2083 ccw_device_unregister(cdev);
2084 else
2085 ccw_device_call_sch_unregister(cdev);
2086 break;
2087 default:
2088 break;
2089 }
2090 /* Release workqueue ref. */
2091 put_device(&cdev->dev);
2092}
2093
2094/**
2095 * ccw_device_sched_todo - schedule ccw device operation
2096 * @cdev: ccw device
2097 * @todo: todo
2098 *
2099 * Schedule the operation identified by @todo to be performed on the slow path
2100 * workqueue. Do nothing if another operation with higher priority is already
2101 * scheduled. Needs to be called with ccwdev lock held.
2102 */
2103void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo)
2104{
2105 CIO_MSG_EVENT(4, "cdev_todo: sched cdev=0.%x.%04x todo=%d\n",
2106 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
2107 todo);
2108 if (cdev->private->todo >= todo)
2109 return;
2110 cdev->private->todo = todo;
2111 /* Get workqueue ref. */
2112 if (!get_device(&cdev->dev))
2113 return;
Sebastian Ottbe5d3822010-02-26 22:37:24 +01002114 if (!queue_work(cio_work_q, &cdev->private->todo_work)) {
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01002115 /* Already queued, release workqueue ref. */
2116 put_device(&cdev->dev);
2117 }
2118}
2119
Michael Ernstfd0457a2010-08-09 18:12:50 +02002120/**
2121 * ccw_device_siosl() - initiate logging
2122 * @cdev: ccw device
2123 *
2124 * This function is used to invoke model-dependent logging within the channel
2125 * subsystem.
2126 */
2127int ccw_device_siosl(struct ccw_device *cdev)
2128{
2129 struct subchannel *sch = to_subchannel(cdev->dev.parent);
2130
2131 return chsc_siosl(sch->schid);
2132}
2133EXPORT_SYMBOL_GPL(ccw_device_siosl);
2134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135MODULE_LICENSE("GPL");
2136EXPORT_SYMBOL(ccw_device_set_online);
2137EXPORT_SYMBOL(ccw_device_set_offline);
2138EXPORT_SYMBOL(ccw_driver_register);
2139EXPORT_SYMBOL(ccw_driver_unregister);
2140EXPORT_SYMBOL(get_ccwdev_by_busid);