blob: 02d015259461623719bc4b3c09b89e18bb1050b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/cio/device.c
3 * bus driver for ccw devices
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Cornelia Huckc820de32008-07-14 09:58:45 +02005 * Copyright IBM Corp. 2002,2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08007 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 */
Peter Oberparleitera7ae2c02009-12-07 12:51:20 +010010
11#define KMSG_COMPONENT "cio"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/spinlock.h>
17#include <linux/errno.h>
18#include <linux/err.h>
19#include <linux/slab.h>
20#include <linux/list.h>
21#include <linux/device.h>
22#include <linux/workqueue.h>
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010023#include <linux/timer.h>
Peter Oberparleiterde400d62011-10-30 15:16:04 +010024#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/ccwdev.h>
27#include <asm/cio.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080028#include <asm/param.h> /* HZ */
Cornelia Huck1842f2b2007-10-12 16:11:22 +020029#include <asm/cmb.h>
Cornelia Huck3a3fc292008-07-14 09:58:58 +020030#include <asm/isc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +020032#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "cio.h"
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +010034#include "cio_debug.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "css.h"
36#include "device.h"
37#include "ioasm.h"
Cornelia Huckcd6b4f22008-01-26 14:10:43 +010038#include "io_sch.h"
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +020039#include "blacklist.h"
Michael Ernstfd0457a2010-08-09 18:12:50 +020040#include "chsc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010042static struct timer_list recovery_timer;
Cornelia Huck486d0a02008-02-19 15:29:23 +010043static DEFINE_SPINLOCK(recovery_lock);
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010044static int recovery_phase;
45static const unsigned long recovery_delay[] = { 3, 30, 300 };
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/******************* bus type handling ***********************/
48
49/* The Linux driver model distinguishes between a bus type and
50 * the bus itself. Of course we only have one channel
51 * subsystem driver and one channel system per machine, but
52 * we still use the abstraction. T.R. says it's a good idea. */
53static int
54ccw_bus_match (struct device * dev, struct device_driver * drv)
55{
56 struct ccw_device *cdev = to_ccwdev(dev);
57 struct ccw_driver *cdrv = to_ccwdrv(drv);
58 const struct ccw_device_id *ids = cdrv->ids, *found;
59
60 if (!ids)
61 return 0;
62
63 found = ccw_device_id_match(ids, &cdev->id);
64 if (!found)
65 return 0;
66
67 cdev->id.driver_info = found->driver_info;
68
69 return 1;
70}
71
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020072/* Store modalias string delimited by prefix/suffix string into buffer with
73 * specified size. Return length of resulting string (excluding trailing '\0')
74 * even if string doesn't fit buffer (snprintf semantics). */
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020075static int snprint_alias(char *buf, size_t size,
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020076 struct ccw_device_id *id, const char *suffix)
77{
78 int len;
79
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020080 len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020081 if (len > size)
82 return len;
83 buf += len;
84 size -= len;
85
86 if (id->dev_type != 0)
87 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
88 id->dev_model, suffix);
89 else
90 len += snprintf(buf, size, "dtdm%s", suffix);
91
92 return len;
93}
94
95/* Set up environment variables for ccw device uevent. Return 0 on success,
96 * non-zero otherwise. */
Kay Sievers7eff2e72007-08-14 15:15:12 +020097static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
99 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200100 struct ccw_device_id *id = &(cdev->id);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200101 int ret;
102 char modalias_buf[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200104 /* CU_TYPE= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200105 ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200106 if (ret)
107 return ret;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200108
109 /* CU_MODEL= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200110 ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200111 if (ret)
112 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* The next two can be zero, that's ok for us */
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200115 /* DEV_TYPE= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200116 ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200117 if (ret)
118 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200120 /* DEV_MODEL= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200121 ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200122 if (ret)
123 return ret;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200124
125 /* MODALIAS= */
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200126 snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
Kay Sievers7eff2e72007-08-14 15:15:12 +0200127 ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf);
128 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Sebastian Ottd5ab5272011-03-23 10:16:03 +0100131static struct bus_type ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Cornelia Huck602b20f2008-01-26 14:10:39 +0100133static void io_subchannel_irq(struct subchannel *);
134static int io_subchannel_probe(struct subchannel *);
135static int io_subchannel_remove(struct subchannel *);
Cornelia Huck8bbace72006-01-11 10:56:22 +0100136static void io_subchannel_shutdown(struct subchannel *);
Cornelia Huckc820de32008-07-14 09:58:45 +0200137static int io_subchannel_sch_event(struct subchannel *, int);
Cornelia Huck99611f82008-07-14 09:59:02 +0200138static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
139 int);
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200140static void recovery_func(unsigned long data);
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200141wait_queue_head_t ccw_device_init_wq;
142atomic_t ccw_device_init_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Cornelia Huckf08adc02008-07-14 09:59:03 +0200144static struct css_device_id io_subchannel_ids[] = {
145 { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, },
146 { /* end of list */ },
147};
148MODULE_DEVICE_TABLE(css, io_subchannel_ids);
149
Cornelia Huck93a27592009-06-16 10:30:23 +0200150static int io_subchannel_prepare(struct subchannel *sch)
151{
152 struct ccw_device *cdev;
153 /*
154 * Don't allow suspend while a ccw device registration
155 * is still outstanding.
156 */
157 cdev = sch_get_cdev(sch);
158 if (cdev && !device_is_registered(&cdev->dev))
159 return -EAGAIN;
160 return 0;
161}
162
Sebastian Ottb4c70722010-02-26 22:37:27 +0100163static int io_subchannel_settle(void)
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200164{
Sebastian Ottb4c70722010-02-26 22:37:27 +0100165 int ret;
166
167 ret = wait_event_interruptible(ccw_device_init_wq,
168 atomic_read(&ccw_device_init_count) == 0);
169 if (ret)
170 return -EINTR;
Sebastian Ottbe5d3822010-02-26 22:37:24 +0100171 flush_workqueue(cio_work_q);
Sebastian Ottb4c70722010-02-26 22:37:27 +0100172 return 0;
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200173}
174
Cornelia Huckf7e5d672007-05-10 15:45:43 +0200175static struct css_driver io_subchannel_driver = {
Sebastian Otte6aed122011-03-15 17:08:30 +0100176 .drv = {
177 .owner = THIS_MODULE,
178 .name = "io_subchannel",
179 },
Cornelia Huckf08adc02008-07-14 09:59:03 +0200180 .subchannel_type = io_subchannel_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 .irq = io_subchannel_irq,
Cornelia Huckc820de32008-07-14 09:58:45 +0200182 .sch_event = io_subchannel_sch_event,
183 .chp_event = io_subchannel_chp_event,
Cornelia Huck8bbace72006-01-11 10:56:22 +0100184 .probe = io_subchannel_probe,
185 .remove = io_subchannel_remove,
186 .shutdown = io_subchannel_shutdown,
Cornelia Huck93a27592009-06-16 10:30:23 +0200187 .prepare = io_subchannel_prepare,
Sebastian Ott8ea7f552009-09-22 22:58:35 +0200188 .settle = io_subchannel_settle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
Sebastian Ott2f176442009-09-22 22:58:33 +0200191int __init io_subchannel_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 int ret;
194
195 init_waitqueue_head(&ccw_device_init_wq);
196 atomic_set(&ccw_device_init_count, 0);
Peter Oberparleiter90ab1332008-01-26 14:10:52 +0100197 setup_timer(&recovery_timer, recovery_func, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Sebastian Ottbe5d3822010-02-26 22:37:24 +0100199 ret = bus_register(&ccw_bus_type);
200 if (ret)
201 return ret;
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100202 ret = css_driver_register(&io_subchannel_driver);
203 if (ret)
Sebastian Ottbe5d3822010-02-26 22:37:24 +0100204 bus_unregister(&ccw_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return ret;
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/************************ device handling **************************/
211
212/*
213 * A ccw_device has some interfaces in sysfs in addition to the
214 * standard ones.
215 * The following entries are designed to export the information which
216 * resided in 2.4 in /proc/subchannels. Subchannel and device number
217 * are obvious, so they don't have an entry :)
218 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
219 */
220static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400221chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 struct subchannel *sch = to_subchannel(dev);
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200224 struct chsc_ssd_info *ssd = &sch->ssd_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 ssize_t ret = 0;
226 int chp;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200227 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200229 for (chp = 0; chp < 8; chp++) {
230 mask = 0x80 >> chp;
231 if (ssd->path_mask & mask)
232 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
233 else
234 ret += sprintf(buf + ret, "00 ");
235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 ret += sprintf (buf+ret, "\n");
237 return min((ssize_t)PAGE_SIZE, ret);
238}
239
240static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400241pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
243 struct subchannel *sch = to_subchannel(dev);
244 struct pmcw *pmcw = &sch->schib.pmcw;
245
246 return sprintf (buf, "%02x %02x %02x\n",
247 pmcw->pim, pmcw->pam, pmcw->pom);
248}
249
250static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400251devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 struct ccw_device *cdev = to_ccwdev(dev);
254 struct ccw_device_id *id = &(cdev->id);
255
256 if (id->dev_type != 0)
257 return sprintf(buf, "%04x/%02x\n",
258 id->dev_type, id->dev_model);
259 else
260 return sprintf(buf, "n/a\n");
261}
262
263static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400264cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 struct ccw_device *cdev = to_ccwdev(dev);
267 struct ccw_device_id *id = &(cdev->id);
268
269 return sprintf(buf, "%04x/%02x\n",
270 id->cu_type, id->cu_model);
271}
272
273static ssize_t
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800274modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
275{
276 struct ccw_device *cdev = to_ccwdev(dev);
277 struct ccw_device_id *id = &(cdev->id);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200278 int len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800279
Cornelia Huck086a6c62007-07-17 13:36:08 +0200280 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200281
282 return len > PAGE_SIZE ? PAGE_SIZE : len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800283}
284
285static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400286online_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct ccw_device *cdev = to_ccwdev(dev);
289
290 return sprintf(buf, cdev->online ? "1\n" : "0\n");
291}
292
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100293int ccw_device_is_orphan(struct ccw_device *cdev)
294{
295 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
296}
297
Cornelia Huckef995162007-04-27 16:01:39 +0200298static void ccw_device_unregister(struct ccw_device *cdev)
Cornelia Huck7674da72006-12-08 15:54:21 +0100299{
Sebastian Ott7d253b92009-12-07 12:51:33 +0100300 if (device_is_registered(&cdev->dev)) {
Sebastian Ott24a18722009-12-07 12:51:34 +0100301 /* Undo device_add(). */
Cornelia Huckef995162007-04-27 16:01:39 +0200302 device_del(&cdev->dev);
Sebastian Ott24a18722009-12-07 12:51:34 +0100303 }
304 if (cdev->private->flags.initialized) {
305 cdev->private->flags.initialized = 0;
Sebastian Ott3b554a12009-09-11 10:28:26 +0200306 /* Release reference from device_initialize(). */
307 put_device(&cdev->dev);
308 }
Cornelia Huck7674da72006-12-08 15:54:21 +0100309}
310
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100311static void io_subchannel_quiesce(struct subchannel *);
312
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200313/**
314 * ccw_device_set_offline() - disable a ccw device for I/O
315 * @cdev: target ccw device
316 *
317 * This function calls the driver's set_offline() function for @cdev, if
318 * given, and then disables @cdev.
319 * Returns:
320 * %0 on success and a negative error value on failure.
321 * Context:
322 * enabled, ccw device lock not held
323 */
324int ccw_device_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100326 struct subchannel *sch;
327 int ret, state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (!cdev)
330 return -ENODEV;
331 if (!cdev->online || !cdev->drv)
332 return -EINVAL;
333
334 if (cdev->drv->set_offline) {
335 ret = cdev->drv->set_offline(cdev);
336 if (ret != 0)
337 return ret;
338 }
339 cdev->online = 0;
340 spin_lock_irq(cdev->ccwlock);
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100341 sch = to_subchannel(cdev->dev.parent);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200342 /* Wait until a final state or DISCONNECTED is reached */
343 while (!dev_fsm_final_state(cdev) &&
344 cdev->private->state != DEV_STATE_DISCONNECTED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 spin_unlock_irq(cdev->ccwlock);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200346 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
347 cdev->private->state == DEV_STATE_DISCONNECTED));
348 spin_lock_irq(cdev->ccwlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
Sebastian Ottd40f7b72009-12-07 12:51:41 +0100350 do {
351 ret = ccw_device_offline(cdev);
352 if (!ret)
353 break;
354 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device "
355 "0.%x.%04x\n", ret, cdev->private->dev_id.ssid,
356 cdev->private->dev_id.devno);
357 if (ret != -EBUSY)
358 goto error;
359 state = cdev->private->state;
360 spin_unlock_irq(cdev->ccwlock);
361 io_subchannel_quiesce(sch);
362 spin_lock_irq(cdev->ccwlock);
363 cdev->private->state = state;
364 } while (ret == -EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 spin_unlock_irq(cdev->ccwlock);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200366 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
367 cdev->private->state == DEV_STATE_DISCONNECTED));
Peter Oberparleitera7ae2c02009-12-07 12:51:20 +0100368 /* Inform the user if set offline failed. */
369 if (cdev->private->state == DEV_STATE_BOXED) {
370 pr_warning("%s: The device entered boxed state while "
371 "being set offline\n", dev_name(&cdev->dev));
372 } else if (cdev->private->state == DEV_STATE_NOT_OPER) {
373 pr_warning("%s: The device stopped operating while "
374 "being set offline\n", dev_name(&cdev->dev));
375 }
Michael Ernst217ee6c2009-09-11 10:28:21 +0200376 /* Give up reference from ccw_device_set_online(). */
377 put_device(&cdev->dev);
378 return 0;
379
380error:
Michael Ernst217ee6c2009-09-11 10:28:21 +0200381 cdev->private->state = DEV_STATE_OFFLINE;
382 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
383 spin_unlock_irq(cdev->ccwlock);
384 /* Give up reference from ccw_device_set_online(). */
385 put_device(&cdev->dev);
386 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200389/**
390 * ccw_device_set_online() - enable a ccw device for I/O
391 * @cdev: target ccw device
392 *
393 * This function first enables @cdev and then calls the driver's set_online()
394 * function for @cdev, if given. If set_online() returns an error, @cdev is
395 * disabled again.
396 * Returns:
397 * %0 on success and a negative error value on failure.
398 * Context:
399 * enabled, ccw device lock not held
400 */
401int ccw_device_set_online(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 int ret;
Michael Ernst217ee6c2009-09-11 10:28:21 +0200404 int ret2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 if (!cdev)
407 return -ENODEV;
408 if (cdev->online || !cdev->drv)
409 return -EINVAL;
Cornelia Huck9cd67422008-12-25 13:39:06 +0100410 /* Hold on to an extra reference while device is online. */
411 if (!get_device(&cdev->dev))
412 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 spin_lock_irq(cdev->ccwlock);
415 ret = ccw_device_online(cdev);
416 spin_unlock_irq(cdev->ccwlock);
417 if (ret == 0)
418 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
419 else {
Michael Ernst139b83d2008-05-07 09:22:54 +0200420 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200421 "device 0.%x.%04x\n",
422 ret, cdev->private->dev_id.ssid,
423 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +0100424 /* Give up online reference since onlining failed. */
425 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return ret;
427 }
Michael Ernst217ee6c2009-09-11 10:28:21 +0200428 spin_lock_irq(cdev->ccwlock);
429 /* Check if online processing was successful */
430 if ((cdev->private->state != DEV_STATE_ONLINE) &&
431 (cdev->private->state != DEV_STATE_W4SENSE)) {
432 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleitera7ae2c02009-12-07 12:51:20 +0100433 /* Inform the user that set online failed. */
434 if (cdev->private->state == DEV_STATE_BOXED) {
435 pr_warning("%s: Setting the device online failed "
436 "because it is boxed\n",
437 dev_name(&cdev->dev));
438 } else if (cdev->private->state == DEV_STATE_NOT_OPER) {
439 pr_warning("%s: Setting the device online failed "
440 "because it is not operational\n",
441 dev_name(&cdev->dev));
442 }
Cornelia Huck9cd67422008-12-25 13:39:06 +0100443 /* Give up online reference since onlining failed. */
444 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return -ENODEV;
Cornelia Huck9cd67422008-12-25 13:39:06 +0100446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 spin_unlock_irq(cdev->ccwlock);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200448 if (cdev->drv->set_online)
449 ret = cdev->drv->set_online(cdev);
450 if (ret)
451 goto rollback;
452 cdev->online = 1;
453 return 0;
454
455rollback:
456 spin_lock_irq(cdev->ccwlock);
457 /* Wait until a final state or DISCONNECTED is reached */
458 while (!dev_fsm_final_state(cdev) &&
459 cdev->private->state != DEV_STATE_DISCONNECTED) {
460 spin_unlock_irq(cdev->ccwlock);
461 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
462 cdev->private->state == DEV_STATE_DISCONNECTED));
463 spin_lock_irq(cdev->ccwlock);
464 }
465 ret2 = ccw_device_offline(cdev);
466 if (ret2)
467 goto error;
468 spin_unlock_irq(cdev->ccwlock);
469 wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
470 cdev->private->state == DEV_STATE_DISCONNECTED));
Cornelia Huck9cd67422008-12-25 13:39:06 +0100471 /* Give up online reference since onlining failed. */
472 put_device(&cdev->dev);
Michael Ernst217ee6c2009-09-11 10:28:21 +0200473 return ret;
474
475error:
476 CIO_MSG_EVENT(0, "rollback ccw_device_offline returned %d, "
477 "device 0.%x.%04x\n",
478 ret2, cdev->private->dev_id.ssid,
479 cdev->private->dev_id.devno);
480 cdev->private->state = DEV_STATE_OFFLINE;
481 spin_unlock_irq(cdev->ccwlock);
482 /* Give up online reference since onlining failed. */
483 put_device(&cdev->dev);
484 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100487static int online_store_handle_offline(struct ccw_device *cdev)
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200488{
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100489 if (cdev->private->state == DEV_STATE_DISCONNECTED) {
490 spin_lock_irq(cdev->ccwlock);
491 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL);
492 spin_unlock_irq(cdev->ccwlock);
Sebastian Ott7cd40312010-08-09 18:12:52 +0200493 return 0;
494 }
495 if (cdev->drv && cdev->drv->set_offline)
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100496 return ccw_device_set_offline(cdev);
Sebastian Ott7cd40312010-08-09 18:12:52 +0200497 return -EINVAL;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200498}
499
500static int online_store_recog_and_online(struct ccw_device *cdev)
501{
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200502 /* Do device recognition, if needed. */
Sebastian Ott99f6a5702009-03-31 19:16:07 +0200503 if (cdev->private->state == DEV_STATE_BOXED) {
Peter Oberparleiter1f5bd382009-12-07 12:51:23 +0100504 spin_lock_irq(cdev->ccwlock);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100505 ccw_device_recognition(cdev);
Peter Oberparleiter1f5bd382009-12-07 12:51:23 +0100506 spin_unlock_irq(cdev->ccwlock);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200507 wait_event(cdev->private->wait_q,
508 cdev->private->flags.recog_done);
Sebastian Ott156013f2009-03-31 19:16:03 +0200509 if (cdev->private->state != DEV_STATE_OFFLINE)
510 /* recognition failed */
511 return -EAGAIN;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200512 }
513 if (cdev->drv && cdev->drv->set_online)
Sebastian Ott7cd40312010-08-09 18:12:52 +0200514 return ccw_device_set_online(cdev);
515 return -EINVAL;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200516}
Sebastian Ott156013f2009-03-31 19:16:03 +0200517
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200518static int online_store_handle_online(struct ccw_device *cdev, int force)
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200519{
520 int ret;
521
522 ret = online_store_recog_and_online(cdev);
Sebastian Ott156013f2009-03-31 19:16:03 +0200523 if (ret && !force)
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200524 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200525 if (force && cdev->private->state == DEV_STATE_BOXED) {
526 ret = ccw_device_stlck(cdev);
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200527 if (ret)
528 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200529 if (cdev->id.cu_type == 0)
530 cdev->private->state = DEV_STATE_NOT_OPER;
Sebastian Ott156013f2009-03-31 19:16:03 +0200531 ret = online_store_recog_and_online(cdev);
532 if (ret)
533 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200534 }
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200535 return 0;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200536}
537
538static ssize_t online_store (struct device *dev, struct device_attribute *attr,
539 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
541 struct ccw_device *cdev = to_ccwdev(dev);
Cornelia Huck2f972202008-04-30 13:38:33 +0200542 int force, ret;
543 unsigned long i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200545 /* Prevent conflict between multiple on-/offline processing requests. */
Peter Oberparleiter350e9122009-12-07 12:51:28 +0100546 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return -EAGAIN;
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200548 /* Prevent conflict between internal I/Os and on-/offline processing. */
549 if (!dev_fsm_final_state(cdev) &&
550 cdev->private->state != DEV_STATE_DISCONNECTED) {
551 ret = -EAGAIN;
552 goto out_onoff;
553 }
554 /* Prevent conflict between pending work and on-/offline processing.*/
555 if (work_pending(&cdev->private->todo_work)) {
556 ret = -EAGAIN;
557 goto out_onoff;
558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Sebastian Ott3bda0582011-03-23 10:16:02 +0100560 if (cdev->drv && !try_module_get(cdev->drv->driver.owner)) {
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200561 ret = -EINVAL;
562 goto out_onoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
564 if (!strncmp(buf, "force\n", count)) {
565 force = 1;
566 i = 1;
Cornelia Huck2f972202008-04-30 13:38:33 +0200567 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 } else {
569 force = 0;
Cornelia Huck2f972202008-04-30 13:38:33 +0200570 ret = strict_strtoul(buf, 16, &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
Cornelia Huck2f972202008-04-30 13:38:33 +0200572 if (ret)
573 goto out;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200574 switch (i) {
575 case 0:
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100576 ret = online_store_handle_offline(cdev);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200577 break;
578 case 1:
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200579 ret = online_store_handle_online(cdev, force);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200580 break;
581 default:
Cornelia Huck2f972202008-04-30 13:38:33 +0200582 ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 }
Cornelia Huck2f972202008-04-30 13:38:33 +0200584out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 if (cdev->drv)
Sebastian Ott3bda0582011-03-23 10:16:02 +0100586 module_put(cdev->drv->driver.owner);
Peter Oberparleitera2fc8482011-04-04 09:43:32 +0200587out_onoff:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 atomic_set(&cdev->private->onoff, 0);
Sebastian Otte74fe0c2009-03-26 15:24:08 +0100589 return (ret < 0) ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400593available_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
595 struct ccw_device *cdev = to_ccwdev(dev);
596 struct subchannel *sch;
597
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100598 if (ccw_device_is_orphan(cdev))
599 return sprintf(buf, "no device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 switch (cdev->private->state) {
601 case DEV_STATE_BOXED:
602 return sprintf(buf, "boxed\n");
603 case DEV_STATE_DISCONNECTED:
604 case DEV_STATE_DISCONNECTED_SENSE_ID:
605 case DEV_STATE_NOT_OPER:
606 sch = to_subchannel(dev->parent);
607 if (!sch->lpm)
608 return sprintf(buf, "no path\n");
609 else
610 return sprintf(buf, "no device\n");
611 default:
612 /* All other states considered fine. */
613 return sprintf(buf, "good\n");
614 }
615}
616
Michael Ernstfd0457a2010-08-09 18:12:50 +0200617static ssize_t
618initiate_logging(struct device *dev, struct device_attribute *attr,
619 const char *buf, size_t count)
620{
621 struct subchannel *sch = to_subchannel(dev);
622 int rc;
623
624 rc = chsc_siosl(sch->schid);
625 if (rc < 0) {
626 pr_warning("Logging for subchannel 0.%x.%04x failed with "
627 "errno=%d\n",
628 sch->schid.ssid, sch->schid.sch_no, rc);
629 return rc;
630 }
631 pr_notice("Logging for subchannel 0.%x.%04x was triggered\n",
632 sch->schid.ssid, sch->schid.sch_no);
633 return count;
634}
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
637static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
638static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
639static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800640static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641static DEVICE_ATTR(online, 0644, online_show, online_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642static DEVICE_ATTR(availability, 0444, available_show, NULL);
Michael Ernstfd0457a2010-08-09 18:12:50 +0200643static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200645static struct attribute *io_subchannel_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 &dev_attr_chpids.attr,
647 &dev_attr_pimpampom.attr,
Michael Ernstfd0457a2010-08-09 18:12:50 +0200648 &dev_attr_logging.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 NULL,
650};
651
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200652static struct attribute_group io_subchannel_attr_group = {
653 .attrs = io_subchannel_attrs,
Cornelia Huck529192f2006-12-08 15:55:57 +0100654};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656static struct attribute * ccwdev_attrs[] = {
657 &dev_attr_devtype.attr,
658 &dev_attr_cutype.attr,
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800659 &dev_attr_modalias.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 &dev_attr_online.attr,
661 &dev_attr_cmb_enable.attr,
662 &dev_attr_availability.attr,
663 NULL,
664};
665
666static struct attribute_group ccwdev_attr_group = {
667 .attrs = ccwdev_attrs,
668};
669
David Brownella4dbd672009-06-24 10:06:31 -0700670static const struct attribute_group *ccwdev_attr_groups[] = {
Cornelia Huckef995162007-04-27 16:01:39 +0200671 &ccwdev_attr_group,
672 NULL,
673};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675/* this is a simple abstraction for device_register that sets the
676 * correct bus type and adds the bus specific files */
Cornelia Huck3c9da7b2006-10-27 12:39:33 +0200677static int ccw_device_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
679 struct device *dev = &cdev->dev;
680 int ret;
681
682 dev->bus = &ccw_bus_type;
Sebastian Ott3ac276f2009-09-11 10:28:27 +0200683 ret = dev_set_name(&cdev->dev, "0.%x.%04x", cdev->private->dev_id.ssid,
684 cdev->private->dev_id.devno);
685 if (ret)
686 return ret;
Sebastian Ott7d253b92009-12-07 12:51:33 +0100687 return device_add(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100690static int match_dev_id(struct device *dev, void *data)
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700691{
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100692 struct ccw_device *cdev = to_ccwdev(dev);
693 struct ccw_dev_id *dev_id = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700694
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100695 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
696}
697
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100698static struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id)
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100699{
700 struct device *dev;
701
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100702 dev = bus_find_device(&ccw_bus_type, NULL, dev_id, match_dev_id);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100703
704 return dev ? to_ccwdev(dev) : NULL;
705}
706
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100707static void ccw_device_do_unbind_bind(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Cornelia Huckeb32ae82009-03-26 15:24:05 +0100709 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Sebastian Ott7d253b92009-12-07 12:51:33 +0100711 if (device_is_registered(&cdev->dev)) {
Cornelia Huckeb32ae82009-03-26 15:24:05 +0100712 device_release_driver(&cdev->dev);
713 ret = device_attach(&cdev->dev);
714 WARN_ON(ret == -ENODEV);
715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718static void
719ccw_device_release(struct device *dev)
720{
721 struct ccw_device *cdev;
722
723 cdev = to_ccwdev(dev);
Cornelia Huck6eff2082008-12-25 13:39:07 +0100724 /* Release reference of parent subchannel. */
725 put_device(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 kfree(cdev->private);
727 kfree(cdev);
728}
729
Cornelia Huck7674da72006-12-08 15:54:21 +0100730static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
731{
732 struct ccw_device *cdev;
733
734 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
735 if (cdev) {
736 cdev->private = kzalloc(sizeof(struct ccw_device_private),
737 GFP_KERNEL | GFP_DMA);
738 if (cdev->private)
739 return cdev;
740 }
741 kfree(cdev);
742 return ERR_PTR(-ENOMEM);
743}
744
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100745static void ccw_device_todo(struct work_struct *work);
746
Cornelia Huck7674da72006-12-08 15:54:21 +0100747static int io_subchannel_initialize_dev(struct subchannel *sch,
748 struct ccw_device *cdev)
749{
750 cdev->private->cdev = cdev;
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100751 cdev->private->int_class = IOINT_CIO;
Cornelia Huck7674da72006-12-08 15:54:21 +0100752 atomic_set(&cdev->private->onoff, 0);
753 cdev->dev.parent = &sch->dev;
754 cdev->dev.release = ccw_device_release;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100755 INIT_WORK(&cdev->private->todo_work, ccw_device_todo);
Cornelia Huckef995162007-04-27 16:01:39 +0200756 cdev->dev.groups = ccwdev_attr_groups;
Cornelia Huck7674da72006-12-08 15:54:21 +0100757 /* Do first half of device_register. */
758 device_initialize(&cdev->dev);
759 if (!get_device(&sch->dev)) {
Cornelia Huck283fdd02008-12-25 13:39:10 +0100760 /* Release reference from device_initialize(). */
761 put_device(&cdev->dev);
Cornelia Huck7674da72006-12-08 15:54:21 +0100762 return -ENODEV;
763 }
Sebastian Ott24a18722009-12-07 12:51:34 +0100764 cdev->private->flags.initialized = 1;
Cornelia Huck7674da72006-12-08 15:54:21 +0100765 return 0;
766}
767
768static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
769{
770 struct ccw_device *cdev;
771 int ret;
772
773 cdev = io_subchannel_allocate_dev(sch);
774 if (!IS_ERR(cdev)) {
775 ret = io_subchannel_initialize_dev(sch, cdev);
Sebastian Ott06739a82009-08-23 18:09:04 +0200776 if (ret)
Cornelia Huck7674da72006-12-08 15:54:21 +0100777 cdev = ERR_PTR(ret);
Cornelia Huck7674da72006-12-08 15:54:21 +0100778 }
779 return cdev;
780}
781
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100782static void io_subchannel_recog(struct ccw_device *, struct subchannel *);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100783
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100784static void sch_create_and_recog_new_device(struct subchannel *sch)
785{
786 struct ccw_device *cdev;
787
788 /* Need to allocate a new ccw device. */
789 cdev = io_subchannel_create_ccwdev(sch);
790 if (IS_ERR(cdev)) {
791 /* OK, we did everything we could... */
792 css_sch_device_unregister(sch);
793 return;
794 }
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100795 /* Start recognition for the new ccw device. */
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100796 io_subchannel_recog(cdev, sch);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100797}
798
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799/*
800 * Register recognized device.
801 */
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100802static void io_subchannel_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 struct subchannel *sch;
Sebastian Otta2901562010-03-08 12:25:17 +0100805 int ret, adjust_init_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 unsigned long flags;
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100809 /*
810 * Check if subchannel is still registered. It may have become
811 * unregistered if a machine check hit us after finishing
812 * device recognition but before the register work could be
813 * queued.
814 */
815 if (!device_is_registered(&sch->dev))
816 goto out_err;
Cornelia Huck82b7ac02007-04-27 16:01:36 +0200817 css_update_ssd_info(sch);
Cornelia Huck47af5512006-12-04 15:41:07 +0100818 /*
819 * io_subchannel_register() will also be called after device
820 * recognition has been done for a boxed device (which will already
821 * be registered). We need to reprobe since we may now have sense id
822 * information.
823 */
Cornelia Huckd6a30762008-12-25 13:39:11 +0100824 if (device_is_registered(&cdev->dev)) {
Cornelia Huck47af5512006-12-04 15:41:07 +0100825 if (!cdev->drv) {
826 ret = device_reprobe(&cdev->dev);
827 if (ret)
828 /* We can't do much here. */
Michael Ernst139b83d2008-05-07 09:22:54 +0200829 CIO_MSG_EVENT(0, "device_reprobe() returned"
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200830 " %d for 0.%x.%04x\n", ret,
831 cdev->private->dev_id.ssid,
832 cdev->private->dev_id.devno);
Cornelia Huck47af5512006-12-04 15:41:07 +0100833 }
Sebastian Otta2901562010-03-08 12:25:17 +0100834 adjust_init_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 goto out;
836 }
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700837 /*
838 * Now we know this subchannel will stay, we can throw
839 * our delayed uevent.
840 */
Ming Leif67f1292009-03-01 21:10:49 +0800841 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700842 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 /* make it known to the system */
844 ret = ccw_device_register(cdev);
845 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200846 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
847 cdev->private->dev_id.ssid,
848 cdev->private->dev_id.devno, ret);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100849 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100850 sch_set_cdev(sch, NULL);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100851 spin_unlock_irqrestore(sch->lock, flags);
Cornelia Huck6eff2082008-12-25 13:39:07 +0100852 /* Release initial device reference. */
853 put_device(&cdev->dev);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100854 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856out:
857 cdev->private->flags.recog_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 wake_up(&cdev->private->wait_q);
Cornelia Huck5fb6b852008-12-25 13:39:08 +0100859out_err:
Sebastian Otta2901562010-03-08 12:25:17 +0100860 if (adjust_init_count && atomic_dec_and_test(&ccw_device_init_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 wake_up(&ccw_device_init_wq);
862}
863
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100864static void ccw_device_call_sch_unregister(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 struct subchannel *sch;
867
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200868 /* Get subchannel reference for local processing. */
869 if (!get_device(cdev->dev.parent))
870 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200872 css_sch_device_unregister(sch);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200873 /* Release subchannel reference for local processing. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 put_device(&sch->dev);
875}
876
877/*
878 * subchannel recognition done. Called from the state machine.
879 */
880void
881io_subchannel_recog_done(struct ccw_device *cdev)
882{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 if (css_init_done == 0) {
884 cdev->private->flags.recog_done = 1;
885 return;
886 }
887 switch (cdev->private->state) {
Sebastian Ott47593bf2009-03-31 19:16:05 +0200888 case DEV_STATE_BOXED:
889 /* Device did not respond in time. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 case DEV_STATE_NOT_OPER:
891 cdev->private->flags.recog_done = 1;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100892 /* Remove device found not operational. */
893 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 if (atomic_dec_and_test(&ccw_device_init_count))
895 wake_up(&ccw_device_init_wq);
896 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 case DEV_STATE_OFFLINE:
898 /*
899 * We can't register the device in interrupt context so
900 * we schedule a work item.
901 */
Peter Oberparleiter37de53b2009-12-07 12:51:19 +0100902 ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 break;
904 }
905}
906
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100907static void io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 struct ccw_device_private *priv;
910
Cornelia Huck2ec22982006-12-08 15:54:26 +0100911 cdev->ccwlock = sch->lock;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 /* Init private data. */
914 priv = cdev->private;
Cornelia Huck78964262006-10-11 15:31:38 +0200915 priv->dev_id.devno = sch->schib.pmcw.dev;
916 priv->dev_id.ssid = sch->schid.ssid;
917 priv->schid = sch->schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 priv->state = DEV_STATE_NOT_OPER;
919 INIT_LIST_HEAD(&priv->cmb_list);
920 init_waitqueue_head(&priv->wait_q);
921 init_timer(&priv->timer);
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* Increase counter of devices currently in recognition. */
924 atomic_inc(&ccw_device_init_count);
925
926 /* Start async. device sensing. */
Cornelia Huck2ec22982006-12-08 15:54:26 +0100927 spin_lock_irq(sch->lock);
Peter Oberparleiter60e4dac2009-12-07 12:51:16 +0100928 sch_set_cdev(sch, cdev);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +0100929 ccw_device_recognition(cdev);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100930 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100933static int ccw_device_move_to_sch(struct ccw_device *cdev,
934 struct subchannel *sch)
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100935{
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100936 struct subchannel *old_sch;
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100937 int rc, old_enabled = 0;
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100938
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100939 old_sch = to_subchannel(cdev->dev.parent);
940 /* Obtain child reference for new parent. */
Cornelia Huck6eff2082008-12-25 13:39:07 +0100941 if (!get_device(&sch->dev))
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100942 return -ENODEV;
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100943
944 if (!sch_is_pseudo_sch(old_sch)) {
945 spin_lock_irq(old_sch->lock);
946 old_enabled = old_sch->schib.pmcw.ena;
947 rc = 0;
948 if (old_enabled)
949 rc = cio_disable_subchannel(old_sch);
950 spin_unlock_irq(old_sch->lock);
951 if (rc == -EBUSY) {
952 /* Release child reference for new parent. */
953 put_device(&sch->dev);
954 return rc;
955 }
956 }
957
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100958 mutex_lock(&sch->reg_mutex);
Cornelia Huckffa6a702009-03-04 12:44:00 +0100959 rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100960 mutex_unlock(&sch->reg_mutex);
961 if (rc) {
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100962 CIO_MSG_EVENT(0, "device_move(0.%x.%04x,0.%x.%04x)=%d\n",
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100963 cdev->private->dev_id.ssid,
964 cdev->private->dev_id.devno, sch->schid.ssid,
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100965 sch->schib.pmcw.dev, rc);
Sebastian Ott0c609fc2009-12-07 12:51:37 +0100966 if (old_enabled) {
967 /* Try to reenable the old subchannel. */
968 spin_lock_irq(old_sch->lock);
969 cio_enable_subchannel(old_sch, (u32)(addr_t)old_sch);
970 spin_unlock_irq(old_sch->lock);
971 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100972 /* Release child reference for new parent. */
Cornelia Huck6eff2082008-12-25 13:39:07 +0100973 put_device(&sch->dev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100974 return rc;
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100975 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100976 /* Clean up old subchannel. */
977 if (!sch_is_pseudo_sch(old_sch)) {
978 spin_lock_irq(old_sch->lock);
979 sch_set_cdev(old_sch, NULL);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100980 spin_unlock_irq(old_sch->lock);
981 css_schedule_eval(old_sch->schid);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100982 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +0100983 /* Release child reference for old parent. */
984 put_device(&old_sch->dev);
985 /* Initialize new subchannel. */
986 spin_lock_irq(sch->lock);
987 cdev->private->schid = sch->schid;
988 cdev->ccwlock = sch->lock;
989 if (!sch_is_pseudo_sch(sch))
990 sch_set_cdev(sch, cdev);
991 spin_unlock_irq(sch->lock);
992 if (!sch_is_pseudo_sch(sch))
993 css_update_ssd_info(sch);
994 return 0;
995}
996
997static int ccw_device_move_to_orph(struct ccw_device *cdev)
998{
999 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1000 struct channel_subsystem *css = to_css(sch->dev.parent);
1001
1002 return ccw_device_move_to_sch(cdev, css->pseudo_subchannel);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +01001003}
1004
Cornelia Huck602b20f2008-01-26 14:10:39 +01001005static void io_subchannel_irq(struct subchannel *sch)
1006{
1007 struct ccw_device *cdev;
1008
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001009 cdev = sch_get_cdev(sch);
Cornelia Huck602b20f2008-01-26 14:10:39 +01001010
Sebastian Ottefd986d2009-09-11 10:28:18 +02001011 CIO_TRACE_EVENT(6, "IRQ");
1012 CIO_TRACE_EVENT(6, dev_name(&sch->dev));
Cornelia Huck602b20f2008-01-26 14:10:39 +01001013 if (cdev)
1014 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001015 else
1016 kstat_cpu(smp_processor_id()).irqs[IOINT_CIO]++;
Cornelia Huck602b20f2008-01-26 14:10:39 +01001017}
1018
Sebastian Ott13952ec12008-12-25 13:39:13 +01001019void io_subchannel_init_config(struct subchannel *sch)
1020{
1021 memset(&sch->config, 0, sizeof(sch->config));
1022 sch->config.csense = 1;
Sebastian Ott13952ec12008-12-25 13:39:13 +01001023}
1024
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001025static void io_subchannel_init_fields(struct subchannel *sch)
1026{
1027 if (cio_is_console(sch->schid))
1028 sch->opm = 0xff;
1029 else
1030 sch->opm = chp_get_sch_opm(sch);
1031 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Cornelia Huck3a3fc292008-07-14 09:58:58 +02001032 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001033
1034 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1035 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1036 sch->schib.pmcw.dev, sch->schid.ssid,
1037 sch->schid.sch_no, sch->schib.pmcw.pim,
1038 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
Sebastian Ott13952ec12008-12-25 13:39:13 +01001039
1040 io_subchannel_init_config(sch);
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001041}
1042
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001043/*
1044 * Note: We always return 0 so that we bind to the device even on error.
1045 * This is needed so that our remove function is called on unregister.
1046 */
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001047static int io_subchannel_probe(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001049 struct io_subchannel_private *io_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 struct ccw_device *cdev;
1051 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001053 if (cio_is_console(sch->schid)) {
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001054 rc = sysfs_create_group(&sch->dev.kobj,
1055 &io_subchannel_attr_group);
1056 if (rc)
1057 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1058 "attributes for subchannel "
1059 "0.%x.%04x (rc=%d)\n",
1060 sch->schid.ssid, sch->schid.sch_no, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 /*
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001062 * The console subchannel already has an associated ccw_device.
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001063 * Throw the delayed uevent for the subchannel, register
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001064 * the ccw_device and exit.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 */
Ming Leif67f1292009-03-01 21:10:49 +08001066 dev_set_uevent_suppress(&sch->dev, 0);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001067 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Peter Oberparleiter6d7c5af2009-10-14 12:43:50 +02001068 cdev = sch_get_cdev(sch);
Cornelia Hucke1031782007-10-12 16:11:23 +02001069 cdev->dev.groups = ccwdev_attr_groups;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 device_initialize(&cdev->dev);
Sebastian Ott24a18722009-12-07 12:51:34 +01001071 cdev->private->flags.initialized = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 ccw_device_register(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 /*
1074 * Check if the device is already online. If it is
Cornelia Huck9cd67422008-12-25 13:39:06 +01001075 * the reference count needs to be corrected since we
1076 * didn't obtain a reference in ccw_device_set_online.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 */
1078 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1079 cdev->private->state != DEV_STATE_OFFLINE &&
1080 cdev->private->state != DEV_STATE_BOXED)
1081 get_device(&cdev->dev);
1082 return 0;
1083 }
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001084 io_subchannel_init_fields(sch);
Sebastian Ottf444cc02008-12-25 13:39:14 +01001085 rc = cio_commit_config(sch);
1086 if (rc)
1087 goto out_schedule;
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001088 rc = sysfs_create_group(&sch->dev.kobj,
1089 &io_subchannel_attr_group);
1090 if (rc)
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001091 goto out_schedule;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001092 /* Allocate I/O subchannel private data. */
Sebastian Ottf92519e2011-03-15 17:08:27 +01001093 io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA);
1094 if (!io_priv)
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001095 goto out_schedule;
Sebastian Ottf92519e2011-03-15 17:08:27 +01001096
1097 set_io_private(sch, io_priv);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001098 css_schedule_eval(sch->schid);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001099 return 0;
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001100
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001101out_schedule:
Peter Oberparleiter390935a2009-12-07 12:51:18 +01001102 spin_lock_irq(sch->lock);
1103 css_sched_sch_todo(sch, SCH_TODO_UNREG);
1104 spin_unlock_irq(sch->lock);
Cornelia Huck90ed2b62008-12-25 13:39:09 +01001105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108static int
Cornelia Huck8bbace72006-01-11 10:56:22 +01001109io_subchannel_remove (struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001111 struct io_subchannel_private *io_priv = to_io_private(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 struct ccw_device *cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001114 cdev = sch_get_cdev(sch);
1115 if (!cdev)
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001116 goto out_free;
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001117 io_subchannel_quiesce(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 /* Set ccw device to not operational and drop reference. */
Sebastian Ott7a8ad102009-12-07 12:51:39 +01001119 spin_lock_irq(cdev->ccwlock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001120 sch_set_cdev(sch, NULL);
Sebastian Ottf92519e2011-03-15 17:08:27 +01001121 set_io_private(sch, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 cdev->private->state = DEV_STATE_NOT_OPER;
Sebastian Ott7a8ad102009-12-07 12:51:39 +01001123 spin_unlock_irq(cdev->ccwlock);
Cornelia Huckef995162007-04-27 16:01:39 +02001124 ccw_device_unregister(cdev);
Peter Oberparleiter48e4c382009-12-07 12:51:15 +01001125out_free:
Sebastian Ottf92519e2011-03-15 17:08:27 +01001126 kfree(io_priv);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001127 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 return 0;
1129}
1130
Cornelia Huck602b20f2008-01-26 14:10:39 +01001131static void io_subchannel_verify(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
1133 struct ccw_device *cdev;
1134
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001135 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 if (cdev)
1137 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1138}
1139
Cornelia Huckc820de32008-07-14 09:58:45 +02001140static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
1142 struct ccw_device *cdev;
1143
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001144 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 if (!cdev)
1146 return;
Peter Oberparleiter4257aae2009-12-07 12:51:29 +01001147 if (cio_update_schib(sch))
1148 goto err;
1149 /* Check for I/O on path. */
1150 if (scsw_actl(&sch->schib.scsw) == 0 || sch->schib.pmcw.lpum != mask)
1151 goto out;
1152 if (cdev->private->state == DEV_STATE_ONLINE) {
1153 ccw_device_kill_io(cdev);
1154 goto out;
1155 }
1156 if (cio_clear(sch))
1157 goto err;
1158out:
1159 /* Trigger path verification. */
1160 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1161 return;
Cornelia Huckc820de32008-07-14 09:58:45 +02001162
Peter Oberparleiter4257aae2009-12-07 12:51:29 +01001163err:
1164 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
Cornelia Huckc820de32008-07-14 09:58:45 +02001165}
1166
Cornelia Huck99611f82008-07-14 09:59:02 +02001167static int io_subchannel_chp_event(struct subchannel *sch,
1168 struct chp_link *link, int event)
Cornelia Huckc820de32008-07-14 09:58:45 +02001169{
Sebastian Ott585b9542010-10-25 16:10:34 +02001170 struct ccw_device *cdev = sch_get_cdev(sch);
Cornelia Huckc820de32008-07-14 09:58:45 +02001171 int mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001172
Cornelia Huck99611f82008-07-14 09:59:02 +02001173 mask = chp_ssd_get_mask(&sch->ssd_info, link);
Cornelia Huckc820de32008-07-14 09:58:45 +02001174 if (!mask)
1175 return 0;
1176 switch (event) {
1177 case CHP_VARY_OFF:
1178 sch->opm &= ~mask;
1179 sch->lpm &= ~mask;
Sebastian Ott585b9542010-10-25 16:10:34 +02001180 if (cdev)
1181 cdev->private->path_gone_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001182 io_subchannel_terminate_path(sch, mask);
1183 break;
1184 case CHP_VARY_ON:
1185 sch->opm |= mask;
1186 sch->lpm |= mask;
Sebastian Ott585b9542010-10-25 16:10:34 +02001187 if (cdev)
1188 cdev->private->path_new_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001189 io_subchannel_verify(sch);
1190 break;
1191 case CHP_OFFLINE:
Sebastian Ottcdb912a2008-12-25 13:39:12 +01001192 if (cio_update_schib(sch))
Cornelia Huckc820de32008-07-14 09:58:45 +02001193 return -ENODEV;
Sebastian Ott585b9542010-10-25 16:10:34 +02001194 if (cdev)
1195 cdev->private->path_gone_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001196 io_subchannel_terminate_path(sch, mask);
1197 break;
1198 case CHP_ONLINE:
Sebastian Ottcdb912a2008-12-25 13:39:12 +01001199 if (cio_update_schib(sch))
1200 return -ENODEV;
Cornelia Huckc820de32008-07-14 09:58:45 +02001201 sch->lpm |= mask & sch->opm;
Sebastian Ott585b9542010-10-25 16:10:34 +02001202 if (cdev)
1203 cdev->private->path_new_mask |= mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001204 io_subchannel_verify(sch);
1205 break;
1206 }
1207 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208}
1209
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001210static void io_subchannel_quiesce(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 struct ccw_device *cdev;
1213 int ret;
1214
Sebastian Ott56e6b792009-12-07 12:51:35 +01001215 spin_lock_irq(sch->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001216 cdev = sch_get_cdev(sch);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001217 if (cio_is_console(sch->schid))
Sebastian Ott56e6b792009-12-07 12:51:35 +01001218 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 if (!sch->schib.pmcw.ena)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001220 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 ret = cio_disable_subchannel(sch);
1222 if (ret != -EBUSY)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001223 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 if (cdev->handler)
Sebastian Ott56e6b792009-12-07 12:51:35 +01001225 cdev->handler(cdev, cdev->private->intparm, ERR_PTR(-EIO));
1226 while (ret == -EBUSY) {
1227 cdev->private->state = DEV_STATE_QUIESCE;
Peter Oberparleiter376ae472010-10-25 16:10:44 +02001228 cdev->private->iretry = 255;
Sebastian Ott56e6b792009-12-07 12:51:35 +01001229 ret = ccw_device_cancel_halt_clear(cdev);
1230 if (ret == -EBUSY) {
1231 ccw_device_set_timeout(cdev, HZ/10);
1232 spin_unlock_irq(sch->lock);
1233 wait_event(cdev->private->wait_q,
1234 cdev->private->state != DEV_STATE_QUIESCE);
1235 spin_lock_irq(sch->lock);
1236 }
1237 ret = cio_disable_subchannel(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
Sebastian Ott56e6b792009-12-07 12:51:35 +01001239out_unlock:
1240 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Sebastian Ott6e9a0f62009-12-07 12:51:38 +01001243static void io_subchannel_shutdown(struct subchannel *sch)
1244{
1245 io_subchannel_quiesce(sch);
1246}
1247
Cornelia Huckc820de32008-07-14 09:58:45 +02001248static int device_is_disconnected(struct ccw_device *cdev)
1249{
1250 if (!cdev)
1251 return 0;
1252 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1253 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1254}
1255
1256static int recovery_check(struct device *dev, void *data)
1257{
1258 struct ccw_device *cdev = to_ccwdev(dev);
1259 int *redo = data;
1260
1261 spin_lock_irq(cdev->ccwlock);
1262 switch (cdev->private->state) {
1263 case DEV_STATE_DISCONNECTED:
1264 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1265 cdev->private->dev_id.ssid,
1266 cdev->private->dev_id.devno);
1267 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1268 *redo = 1;
1269 break;
1270 case DEV_STATE_DISCONNECTED_SENSE_ID:
1271 *redo = 1;
1272 break;
1273 }
1274 spin_unlock_irq(cdev->ccwlock);
1275
1276 return 0;
1277}
1278
1279static void recovery_work_func(struct work_struct *unused)
1280{
1281 int redo = 0;
1282
1283 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1284 if (redo) {
1285 spin_lock_irq(&recovery_lock);
1286 if (!timer_pending(&recovery_timer)) {
1287 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1288 recovery_phase++;
1289 mod_timer(&recovery_timer, jiffies +
1290 recovery_delay[recovery_phase] * HZ);
1291 }
1292 spin_unlock_irq(&recovery_lock);
1293 } else
1294 CIO_MSG_EVENT(4, "recovery: end\n");
1295}
1296
1297static DECLARE_WORK(recovery_work, recovery_work_func);
1298
1299static void recovery_func(unsigned long data)
1300{
1301 /*
1302 * We can't do our recovery in softirq context and it's not
1303 * performance critical, so we schedule it.
1304 */
1305 schedule_work(&recovery_work);
1306}
1307
1308static void ccw_device_schedule_recovery(void)
1309{
1310 unsigned long flags;
1311
1312 CIO_MSG_EVENT(4, "recovery: schedule\n");
1313 spin_lock_irqsave(&recovery_lock, flags);
1314 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1315 recovery_phase = 0;
1316 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1317 }
1318 spin_unlock_irqrestore(&recovery_lock, flags);
1319}
1320
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001321static int purge_fn(struct device *dev, void *data)
1322{
1323 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001324 struct ccw_dev_id *id = &cdev->private->dev_id;
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001325
1326 spin_lock_irq(cdev->ccwlock);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001327 if (is_blacklisted(id->ssid, id->devno) &&
Peter Oberparleitera2fc8482011-04-04 09:43:32 +02001328 (cdev->private->state == DEV_STATE_OFFLINE) &&
1329 (atomic_cmpxchg(&cdev->private->onoff, 0, 1) == 0)) {
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001330 CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", id->ssid,
1331 id->devno);
1332 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Peter Oberparleitera2fc8482011-04-04 09:43:32 +02001333 atomic_set(&cdev->private->onoff, 0);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001334 }
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001335 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001336 /* Abort loop in case of pending signal. */
1337 if (signal_pending(current))
1338 return -EINTR;
1339
1340 return 0;
1341}
1342
1343/**
1344 * ccw_purge_blacklisted - purge unused, blacklisted devices
1345 *
1346 * Unregister all ccw devices that are offline and on the blacklist.
1347 */
1348int ccw_purge_blacklisted(void)
1349{
1350 CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n");
1351 bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn);
1352 return 0;
1353}
1354
Peter Oberparleiter6afcc772009-10-06 10:34:02 +02001355void ccw_device_set_disconnected(struct ccw_device *cdev)
Cornelia Huckc820de32008-07-14 09:58:45 +02001356{
1357 if (!cdev)
1358 return;
1359 ccw_device_set_timeout(cdev, 0);
1360 cdev->private->flags.fake_irb = 0;
1361 cdev->private->state = DEV_STATE_DISCONNECTED;
1362 if (cdev->online)
1363 ccw_device_schedule_recovery();
1364}
1365
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001366void ccw_device_set_notoper(struct ccw_device *cdev)
1367{
1368 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1369
1370 CIO_TRACE_EVENT(2, "notoper");
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001371 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001372 ccw_device_set_timeout(cdev, 0);
1373 cio_disable_subchannel(sch);
1374 cdev->private->state = DEV_STATE_NOT_OPER;
1375}
1376
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001377enum io_sch_action {
1378 IO_SCH_UNREG,
1379 IO_SCH_ORPH_UNREG,
1380 IO_SCH_ATTACH,
1381 IO_SCH_UNREG_ATTACH,
1382 IO_SCH_ORPH_ATTACH,
1383 IO_SCH_REPROBE,
1384 IO_SCH_VERIFY,
1385 IO_SCH_DISC,
1386 IO_SCH_NOP,
1387};
1388
1389static enum io_sch_action sch_get_action(struct subchannel *sch)
Cornelia Huckc820de32008-07-14 09:58:45 +02001390{
Cornelia Huckc820de32008-07-14 09:58:45 +02001391 struct ccw_device *cdev;
1392
Cornelia Huckc820de32008-07-14 09:58:45 +02001393 cdev = sch_get_cdev(sch);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001394 if (cio_update_schib(sch)) {
1395 /* Not operational. */
1396 if (!cdev)
1397 return IO_SCH_UNREG;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001398 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001399 return IO_SCH_UNREG;
1400 return IO_SCH_ORPH_UNREG;
Cornelia Huckc820de32008-07-14 09:58:45 +02001401 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001402 /* Operational. */
1403 if (!cdev)
1404 return IO_SCH_ATTACH;
1405 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001406 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001407 return IO_SCH_UNREG_ATTACH;
1408 return IO_SCH_ORPH_ATTACH;
Cornelia Huckc820de32008-07-14 09:58:45 +02001409 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001410 if ((sch->schib.pmcw.pam & sch->opm) == 0) {
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001411 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001412 return IO_SCH_UNREG;
1413 return IO_SCH_DISC;
Cornelia Huckc820de32008-07-14 09:58:45 +02001414 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001415 if (device_is_disconnected(cdev))
1416 return IO_SCH_REPROBE;
1417 if (cdev->online)
1418 return IO_SCH_VERIFY;
1419 return IO_SCH_NOP;
1420}
1421
1422/**
1423 * io_subchannel_sch_event - process subchannel event
1424 * @sch: subchannel
1425 * @process: non-zero if function is called in process context
1426 *
1427 * An unspecified event occurred for this subchannel. Adjust data according
1428 * to the current operational state of the subchannel and device. Return
1429 * zero when the event has been handled sufficiently or -EAGAIN when this
1430 * function should be called again in process context.
1431 */
1432static int io_subchannel_sch_event(struct subchannel *sch, int process)
1433{
1434 unsigned long flags;
1435 struct ccw_device *cdev;
1436 struct ccw_dev_id dev_id;
1437 enum io_sch_action action;
1438 int rc = -EAGAIN;
1439
1440 spin_lock_irqsave(sch->lock, flags);
1441 if (!device_is_registered(&sch->dev))
1442 goto out_unlock;
Peter Oberparleiter390935a2009-12-07 12:51:18 +01001443 if (work_pending(&sch->todo_work))
1444 goto out_unlock;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001445 cdev = sch_get_cdev(sch);
1446 if (cdev && work_pending(&cdev->private->todo_work))
1447 goto out_unlock;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001448 action = sch_get_action(sch);
1449 CIO_MSG_EVENT(2, "event: sch 0.%x.%04x, process=%d, action=%d\n",
1450 sch->schid.ssid, sch->schid.sch_no, process,
1451 action);
1452 /* Perform immediate actions while holding the lock. */
Cornelia Huckc820de32008-07-14 09:58:45 +02001453 switch (action) {
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001454 case IO_SCH_REPROBE:
1455 /* Trigger device recognition. */
Cornelia Huckc820de32008-07-14 09:58:45 +02001456 ccw_device_trigger_reprobe(cdev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001457 rc = 0;
1458 goto out_unlock;
1459 case IO_SCH_VERIFY:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001460 if (cdev->private->flags.resuming == 1) {
1461 if (cio_enable_subchannel(sch, (u32)(addr_t)sch)) {
1462 ccw_device_set_notoper(cdev);
1463 break;
1464 }
1465 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001466 /* Trigger path verification. */
1467 io_subchannel_verify(sch);
1468 rc = 0;
1469 goto out_unlock;
1470 case IO_SCH_DISC:
1471 ccw_device_set_disconnected(cdev);
1472 rc = 0;
1473 goto out_unlock;
1474 case IO_SCH_ORPH_UNREG:
1475 case IO_SCH_ORPH_ATTACH:
Peter Oberparleiter6afcc772009-10-06 10:34:02 +02001476 ccw_device_set_disconnected(cdev);
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001477 break;
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001478 case IO_SCH_UNREG_ATTACH:
1479 case IO_SCH_UNREG:
Sebastian Ott16d2ce22010-11-10 10:05:53 +01001480 if (!cdev)
1481 break;
1482 if (cdev->private->state == DEV_STATE_SENSE_ID) {
1483 /*
1484 * Note: delayed work triggered by this event
1485 * and repeated calls to sch_event are synchronized
1486 * by the above check for work_pending(cdev).
1487 */
1488 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1489 } else
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001490 ccw_device_set_notoper(cdev);
1491 break;
1492 case IO_SCH_NOP:
1493 rc = 0;
1494 goto out_unlock;
Cornelia Huckc820de32008-07-14 09:58:45 +02001495 default:
1496 break;
1497 }
1498 spin_unlock_irqrestore(sch->lock, flags);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001499 /* All other actions require process context. */
1500 if (!process)
1501 goto out;
1502 /* Handle attached ccw device. */
1503 switch (action) {
1504 case IO_SCH_ORPH_UNREG:
1505 case IO_SCH_ORPH_ATTACH:
1506 /* Move ccw device to orphanage. */
1507 rc = ccw_device_move_to_orph(cdev);
1508 if (rc)
1509 goto out;
1510 break;
1511 case IO_SCH_UNREG_ATTACH:
Sebastian Ott74b61272010-10-25 16:10:26 +02001512 if (cdev->private->flags.resuming) {
1513 /* Device will be handled later. */
1514 rc = 0;
1515 goto out;
1516 }
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001517 /* Unregister ccw device. */
Sebastian Ott74b61272010-10-25 16:10:26 +02001518 ccw_device_unregister(cdev);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001519 break;
1520 default:
1521 break;
1522 }
1523 /* Handle subchannel. */
1524 switch (action) {
1525 case IO_SCH_ORPH_UNREG:
1526 case IO_SCH_UNREG:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001527 if (!cdev || !cdev->private->flags.resuming)
1528 css_sch_device_unregister(sch);
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001529 break;
1530 case IO_SCH_ORPH_ATTACH:
1531 case IO_SCH_UNREG_ATTACH:
1532 case IO_SCH_ATTACH:
1533 dev_id.ssid = sch->schid.ssid;
1534 dev_id.devno = sch->schib.pmcw.dev;
1535 cdev = get_ccwdev_by_dev_id(&dev_id);
1536 if (!cdev) {
1537 sch_create_and_recog_new_device(sch);
1538 break;
1539 }
1540 rc = ccw_device_move_to_sch(cdev, sch);
1541 if (rc) {
1542 /* Release reference from get_ccwdev_by_dev_id() */
1543 put_device(&cdev->dev);
1544 goto out;
1545 }
1546 spin_lock_irqsave(sch->lock, flags);
1547 ccw_device_trigger_reprobe(cdev);
1548 spin_unlock_irqrestore(sch->lock, flags);
1549 /* Release reference from get_ccwdev_by_dev_id() */
1550 put_device(&cdev->dev);
1551 break;
1552 default:
1553 break;
1554 }
1555 return 0;
Cornelia Huckc820de32008-07-14 09:58:45 +02001556
Peter Oberparleiter5d6e6b62009-12-07 12:51:17 +01001557out_unlock:
1558 spin_unlock_irqrestore(sch->lock, flags);
1559out:
1560 return rc;
Cornelia Huckc820de32008-07-14 09:58:45 +02001561}
1562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563#ifdef CONFIG_CCW_CONSOLE
1564static struct ccw_device console_cdev;
1565static struct ccw_device_private console_private;
1566static int console_cdev_in_use;
1567
Cornelia Huck2ec22982006-12-08 15:54:26 +01001568static DEFINE_SPINLOCK(ccw_console_lock);
1569
1570spinlock_t * cio_get_console_lock(void)
1571{
1572 return &ccw_console_lock;
1573}
1574
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001575static int ccw_device_console_enable(struct ccw_device *cdev,
1576 struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
Sebastian Ottf92519e2011-03-15 17:08:27 +01001578 struct io_subchannel_private *io_priv = cio_get_console_priv();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 int rc;
1580
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001581 /* Attach subchannel private data. */
Sebastian Ottf92519e2011-03-15 17:08:27 +01001582 memset(io_priv, 0, sizeof(*io_priv));
1583 set_io_private(sch, io_priv);
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001584 io_subchannel_init_fields(sch);
Sebastian Ottf444cc02008-12-25 13:39:14 +01001585 rc = cio_commit_config(sch);
1586 if (rc)
1587 return rc;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001588 sch->driver = &io_subchannel_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 /* Initialize the ccw_device structure. */
Heiko Carstens292888c2006-08-30 14:33:35 +02001590 cdev->dev.parent= &sch->dev;
Sebastian Ottffa8d2a32009-12-18 17:43:15 +01001591 sch_set_cdev(sch, cdev);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001592 io_subchannel_recog(cdev, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 /* Now wait for the async. recognition to come to an end. */
1594 spin_lock_irq(cdev->ccwlock);
1595 while (!dev_fsm_final_state(cdev))
1596 wait_cons_dev();
1597 rc = -EIO;
1598 if (cdev->private->state != DEV_STATE_OFFLINE)
1599 goto out_unlock;
1600 ccw_device_online(cdev);
1601 while (!dev_fsm_final_state(cdev))
1602 wait_cons_dev();
1603 if (cdev->private->state != DEV_STATE_ONLINE)
1604 goto out_unlock;
1605 rc = 0;
1606out_unlock:
1607 spin_unlock_irq(cdev->ccwlock);
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001608 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
1611struct ccw_device *
1612ccw_device_probe_console(void)
1613{
1614 struct subchannel *sch;
1615 int ret;
1616
1617 if (xchg(&console_cdev_in_use, 1) != 0)
Peter Oberparleiter600b5d12006-02-01 03:06:35 -08001618 return ERR_PTR(-EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 sch = cio_probe_console();
1620 if (IS_ERR(sch)) {
1621 console_cdev_in_use = 0;
1622 return (void *) sch;
1623 }
1624 memset(&console_cdev, 0, sizeof(struct ccw_device));
1625 memset(&console_private, 0, sizeof(struct ccw_device_private));
1626 console_cdev.private = &console_private;
Martin Schwidefskyc1637532006-12-08 15:53:57 +01001627 console_private.cdev = &console_cdev;
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001628 console_private.int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 ret = ccw_device_console_enable(&console_cdev, sch);
1630 if (ret) {
1631 cio_release_console();
1632 console_cdev_in_use = 0;
1633 return ERR_PTR(ret);
1634 }
1635 console_cdev.online = 1;
1636 return &console_cdev;
1637}
Cornelia Huck1f4e7ed2008-10-10 21:33:14 +02001638
Martin Schwidefsky66648452009-06-16 10:30:28 +02001639static int ccw_device_pm_restore(struct device *dev);
1640
1641int ccw_device_force_console(void)
1642{
1643 if (!console_cdev_in_use)
1644 return -ENODEV;
1645 return ccw_device_pm_restore(&console_cdev.dev);
1646}
1647EXPORT_SYMBOL_GPL(ccw_device_force_console);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648#endif
1649
1650/*
1651 * get ccw_device matching the busid, but only if owned by cdrv
1652 */
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001653static int
1654__ccwdev_check_busid(struct device *dev, void *id)
1655{
1656 char *bus_id;
1657
Cornelia Huck12975ae2006-10-11 15:31:47 +02001658 bus_id = id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001659
Kay Sievers98df67b2008-12-25 13:38:55 +01001660 return (strcmp(bus_id, dev_name(dev)) == 0);
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001661}
1662
1663
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02001664/**
1665 * get_ccwdev_by_busid() - obtain device from a bus id
1666 * @cdrv: driver the device is owned by
1667 * @bus_id: bus id of the device to be searched
1668 *
1669 * This function searches all devices owned by @cdrv for a device with a bus
1670 * id matching @bus_id.
1671 * Returns:
1672 * If a match is found, its reference count of the found device is increased
1673 * and it is returned; else %NULL is returned.
1674 */
1675struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1676 const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001678 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Sebastian Ott9f30ea92012-01-24 13:35:02 -05001680 dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001681 __ccwdev_check_busid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001683 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
1686/************************** device driver handling ************************/
1687
1688/* This is the implementation of the ccw_driver class. The probe, remove
1689 * and release methods are initially very similar to the device_driver
1690 * implementations, with the difference that they have ccw_device
1691 * arguments.
1692 *
1693 * A ccw driver also contains the information that is needed for
1694 * device matching.
1695 */
1696static int
1697ccw_device_probe (struct device *dev)
1698{
1699 struct ccw_device *cdev = to_ccwdev(dev);
1700 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1701 int ret;
1702
1703 cdev->drv = cdrv; /* to let the driver call _set_online */
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001704 /* Note: we interpret class 0 in this context as an uninitialized
1705 * field since it translates to a non-I/O interrupt class. */
1706 if (cdrv->int_class != 0)
1707 cdev->private->int_class = cdrv->int_class;
1708 else
1709 cdev->private->int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1712
1713 if (ret) {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001714 cdev->drv = NULL;
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001715 cdev->private->int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 return ret;
1717 }
1718
1719 return 0;
1720}
1721
1722static int
1723ccw_device_remove (struct device *dev)
1724{
1725 struct ccw_device *cdev = to_ccwdev(dev);
1726 struct ccw_driver *cdrv = cdev->drv;
1727 int ret;
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 if (cdrv->remove)
1730 cdrv->remove(cdev);
1731 if (cdev->online) {
1732 cdev->online = 0;
1733 spin_lock_irq(cdev->ccwlock);
1734 ret = ccw_device_offline(cdev);
1735 spin_unlock_irq(cdev->ccwlock);
1736 if (ret == 0)
1737 wait_event(cdev->private->wait_q,
1738 dev_fsm_final_state(cdev));
1739 else
Michael Ernst139b83d2008-05-07 09:22:54 +02001740 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +02001741 "device 0.%x.%04x\n",
1742 ret, cdev->private->dev_id.ssid,
1743 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +01001744 /* Give up reference obtained in ccw_device_set_online(). */
1745 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 }
1747 ccw_device_set_timeout(cdev, 0);
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001748 cdev->drv = NULL;
Peter Oberparleiterde400d62011-10-30 15:16:04 +01001749 cdev->private->int_class = IOINT_CIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 return 0;
1751}
1752
Cornelia Huck958974f2007-10-12 16:11:21 +02001753static void ccw_device_shutdown(struct device *dev)
1754{
1755 struct ccw_device *cdev;
1756
1757 cdev = to_ccwdev(dev);
1758 if (cdev->drv && cdev->drv->shutdown)
1759 cdev->drv->shutdown(cdev);
Cornelia Huck1842f2b2007-10-12 16:11:22 +02001760 disable_cmf(cdev);
Cornelia Huck958974f2007-10-12 16:11:21 +02001761}
1762
Sebastian Ott823d4942009-06-16 10:30:20 +02001763static int ccw_device_pm_prepare(struct device *dev)
1764{
1765 struct ccw_device *cdev = to_ccwdev(dev);
1766
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001767 if (work_pending(&cdev->private->todo_work))
Sebastian Ott823d4942009-06-16 10:30:20 +02001768 return -EAGAIN;
1769 /* Fail while device is being set online/offline. */
1770 if (atomic_read(&cdev->private->onoff))
1771 return -EAGAIN;
1772
1773 if (cdev->online && cdev->drv && cdev->drv->prepare)
1774 return cdev->drv->prepare(cdev);
1775
1776 return 0;
1777}
1778
1779static void ccw_device_pm_complete(struct device *dev)
1780{
1781 struct ccw_device *cdev = to_ccwdev(dev);
1782
1783 if (cdev->online && cdev->drv && cdev->drv->complete)
1784 cdev->drv->complete(cdev);
1785}
1786
1787static int ccw_device_pm_freeze(struct device *dev)
1788{
1789 struct ccw_device *cdev = to_ccwdev(dev);
1790 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1791 int ret, cm_enabled;
1792
1793 /* Fail suspend while device is in transistional state. */
1794 if (!dev_fsm_final_state(cdev))
1795 return -EAGAIN;
1796 if (!cdev->online)
1797 return 0;
1798 if (cdev->drv && cdev->drv->freeze) {
1799 ret = cdev->drv->freeze(cdev);
1800 if (ret)
1801 return ret;
1802 }
1803
1804 spin_lock_irq(sch->lock);
1805 cm_enabled = cdev->private->cmb != NULL;
1806 spin_unlock_irq(sch->lock);
1807 if (cm_enabled) {
1808 /* Don't have the css write on memory. */
1809 ret = ccw_set_cmf(cdev, 0);
1810 if (ret)
1811 return ret;
1812 }
1813 /* From here on, disallow device driver I/O. */
1814 spin_lock_irq(sch->lock);
1815 ret = cio_disable_subchannel(sch);
1816 spin_unlock_irq(sch->lock);
1817
1818 return ret;
1819}
1820
1821static int ccw_device_pm_thaw(struct device *dev)
1822{
1823 struct ccw_device *cdev = to_ccwdev(dev);
1824 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1825 int ret, cm_enabled;
1826
1827 if (!cdev->online)
1828 return 0;
1829
1830 spin_lock_irq(sch->lock);
1831 /* Allow device driver I/O again. */
1832 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
1833 cm_enabled = cdev->private->cmb != NULL;
1834 spin_unlock_irq(sch->lock);
1835 if (ret)
1836 return ret;
1837
1838 if (cm_enabled) {
1839 ret = ccw_set_cmf(cdev, 1);
1840 if (ret)
1841 return ret;
1842 }
1843
1844 if (cdev->drv && cdev->drv->thaw)
1845 ret = cdev->drv->thaw(cdev);
1846
1847 return ret;
1848}
1849
1850static void __ccw_device_pm_restore(struct ccw_device *cdev)
1851{
1852 struct subchannel *sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +02001853
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001854 spin_lock_irq(sch->lock);
1855 if (cio_is_console(sch->schid)) {
1856 cio_enable_subchannel(sch, (u32)(addr_t)sch);
1857 goto out_unlock;
1858 }
Sebastian Ott823d4942009-06-16 10:30:20 +02001859 /*
1860 * While we were sleeping, devices may have gone or become
1861 * available again. Kick re-detection.
1862 */
Sebastian Ott823d4942009-06-16 10:30:20 +02001863 cdev->private->flags.resuming = 1;
Sebastian Ottb17295e2011-01-12 09:55:10 +01001864 cdev->private->path_new_mask = LPM_ANYPATH;
Sebastian Ott817e5002011-12-01 13:32:19 +01001865 css_sched_sch_todo(sch, SCH_TODO_EVAL);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001866 spin_unlock_irq(sch->lock);
Sebastian Ott817e5002011-12-01 13:32:19 +01001867 css_wait_for_slow_path();
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001868
1869 /* cdev may have been moved to a different subchannel. */
1870 sch = to_subchannel(cdev->dev.parent);
1871 spin_lock_irq(sch->lock);
1872 if (cdev->private->state != DEV_STATE_ONLINE &&
1873 cdev->private->state != DEV_STATE_OFFLINE)
1874 goto out_unlock;
1875
Peter Oberparleiter736b5db2009-12-07 12:51:21 +01001876 ccw_device_recognition(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001877 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001878 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) ||
1879 cdev->private->state == DEV_STATE_DISCONNECTED);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001880 spin_lock_irq(sch->lock);
1881
1882out_unlock:
Sebastian Ott823d4942009-06-16 10:30:20 +02001883 cdev->private->flags.resuming = 0;
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001884 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001885}
1886
1887static int resume_handle_boxed(struct ccw_device *cdev)
1888{
1889 cdev->private->state = DEV_STATE_BOXED;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001890 if (ccw_device_notify(cdev, CIO_BOXED) == NOTIFY_OK)
Sebastian Ott823d4942009-06-16 10:30:20 +02001891 return 0;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001892 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Sebastian Ott823d4942009-06-16 10:30:20 +02001893 return -ENODEV;
1894}
1895
1896static int resume_handle_disc(struct ccw_device *cdev)
1897{
1898 cdev->private->state = DEV_STATE_DISCONNECTED;
Sebastian Ott76e6fb42010-02-26 22:37:28 +01001899 if (ccw_device_notify(cdev, CIO_GONE) == NOTIFY_OK)
Sebastian Ott823d4942009-06-16 10:30:20 +02001900 return 0;
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001901 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
Sebastian Ott823d4942009-06-16 10:30:20 +02001902 return -ENODEV;
1903}
1904
1905static int ccw_device_pm_restore(struct device *dev)
1906{
1907 struct ccw_device *cdev = to_ccwdev(dev);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001908 struct subchannel *sch;
1909 int ret = 0;
Sebastian Ott823d4942009-06-16 10:30:20 +02001910
1911 __ccw_device_pm_restore(cdev);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001912 sch = to_subchannel(cdev->dev.parent);
Sebastian Ott823d4942009-06-16 10:30:20 +02001913 spin_lock_irq(sch->lock);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001914 if (cio_is_console(sch->schid))
Sebastian Ott823d4942009-06-16 10:30:20 +02001915 goto out_restore;
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001916
Sebastian Ott823d4942009-06-16 10:30:20 +02001917 /* check recognition results */
1918 switch (cdev->private->state) {
1919 case DEV_STATE_OFFLINE:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001920 case DEV_STATE_ONLINE:
1921 cdev->private->flags.donotify = 0;
Sebastian Ott823d4942009-06-16 10:30:20 +02001922 break;
1923 case DEV_STATE_BOXED:
1924 ret = resume_handle_boxed(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001925 if (ret)
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001926 goto out_unlock;
Sebastian Ott823d4942009-06-16 10:30:20 +02001927 goto out_restore;
Sebastian Ott823d4942009-06-16 10:30:20 +02001928 default:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001929 ret = resume_handle_disc(cdev);
1930 if (ret)
1931 goto out_unlock;
1932 goto out_restore;
Sebastian Ott823d4942009-06-16 10:30:20 +02001933 }
1934 /* check if the device type has changed */
1935 if (!ccw_device_test_sense_data(cdev)) {
1936 ccw_device_update_sense_data(cdev);
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01001937 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
Sebastian Ott823d4942009-06-16 10:30:20 +02001938 ret = -ENODEV;
1939 goto out_unlock;
1940 }
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001941 if (!cdev->online)
1942 goto out_unlock;
1943
1944 if (ccw_device_online(cdev)) {
1945 ret = resume_handle_disc(cdev);
1946 if (ret)
1947 goto out_unlock;
1948 goto out_restore;
1949 }
1950 spin_unlock_irq(sch->lock);
1951 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1952 spin_lock_irq(sch->lock);
1953
1954 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) {
1955 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
1956 ret = -ENODEV;
Sebastian Ott823d4942009-06-16 10:30:20 +02001957 goto out_unlock;
1958 }
Sebastian Ott823d4942009-06-16 10:30:20 +02001959
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001960 /* reenable cmf, if needed */
1961 if (cdev->private->cmb) {
1962 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001963 ret = ccw_set_cmf(cdev, 1);
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001964 spin_lock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001965 if (ret) {
Sebastian Ottf0148242009-09-11 10:28:23 +02001966 CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed "
1967 "(rc=%d)\n", cdev->private->dev_id.ssid,
1968 cdev->private->dev_id.devno, ret);
Sebastian Ott823d4942009-06-16 10:30:20 +02001969 ret = 0;
1970 }
1971 }
1972
1973out_restore:
Sebastian Ott0d01bb82010-02-26 22:37:29 +01001974 spin_unlock_irq(sch->lock);
Sebastian Ott823d4942009-06-16 10:30:20 +02001975 if (cdev->online && cdev->drv && cdev->drv->restore)
1976 ret = cdev->drv->restore(cdev);
Sebastian Ott823d4942009-06-16 10:30:20 +02001977 return ret;
1978
Sebastian Ott823d4942009-06-16 10:30:20 +02001979out_unlock:
1980 spin_unlock_irq(sch->lock);
1981 return ret;
1982}
1983
Alexey Dobriyan47145212009-12-14 18:00:08 -08001984static const struct dev_pm_ops ccw_pm_ops = {
Sebastian Ott823d4942009-06-16 10:30:20 +02001985 .prepare = ccw_device_pm_prepare,
1986 .complete = ccw_device_pm_complete,
1987 .freeze = ccw_device_pm_freeze,
1988 .thaw = ccw_device_pm_thaw,
1989 .restore = ccw_device_pm_restore,
1990};
1991
Sebastian Ottd5ab5272011-03-23 10:16:03 +01001992static struct bus_type ccw_bus_type = {
Cornelia Huck8bbace72006-01-11 10:56:22 +01001993 .name = "ccw",
1994 .match = ccw_bus_match,
1995 .uevent = ccw_uevent,
1996 .probe = ccw_device_probe,
1997 .remove = ccw_device_remove,
Cornelia Huck958974f2007-10-12 16:11:21 +02001998 .shutdown = ccw_device_shutdown,
Sebastian Ott823d4942009-06-16 10:30:20 +02001999 .pm = &ccw_pm_ops,
Cornelia Huck8bbace72006-01-11 10:56:22 +01002000};
2001
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02002002/**
2003 * ccw_driver_register() - register a ccw driver
2004 * @cdriver: driver to be registered
2005 *
2006 * This function is mainly a wrapper around driver_register().
2007 * Returns:
2008 * %0 on success and a negative error value on failure.
2009 */
2010int ccw_driver_register(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011{
2012 struct device_driver *drv = &cdriver->driver;
2013
2014 drv->bus = &ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
2016 return driver_register(drv);
2017}
2018
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02002019/**
2020 * ccw_driver_unregister() - deregister a ccw driver
2021 * @cdriver: driver to be deregistered
2022 *
2023 * This function is mainly a wrapper around driver_unregister().
2024 */
2025void ccw_driver_unregister(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026{
2027 driver_unregister(&cdriver->driver);
2028}
2029
Cornelia Hucka8237fc2006-01-06 00:19:21 -08002030/* Helper func for qdio. */
2031struct subchannel_id
2032ccw_device_get_subchannel_id(struct ccw_device *cdev)
2033{
2034 struct subchannel *sch;
2035
2036 sch = to_subchannel(cdev->dev.parent);
2037 return sch->schid;
2038}
2039
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01002040static void ccw_device_todo(struct work_struct *work)
2041{
2042 struct ccw_device_private *priv;
2043 struct ccw_device *cdev;
2044 struct subchannel *sch;
2045 enum cdev_todo todo;
2046
2047 priv = container_of(work, struct ccw_device_private, todo_work);
2048 cdev = priv->cdev;
2049 sch = to_subchannel(cdev->dev.parent);
2050 /* Find out todo. */
2051 spin_lock_irq(cdev->ccwlock);
2052 todo = priv->todo;
2053 priv->todo = CDEV_TODO_NOTHING;
2054 CIO_MSG_EVENT(4, "cdev_todo: cdev=0.%x.%04x todo=%d\n",
2055 priv->dev_id.ssid, priv->dev_id.devno, todo);
2056 spin_unlock_irq(cdev->ccwlock);
2057 /* Perform todo. */
2058 switch (todo) {
2059 case CDEV_TODO_ENABLE_CMF:
2060 cmf_reenable(cdev);
2061 break;
2062 case CDEV_TODO_REBIND:
2063 ccw_device_do_unbind_bind(cdev);
2064 break;
2065 case CDEV_TODO_REGISTER:
2066 io_subchannel_register(cdev);
2067 break;
2068 case CDEV_TODO_UNREG_EVAL:
2069 if (!sch_is_pseudo_sch(sch))
2070 css_schedule_eval(sch->schid);
2071 /* fall-through */
2072 case CDEV_TODO_UNREG:
2073 if (sch_is_pseudo_sch(sch))
2074 ccw_device_unregister(cdev);
2075 else
2076 ccw_device_call_sch_unregister(cdev);
2077 break;
2078 default:
2079 break;
2080 }
2081 /* Release workqueue ref. */
2082 put_device(&cdev->dev);
2083}
2084
2085/**
2086 * ccw_device_sched_todo - schedule ccw device operation
2087 * @cdev: ccw device
2088 * @todo: todo
2089 *
2090 * Schedule the operation identified by @todo to be performed on the slow path
2091 * workqueue. Do nothing if another operation with higher priority is already
2092 * scheduled. Needs to be called with ccwdev lock held.
2093 */
2094void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo)
2095{
2096 CIO_MSG_EVENT(4, "cdev_todo: sched cdev=0.%x.%04x todo=%d\n",
2097 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
2098 todo);
2099 if (cdev->private->todo >= todo)
2100 return;
2101 cdev->private->todo = todo;
2102 /* Get workqueue ref. */
2103 if (!get_device(&cdev->dev))
2104 return;
Sebastian Ottbe5d3822010-02-26 22:37:24 +01002105 if (!queue_work(cio_work_q, &cdev->private->todo_work)) {
Peter Oberparleiter37de53b2009-12-07 12:51:19 +01002106 /* Already queued, release workqueue ref. */
2107 put_device(&cdev->dev);
2108 }
2109}
2110
Michael Ernstfd0457a2010-08-09 18:12:50 +02002111/**
2112 * ccw_device_siosl() - initiate logging
2113 * @cdev: ccw device
2114 *
2115 * This function is used to invoke model-dependent logging within the channel
2116 * subsystem.
2117 */
2118int ccw_device_siosl(struct ccw_device *cdev)
2119{
2120 struct subchannel *sch = to_subchannel(cdev->dev.parent);
2121
2122 return chsc_siosl(sch->schid);
2123}
2124EXPORT_SYMBOL_GPL(ccw_device_siosl);
2125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126MODULE_LICENSE("GPL");
2127EXPORT_SYMBOL(ccw_device_set_online);
2128EXPORT_SYMBOL(ccw_device_set_offline);
2129EXPORT_SYMBOL(ccw_driver_register);
2130EXPORT_SYMBOL(ccw_driver_unregister);
2131EXPORT_SYMBOL(get_ccwdev_by_busid);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08002132EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);