blob: fc916f5d731412c7146465d3ff29277979b69189 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
636static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
637static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
638static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800639static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640static DEVICE_ATTR(online, 0644, online_show, online_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641static DEVICE_ATTR(availability, 0444, available_show, NULL);
Michael Ernstfd0457a2010-08-09 18:12:50 +0200642static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200644static struct attribute *io_subchannel_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 &dev_attr_chpids.attr,
646 &dev_attr_pimpampom.attr,
Michael Ernstfd0457a2010-08-09 18:12:50 +0200647 &dev_attr_logging.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 NULL,
649};
650
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200651static struct attribute_group io_subchannel_attr_group = {
652 .attrs = io_subchannel_attrs,
Cornelia Huck529192f2006-12-08 15:55:57 +0100653};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655static struct attribute * ccwdev_attrs[] = {
656 &dev_attr_devtype.attr,
657 &dev_attr_cutype.attr,
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800658 &dev_attr_modalias.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 &dev_attr_online.attr,
660 &dev_attr_cmb_enable.attr,
661 &dev_attr_availability.attr,
662 NULL,
663};
664
665static struct attribute_group ccwdev_attr_group = {
666 .attrs = ccwdev_attrs,
667};
668
David Brownella4dbd672009-06-24 10:06:31 -0700669static const struct attribute_group *ccwdev_attr_groups[] = {
Cornelia Huckef995162007-04-27 16:01:39 +0200670 &ccwdev_attr_group,
671 NULL,
672};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674/* this is a simple abstraction for device_register that sets the
675 * correct bus type and adds the bus specific files */
Cornelia Huck3c9da7b2006-10-27 12:39:33 +0200676static int ccw_device_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
678 struct device *dev = &cdev->dev;
679 int ret;
680
681 dev->bus = &ccw_bus_type;
Sebastian Ott3ac276f2009-09-11 10:28:27 +0200682 ret = dev_set_name(&cdev->dev, "0.%x.%04x", cdev->private->dev_id.ssid,
683 cdev->private->dev_id.devno);
684 if (ret)
685 return ret;
Sebastian Ott7d253b92009-12-07 12:51:33 +0100686 return device_add(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100689static int match_dev_id(struct device *dev, void *data)
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700690{
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100691 struct ccw_device *cdev = to_ccwdev(dev);
692 struct ccw_dev_id *dev_id = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700693
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100694 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
695}
696
Sebastian Ottb7a610f2012-05-15 17:52:07 +0200697/**
698 * get_ccwdev_by_dev_id() - obtain device from a ccw device id
699 * @dev_id: id of the device to be searched
700 *
701 * This function searches all devices attached to the ccw bus for a device
702 * matching @dev_id.
703 * Returns:
704 * If a device is found its reference count is increased and returned;
705 * else %NULL is returned.
706 */
707struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id)
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100708{
709 struct device *dev;
710
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100711 dev = bus_find_device(&ccw_bus_type, NULL, dev_id, match_dev_id);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100712
713 return dev ? to_ccwdev(dev) : NULL;
714}
Sebastian Ottb7a610f2012-05-15 17:52:07 +0200715EXPORT_SYMBOL_GPL(get_ccwdev_by_dev_id);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100716
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100717static void ccw_device_do_unbind_bind(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718{
Cornelia Huckeb32ae82009-03-26 15:24:05 +0100719 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Sebastian Ott7d253b92009-12-07 12:51:33 +0100721 if (device_is_registered(&cdev->dev)) {
Cornelia Huckeb32ae82009-03-26 15:24:05 +0100722 device_release_driver(&cdev->dev);
723 ret = device_attach(&cdev->dev);
724 WARN_ON(ret == -ENODEV);
725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
728static void
729ccw_device_release(struct device *dev)
730{
731 struct ccw_device *cdev;
732
733 cdev = to_ccwdev(dev);
Cornelia Huck6eff2082008-12-25 13:39:07 +0100734 /* Release reference of parent subchannel. */
735 put_device(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 kfree(cdev->private);
737 kfree(cdev);
738}
739
Cornelia Huck7674da72006-12-08 15:54:21 +0100740static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
741{
742 struct ccw_device *cdev;
743
744 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
745 if (cdev) {
746 cdev->private = kzalloc(sizeof(struct ccw_device_private),
747 GFP_KERNEL | GFP_DMA);
748 if (cdev->private)
749 return cdev;
750 }
751 kfree(cdev);
752 return ERR_PTR(-ENOMEM);
753}
754
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100755static void ccw_device_todo(struct work_struct *work);
756
Cornelia Huck7674da72006-12-08 15:54:21 +0100757static int io_subchannel_initialize_dev(struct subchannel *sch,
758 struct ccw_device *cdev)
759{
760 cdev->private->cdev = cdev;
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100761 cdev->private->int_class = IOINT_CIO;
Cornelia Huck7674da72006-12-08 15:54:21 +0100762 atomic_set(&cdev->private->onoff, 0);
763 cdev->dev.parent = &sch->dev;
764 cdev->dev.release = ccw_device_release;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100765 INIT_WORK(&cdev->private->todo_work, ccw_device_todo);
Cornelia Huckef995162007-04-27 16:01:39 +0200766 cdev->dev.groups = ccwdev_attr_groups;
Cornelia Huck7674da72006-12-08 15:54:21 +0100767 /* Do first half of device_register. */
768 device_initialize(&cdev->dev);
769 if (!get_device(&sch->dev)) {
Cornelia Huck283fdd02008-12-25 13:39:10 +0100770 /* Release reference from device_initialize(). */
771 put_device(&cdev->dev);
Cornelia Huck7674da72006-12-08 15:54:21 +0100772 return -ENODEV;
773 }
Sebastian Ott24a18722009-12-07 12:51:34 +0100774 cdev->private->flags.initialized = 1;
Cornelia Huck7674da72006-12-08 15:54:21 +0100775 return 0;
776}
777
778static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
779{
780 struct ccw_device *cdev;
781 int ret;
782
783 cdev = io_subchannel_allocate_dev(sch);
784 if (!IS_ERR(cdev)) {
785 ret = io_subchannel_initialize_dev(sch, cdev);
Sebastian Ott06739a82009-08-23 18:09:04 +0200786 if (ret)
Cornelia Huck7674da72006-12-08 15:54:21 +0100787 cdev = ERR_PTR(ret);
Cornelia Huck7674da72006-12-08 15:54:21 +0100788 }
789 return cdev;
790}
791
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100792static void io_subchannel_recog(struct ccw_device *, struct subchannel *);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100793
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100794static void sch_create_and_recog_new_device(struct subchannel *sch)
795{
796 struct ccw_device *cdev;
797
798 /* Need to allocate a new ccw device. */
799 cdev = io_subchannel_create_ccwdev(sch);
800 if (IS_ERR(cdev)) {
801 /* OK, we did everything we could... */
802 css_sch_device_unregister(sch);
803 return;
804 }
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100805 /* Start recognition for the new ccw device. */
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100806 io_subchannel_recog(cdev, sch);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100807}
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809/*
810 * Register recognized device.
811 */
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100812static void io_subchannel_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 struct subchannel *sch;
Sebastian Otta2901562010-03-08 12:25:17 +0100815 int ret, adjust_init_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 unsigned long flags;
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100819 /*
820 * Check if subchannel is still registered. It may have become
821 * unregistered if a machine check hit us after finishing
822 * device recognition but before the register work could be
823 * queued.
824 */
825 if (!device_is_registered(&sch->dev))
826 goto out_err;
Cornelia Huck82b7ac02007-04-27 16:01:36 +0200827 css_update_ssd_info(sch);
Cornelia Huck47af5512006-12-04 15:41:07 +0100828 /*
829 * io_subchannel_register() will also be called after device
830 * recognition has been done for a boxed device (which will already
831 * be registered). We need to reprobe since we may now have sense id
832 * information.
833 */
Cornelia Huckd6a30762008-12-25 13:39:11 +0100834 if (device_is_registered(&cdev->dev)) {
Cornelia Huck47af5512006-12-04 15:41:07 +0100835 if (!cdev->drv) {
836 ret = device_reprobe(&cdev->dev);
837 if (ret)
838 /* We can't do much here. */
Michael Ernst139b83d2008-05-07 09:22:54 +0200839 CIO_MSG_EVENT(0, "device_reprobe() returned"
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200840 " %d for 0.%x.%04x\n", ret,
841 cdev->private->dev_id.ssid,
842 cdev->private->dev_id.devno);
Cornelia Huck47af5512006-12-04 15:41:07 +0100843 }
Sebastian Otta2901562010-03-08 12:25:17 +0100844 adjust_init_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 goto out;
846 }
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700847 /*
848 * Now we know this subchannel will stay, we can throw
849 * our delayed uevent.
850 */
Ming Leif67f1292009-03-01 21:10:49 +0800851 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700852 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 /* make it known to the system */
854 ret = ccw_device_register(cdev);
855 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200856 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
857 cdev->private->dev_id.ssid,
858 cdev->private->dev_id.devno, ret);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100859 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100860 sch_set_cdev(sch, NULL);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100861 spin_unlock_irqrestore(sch->lock, flags);
Cornelia Huck6eff2082008-12-25 13:39:07 +0100862 /* Release initial device reference. */
863 put_device(&cdev->dev);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100864 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866out:
867 cdev->private->flags.recog_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 wake_up(&cdev->private->wait_q);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100869out_err:
Sebastian Otta2901562010-03-08 12:25:17 +0100870 if (adjust_init_count && atomic_dec_and_test(&ccw_device_init_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 wake_up(&ccw_device_init_wq);
872}
873
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100874static void ccw_device_call_sch_unregister(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 struct subchannel *sch;
877
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200878 /* Get subchannel reference for local processing. */
879 if (!get_device(cdev->dev.parent))
880 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200882 css_sch_device_unregister(sch);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200883 /* Release subchannel reference for local processing. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 put_device(&sch->dev);
885}
886
887/*
888 * subchannel recognition done. Called from the state machine.
889 */
890void
891io_subchannel_recog_done(struct ccw_device *cdev)
892{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (css_init_done == 0) {
894 cdev->private->flags.recog_done = 1;
895 return;
896 }
897 switch (cdev->private->state) {
Sebastian Ott47593bf2009-03-31 19:16:05 +0200898 case DEV_STATE_BOXED:
899 /* Device did not respond in time. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 case DEV_STATE_NOT_OPER:
901 cdev->private->flags.recog_done = 1;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100902 /* Remove device found not operational. */
903 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 if (atomic_dec_and_test(&ccw_device_init_count))
905 wake_up(&ccw_device_init_wq);
906 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 case DEV_STATE_OFFLINE:
908 /*
909 * We can't register the device in interrupt context so
910 * we schedule a work item.
911 */
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100912 ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 break;
914 }
915}
916
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100917static void io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 struct ccw_device_private *priv;
920
Cornelia Huck2ec22982006-12-08 15:54:26 +0100921 cdev->ccwlock = sch->lock;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* Init private data. */
924 priv = cdev->private;
Cornelia Huck78964262006-10-11 15:31:38 +0200925 priv->dev_id.devno = sch->schib.pmcw.dev;
926 priv->dev_id.ssid = sch->schid.ssid;
927 priv->schid = sch->schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 priv->state = DEV_STATE_NOT_OPER;
929 INIT_LIST_HEAD(&priv->cmb_list);
930 init_waitqueue_head(&priv->wait_q);
931 init_timer(&priv->timer);
932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 /* Increase counter of devices currently in recognition. */
934 atomic_inc(&ccw_device_init_count);
935
936 /* Start async. device sensing. */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100937 spin_lock_irq(sch->lock);
Peter Oberparleiter60e4dac2009-12-07 12:51:16 +0100938 sch_set_cdev(sch, cdev);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100939 ccw_device_recognition(cdev);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100940 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100943static int ccw_device_move_to_sch(struct ccw_device *cdev,
944 struct subchannel *sch)
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100945{
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100946 struct subchannel *old_sch;
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100947 int rc, old_enabled = 0;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100948
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100949 old_sch = to_subchannel(cdev->dev.parent);
950 /* Obtain child reference for new parent. */
Cornelia Huck6eff2082008-12-25 13:39:07 +0100951 if (!get_device(&sch->dev))
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100952 return -ENODEV;
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100953
954 if (!sch_is_pseudo_sch(old_sch)) {
955 spin_lock_irq(old_sch->lock);
956 old_enabled = old_sch->schib.pmcw.ena;
957 rc = 0;
958 if (old_enabled)
959 rc = cio_disable_subchannel(old_sch);
960 spin_unlock_irq(old_sch->lock);
961 if (rc == -EBUSY) {
962 /* Release child reference for new parent. */
963 put_device(&sch->dev);
964 return rc;
965 }
966 }
967
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100968 mutex_lock(&sch->reg_mutex);
Cornelia Huckffa6a702009-03-04 12:44:00 +0100969 rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100970 mutex_unlock(&sch->reg_mutex);
971 if (rc) {
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100972 CIO_MSG_EVENT(0, "device_move(0.%x.%04x,0.%x.%04x)=%d\n",
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100973 cdev->private->dev_id.ssid,
974 cdev->private->dev_id.devno, sch->schid.ssid,
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100975 sch->schib.pmcw.dev, rc);
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100976 if (old_enabled) {
977 /* Try to reenable the old subchannel. */
978 spin_lock_irq(old_sch->lock);
979 cio_enable_subchannel(old_sch, (u32)(addr_t)old_sch);
980 spin_unlock_irq(old_sch->lock);
981 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100982 /* Release child reference for new parent. */
Cornelia Huck6eff2082008-12-25 13:39:07 +0100983 put_device(&sch->dev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100984 return rc;
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100985 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100986 /* Clean up old subchannel. */
987 if (!sch_is_pseudo_sch(old_sch)) {
988 spin_lock_irq(old_sch->lock);
989 sch_set_cdev(old_sch, NULL);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100990 spin_unlock_irq(old_sch->lock);
991 css_schedule_eval(old_sch->schid);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +0100992 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100993 /* Release child reference for old parent. */
994 put_device(&old_sch->dev);
995 /* Initialize new subchannel. */
996 spin_lock_irq(sch->lock);
997 cdev->private->schid = sch->schid;
998 cdev->ccwlock = sch->lock;
999 if (!sch_is_pseudo_sch(sch))
1000 sch_set_cdev(sch, cdev);
1001 spin_unlock_irq(sch->lock);
1002 if (!sch_is_pseudo_sch(sch))
1003 css_update_ssd_info(sch);
1004 return 0;
1005}
1006
1007static int ccw_device_move_to_orph(struct ccw_device *cdev)
1008{
1009 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1010 struct channel_subsystem *css = to_css(sch->dev.parent);
1011
1012 return ccw_device_move_to_sch(cdev, css->pseudo_subchannel);
Cornelia Huckd7b5a4c92006-12-08 15:54:28 +01001013}
1014
Cornelia Huck602b20f2008-01-26 14:10:39 +01001015static void io_subchannel_irq(struct subchannel *sch)
1016{
1017 struct ccw_device *cdev;
1018
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001019 cdev = sch_get_cdev(sch);
Cornelia Huck602b20f2008-01-26 14:10:39 +01001020
Sebastian Ottefd986d2009-09-11 10:28:18 +02001021 CIO_TRACE_EVENT(6, "IRQ");
1022 CIO_TRACE_EVENT(6, dev_name(&sch->dev));
Cornelia Huck602b20f2008-01-26 14:10:39 +01001023 if (cdev)
1024 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001025 else
1026 kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
Cornelia Huck602b20f2008-01-26 14:10:39 +01001027}
1028
Sebastian Ott13952ec2008-12-25 13:39:13 +01001029void io_subchannel_init_config(struct subchannel *sch)
1030{
1031 memset(&sch->config, 0, sizeof(sch->config));
1032 sch->config.csense = 1;
Sebastian Ott13952ec2008-12-25 13:39:13 +01001033}
1034
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001035static void io_subchannel_init_fields(struct subchannel *sch)
1036{
1037 if (cio_is_console(sch->schid))
1038 sch->opm = 0xff;
1039 else
1040 sch->opm = chp_get_sch_opm(sch);
1041 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Cornelia Huck3a3fc292008-07-14 09:58:58 +02001042 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001043
1044 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1045 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1046 sch->schib.pmcw.dev, sch->schid.ssid,
1047 sch->schid.sch_no, sch->schib.pmcw.pim,
1048 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
Sebastian Ott13952ec2008-12-25 13:39:13 +01001049
1050 io_subchannel_init_config(sch);
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001051}
1052
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001053/*
1054 * Note: We always return 0 so that we bind to the device even on error.
1055 * This is needed so that our remove function is called on unregister.
1056 */
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001057static int io_subchannel_probe(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001059 struct io_subchannel_private *io_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 struct ccw_device *cdev;
1061 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001063 if (cio_is_console(sch->schid)) {
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001064 rc = sysfs_create_group(&sch->dev.kobj,
1065 &io_subchannel_attr_group);
1066 if (rc)
1067 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1068 "attributes for subchannel "
1069 "0.%x.%04x (rc=%d)\n",
1070 sch->schid.ssid, sch->schid.sch_no, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 /*
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001072 * The console subchannel already has an associated ccw_device.
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001073 * Throw the delayed uevent for the subchannel, register
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001074 * the ccw_device and exit.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 */
Ming Leif67f1292009-03-01 21:10:49 +08001076 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001077 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001078 cdev = sch_get_cdev(sch);
Cornelia Hucke1031782007-10-12 16:11:23 +02001079 cdev->dev.groups = ccwdev_attr_groups;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 device_initialize(&cdev->dev);
Sebastian Ott24a18722009-12-07 12:51:34 +01001081 cdev->private->flags.initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 ccw_device_register(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 /*
1084 * Check if the device is already online. If it is
Cornelia Huck9cd67422008-12-25 13:39:06 +01001085 * the reference count needs to be corrected since we
1086 * didn't obtain a reference in ccw_device_set_online.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 */
1088 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1089 cdev->private->state != DEV_STATE_OFFLINE &&
1090 cdev->private->state != DEV_STATE_BOXED)
1091 get_device(&cdev->dev);
1092 return 0;
1093 }
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001094 io_subchannel_init_fields(sch);
Sebastian Ottf444cc02008-12-25 13:39:14 +01001095 rc = cio_commit_config(sch);
1096 if (rc)
1097 goto out_schedule;
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001098 rc = sysfs_create_group(&sch->dev.kobj,
1099 &io_subchannel_attr_group);
1100 if (rc)
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001101 goto out_schedule;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001102 /* Allocate I/O subchannel private data. */
Sebastian Ottf92519e2011-03-15 17:08:27 +01001103 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA);
1104 if (!io_priv)
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001105 goto out_schedule;
Sebastian Ottf92519e2011-03-15 17:08:27 +01001106
1107 set_io_private(sch, io_priv);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001108 css_schedule_eval(sch->schid);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001109 return 0;
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001110
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001111out_schedule:
Peter Oberparleiter390935a2009-12-07 12:51:18 +01001112 spin_lock_irq(sch->lock);
1113 css_sched_sch_todo(sch, SCH_TODO_UNREG);
1114 spin_unlock_irq(sch->lock);
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001115 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118static int
Cornelia Huck8bbace72006-01-11 10:56:22 +01001119io_subchannel_remove (struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001121 struct io_subchannel_private *io_priv = to_io_private(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 struct ccw_device *cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001124 cdev = sch_get_cdev(sch);
1125 if (!cdev)
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001126 goto out_free;
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001127 io_subchannel_quiesce(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 /* Set ccw device to not operational and drop reference. */
Sebastian Ott7a8ad102009-12-07 12:51:39 +01001129 spin_lock_irq(cdev->ccwlock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001130 sch_set_cdev(sch, NULL);
Sebastian Ottf92519e2011-03-15 17:08:27 +01001131 set_io_private(sch, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 cdev->private->state = DEV_STATE_NOT_OPER;
Sebastian Ott7a8ad102009-12-07 12:51:39 +01001133 spin_unlock_irq(cdev->ccwlock);
Cornelia Huckef995162007-04-27 16:01:39 +02001134 ccw_device_unregister(cdev);
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001135out_free:
Sebastian Ottf92519e2011-03-15 17:08:27 +01001136 kfree(io_priv);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001137 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 return 0;
1139}
1140
Cornelia Huck602b20f2008-01-26 14:10:39 +01001141static void io_subchannel_verify(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
1143 struct ccw_device *cdev;
1144
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001145 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 if (cdev)
1147 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1148}
1149
Cornelia Huckc820de32008-07-14 09:58:45 +02001150static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
1152 struct ccw_device *cdev;
1153
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001154 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (!cdev)
1156 return;
Peter Oberparleiter4257aae2009-12-07 12:51:29 +01001157 if (cio_update_schib(sch))
1158 goto err;
1159 /* Check for I/O on path. */
1160 if (scsw_actl(&sch->schib.scsw) == 0 || sch->schib.pmcw.lpum != mask)
1161 goto out;
1162 if (cdev->private->state == DEV_STATE_ONLINE) {
1163 ccw_device_kill_io(cdev);
1164 goto out;
1165 }
1166 if (cio_clear(sch))
1167 goto err;
1168out:
1169 /* Trigger path verification. */
1170 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1171 return;
Cornelia Huckc820de32008-07-14 09:58:45 +02001172
Peter Oberparleiter4257aae2009-12-07 12:51:29 +01001173err:
1174 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
Cornelia Huckc820de32008-07-14 09:58:45 +02001175}
1176
Cornelia Huck99611f82008-07-14 09:59:02 +02001177static int io_subchannel_chp_event(struct subchannel *sch,
1178 struct chp_link *link, int event)
Cornelia Huckc820de32008-07-14 09:58:45 +02001179{
Sebastian Ott585b9542010-10-25 16:10:34 +02001180 struct ccw_device *cdev = sch_get_cdev(sch);
Cornelia Huckc820de32008-07-14 09:58:45 +02001181 int mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001182
Cornelia Huck99611f82008-07-14 09:59:02 +02001183 mask = chp_ssd_get_mask(&sch->ssd_info, link);
Cornelia Huckc820de32008-07-14 09:58:45 +02001184 if (!mask)
1185 return 0;
1186 switch (event) {
1187 case CHP_VARY_OFF:
1188 sch->opm &= ~mask;
1189 sch->lpm &= ~mask;
Sebastian Ott585b9542010-10-25 16:10:34 +02001190 if (cdev)
1191 cdev->private->path_gone_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001192 io_subchannel_terminate_path(sch, mask);
1193 break;
1194 case CHP_VARY_ON:
1195 sch->opm |= mask;
1196 sch->lpm |= mask;
Sebastian Ott585b9542010-10-25 16:10:34 +02001197 if (cdev)
1198 cdev->private->path_new_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001199 io_subchannel_verify(sch);
1200 break;
1201 case CHP_OFFLINE:
Sebastian Ottcdb912a2008-12-25 13:39:12 +01001202 if (cio_update_schib(sch))
Cornelia Huckc820de32008-07-14 09:58:45 +02001203 return -ENODEV;
Sebastian Ott585b9542010-10-25 16:10:34 +02001204 if (cdev)
1205 cdev->private->path_gone_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001206 io_subchannel_terminate_path(sch, mask);
1207 break;
1208 case CHP_ONLINE:
Sebastian Ottcdb912a2008-12-25 13:39:12 +01001209 if (cio_update_schib(sch))
1210 return -ENODEV;
Cornelia Huckc820de32008-07-14 09:58:45 +02001211 sch->lpm |= mask & sch->opm;
Sebastian Ott585b9542010-10-25 16:10:34 +02001212 if (cdev)
1213 cdev->private->path_new_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001214 io_subchannel_verify(sch);
1215 break;
1216 }
1217 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001220static void io_subchannel_quiesce(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 struct ccw_device *cdev;
1223 int ret;
1224
Sebastian Ott56e6b792009-12-07 12:51:35 +01001225 spin_lock_irq(sch->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001226 cdev = sch_get_cdev(sch);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001227 if (cio_is_console(sch->schid))
Sebastian Ott56e6b792009-12-07 12:51:35 +01001228 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 if (!sch->schib.pmcw.ena)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001230 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 ret = cio_disable_subchannel(sch);
1232 if (ret != -EBUSY)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001233 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 if (cdev->handler)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001235 cdev->handler(cdev, cdev->private->intparm, ERR_PTR(-EIO));
1236 while (ret == -EBUSY) {
1237 cdev->private->state = DEV_STATE_QUIESCE;
Peter Oberparleiter376ae472010-10-25 16:10:44 +02001238 cdev->private->iretry = 255;
Sebastian Ott56e6b792009-12-07 12:51:35 +01001239 ret = ccw_device_cancel_halt_clear(cdev);
1240 if (ret == -EBUSY) {
1241 ccw_device_set_timeout(cdev, HZ/10);
1242 spin_unlock_irq(sch->lock);
1243 wait_event(cdev->private->wait_q,
1244 cdev->private->state != DEV_STATE_QUIESCE);
1245 spin_lock_irq(sch->lock);
1246 }
1247 ret = cio_disable_subchannel(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
Sebastian Ott56e6b792009-12-07 12:51:35 +01001249out_unlock:
1250 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251}
1252
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001253static void io_subchannel_shutdown(struct subchannel *sch)
1254{
1255 io_subchannel_quiesce(sch);
1256}
1257
Cornelia Huckc820de32008-07-14 09:58:45 +02001258static int device_is_disconnected(struct ccw_device *cdev)
1259{
1260 if (!cdev)
1261 return 0;
1262 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1263 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1264}
1265
1266static int recovery_check(struct device *dev, void *data)
1267{
1268 struct ccw_device *cdev = to_ccwdev(dev);
1269 int *redo = data;
1270
1271 spin_lock_irq(cdev->ccwlock);
1272 switch (cdev->private->state) {
1273 case DEV_STATE_DISCONNECTED:
1274 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1275 cdev->private->dev_id.ssid,
1276 cdev->private->dev_id.devno);
1277 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1278 *redo = 1;
1279 break;
1280 case DEV_STATE_DISCONNECTED_SENSE_ID:
1281 *redo = 1;
1282 break;
1283 }
1284 spin_unlock_irq(cdev->ccwlock);
1285
1286 return 0;
1287}
1288
1289static void recovery_work_func(struct work_struct *unused)
1290{
1291 int redo = 0;
1292
1293 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1294 if (redo) {
1295 spin_lock_irq(&recovery_lock);
1296 if (!timer_pending(&recovery_timer)) {
1297 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1298 recovery_phase++;
1299 mod_timer(&recovery_timer, jiffies +
1300 recovery_delay[recovery_phase] * HZ);
1301 }
1302 spin_unlock_irq(&recovery_lock);
1303 } else
1304 CIO_MSG_EVENT(4, "recovery: end\n");
1305}
1306
1307static DECLARE_WORK(recovery_work, recovery_work_func);
1308
1309static void recovery_func(unsigned long data)
1310{
1311 /*
1312 * We can't do our recovery in softirq context and it's not
1313 * performance critical, so we schedule it.
1314 */
1315 schedule_work(&recovery_work);
1316}
1317
1318static void ccw_device_schedule_recovery(void)
1319{
1320 unsigned long flags;
1321
1322 CIO_MSG_EVENT(4, "recovery: schedule\n");
1323 spin_lock_irqsave(&recovery_lock, flags);
1324 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1325 recovery_phase = 0;
1326 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1327 }
1328 spin_unlock_irqrestore(&recovery_lock, flags);
1329}
1330
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001331static int purge_fn(struct device *dev, void *data)
1332{
1333 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001334 struct ccw_dev_id *id = &cdev->private->dev_id;
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001335
1336 spin_lock_irq(cdev->ccwlock);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001337 if (is_blacklisted(id->ssid, id->devno) &&
Peter Oberparleitera2fc8482011-04-04 09:43:32 +02001338 (cdev->private->state == DEV_STATE_OFFLINE) &&
1339 (atomic_cmpxchg(&cdev->private->onoff, 0, 1) == 0)) {
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001340 CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", id->ssid,
1341 id->devno);
1342 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Peter Oberparleitera2fc8482011-04-04 09:43:32 +02001343 atomic_set(&cdev->private->onoff, 0);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001344 }
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001345 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001346 /* Abort loop in case of pending signal. */
1347 if (signal_pending(current))
1348 return -EINTR;
1349
1350 return 0;
1351}
1352
1353/**
1354 * ccw_purge_blacklisted - purge unused, blacklisted devices
1355 *
1356 * Unregister all ccw devices that are offline and on the blacklist.
1357 */
1358int ccw_purge_blacklisted(void)
1359{
1360 CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n");
1361 bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn);
1362 return 0;
1363}
1364
Peter Oberparleiter6afcc772009-10-06 10:34:02 +02001365void ccw_device_set_disconnected(struct ccw_device *cdev)
Cornelia Huckc820de32008-07-14 09:58:45 +02001366{
1367 if (!cdev)
1368 return;
1369 ccw_device_set_timeout(cdev, 0);
1370 cdev->private->flags.fake_irb = 0;
1371 cdev->private->state = DEV_STATE_DISCONNECTED;
1372 if (cdev->online)
1373 ccw_device_schedule_recovery();
1374}
1375
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001376void ccw_device_set_notoper(struct ccw_device *cdev)
1377{
1378 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1379
1380 CIO_TRACE_EVENT(2, "notoper");
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001381 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001382 ccw_device_set_timeout(cdev, 0);
1383 cio_disable_subchannel(sch);
1384 cdev->private->state = DEV_STATE_NOT_OPER;
1385}
1386
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001387enum io_sch_action {
1388 IO_SCH_UNREG,
1389 IO_SCH_ORPH_UNREG,
1390 IO_SCH_ATTACH,
1391 IO_SCH_UNREG_ATTACH,
1392 IO_SCH_ORPH_ATTACH,
1393 IO_SCH_REPROBE,
1394 IO_SCH_VERIFY,
1395 IO_SCH_DISC,
1396 IO_SCH_NOP,
1397};
1398
1399static enum io_sch_action sch_get_action(struct subchannel *sch)
Cornelia Huckc820de32008-07-14 09:58:45 +02001400{
Cornelia Huckc820de32008-07-14 09:58:45 +02001401 struct ccw_device *cdev;
1402
Cornelia Huckc820de32008-07-14 09:58:45 +02001403 cdev = sch_get_cdev(sch);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001404 if (cio_update_schib(sch)) {
1405 /* Not operational. */
1406 if (!cdev)
1407 return IO_SCH_UNREG;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001408 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001409 return IO_SCH_UNREG;
1410 return IO_SCH_ORPH_UNREG;
Cornelia Huckc820de32008-07-14 09:58:45 +02001411 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001412 /* Operational. */
1413 if (!cdev)
1414 return IO_SCH_ATTACH;
1415 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001416 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001417 return IO_SCH_UNREG_ATTACH;
1418 return IO_SCH_ORPH_ATTACH;
Cornelia Huckc820de32008-07-14 09:58:45 +02001419 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001420 if ((sch->schib.pmcw.pam & sch->opm) == 0) {
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001421 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001422 return IO_SCH_UNREG;
1423 return IO_SCH_DISC;
Cornelia Huckc820de32008-07-14 09:58:45 +02001424 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001425 if (device_is_disconnected(cdev))
1426 return IO_SCH_REPROBE;
1427 if (cdev->online)
1428 return IO_SCH_VERIFY;
Sebastian Ott43d0be72012-09-05 14:19:42 +02001429 if (cdev->private->state == DEV_STATE_NOT_OPER)
1430 return IO_SCH_UNREG_ATTACH;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001431 return IO_SCH_NOP;
1432}
1433
1434/**
1435 * io_subchannel_sch_event - process subchannel event
1436 * @sch: subchannel
1437 * @process: non-zero if function is called in process context
1438 *
1439 * An unspecified event occurred for this subchannel. Adjust data according
1440 * to the current operational state of the subchannel and device. Return
1441 * zero when the event has been handled sufficiently or -EAGAIN when this
1442 * function should be called again in process context.
1443 */
1444static int io_subchannel_sch_event(struct subchannel *sch, int process)
1445{
1446 unsigned long flags;
1447 struct ccw_device *cdev;
1448 struct ccw_dev_id dev_id;
1449 enum io_sch_action action;
1450 int rc = -EAGAIN;
1451
1452 spin_lock_irqsave(sch->lock, flags);
1453 if (!device_is_registered(&sch->dev))
1454 goto out_unlock;
Peter Oberparleiter390935a2009-12-07 12:51:18 +01001455 if (work_pending(&sch->todo_work))
1456 goto out_unlock;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001457 cdev = sch_get_cdev(sch);
1458 if (cdev && work_pending(&cdev->private->todo_work))
1459 goto out_unlock;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001460 action = sch_get_action(sch);
1461 CIO_MSG_EVENT(2, "event: sch 0.%x.%04x, process=%d, action=%d\n",
1462 sch->schid.ssid, sch->schid.sch_no, process,
1463 action);
1464 /* Perform immediate actions while holding the lock. */
Cornelia Huckc820de32008-07-14 09:58:45 +02001465 switch (action) {
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001466 case IO_SCH_REPROBE:
1467 /* Trigger device recognition. */
Cornelia Huckc820de32008-07-14 09:58:45 +02001468 ccw_device_trigger_reprobe(cdev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001469 rc = 0;
1470 goto out_unlock;
1471 case IO_SCH_VERIFY:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001472 if (cdev->private->flags.resuming == 1) {
1473 if (cio_enable_subchannel(sch, (u32)(addr_t)sch)) {
1474 ccw_device_set_notoper(cdev);
1475 break;
1476 }
1477 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001478 /* Trigger path verification. */
1479 io_subchannel_verify(sch);
1480 rc = 0;
1481 goto out_unlock;
1482 case IO_SCH_DISC:
1483 ccw_device_set_disconnected(cdev);
1484 rc = 0;
1485 goto out_unlock;
1486 case IO_SCH_ORPH_UNREG:
1487 case IO_SCH_ORPH_ATTACH:
Peter Oberparleiter6afcc772009-10-06 10:34:02 +02001488 ccw_device_set_disconnected(cdev);
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001489 break;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001490 case IO_SCH_UNREG_ATTACH:
1491 case IO_SCH_UNREG:
Sebastian Ott16d2ce22010-11-10 10:05:53 +01001492 if (!cdev)
1493 break;
1494 if (cdev->private->state == DEV_STATE_SENSE_ID) {
1495 /*
1496 * Note: delayed work triggered by this event
1497 * and repeated calls to sch_event are synchronized
1498 * by the above check for work_pending(cdev).
1499 */
1500 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1501 } else
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001502 ccw_device_set_notoper(cdev);
1503 break;
1504 case IO_SCH_NOP:
1505 rc = 0;
1506 goto out_unlock;
Cornelia Huckc820de32008-07-14 09:58:45 +02001507 default:
1508 break;
1509 }
1510 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001511 /* All other actions require process context. */
1512 if (!process)
1513 goto out;
1514 /* Handle attached ccw device. */
1515 switch (action) {
1516 case IO_SCH_ORPH_UNREG:
1517 case IO_SCH_ORPH_ATTACH:
1518 /* Move ccw device to orphanage. */
1519 rc = ccw_device_move_to_orph(cdev);
1520 if (rc)
1521 goto out;
1522 break;
1523 case IO_SCH_UNREG_ATTACH:
Sebastian Ott3368ba22012-09-05 14:20:41 +02001524 spin_lock_irqsave(sch->lock, flags);
Sebastian Ott74b61272010-10-25 16:10:26 +02001525 if (cdev->private->flags.resuming) {
1526 /* Device will be handled later. */
1527 rc = 0;
Sebastian Ott3368ba22012-09-05 14:20:41 +02001528 goto out_unlock;
Sebastian Ott74b61272010-10-25 16:10:26 +02001529 }
Sebastian Ott3368ba22012-09-05 14:20:41 +02001530 sch_set_cdev(sch, NULL);
1531 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001532 /* Unregister ccw device. */
Sebastian Ott74b61272010-10-25 16:10:26 +02001533 ccw_device_unregister(cdev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001534 break;
1535 default:
1536 break;
1537 }
1538 /* Handle subchannel. */
1539 switch (action) {
1540 case IO_SCH_ORPH_UNREG:
1541 case IO_SCH_UNREG:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001542 if (!cdev || !cdev->private->flags.resuming)
1543 css_sch_device_unregister(sch);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001544 break;
1545 case IO_SCH_ORPH_ATTACH:
1546 case IO_SCH_UNREG_ATTACH:
1547 case IO_SCH_ATTACH:
1548 dev_id.ssid = sch->schid.ssid;
1549 dev_id.devno = sch->schib.pmcw.dev;
1550 cdev = get_ccwdev_by_dev_id(&dev_id);
1551 if (!cdev) {
1552 sch_create_and_recog_new_device(sch);
1553 break;
1554 }
1555 rc = ccw_device_move_to_sch(cdev, sch);
1556 if (rc) {
1557 /* Release reference from get_ccwdev_by_dev_id() */
1558 put_device(&cdev->dev);
1559 goto out;
1560 }
1561 spin_lock_irqsave(sch->lock, flags);
1562 ccw_device_trigger_reprobe(cdev);
1563 spin_unlock_irqrestore(sch->lock, flags);
1564 /* Release reference from get_ccwdev_by_dev_id() */
1565 put_device(&cdev->dev);
1566 break;
1567 default:
1568 break;
1569 }
1570 return 0;
Cornelia Huckc820de32008-07-14 09:58:45 +02001571
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001572out_unlock:
1573 spin_unlock_irqrestore(sch->lock, flags);
1574out:
1575 return rc;
Cornelia Huckc820de32008-07-14 09:58:45 +02001576}
1577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578#ifdef CONFIG_CCW_CONSOLE
1579static struct ccw_device console_cdev;
1580static struct ccw_device_private console_private;
1581static int console_cdev_in_use;
1582
Cornelia Huck2ec22982006-12-08 15:54:26 +01001583static DEFINE_SPINLOCK(ccw_console_lock);
1584
1585spinlock_t * cio_get_console_lock(void)
1586{
1587 return &ccw_console_lock;
1588}
1589
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001590static int ccw_device_console_enable(struct ccw_device *cdev,
1591 struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001593 struct io_subchannel_private *io_priv = cio_get_console_priv();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 int rc;
1595
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001596 /* Attach subchannel private data. */
Sebastian Ottf92519e2011-03-15 17:08:27 +01001597 memset(io_priv, 0, sizeof(*io_priv));
1598 set_io_private(sch, io_priv);
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001599 io_subchannel_init_fields(sch);
Sebastian Ottf444cc02008-12-25 13:39:14 +01001600 rc = cio_commit_config(sch);
1601 if (rc)
1602 return rc;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001603 sch->driver = &io_subchannel_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 /* Initialize the ccw_device structure. */
Heiko Carstens292888c2006-08-30 14:33:35 +02001605 cdev->dev.parent= &sch->dev;
Sebastian Ottffa8d2a2009-12-18 17:43:15 +01001606 sch_set_cdev(sch, cdev);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001607 io_subchannel_recog(cdev, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 /* Now wait for the async. recognition to come to an end. */
1609 spin_lock_irq(cdev->ccwlock);
1610 while (!dev_fsm_final_state(cdev))
1611 wait_cons_dev();
1612 rc = -EIO;
1613 if (cdev->private->state != DEV_STATE_OFFLINE)
1614 goto out_unlock;
1615 ccw_device_online(cdev);
1616 while (!dev_fsm_final_state(cdev))
1617 wait_cons_dev();
1618 if (cdev->private->state != DEV_STATE_ONLINE)
1619 goto out_unlock;
1620 rc = 0;
1621out_unlock:
1622 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001623 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624}
1625
1626struct ccw_device *
1627ccw_device_probe_console(void)
1628{
1629 struct subchannel *sch;
1630 int ret;
1631
1632 if (xchg(&console_cdev_in_use, 1) != 0)
Peter Oberparleiter600b5d12006-02-01 03:06:35 -08001633 return ERR_PTR(-EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 sch = cio_probe_console();
1635 if (IS_ERR(sch)) {
1636 console_cdev_in_use = 0;
1637 return (void *) sch;
1638 }
1639 memset(&console_cdev, 0, sizeof(struct ccw_device));
1640 memset(&console_private, 0, sizeof(struct ccw_device_private));
1641 console_cdev.private = &console_private;
Martin Schwidefskyc1637532006-12-08 15:53:57 +01001642 console_private.cdev = &console_cdev;
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001643 console_private.int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 ret = ccw_device_console_enable(&console_cdev, sch);
1645 if (ret) {
1646 cio_release_console();
1647 console_cdev_in_use = 0;
1648 return ERR_PTR(ret);
1649 }
1650 console_cdev.online = 1;
1651 return &console_cdev;
1652}
Cornelia Huck1f4e7ed2008-10-10 21:33:14 +02001653
Martin Schwidefsky66648452009-06-16 10:30:28 +02001654static int ccw_device_pm_restore(struct device *dev);
1655
1656int ccw_device_force_console(void)
1657{
1658 if (!console_cdev_in_use)
1659 return -ENODEV;
1660 return ccw_device_pm_restore(&console_cdev.dev);
1661}
1662EXPORT_SYMBOL_GPL(ccw_device_force_console);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663#endif
1664
1665/*
1666 * get ccw_device matching the busid, but only if owned by cdrv
1667 */
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001668static int
1669__ccwdev_check_busid(struct device *dev, void *id)
1670{
1671 char *bus_id;
1672
Cornelia Huck12975ae2006-10-11 15:31:47 +02001673 bus_id = id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001674
Kay Sievers98df67b2008-12-25 13:38:55 +01001675 return (strcmp(bus_id, dev_name(dev)) == 0);
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001676}
1677
1678
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02001679/**
1680 * get_ccwdev_by_busid() - obtain device from a bus id
1681 * @cdrv: driver the device is owned by
1682 * @bus_id: bus id of the device to be searched
1683 *
1684 * This function searches all devices owned by @cdrv for a device with a bus
1685 * id matching @bus_id.
1686 * Returns:
1687 * If a match is found, its reference count of the found device is increased
1688 * and it is returned; else %NULL is returned.
1689 */
1690struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1691 const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001693 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Sebastian Ott9f30ea92012-01-24 13:35:02 -05001695 dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001696 __ccwdev_check_busid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001698 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
1701/************************** device driver handling ************************/
1702
1703/* This is the implementation of the ccw_driver class. The probe, remove
1704 * and release methods are initially very similar to the device_driver
1705 * implementations, with the difference that they have ccw_device
1706 * arguments.
1707 *
1708 * A ccw driver also contains the information that is needed for
1709 * device matching.
1710 */
1711static int
1712ccw_device_probe (struct device *dev)
1713{
1714 struct ccw_device *cdev = to_ccwdev(dev);
1715 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1716 int ret;
1717
1718 cdev->drv = cdrv; /* to let the driver call _set_online */
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001719 /* Note: we interpret class 0 in this context as an uninitialized
1720 * field since it translates to a non-I/O interrupt class. */
1721 if (cdrv->int_class != 0)
1722 cdev->private->int_class = cdrv->int_class;
1723 else
1724 cdev->private->int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1727
1728 if (ret) {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001729 cdev->drv = NULL;
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001730 cdev->private->int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 return ret;
1732 }
1733
1734 return 0;
1735}
1736
1737static int
1738ccw_device_remove (struct device *dev)
1739{
1740 struct ccw_device *cdev = to_ccwdev(dev);
1741 struct ccw_driver *cdrv = cdev->drv;
1742 int ret;
1743
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 if (cdrv->remove)
1745 cdrv->remove(cdev);
1746 if (cdev->online) {
1747 cdev->online = 0;
1748 spin_lock_irq(cdev->ccwlock);
1749 ret = ccw_device_offline(cdev);
1750 spin_unlock_irq(cdev->ccwlock);
1751 if (ret == 0)
1752 wait_event(cdev->private->wait_q,
1753 dev_fsm_final_state(cdev));
1754 else
Michael Ernst139b83d2008-05-07 09:22:54 +02001755 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +02001756 "device 0.%x.%04x\n",
1757 ret, cdev->private->dev_id.ssid,
1758 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +01001759 /* Give up reference obtained in ccw_device_set_online(). */
1760 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 }
1762 ccw_device_set_timeout(cdev, 0);
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001763 cdev->drv = NULL;
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001764 cdev->private->int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return 0;
1766}
1767
Cornelia Huck958974fb2007-10-12 16:11:21 +02001768static void ccw_device_shutdown(struct device *dev)
1769{
1770 struct ccw_device *cdev;
1771
1772 cdev = to_ccwdev(dev);
1773 if (cdev->drv && cdev->drv->shutdown)
1774 cdev->drv->shutdown(cdev);
Cornelia Huck1842f2b2007-10-12 16:11:22 +02001775 disable_cmf(cdev);
Cornelia Huck958974fb2007-10-12 16:11:21 +02001776}
1777
Sebastian Ott823d4942009-06-16 10:30:20 +02001778static int ccw_device_pm_prepare(struct device *dev)
1779{
1780 struct ccw_device *cdev = to_ccwdev(dev);
1781
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001782 if (work_pending(&cdev->private->todo_work))
Sebastian Ott823d4942009-06-16 10:30:20 +02001783 return -EAGAIN;
1784 /* Fail while device is being set online/offline. */
1785 if (atomic_read(&cdev->private->onoff))
1786 return -EAGAIN;
1787
1788 if (cdev->online && cdev->drv && cdev->drv->prepare)
1789 return cdev->drv->prepare(cdev);
1790
1791 return 0;
1792}
1793
1794static void ccw_device_pm_complete(struct device *dev)
1795{
1796 struct ccw_device *cdev = to_ccwdev(dev);
1797
1798 if (cdev->online && cdev->drv && cdev->drv->complete)
1799 cdev->drv->complete(cdev);
1800}
1801
1802static int ccw_device_pm_freeze(struct device *dev)
1803{
1804 struct ccw_device *cdev = to_ccwdev(dev);
1805 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1806 int ret, cm_enabled;
1807
1808 /* Fail suspend while device is in transistional state. */
1809 if (!dev_fsm_final_state(cdev))
1810 return -EAGAIN;
1811 if (!cdev->online)
1812 return 0;
1813 if (cdev->drv && cdev->drv->freeze) {
1814 ret = cdev->drv->freeze(cdev);
1815 if (ret)
1816 return ret;
1817 }
1818
1819 spin_lock_irq(sch->lock);
1820 cm_enabled = cdev->private->cmb != NULL;
1821 spin_unlock_irq(sch->lock);
1822 if (cm_enabled) {
1823 /* Don't have the css write on memory. */
1824 ret = ccw_set_cmf(cdev, 0);
1825 if (ret)
1826 return ret;
1827 }
1828 /* From here on, disallow device driver I/O. */
1829 spin_lock_irq(sch->lock);
1830 ret = cio_disable_subchannel(sch);
1831 spin_unlock_irq(sch->lock);
1832
1833 return ret;
1834}
1835
1836static int ccw_device_pm_thaw(struct device *dev)
1837{
1838 struct ccw_device *cdev = to_ccwdev(dev);
1839 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1840 int ret, cm_enabled;
1841
1842 if (!cdev->online)
1843 return 0;
1844
1845 spin_lock_irq(sch->lock);
1846 /* Allow device driver I/O again. */
1847 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
1848 cm_enabled = cdev->private->cmb != NULL;
1849 spin_unlock_irq(sch->lock);
1850 if (ret)
1851 return ret;
1852
1853 if (cm_enabled) {
1854 ret = ccw_set_cmf(cdev, 1);
1855 if (ret)
1856 return ret;
1857 }
1858
1859 if (cdev->drv && cdev->drv->thaw)
1860 ret = cdev->drv->thaw(cdev);
1861
1862 return ret;
1863}
1864
1865static void __ccw_device_pm_restore(struct ccw_device *cdev)
1866{
1867 struct subchannel *sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +02001868
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001869 spin_lock_irq(sch->lock);
1870 if (cio_is_console(sch->schid)) {
1871 cio_enable_subchannel(sch, (u32)(addr_t)sch);
1872 goto out_unlock;
1873 }
Sebastian Ott823d4942009-06-16 10:30:20 +02001874 /*
1875 * While we were sleeping, devices may have gone or become
1876 * available again. Kick re-detection.
1877 */
Sebastian Ott823d4942009-06-16 10:30:20 +02001878 cdev->private->flags.resuming = 1;
Sebastian Ottb17295e2011-01-12 09:55:10 +01001879 cdev->private->path_new_mask = LPM_ANYPATH;
Sebastian Ott817e5002011-12-01 13:32:19 +01001880 css_sched_sch_todo(sch, SCH_TODO_EVAL);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001881 spin_unlock_irq(sch->lock);
Sebastian Ott817e5002011-12-01 13:32:19 +01001882 css_wait_for_slow_path();
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001883
1884 /* cdev may have been moved to a different subchannel. */
1885 sch = to_subchannel(cdev->dev.parent);
1886 spin_lock_irq(sch->lock);
1887 if (cdev->private->state != DEV_STATE_ONLINE &&
1888 cdev->private->state != DEV_STATE_OFFLINE)
1889 goto out_unlock;
1890
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001891 ccw_device_recognition(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001892 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001893 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) ||
1894 cdev->private->state == DEV_STATE_DISCONNECTED);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001895 spin_lock_irq(sch->lock);
1896
1897out_unlock:
Sebastian Ott823d4942009-06-16 10:30:20 +02001898 cdev->private->flags.resuming = 0;
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001899 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001900}
1901
1902static int resume_handle_boxed(struct ccw_device *cdev)
1903{
1904 cdev->private->state = DEV_STATE_BOXED;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001905 if (ccw_device_notify(cdev, CIO_BOXED) == NOTIFY_OK)
Sebastian Ott823d4942009-06-16 10:30:20 +02001906 return 0;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001907 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Sebastian Ott823d4942009-06-16 10:30:20 +02001908 return -ENODEV;
1909}
1910
1911static int resume_handle_disc(struct ccw_device *cdev)
1912{
1913 cdev->private->state = DEV_STATE_DISCONNECTED;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001914 if (ccw_device_notify(cdev, CIO_GONE) == NOTIFY_OK)
Sebastian Ott823d4942009-06-16 10:30:20 +02001915 return 0;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001916 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Sebastian Ott823d4942009-06-16 10:30:20 +02001917 return -ENODEV;
1918}
1919
1920static int ccw_device_pm_restore(struct device *dev)
1921{
1922 struct ccw_device *cdev = to_ccwdev(dev);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001923 struct subchannel *sch;
1924 int ret = 0;
Sebastian Ott823d4942009-06-16 10:30:20 +02001925
1926 __ccw_device_pm_restore(cdev);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001927 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +02001928 spin_lock_irq(sch->lock);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001929 if (cio_is_console(sch->schid))
Sebastian Ott823d4942009-06-16 10:30:20 +02001930 goto out_restore;
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001931
Sebastian Ott823d4942009-06-16 10:30:20 +02001932 /* check recognition results */
1933 switch (cdev->private->state) {
1934 case DEV_STATE_OFFLINE:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001935 case DEV_STATE_ONLINE:
1936 cdev->private->flags.donotify = 0;
Sebastian Ott823d4942009-06-16 10:30:20 +02001937 break;
1938 case DEV_STATE_BOXED:
1939 ret = resume_handle_boxed(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001940 if (ret)
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001941 goto out_unlock;
Sebastian Ott823d4942009-06-16 10:30:20 +02001942 goto out_restore;
Sebastian Ott823d4942009-06-16 10:30:20 +02001943 default:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001944 ret = resume_handle_disc(cdev);
1945 if (ret)
1946 goto out_unlock;
1947 goto out_restore;
Sebastian Ott823d4942009-06-16 10:30:20 +02001948 }
1949 /* check if the device type has changed */
1950 if (!ccw_device_test_sense_data(cdev)) {
1951 ccw_device_update_sense_data(cdev);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001952 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
Sebastian Ott823d4942009-06-16 10:30:20 +02001953 ret = -ENODEV;
1954 goto out_unlock;
1955 }
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001956 if (!cdev->online)
1957 goto out_unlock;
1958
1959 if (ccw_device_online(cdev)) {
1960 ret = resume_handle_disc(cdev);
1961 if (ret)
1962 goto out_unlock;
1963 goto out_restore;
1964 }
1965 spin_unlock_irq(sch->lock);
1966 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1967 spin_lock_irq(sch->lock);
1968
1969 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) {
1970 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
1971 ret = -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +02001972 goto out_unlock;
1973 }
Sebastian Ott823d4942009-06-16 10:30:20 +02001974
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001975 /* reenable cmf, if needed */
1976 if (cdev->private->cmb) {
1977 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001978 ret = ccw_set_cmf(cdev, 1);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001979 spin_lock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001980 if (ret) {
Sebastian Ottf0148242009-09-11 10:28:23 +02001981 CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed "
1982 "(rc=%d)\n", cdev->private->dev_id.ssid,
1983 cdev->private->dev_id.devno, ret);
Sebastian Ott823d4942009-06-16 10:30:20 +02001984 ret = 0;
1985 }
1986 }
1987
1988out_restore:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001989 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001990 if (cdev->online && cdev->drv && cdev->drv->restore)
1991 ret = cdev->drv->restore(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001992 return ret;
1993
Sebastian Ott823d4942009-06-16 10:30:20 +02001994out_unlock:
1995 spin_unlock_irq(sch->lock);
1996 return ret;
1997}
1998
Alexey Dobriyan47145212009-12-14 18:00:08 -08001999static const struct dev_pm_ops ccw_pm_ops = {
Sebastian Ott823d4942009-06-16 10:30:20 +02002000 .prepare = ccw_device_pm_prepare,
2001 .complete = ccw_device_pm_complete,
2002 .freeze = ccw_device_pm_freeze,
2003 .thaw = ccw_device_pm_thaw,
2004 .restore = ccw_device_pm_restore,
2005};
2006
Sebastian Ottd5ab5272011-03-23 10:16:03 +01002007static struct bus_type ccw_bus_type = {
Cornelia Huck8bbace72006-01-11 10:56:22 +01002008 .name = "ccw",
2009 .match = ccw_bus_match,
2010 .uevent = ccw_uevent,
2011 .probe = ccw_device_probe,
2012 .remove = ccw_device_remove,
Cornelia Huck958974fb2007-10-12 16:11:21 +02002013 .shutdown = ccw_device_shutdown,
Sebastian Ott823d4942009-06-16 10:30:20 +02002014 .pm = &ccw_pm_ops,
Cornelia Huck8bbace72006-01-11 10:56:22 +01002015};
2016
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02002017/**
2018 * ccw_driver_register() - register a ccw driver
2019 * @cdriver: driver to be registered
2020 *
2021 * This function is mainly a wrapper around driver_register().
2022 * Returns:
2023 * %0 on success and a negative error value on failure.
2024 */
2025int ccw_driver_register(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026{
2027 struct device_driver *drv = &cdriver->driver;
2028
2029 drv->bus = &ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
2031 return driver_register(drv);
2032}
2033
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02002034/**
2035 * ccw_driver_unregister() - deregister a ccw driver
2036 * @cdriver: driver to be deregistered
2037 *
2038 * This function is mainly a wrapper around driver_unregister().
2039 */
2040void ccw_driver_unregister(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041{
2042 driver_unregister(&cdriver->driver);
2043}
2044
Cornelia Hucka8237fc2006-01-06 00:19:21 -08002045/* Helper func for qdio. */
2046struct subchannel_id
2047ccw_device_get_subchannel_id(struct ccw_device *cdev)
2048{
2049 struct subchannel *sch;
2050
2051 sch = to_subchannel(cdev->dev.parent);
2052 return sch->schid;
2053}
2054
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01002055static void ccw_device_todo(struct work_struct *work)
2056{
2057 struct ccw_device_private *priv;
2058 struct ccw_device *cdev;
2059 struct subchannel *sch;
2060 enum cdev_todo todo;
2061
2062 priv = container_of(work, struct ccw_device_private, todo_work);
2063 cdev = priv->cdev;
2064 sch = to_subchannel(cdev->dev.parent);
2065 /* Find out todo. */
2066 spin_lock_irq(cdev->ccwlock);
2067 todo = priv->todo;
2068 priv->todo = CDEV_TODO_NOTHING;
2069 CIO_MSG_EVENT(4, "cdev_todo: cdev=0.%x.%04x todo=%d\n",
2070 priv->dev_id.ssid, priv->dev_id.devno, todo);
2071 spin_unlock_irq(cdev->ccwlock);
2072 /* Perform todo. */
2073 switch (todo) {
2074 case CDEV_TODO_ENABLE_CMF:
2075 cmf_reenable(cdev);
2076 break;
2077 case CDEV_TODO_REBIND:
2078 ccw_device_do_unbind_bind(cdev);
2079 break;
2080 case CDEV_TODO_REGISTER:
2081 io_subchannel_register(cdev);
2082 break;
2083 case CDEV_TODO_UNREG_EVAL:
2084 if (!sch_is_pseudo_sch(sch))
2085 css_schedule_eval(sch->schid);
2086 /* fall-through */
2087 case CDEV_TODO_UNREG:
2088 if (sch_is_pseudo_sch(sch))
2089 ccw_device_unregister(cdev);
2090 else
2091 ccw_device_call_sch_unregister(cdev);
2092 break;
2093 default:
2094 break;
2095 }
2096 /* Release workqueue ref. */
2097 put_device(&cdev->dev);
2098}
2099
2100/**
2101 * ccw_device_sched_todo - schedule ccw device operation
2102 * @cdev: ccw device
2103 * @todo: todo
2104 *
2105 * Schedule the operation identified by @todo to be performed on the slow path
2106 * workqueue. Do nothing if another operation with higher priority is already
2107 * scheduled. Needs to be called with ccwdev lock held.
2108 */
2109void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo)
2110{
2111 CIO_MSG_EVENT(4, "cdev_todo: sched cdev=0.%x.%04x todo=%d\n",
2112 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
2113 todo);
2114 if (cdev->private->todo >= todo)
2115 return;
2116 cdev->private->todo = todo;
2117 /* Get workqueue ref. */
2118 if (!get_device(&cdev->dev))
2119 return;
Sebastian Ottbe5d3822010-02-26 22:37:24 +01002120 if (!queue_work(cio_work_q, &cdev->private->todo_work)) {
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01002121 /* Already queued, release workqueue ref. */
2122 put_device(&cdev->dev);
2123 }
2124}
2125
Michael Ernstfd0457a2010-08-09 18:12:50 +02002126/**
2127 * ccw_device_siosl() - initiate logging
2128 * @cdev: ccw device
2129 *
2130 * This function is used to invoke model-dependent logging within the channel
2131 * subsystem.
2132 */
2133int ccw_device_siosl(struct ccw_device *cdev)
2134{
2135 struct subchannel *sch = to_subchannel(cdev->dev.parent);
2136
2137 return chsc_siosl(sch->schid);
2138}
2139EXPORT_SYMBOL_GPL(ccw_device_siosl);
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141MODULE_LICENSE("GPL");
2142EXPORT_SYMBOL(ccw_device_set_online);
2143EXPORT_SYMBOL(ccw_device_set_offline);
2144EXPORT_SYMBOL(ccw_driver_register);
2145EXPORT_SYMBOL(ccw_driver_unregister);
2146EXPORT_SYMBOL(get_ccwdev_by_busid);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08002147EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);