blob: 039ef03cf217ff641771f96b4cff465b97911a6d [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/spinlock.h>
13#include <linux/errno.h>
14#include <linux/err.h>
15#include <linux/slab.h>
16#include <linux/list.h>
17#include <linux/device.h>
18#include <linux/workqueue.h>
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010019#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/ccwdev.h>
22#include <asm/cio.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080023#include <asm/param.h> /* HZ */
Cornelia Huck1842f2b2007-10-12 16:11:22 +020024#include <asm/cmb.h>
Cornelia Huck3a3fc292008-07-14 09:58:58 +020025#include <asm/isc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +020027#include "chp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "cio.h"
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +010029#include "cio_debug.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "css.h"
31#include "device.h"
32#include "ioasm.h"
Cornelia Huckcd6b4f22008-01-26 14:10:43 +010033#include "io_sch.h"
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +020034#include "blacklist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010036static struct timer_list recovery_timer;
Cornelia Huck486d0a02008-02-19 15:29:23 +010037static DEFINE_SPINLOCK(recovery_lock);
Peter Oberparleiter90ab1332008-01-26 14:10:52 +010038static int recovery_phase;
39static const unsigned long recovery_delay[] = { 3, 30, 300 };
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/******************* bus type handling ***********************/
42
43/* The Linux driver model distinguishes between a bus type and
44 * the bus itself. Of course we only have one channel
45 * subsystem driver and one channel system per machine, but
46 * we still use the abstraction. T.R. says it's a good idea. */
47static int
48ccw_bus_match (struct device * dev, struct device_driver * drv)
49{
50 struct ccw_device *cdev = to_ccwdev(dev);
51 struct ccw_driver *cdrv = to_ccwdrv(drv);
52 const struct ccw_device_id *ids = cdrv->ids, *found;
53
54 if (!ids)
55 return 0;
56
57 found = ccw_device_id_match(ids, &cdev->id);
58 if (!found)
59 return 0;
60
61 cdev->id.driver_info = found->driver_info;
62
63 return 1;
64}
65
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020066/* Store modalias string delimited by prefix/suffix string into buffer with
67 * specified size. Return length of resulting string (excluding trailing '\0')
68 * even if string doesn't fit buffer (snprintf semantics). */
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020069static int snprint_alias(char *buf, size_t size,
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020070 struct ccw_device_id *id, const char *suffix)
71{
72 int len;
73
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020074 len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020075 if (len > size)
76 return len;
77 buf += len;
78 size -= len;
79
80 if (id->dev_type != 0)
81 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
82 id->dev_model, suffix);
83 else
84 len += snprintf(buf, size, "dtdm%s", suffix);
85
86 return len;
87}
88
89/* Set up environment variables for ccw device uevent. Return 0 on success,
90 * non-zero otherwise. */
Kay Sievers7eff2e72007-08-14 15:15:12 +020091static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020094 struct ccw_device_id *id = &(cdev->id);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +020095 int ret;
96 char modalias_buf[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020098 /* CU_TYPE= */
Kay Sievers7eff2e72007-08-14 15:15:12 +020099 ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200100 if (ret)
101 return ret;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200102
103 /* CU_MODEL= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200104 ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200105 if (ret)
106 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* The next two can be zero, that's ok for us */
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200109 /* DEV_TYPE= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200110 ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200111 if (ret)
112 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200114 /* DEV_MODEL= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200115 ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model);
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200116 if (ret)
117 return ret;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200118
119 /* MODALIAS= */
Cornelia Huckcfbe9bb2007-04-27 16:01:32 +0200120 snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
Kay Sievers7eff2e72007-08-14 15:15:12 +0200121 ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf);
122 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Cornelia Huck8bbace72006-01-11 10:56:22 +0100125struct bus_type ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Cornelia Huck602b20f2008-01-26 14:10:39 +0100127static void io_subchannel_irq(struct subchannel *);
128static int io_subchannel_probe(struct subchannel *);
129static int io_subchannel_remove(struct subchannel *);
Cornelia Huck8bbace72006-01-11 10:56:22 +0100130static void io_subchannel_shutdown(struct subchannel *);
Cornelia Huckc820de32008-07-14 09:58:45 +0200131static int io_subchannel_sch_event(struct subchannel *, int);
Cornelia Huck99611f82008-07-14 09:59:02 +0200132static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
133 int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Cornelia Huckf08adc02008-07-14 09:59:03 +0200135static struct css_device_id io_subchannel_ids[] = {
136 { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, },
137 { /* end of list */ },
138};
139MODULE_DEVICE_TABLE(css, io_subchannel_ids);
140
Cornelia Huckf7e5d672007-05-10 15:45:43 +0200141static struct css_driver io_subchannel_driver = {
Cornelia Huck4beee642008-01-26 14:10:47 +0100142 .owner = THIS_MODULE,
Cornelia Huckf08adc02008-07-14 09:59:03 +0200143 .subchannel_type = io_subchannel_ids,
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100144 .name = "io_subchannel",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 .irq = io_subchannel_irq,
Cornelia Huckc820de32008-07-14 09:58:45 +0200146 .sch_event = io_subchannel_sch_event,
147 .chp_event = io_subchannel_chp_event,
Cornelia Huck8bbace72006-01-11 10:56:22 +0100148 .probe = io_subchannel_probe,
149 .remove = io_subchannel_remove,
150 .shutdown = io_subchannel_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
153struct workqueue_struct *ccw_device_work;
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200154wait_queue_head_t ccw_device_init_wq;
155atomic_t ccw_device_init_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Peter Oberparleiter90ab1332008-01-26 14:10:52 +0100157static void recovery_func(unsigned long data);
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static int __init
160init_ccw_bus_type (void)
161{
162 int ret;
163
164 init_waitqueue_head(&ccw_device_init_wq);
165 atomic_set(&ccw_device_init_count, 0);
Peter Oberparleiter90ab1332008-01-26 14:10:52 +0100166 setup_timer(&recovery_timer, recovery_func, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 ccw_device_work = create_singlethread_workqueue("cio");
169 if (!ccw_device_work)
170 return -ENOMEM; /* FIXME: better errno ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 slow_path_wq = create_singlethread_workqueue("kslowcrw");
172 if (!slow_path_wq) {
173 ret = -ENOMEM; /* FIXME: better errno ? */
174 goto out_err;
175 }
176 if ((ret = bus_register (&ccw_bus_type)))
177 goto out_err;
178
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100179 ret = css_driver_register(&io_subchannel_driver);
180 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 goto out_err;
182
183 wait_event(ccw_device_init_wq,
184 atomic_read(&ccw_device_init_count) == 0);
185 flush_workqueue(ccw_device_work);
186 return 0;
187out_err:
188 if (ccw_device_work)
189 destroy_workqueue(ccw_device_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (slow_path_wq)
191 destroy_workqueue(slow_path_wq);
192 return ret;
193}
194
195static void __exit
196cleanup_ccw_bus_type (void)
197{
Cornelia Huck25b7bb52008-01-26 14:10:41 +0100198 css_driver_unregister(&io_subchannel_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 bus_unregister(&ccw_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 destroy_workqueue(ccw_device_work);
201}
202
203subsys_initcall(init_ccw_bus_type);
204module_exit(cleanup_ccw_bus_type);
205
206/************************ device handling **************************/
207
208/*
209 * A ccw_device has some interfaces in sysfs in addition to the
210 * standard ones.
211 * The following entries are designed to export the information which
212 * resided in 2.4 in /proc/subchannels. Subchannel and device number
213 * are obvious, so they don't have an entry :)
214 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
215 */
216static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400217chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 struct subchannel *sch = to_subchannel(dev);
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200220 struct chsc_ssd_info *ssd = &sch->ssd_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 ssize_t ret = 0;
222 int chp;
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200223 int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Peter Oberparleiter7ad6a242007-04-27 16:01:35 +0200225 for (chp = 0; chp < 8; chp++) {
226 mask = 0x80 >> chp;
227 if (ssd->path_mask & mask)
228 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
229 else
230 ret += sprintf(buf + ret, "00 ");
231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 ret += sprintf (buf+ret, "\n");
233 return min((ssize_t)PAGE_SIZE, ret);
234}
235
236static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400237pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 struct subchannel *sch = to_subchannel(dev);
240 struct pmcw *pmcw = &sch->schib.pmcw;
241
242 return sprintf (buf, "%02x %02x %02x\n",
243 pmcw->pim, pmcw->pam, pmcw->pom);
244}
245
246static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400247devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 struct ccw_device *cdev = to_ccwdev(dev);
250 struct ccw_device_id *id = &(cdev->id);
251
252 if (id->dev_type != 0)
253 return sprintf(buf, "%04x/%02x\n",
254 id->dev_type, id->dev_model);
255 else
256 return sprintf(buf, "n/a\n");
257}
258
259static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400260cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 struct ccw_device *cdev = to_ccwdev(dev);
263 struct ccw_device_id *id = &(cdev->id);
264
265 return sprintf(buf, "%04x/%02x\n",
266 id->cu_type, id->cu_model);
267}
268
269static ssize_t
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800270modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
271{
272 struct ccw_device *cdev = to_ccwdev(dev);
273 struct ccw_device_id *id = &(cdev->id);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200274 int len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800275
Cornelia Huck086a6c62007-07-17 13:36:08 +0200276 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200277
278 return len > PAGE_SIZE ? PAGE_SIZE : len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800279}
280
281static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400282online_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 struct ccw_device *cdev = to_ccwdev(dev);
285
286 return sprintf(buf, cdev->online ? "1\n" : "0\n");
287}
288
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100289int ccw_device_is_orphan(struct ccw_device *cdev)
290{
291 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
292}
293
Cornelia Huckef995162007-04-27 16:01:39 +0200294static void ccw_device_unregister(struct ccw_device *cdev)
Cornelia Huck7674da72006-12-08 15:54:21 +0100295{
Cornelia Huck7674da72006-12-08 15:54:21 +0100296 if (test_and_clear_bit(1, &cdev->private->registered))
Cornelia Huckef995162007-04-27 16:01:39 +0200297 device_del(&cdev->dev);
Cornelia Huck7674da72006-12-08 15:54:21 +0100298}
299
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200300static void ccw_device_remove_orphan_cb(struct work_struct *work)
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200301{
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200302 struct ccw_device_private *priv;
303 struct ccw_device *cdev;
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200304
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200305 priv = container_of(work, struct ccw_device_private, kick_work);
306 cdev = priv->cdev;
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200307 ccw_device_unregister(cdev);
308 put_device(&cdev->dev);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200309 /* Release cdev reference for workqueue processing. */
310 put_device(&cdev->dev);
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200311}
312
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200313static void ccw_device_call_sch_unregister(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200315static void
316ccw_device_remove_disconnected(struct ccw_device *cdev)
317{
318 unsigned long flags;
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200319
320 /*
321 * Forced offline in disconnected state means
322 * 'throw away device'.
323 */
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200324 /* Get cdev reference for workqueue processing. */
325 if (!get_device(&cdev->dev))
326 return;
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200327 if (ccw_device_is_orphan(cdev)) {
328 /*
329 * Deregister ccw device.
330 * Unfortunately, we cannot do this directly from the
331 * attribute method.
332 */
333 spin_lock_irqsave(cdev->ccwlock, flags);
334 cdev->private->state = DEV_STATE_NOT_OPER;
335 spin_unlock_irqrestore(cdev->ccwlock, flags);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200336 PREPARE_WORK(&cdev->private->kick_work,
337 ccw_device_remove_orphan_cb);
338 } else
339 /* Deregister subchannel, which will kill the ccw device. */
340 PREPARE_WORK(&cdev->private->kick_work,
341 ccw_device_call_sch_unregister);
342 queue_work(slow_path_wq, &cdev->private->kick_work);
Cornelia Huck59a8a6e2007-05-31 17:38:06 +0200343}
344
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200345/**
346 * ccw_device_set_offline() - disable a ccw device for I/O
347 * @cdev: target ccw device
348 *
349 * This function calls the driver's set_offline() function for @cdev, if
350 * given, and then disables @cdev.
351 * Returns:
352 * %0 on success and a negative error value on failure.
353 * Context:
354 * enabled, ccw device lock not held
355 */
356int ccw_device_set_offline(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
358 int ret;
359
360 if (!cdev)
361 return -ENODEV;
362 if (!cdev->online || !cdev->drv)
363 return -EINVAL;
364
365 if (cdev->drv->set_offline) {
366 ret = cdev->drv->set_offline(cdev);
367 if (ret != 0)
368 return ret;
369 }
370 cdev->online = 0;
371 spin_lock_irq(cdev->ccwlock);
372 ret = ccw_device_offline(cdev);
373 if (ret == -ENODEV) {
374 if (cdev->private->state != DEV_STATE_NOT_OPER) {
375 cdev->private->state = DEV_STATE_OFFLINE;
376 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
377 }
378 spin_unlock_irq(cdev->ccwlock);
Cornelia Huck9cd67422008-12-25 13:39:06 +0100379 /* Give up reference from ccw_device_set_online(). */
380 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return ret;
382 }
383 spin_unlock_irq(cdev->ccwlock);
Cornelia Huck9cd67422008-12-25 13:39:06 +0100384 if (ret == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
Cornelia Huck9cd67422008-12-25 13:39:06 +0100386 /* Give up reference from ccw_device_set_online(). */
387 put_device(&cdev->dev);
388 } else {
Michael Ernst139b83d2008-05-07 09:22:54 +0200389 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200390 "device 0.%x.%04x\n",
391 ret, cdev->private->dev_id.ssid,
392 cdev->private->dev_id.devno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 cdev->online = 1;
394 }
Cornelia Huck9cd67422008-12-25 13:39:06 +0100395 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +0200398/**
399 * ccw_device_set_online() - enable a ccw device for I/O
400 * @cdev: target ccw device
401 *
402 * This function first enables @cdev and then calls the driver's set_online()
403 * function for @cdev, if given. If set_online() returns an error, @cdev is
404 * disabled again.
405 * Returns:
406 * %0 on success and a negative error value on failure.
407 * Context:
408 * enabled, ccw device lock not held
409 */
410int ccw_device_set_online(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
412 int ret;
413
414 if (!cdev)
415 return -ENODEV;
416 if (cdev->online || !cdev->drv)
417 return -EINVAL;
Cornelia Huck9cd67422008-12-25 13:39:06 +0100418 /* Hold on to an extra reference while device is online. */
419 if (!get_device(&cdev->dev))
420 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 spin_lock_irq(cdev->ccwlock);
423 ret = ccw_device_online(cdev);
424 spin_unlock_irq(cdev->ccwlock);
425 if (ret == 0)
426 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
427 else {
Michael Ernst139b83d2008-05-07 09:22:54 +0200428 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200429 "device 0.%x.%04x\n",
430 ret, cdev->private->dev_id.ssid,
431 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +0100432 /* Give up online reference since onlining failed. */
433 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return ret;
435 }
Cornelia Huck9cd67422008-12-25 13:39:06 +0100436 if (cdev->private->state != DEV_STATE_ONLINE) {
437 /* Give up online reference since onlining failed. */
438 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 return -ENODEV;
Cornelia Huck9cd67422008-12-25 13:39:06 +0100440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
442 cdev->online = 1;
443 return 0;
444 }
445 spin_lock_irq(cdev->ccwlock);
446 ret = ccw_device_offline(cdev);
447 spin_unlock_irq(cdev->ccwlock);
448 if (ret == 0)
449 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200450 else
Michael Ernst139b83d2008-05-07 09:22:54 +0200451 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200452 "device 0.%x.%04x\n",
453 ret, cdev->private->dev_id.ssid,
454 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +0100455 /* Give up online reference since onlining failed. */
456 put_device(&cdev->dev);
Cornelia Huck6cadb782006-02-17 13:52:49 -0800457 return (ret == 0) ? -ENODEV : ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200460static void online_store_handle_offline(struct ccw_device *cdev)
461{
462 if (cdev->private->state == DEV_STATE_DISCONNECTED)
463 ccw_device_remove_disconnected(cdev);
464 else if (cdev->drv && cdev->drv->set_offline)
465 ccw_device_set_offline(cdev);
466}
467
468static int online_store_recog_and_online(struct ccw_device *cdev)
469{
470 int ret;
471
472 /* Do device recognition, if needed. */
473 if (cdev->id.cu_type == 0) {
474 ret = ccw_device_recognition(cdev);
475 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200476 CIO_MSG_EVENT(0, "Couldn't start recognition "
477 "for device 0.%x.%04x (ret=%d)\n",
478 cdev->private->dev_id.ssid,
479 cdev->private->dev_id.devno, ret);
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200480 return ret;
481 }
482 wait_event(cdev->private->wait_q,
483 cdev->private->flags.recog_done);
484 }
485 if (cdev->drv && cdev->drv->set_online)
486 ccw_device_set_online(cdev);
487 return 0;
488}
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200489static int online_store_handle_online(struct ccw_device *cdev, int force)
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200490{
491 int ret;
492
493 ret = online_store_recog_and_online(cdev);
494 if (ret)
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200495 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200496 if (force && cdev->private->state == DEV_STATE_BOXED) {
497 ret = ccw_device_stlck(cdev);
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200498 if (ret)
499 return ret;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200500 if (cdev->id.cu_type == 0)
501 cdev->private->state = DEV_STATE_NOT_OPER;
502 online_store_recog_and_online(cdev);
503 }
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200504 return 0;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200505}
506
507static ssize_t online_store (struct device *dev, struct device_attribute *attr,
508 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
510 struct ccw_device *cdev = to_ccwdev(dev);
Cornelia Huck2f972202008-04-30 13:38:33 +0200511 int force, ret;
512 unsigned long i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Martin Schwidefsky973bd992006-01-06 00:19:07 -0800514 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return -EAGAIN;
516
517 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
518 atomic_set(&cdev->private->onoff, 0);
519 return -EINVAL;
520 }
521 if (!strncmp(buf, "force\n", count)) {
522 force = 1;
523 i = 1;
Cornelia Huck2f972202008-04-30 13:38:33 +0200524 ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 } else {
526 force = 0;
Cornelia Huck2f972202008-04-30 13:38:33 +0200527 ret = strict_strtoul(buf, 16, &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 }
Cornelia Huck2f972202008-04-30 13:38:33 +0200529 if (ret)
530 goto out;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200531 switch (i) {
532 case 0:
533 online_store_handle_offline(cdev);
Cornelia Huck2f972202008-04-30 13:38:33 +0200534 ret = count;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200535 break;
536 case 1:
Michael Ernstc78aa6c2008-07-14 09:59:22 +0200537 ret = online_store_handle_online(cdev, force);
538 if (!ret)
539 ret = count;
Cornelia Huckf5ba6c82007-04-27 16:01:30 +0200540 break;
541 default:
Cornelia Huck2f972202008-04-30 13:38:33 +0200542 ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
Cornelia Huck2f972202008-04-30 13:38:33 +0200544out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 if (cdev->drv)
546 module_put(cdev->drv->owner);
547 atomic_set(&cdev->private->onoff, 0);
Cornelia Huck2f972202008-04-30 13:38:33 +0200548 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549}
550
551static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400552available_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 struct ccw_device *cdev = to_ccwdev(dev);
555 struct subchannel *sch;
556
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100557 if (ccw_device_is_orphan(cdev))
558 return sprintf(buf, "no device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 switch (cdev->private->state) {
560 case DEV_STATE_BOXED:
561 return sprintf(buf, "boxed\n");
562 case DEV_STATE_DISCONNECTED:
563 case DEV_STATE_DISCONNECTED_SENSE_ID:
564 case DEV_STATE_NOT_OPER:
565 sch = to_subchannel(dev->parent);
566 if (!sch->lpm)
567 return sprintf(buf, "no path\n");
568 else
569 return sprintf(buf, "no device\n");
570 default:
571 /* All other states considered fine. */
572 return sprintf(buf, "good\n");
573 }
574}
575
576static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
577static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
578static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
579static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800580static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581static DEVICE_ATTR(online, 0644, online_show, online_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582static DEVICE_ATTR(availability, 0444, available_show, NULL);
583
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200584static struct attribute *io_subchannel_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 &dev_attr_chpids.attr,
586 &dev_attr_pimpampom.attr,
587 NULL,
588};
589
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200590static struct attribute_group io_subchannel_attr_group = {
591 .attrs = io_subchannel_attrs,
Cornelia Huck529192f2006-12-08 15:55:57 +0100592};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594static struct attribute * ccwdev_attrs[] = {
595 &dev_attr_devtype.attr,
596 &dev_attr_cutype.attr,
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800597 &dev_attr_modalias.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 &dev_attr_online.attr,
599 &dev_attr_cmb_enable.attr,
600 &dev_attr_availability.attr,
601 NULL,
602};
603
604static struct attribute_group ccwdev_attr_group = {
605 .attrs = ccwdev_attrs,
606};
607
Cornelia Huckf7e5d672007-05-10 15:45:43 +0200608static struct attribute_group *ccwdev_attr_groups[] = {
Cornelia Huckef995162007-04-27 16:01:39 +0200609 &ccwdev_attr_group,
610 NULL,
611};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613/* this is a simple abstraction for device_register that sets the
614 * correct bus type and adds the bus specific files */
Cornelia Huck3c9da7b2006-10-27 12:39:33 +0200615static int ccw_device_register(struct ccw_device *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
617 struct device *dev = &cdev->dev;
618 int ret;
619
620 dev->bus = &ccw_bus_type;
621
622 if ((ret = device_add(dev)))
623 return ret;
624
625 set_bit(1, &cdev->private->registered);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 return ret;
627}
628
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700629struct match_data {
Cornelia Huck78964262006-10-11 15:31:38 +0200630 struct ccw_dev_id dev_id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700631 struct ccw_device * sibling;
632};
633
634static int
635match_devno(struct device * dev, void * data)
636{
Cornelia Huck78964262006-10-11 15:31:38 +0200637 struct match_data * d = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700638 struct ccw_device * cdev;
639
640 cdev = to_ccwdev(dev);
641 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100642 !ccw_device_is_orphan(cdev) &&
Cornelia Huck78964262006-10-11 15:31:38 +0200643 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100644 (cdev != d->sibling))
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700645 return 1;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700646 return 0;
647}
648
Cornelia Huck78964262006-10-11 15:31:38 +0200649static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
650 struct ccw_device *sibling)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 struct device *dev;
Heiko Carstens292888c2006-08-30 14:33:35 +0200653 struct match_data data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Cornelia Huck78964262006-10-11 15:31:38 +0200655 data.dev_id = *dev_id;
Heiko Carstens292888c2006-08-30 14:33:35 +0200656 data.sibling = sibling;
Cornelia Hucke5945b42005-10-11 08:28:59 -0700657 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700659 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100662static int match_orphan(struct device *dev, void *data)
663{
664 struct ccw_dev_id *dev_id;
665 struct ccw_device *cdev;
666
667 dev_id = data;
668 cdev = to_ccwdev(dev);
669 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
670}
671
672static struct ccw_device *
673get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
674 struct ccw_dev_id *dev_id)
675{
676 struct device *dev;
677
678 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
679 match_orphan);
680
681 return dev ? to_ccwdev(dev) : NULL;
682}
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100685ccw_device_add_changed(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100687 struct ccw_device_private *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 struct ccw_device *cdev;
689
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100690 priv = container_of(work, struct ccw_device_private, kick_work);
691 cdev = priv->cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (device_add(&cdev->dev)) {
693 put_device(&cdev->dev);
694 return;
695 }
696 set_bit(1, &cdev->private->registered);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697}
698
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100699void ccw_device_do_unreg_rereg(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100701 struct ccw_device_private *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 struct ccw_device *cdev;
703 struct subchannel *sch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100705 priv = container_of(work, struct ccw_device_private, kick_work);
706 cdev = priv->cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 sch = to_subchannel(cdev->dev.parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Cornelia Huckef995162007-04-27 16:01:39 +0200709 ccw_device_unregister(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 PREPARE_WORK(&cdev->private->kick_work,
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100711 ccw_device_add_changed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 queue_work(ccw_device_work, &cdev->private->kick_work);
713}
714
715static void
716ccw_device_release(struct device *dev)
717{
718 struct ccw_device *cdev;
719
720 cdev = to_ccwdev(dev);
721 kfree(cdev->private);
722 kfree(cdev);
723}
724
Cornelia Huck7674da72006-12-08 15:54:21 +0100725static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
726{
727 struct ccw_device *cdev;
728
729 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
730 if (cdev) {
731 cdev->private = kzalloc(sizeof(struct ccw_device_private),
732 GFP_KERNEL | GFP_DMA);
733 if (cdev->private)
734 return cdev;
735 }
736 kfree(cdev);
737 return ERR_PTR(-ENOMEM);
738}
739
740static int io_subchannel_initialize_dev(struct subchannel *sch,
741 struct ccw_device *cdev)
742{
743 cdev->private->cdev = cdev;
744 atomic_set(&cdev->private->onoff, 0);
745 cdev->dev.parent = &sch->dev;
746 cdev->dev.release = ccw_device_release;
Heiko Carstens33583c32007-11-05 11:10:07 +0100747 INIT_WORK(&cdev->private->kick_work, NULL);
Cornelia Huckef995162007-04-27 16:01:39 +0200748 cdev->dev.groups = ccwdev_attr_groups;
Cornelia Huck7674da72006-12-08 15:54:21 +0100749 /* Do first half of device_register. */
750 device_initialize(&cdev->dev);
751 if (!get_device(&sch->dev)) {
752 if (cdev->dev.release)
753 cdev->dev.release(&cdev->dev);
754 return -ENODEV;
755 }
756 return 0;
757}
758
759static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
760{
761 struct ccw_device *cdev;
762 int ret;
763
764 cdev = io_subchannel_allocate_dev(sch);
765 if (!IS_ERR(cdev)) {
766 ret = io_subchannel_initialize_dev(sch, cdev);
767 if (ret) {
768 kfree(cdev);
769 cdev = ERR_PTR(ret);
770 }
771 }
772 return cdev;
773}
774
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100775static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
776
777static void sch_attach_device(struct subchannel *sch,
778 struct ccw_device *cdev)
779{
Cornelia Huck82b7ac02007-04-27 16:01:36 +0200780 css_update_ssd_info(sch);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100781 spin_lock_irq(sch->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100782 sch_set_cdev(sch, cdev);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100783 cdev->private->schid = sch->schid;
784 cdev->ccwlock = sch->lock;
Cornelia Huckc820de32008-07-14 09:58:45 +0200785 ccw_device_trigger_reprobe(cdev);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100786 spin_unlock_irq(sch->lock);
787}
788
789static void sch_attach_disconnected_device(struct subchannel *sch,
790 struct ccw_device *cdev)
791{
792 struct subchannel *other_sch;
793 int ret;
794
795 other_sch = to_subchannel(get_device(cdev->dev.parent));
796 ret = device_move(&cdev->dev, &sch->dev);
797 if (ret) {
Michael Ernst139b83d2008-05-07 09:22:54 +0200798 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100799 "(ret=%d)!\n", cdev->private->dev_id.ssid,
800 cdev->private->dev_id.devno, ret);
801 put_device(&other_sch->dev);
802 return;
803 }
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100804 sch_set_cdev(other_sch, NULL);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100805 /* No need to keep a subchannel without ccw device around. */
806 css_sch_device_unregister(other_sch);
807 put_device(&other_sch->dev);
808 sch_attach_device(sch, cdev);
809}
810
811static void sch_attach_orphaned_device(struct subchannel *sch,
812 struct ccw_device *cdev)
813{
814 int ret;
815
816 /* Try to move the ccw device to its new subchannel. */
817 ret = device_move(&cdev->dev, &sch->dev);
818 if (ret) {
819 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
820 "failed (ret=%d)!\n",
821 cdev->private->dev_id.ssid,
822 cdev->private->dev_id.devno, ret);
823 return;
824 }
825 sch_attach_device(sch, cdev);
826}
827
828static void sch_create_and_recog_new_device(struct subchannel *sch)
829{
830 struct ccw_device *cdev;
831
832 /* Need to allocate a new ccw device. */
833 cdev = io_subchannel_create_ccwdev(sch);
834 if (IS_ERR(cdev)) {
835 /* OK, we did everything we could... */
836 css_sch_device_unregister(sch);
837 return;
838 }
839 spin_lock_irq(sch->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100840 sch_set_cdev(sch, cdev);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100841 spin_unlock_irq(sch->lock);
842 /* Start recognition for the new ccw device. */
843 if (io_subchannel_recog(cdev, sch)) {
844 spin_lock_irq(sch->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100845 sch_set_cdev(sch, NULL);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100846 spin_unlock_irq(sch->lock);
847 if (cdev->dev.release)
848 cdev->dev.release(&cdev->dev);
849 css_sch_device_unregister(sch);
850 }
851}
852
853
854void ccw_device_move_to_orphanage(struct work_struct *work)
855{
856 struct ccw_device_private *priv;
857 struct ccw_device *cdev;
858 struct ccw_device *replacing_cdev;
859 struct subchannel *sch;
860 int ret;
861 struct channel_subsystem *css;
862 struct ccw_dev_id dev_id;
863
864 priv = container_of(work, struct ccw_device_private, kick_work);
865 cdev = priv->cdev;
866 sch = to_subchannel(cdev->dev.parent);
867 css = to_css(sch->dev.parent);
868 dev_id.devno = sch->schib.pmcw.dev;
869 dev_id.ssid = sch->schid.ssid;
870
871 /*
872 * Move the orphaned ccw device to the orphanage so the replacing
873 * ccw device can take its place on the subchannel.
874 */
875 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
876 if (ret) {
877 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
878 "(ret=%d)!\n", cdev->private->dev_id.ssid,
879 cdev->private->dev_id.devno, ret);
880 return;
881 }
882 cdev->ccwlock = css->pseudo_subchannel->lock;
883 /*
884 * Search for the replacing ccw device
885 * - among the disconnected devices
886 * - in the orphanage
887 */
888 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
889 if (replacing_cdev) {
890 sch_attach_disconnected_device(sch, replacing_cdev);
Cornelia Huck85acc402008-11-14 18:18:06 +0100891 /* Release reference from get_disc_ccwdev_by_dev_id() */
Cornelia Huck97166f52008-12-25 13:39:05 +0100892 put_device(&replacing_cdev->dev);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100893 return;
894 }
895 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
896 if (replacing_cdev) {
897 sch_attach_orphaned_device(sch, replacing_cdev);
Cornelia Huck85acc402008-11-14 18:18:06 +0100898 /* Release reference from get_orphaned_ccwdev_by_dev_id() */
Cornelia Huck97166f52008-12-25 13:39:05 +0100899 put_device(&replacing_cdev->dev);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +0100900 return;
901 }
902 sch_create_and_recog_new_device(sch);
903}
904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905/*
906 * Register recognized device.
907 */
908static void
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100909io_subchannel_register(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100911 struct ccw_device_private *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 struct ccw_device *cdev;
913 struct subchannel *sch;
914 int ret;
915 unsigned long flags;
916
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100917 priv = container_of(work, struct ccw_device_private, kick_work);
918 cdev = priv->cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck82b7ac02007-04-27 16:01:36 +0200920 css_update_ssd_info(sch);
Cornelia Huck47af5512006-12-04 15:41:07 +0100921 /*
922 * io_subchannel_register() will also be called after device
923 * recognition has been done for a boxed device (which will already
924 * be registered). We need to reprobe since we may now have sense id
925 * information.
926 */
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700927 if (klist_node_attached(&cdev->dev.knode_parent)) {
Cornelia Huck47af5512006-12-04 15:41:07 +0100928 if (!cdev->drv) {
929 ret = device_reprobe(&cdev->dev);
930 if (ret)
931 /* We can't do much here. */
Michael Ernst139b83d2008-05-07 09:22:54 +0200932 CIO_MSG_EVENT(0, "device_reprobe() returned"
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200933 " %d for 0.%x.%04x\n", ret,
934 cdev->private->dev_id.ssid,
935 cdev->private->dev_id.devno);
Cornelia Huck47af5512006-12-04 15:41:07 +0100936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 goto out;
938 }
Cornelia Huckfa1a8c22007-04-26 00:12:03 -0700939 /*
940 * Now we know this subchannel will stay, we can throw
941 * our delayed uevent.
942 */
943 sch->dev.uevent_suppress = 0;
944 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 /* make it known to the system */
946 ret = ccw_device_register(cdev);
947 if (ret) {
Cornelia Hucke556bbb2007-07-27 12:29:19 +0200948 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
949 cdev->private->dev_id.ssid,
950 cdev->private->dev_id.devno, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 put_device(&cdev->dev);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100952 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckdb6a6422008-01-26 14:10:46 +0100953 sch_set_cdev(sch, NULL);
Cornelia Huck2ec22982006-12-08 15:54:26 +0100954 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 kfree (cdev->private);
956 kfree (cdev);
957 put_device(&sch->dev);
958 if (atomic_dec_and_test(&ccw_device_init_count))
959 wake_up(&ccw_device_init_wq);
960 return;
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 put_device(&cdev->dev);
963out:
964 cdev->private->flags.recog_done = 1;
965 put_device(&sch->dev);
966 wake_up(&cdev->private->wait_q);
967 if (atomic_dec_and_test(&ccw_device_init_count))
968 wake_up(&ccw_device_init_wq);
969}
970
Cornelia Huck3f4cf6e2007-10-12 16:11:26 +0200971static void ccw_device_call_sch_unregister(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100973 struct ccw_device_private *priv;
974 struct ccw_device *cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 struct subchannel *sch;
976
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100977 priv = container_of(work, struct ccw_device_private, kick_work);
978 cdev = priv->cdev;
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200979 /* Get subchannel reference for local processing. */
980 if (!get_device(cdev->dev.parent))
981 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200983 css_sch_device_unregister(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 /* Reset intparm to zeroes. */
985 sch->schib.pmcw.intparm = 0;
986 cio_modify(sch);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200987 /* Release cdev reference for workqueue processing.*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 put_device(&cdev->dev);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +0200989 /* Release subchannel reference for local processing. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 put_device(&sch->dev);
991}
992
993/*
994 * subchannel recognition done. Called from the state machine.
995 */
996void
997io_subchannel_recog_done(struct ccw_device *cdev)
998{
999 struct subchannel *sch;
1000
1001 if (css_init_done == 0) {
1002 cdev->private->flags.recog_done = 1;
1003 return;
1004 }
1005 switch (cdev->private->state) {
1006 case DEV_STATE_NOT_OPER:
1007 cdev->private->flags.recog_done = 1;
1008 /* Remove device found not operational. */
1009 if (!get_device(&cdev->dev))
1010 break;
1011 sch = to_subchannel(cdev->dev.parent);
1012 PREPARE_WORK(&cdev->private->kick_work,
Martin Schwidefskyc1637532006-12-08 15:53:57 +01001013 ccw_device_call_sch_unregister);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 queue_work(slow_path_wq, &cdev->private->kick_work);
Peter Oberparleiter46fbe4e2008-10-10 21:33:05 +02001015 /* Release subchannel reference for asynchronous recognition. */
1016 put_device(&sch->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (atomic_dec_and_test(&ccw_device_init_count))
1018 wake_up(&ccw_device_init_wq);
1019 break;
1020 case DEV_STATE_BOXED:
1021 /* Device did not respond in time. */
1022 case DEV_STATE_OFFLINE:
1023 /*
1024 * We can't register the device in interrupt context so
1025 * we schedule a work item.
1026 */
1027 if (!get_device(&cdev->dev))
1028 break;
1029 PREPARE_WORK(&cdev->private->kick_work,
Martin Schwidefskyc1637532006-12-08 15:53:57 +01001030 io_subchannel_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 queue_work(slow_path_wq, &cdev->private->kick_work);
1032 break;
1033 }
1034}
1035
1036static int
1037io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
1038{
1039 int rc;
1040 struct ccw_device_private *priv;
1041
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001042 sch_set_cdev(sch, cdev);
Cornelia Huck2ec22982006-12-08 15:54:26 +01001043 cdev->ccwlock = sch->lock;
Cornelia Huckfb6958a2006-01-06 00:19:25 -08001044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 /* Init private data. */
1046 priv = cdev->private;
Cornelia Huck78964262006-10-11 15:31:38 +02001047 priv->dev_id.devno = sch->schib.pmcw.dev;
1048 priv->dev_id.ssid = sch->schid.ssid;
1049 priv->schid = sch->schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 priv->state = DEV_STATE_NOT_OPER;
1051 INIT_LIST_HEAD(&priv->cmb_list);
1052 init_waitqueue_head(&priv->wait_q);
1053 init_timer(&priv->timer);
1054
1055 /* Set an initial name for the device. */
Cornelia Huck1f4e7ed2008-10-10 21:33:14 +02001056 if (cio_is_console(sch->schid))
1057 cdev->dev.init_name = cio_get_console_cdev_name(sch);
1058 else
1059 dev_set_name(&cdev->dev, "0.%x.%04x",
1060 sch->schid.ssid, sch->schib.pmcw.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 /* Increase counter of devices currently in recognition. */
1063 atomic_inc(&ccw_device_init_count);
1064
1065 /* Start async. device sensing. */
Cornelia Huck2ec22982006-12-08 15:54:26 +01001066 spin_lock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 rc = ccw_device_recognition(cdev);
Cornelia Huck2ec22982006-12-08 15:54:26 +01001068 spin_unlock_irq(sch->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 if (rc) {
1070 if (atomic_dec_and_test(&ccw_device_init_count))
1071 wake_up(&ccw_device_init_wq);
1072 }
1073 return rc;
1074}
1075
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +01001076static void ccw_device_move_to_sch(struct work_struct *work)
1077{
1078 struct ccw_device_private *priv;
1079 int rc;
1080 struct subchannel *sch;
1081 struct ccw_device *cdev;
1082 struct subchannel *former_parent;
1083
1084 priv = container_of(work, struct ccw_device_private, kick_work);
1085 sch = priv->sch;
1086 cdev = priv->cdev;
1087 former_parent = ccw_device_is_orphan(cdev) ?
1088 NULL : to_subchannel(get_device(cdev->dev.parent));
1089 mutex_lock(&sch->reg_mutex);
1090 /* Try to move the ccw device to its new subchannel. */
1091 rc = device_move(&cdev->dev, &sch->dev);
1092 mutex_unlock(&sch->reg_mutex);
1093 if (rc) {
Michael Ernst139b83d2008-05-07 09:22:54 +02001094 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +01001095 "0.%x.%04x failed (ret=%d)!\n",
1096 cdev->private->dev_id.ssid,
1097 cdev->private->dev_id.devno, sch->schid.ssid,
1098 sch->schid.sch_no, rc);
1099 css_sch_device_unregister(sch);
1100 goto out;
1101 }
1102 if (former_parent) {
1103 spin_lock_irq(former_parent->lock);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001104 sch_set_cdev(former_parent, NULL);
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +01001105 spin_unlock_irq(former_parent->lock);
1106 css_sch_device_unregister(former_parent);
1107 /* Reset intparm to zeroes. */
1108 former_parent->schib.pmcw.intparm = 0;
1109 cio_modify(former_parent);
1110 }
1111 sch_attach_device(sch, cdev);
1112out:
1113 if (former_parent)
1114 put_device(&former_parent->dev);
1115 put_device(&cdev->dev);
1116}
1117
Cornelia Huck602b20f2008-01-26 14:10:39 +01001118static void io_subchannel_irq(struct subchannel *sch)
1119{
1120 struct ccw_device *cdev;
1121
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001122 cdev = sch_get_cdev(sch);
Cornelia Huck602b20f2008-01-26 14:10:39 +01001123
1124 CIO_TRACE_EVENT(3, "IRQ");
Kay Sievers2a0217d2008-10-10 21:33:09 +02001125 CIO_TRACE_EVENT(3, dev_name(&sch->dev));
Cornelia Huck602b20f2008-01-26 14:10:39 +01001126 if (cdev)
1127 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1128}
1129
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001130static void io_subchannel_init_fields(struct subchannel *sch)
1131{
1132 if (cio_is_console(sch->schid))
1133 sch->opm = 0xff;
1134 else
1135 sch->opm = chp_get_sch_opm(sch);
1136 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Cornelia Huck3a3fc292008-07-14 09:58:58 +02001137 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001138
1139 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1140 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1141 sch->schib.pmcw.dev, sch->schid.ssid,
1142 sch->schid.sch_no, sch->schib.pmcw.pim,
1143 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
1144 /* Initially set up some fields in the pmcw. */
1145 sch->schib.pmcw.ena = 0;
1146 sch->schib.pmcw.csense = 1; /* concurrent sense */
1147 if ((sch->lpm & (sch->lpm - 1)) != 0)
1148 sch->schib.pmcw.mp = 1; /* multipath mode */
1149 /* clean up possible residual cmf stuff */
1150 sch->schib.pmcw.mme = 0;
1151 sch->schib.pmcw.mbfc = 0;
1152 sch->schib.pmcw.mbi = 0;
1153 sch->schib.mba = 0;
1154}
1155
1156static int io_subchannel_probe(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 struct ccw_device *cdev;
1159 int rc;
1160 unsigned long flags;
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +01001161 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001163 cdev = sch_get_cdev(sch);
1164 if (cdev) {
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001165 rc = sysfs_create_group(&sch->dev.kobj,
1166 &io_subchannel_attr_group);
1167 if (rc)
1168 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1169 "attributes for subchannel "
1170 "0.%x.%04x (rc=%d)\n",
1171 sch->schid.ssid, sch->schid.sch_no, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /*
1173 * This subchannel already has an associated ccw_device.
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001174 * Throw the delayed uevent for the subchannel, register
1175 * the ccw_device and exit. This happens for all early
1176 * devices, e.g. the console.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 */
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001178 sch->dev.uevent_suppress = 0;
1179 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
Cornelia Hucke1031782007-10-12 16:11:23 +02001180 cdev->dev.groups = ccwdev_attr_groups;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 device_initialize(&cdev->dev);
1182 ccw_device_register(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 /*
1184 * Check if the device is already online. If it is
Cornelia Huck9cd67422008-12-25 13:39:06 +01001185 * the reference count needs to be corrected since we
1186 * didn't obtain a reference in ccw_device_set_online.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 */
1188 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1189 cdev->private->state != DEV_STATE_OFFLINE &&
1190 cdev->private->state != DEV_STATE_BOXED)
1191 get_device(&cdev->dev);
1192 return 0;
1193 }
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001194 io_subchannel_init_fields(sch);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001195 rc = sysfs_create_group(&sch->dev.kobj,
1196 &io_subchannel_attr_group);
1197 if (rc)
1198 return rc;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001199 /* Allocate I/O subchannel private data. */
1200 sch->private = kzalloc(sizeof(struct io_subchannel_private),
1201 GFP_KERNEL | GFP_DMA);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001202 if (!sch->private) {
1203 rc = -ENOMEM;
1204 goto out_err;
1205 }
Sebastian Ott111e95a2008-12-25 13:39:03 +01001206 /*
1207 * First check if a fitting device may be found amongst the
1208 * disconnected devices or in the orphanage.
1209 */
1210 dev_id.devno = sch->schib.pmcw.dev;
1211 dev_id.ssid = sch->schid.ssid;
Cornelia Huckd7b5a4c2006-12-08 15:54:28 +01001212 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
1213 if (!cdev)
1214 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
1215 &dev_id);
1216 if (cdev) {
1217 /*
1218 * Schedule moving the device until when we have a registered
1219 * subchannel to move to and succeed the probe. We can
1220 * unregister later again, when the probe is through.
1221 */
1222 cdev->private->sch = sch;
1223 PREPARE_WORK(&cdev->private->kick_work,
1224 ccw_device_move_to_sch);
1225 queue_work(slow_path_wq, &cdev->private->kick_work);
1226 return 0;
1227 }
Cornelia Huck7674da72006-12-08 15:54:21 +01001228 cdev = io_subchannel_create_ccwdev(sch);
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001229 if (IS_ERR(cdev)) {
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001230 rc = PTR_ERR(cdev);
1231 goto out_err;
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001232 }
Cornelia Huck8bbace72006-01-11 10:56:22 +01001233 rc = io_subchannel_recog(cdev, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 if (rc) {
Cornelia Huck2ec22982006-12-08 15:54:26 +01001235 spin_lock_irqsave(sch->lock, flags);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001236 sch_set_cdev(sch, NULL);
Cornelia Huck2ec22982006-12-08 15:54:26 +01001237 spin_unlock_irqrestore(sch->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 if (cdev->dev.release)
1239 cdev->dev.release(&cdev->dev);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001240 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 }
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001242 return 0;
1243out_err:
1244 kfree(sch->private);
1245 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 return rc;
1247}
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249static int
Cornelia Huck8bbace72006-01-11 10:56:22 +01001250io_subchannel_remove (struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
1252 struct ccw_device *cdev;
1253 unsigned long flags;
1254
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001255 cdev = sch_get_cdev(sch);
1256 if (!cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 /* Set ccw device to not operational and drop reference. */
1259 spin_lock_irqsave(cdev->ccwlock, flags);
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001260 sch_set_cdev(sch, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 cdev->private->state = DEV_STATE_NOT_OPER;
1262 spin_unlock_irqrestore(cdev->ccwlock, flags);
Cornelia Huckef995162007-04-27 16:01:39 +02001263 ccw_device_unregister(cdev);
1264 put_device(&cdev->dev);
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001265 kfree(sch->private);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +02001266 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 return 0;
1268}
1269
Cornelia Huck602b20f2008-01-26 14:10:39 +01001270static int io_subchannel_notify(struct subchannel *sch, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
1272 struct ccw_device *cdev;
1273
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001274 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 if (!cdev)
1276 return 0;
Cornelia Huckc820de32008-07-14 09:58:45 +02001277 return ccw_device_notify(cdev, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Cornelia Huck602b20f2008-01-26 14:10:39 +01001280static void io_subchannel_verify(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
1282 struct ccw_device *cdev;
1283
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001284 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 if (cdev)
1286 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1287}
1288
Cornelia Huckc820de32008-07-14 09:58:45 +02001289static int check_for_io_on_path(struct subchannel *sch, int mask)
1290{
1291 int cc;
1292
1293 cc = stsch(sch->schid, &sch->schib);
1294 if (cc)
1295 return 0;
Peter Oberparleiter23d805b2008-07-14 09:58:50 +02001296 if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
Cornelia Huckc820de32008-07-14 09:58:45 +02001297 return 1;
1298 return 0;
1299}
1300
1301static void terminate_internal_io(struct subchannel *sch,
1302 struct ccw_device *cdev)
1303{
1304 if (cio_clear(sch)) {
1305 /* Recheck device in case clear failed. */
1306 sch->lpm = 0;
1307 if (cdev->online)
1308 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1309 else
1310 css_schedule_eval(sch->schid);
1311 return;
1312 }
1313 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
1314 /* Request retry of internal operation. */
1315 cdev->private->flags.intretry = 1;
1316 /* Call handler. */
1317 if (cdev->handler)
1318 cdev->handler(cdev, cdev->private->intparm,
1319 ERR_PTR(-EIO));
1320}
1321
1322static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
1324 struct ccw_device *cdev;
1325
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001326 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (!cdev)
1328 return;
Cornelia Huckc820de32008-07-14 09:58:45 +02001329 if (check_for_io_on_path(sch, mask)) {
1330 if (cdev->private->state == DEV_STATE_ONLINE)
1331 ccw_device_kill_io(cdev);
1332 else {
1333 terminate_internal_io(sch, cdev);
1334 /* Re-start path verification. */
1335 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1336 }
1337 } else
1338 /* trigger path verification. */
1339 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1340
1341}
1342
Cornelia Huck99611f82008-07-14 09:59:02 +02001343static int io_subchannel_chp_event(struct subchannel *sch,
1344 struct chp_link *link, int event)
Cornelia Huckc820de32008-07-14 09:58:45 +02001345{
1346 int mask;
Cornelia Huckc820de32008-07-14 09:58:45 +02001347
Cornelia Huck99611f82008-07-14 09:59:02 +02001348 mask = chp_ssd_get_mask(&sch->ssd_info, link);
Cornelia Huckc820de32008-07-14 09:58:45 +02001349 if (!mask)
1350 return 0;
1351 switch (event) {
1352 case CHP_VARY_OFF:
1353 sch->opm &= ~mask;
1354 sch->lpm &= ~mask;
1355 io_subchannel_terminate_path(sch, mask);
1356 break;
1357 case CHP_VARY_ON:
1358 sch->opm |= mask;
1359 sch->lpm |= mask;
1360 io_subchannel_verify(sch);
1361 break;
1362 case CHP_OFFLINE:
1363 if (stsch(sch->schid, &sch->schib))
1364 return -ENXIO;
1365 if (!css_sch_is_valid(&sch->schib))
1366 return -ENODEV;
1367 io_subchannel_terminate_path(sch, mask);
1368 break;
1369 case CHP_ONLINE:
1370 if (stsch(sch->schid, &sch->schib))
1371 return -ENXIO;
1372 sch->lpm |= mask & sch->opm;
1373 io_subchannel_verify(sch);
1374 break;
1375 }
1376 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
1379static void
Cornelia Huck8bbace72006-01-11 10:56:22 +01001380io_subchannel_shutdown(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 struct ccw_device *cdev;
1383 int ret;
1384
Cornelia Huckdb6a6422008-01-26 14:10:46 +01001385 cdev = sch_get_cdev(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001387 if (cio_is_console(sch->schid))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 return;
1389 if (!sch->schib.pmcw.ena)
1390 /* Nothing to do. */
1391 return;
1392 ret = cio_disable_subchannel(sch);
1393 if (ret != -EBUSY)
1394 /* Subchannel is disabled, we're done. */
1395 return;
1396 cdev->private->state = DEV_STATE_QUIESCE;
1397 if (cdev->handler)
1398 cdev->handler(cdev, cdev->private->intparm,
1399 ERR_PTR(-EIO));
1400 ret = ccw_device_cancel_halt_clear(cdev);
1401 if (ret == -EBUSY) {
1402 ccw_device_set_timeout(cdev, HZ/10);
1403 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1404 }
1405 cio_disable_subchannel(sch);
1406}
1407
Cornelia Huckc820de32008-07-14 09:58:45 +02001408static int io_subchannel_get_status(struct subchannel *sch)
1409{
1410 struct schib schib;
1411
1412 if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
1413 return CIO_GONE;
1414 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
1415 return CIO_REVALIDATE;
1416 if (!sch->lpm)
1417 return CIO_NO_PATH;
1418 return CIO_OPER;
1419}
1420
1421static int device_is_disconnected(struct ccw_device *cdev)
1422{
1423 if (!cdev)
1424 return 0;
1425 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1426 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1427}
1428
1429static int recovery_check(struct device *dev, void *data)
1430{
1431 struct ccw_device *cdev = to_ccwdev(dev);
1432 int *redo = data;
1433
1434 spin_lock_irq(cdev->ccwlock);
1435 switch (cdev->private->state) {
1436 case DEV_STATE_DISCONNECTED:
1437 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1438 cdev->private->dev_id.ssid,
1439 cdev->private->dev_id.devno);
1440 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1441 *redo = 1;
1442 break;
1443 case DEV_STATE_DISCONNECTED_SENSE_ID:
1444 *redo = 1;
1445 break;
1446 }
1447 spin_unlock_irq(cdev->ccwlock);
1448
1449 return 0;
1450}
1451
1452static void recovery_work_func(struct work_struct *unused)
1453{
1454 int redo = 0;
1455
1456 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1457 if (redo) {
1458 spin_lock_irq(&recovery_lock);
1459 if (!timer_pending(&recovery_timer)) {
1460 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1461 recovery_phase++;
1462 mod_timer(&recovery_timer, jiffies +
1463 recovery_delay[recovery_phase] * HZ);
1464 }
1465 spin_unlock_irq(&recovery_lock);
1466 } else
1467 CIO_MSG_EVENT(4, "recovery: end\n");
1468}
1469
1470static DECLARE_WORK(recovery_work, recovery_work_func);
1471
1472static void recovery_func(unsigned long data)
1473{
1474 /*
1475 * We can't do our recovery in softirq context and it's not
1476 * performance critical, so we schedule it.
1477 */
1478 schedule_work(&recovery_work);
1479}
1480
1481static void ccw_device_schedule_recovery(void)
1482{
1483 unsigned long flags;
1484
1485 CIO_MSG_EVENT(4, "recovery: schedule\n");
1486 spin_lock_irqsave(&recovery_lock, flags);
1487 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1488 recovery_phase = 0;
1489 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1490 }
1491 spin_unlock_irqrestore(&recovery_lock, flags);
1492}
1493
Peter Oberparleiterecf5d9e2008-10-10 21:33:06 +02001494static int purge_fn(struct device *dev, void *data)
1495{
1496 struct ccw_device *cdev = to_ccwdev(dev);
1497 struct ccw_device_private *priv = cdev->private;
1498 int unreg;
1499
1500 spin_lock_irq(cdev->ccwlock);
1501 unreg = is_blacklisted(priv->dev_id.ssid, priv->dev_id.devno) &&
1502 (priv->state == DEV_STATE_OFFLINE);
1503 spin_unlock_irq(cdev->ccwlock);
1504 if (!unreg)
1505 goto out;
1506 if (!get_device(&cdev->dev))
1507 goto out;
1508 CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", priv->dev_id.ssid,
1509 priv->dev_id.devno);
1510 PREPARE_WORK(&cdev->private->kick_work, ccw_device_call_sch_unregister);
1511 queue_work(slow_path_wq, &cdev->private->kick_work);
1512
1513out:
1514 /* Abort loop in case of pending signal. */
1515 if (signal_pending(current))
1516 return -EINTR;
1517
1518 return 0;
1519}
1520
1521/**
1522 * ccw_purge_blacklisted - purge unused, blacklisted devices
1523 *
1524 * Unregister all ccw devices that are offline and on the blacklist.
1525 */
1526int ccw_purge_blacklisted(void)
1527{
1528 CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n");
1529 bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn);
1530 return 0;
1531}
1532
Cornelia Huckc820de32008-07-14 09:58:45 +02001533static void device_set_disconnected(struct ccw_device *cdev)
1534{
1535 if (!cdev)
1536 return;
1537 ccw_device_set_timeout(cdev, 0);
1538 cdev->private->flags.fake_irb = 0;
1539 cdev->private->state = DEV_STATE_DISCONNECTED;
1540 if (cdev->online)
1541 ccw_device_schedule_recovery();
1542}
1543
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001544void ccw_device_set_notoper(struct ccw_device *cdev)
1545{
1546 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1547
1548 CIO_TRACE_EVENT(2, "notoper");
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001549 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001550 ccw_device_set_timeout(cdev, 0);
1551 cio_disable_subchannel(sch);
1552 cdev->private->state = DEV_STATE_NOT_OPER;
1553}
1554
Cornelia Huckc820de32008-07-14 09:58:45 +02001555static int io_subchannel_sch_event(struct subchannel *sch, int slow)
1556{
1557 int event, ret, disc;
1558 unsigned long flags;
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001559 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action;
Cornelia Huckc820de32008-07-14 09:58:45 +02001560 struct ccw_device *cdev;
1561
1562 spin_lock_irqsave(sch->lock, flags);
1563 cdev = sch_get_cdev(sch);
1564 disc = device_is_disconnected(cdev);
1565 if (disc && slow) {
1566 /* Disconnected devices are evaluated directly only.*/
1567 spin_unlock_irqrestore(sch->lock, flags);
1568 return 0;
1569 }
1570 /* No interrupt after machine check - kill pending timers. */
1571 if (cdev)
1572 ccw_device_set_timeout(cdev, 0);
1573 if (!disc && !slow) {
1574 /* Non-disconnected devices are evaluated on the slow path. */
1575 spin_unlock_irqrestore(sch->lock, flags);
1576 return -EAGAIN;
1577 }
1578 event = io_subchannel_get_status(sch);
1579 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
1580 sch->schid.ssid, sch->schid.sch_no, event,
1581 disc ? "disconnected" : "normal",
1582 slow ? "slow" : "fast");
1583 /* Analyze subchannel status. */
1584 action = NONE;
1585 switch (event) {
1586 case CIO_NO_PATH:
1587 if (disc) {
1588 /* Check if paths have become available. */
1589 action = REPROBE;
1590 break;
1591 }
1592 /* fall through */
1593 case CIO_GONE:
Cornelia Huckc820de32008-07-14 09:58:45 +02001594 /* Ask driver what to do with device. */
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001595 if (io_subchannel_notify(sch, event))
1596 action = DISC;
1597 else
1598 action = UNREGISTER;
Cornelia Huckc820de32008-07-14 09:58:45 +02001599 break;
1600 case CIO_REVALIDATE:
1601 /* Device will be removed, so no notify necessary. */
1602 if (disc)
1603 /* Reprobe because immediate unregister might block. */
1604 action = REPROBE;
1605 else
1606 action = UNREGISTER_PROBE;
1607 break;
1608 case CIO_OPER:
1609 if (disc)
1610 /* Get device operational again. */
1611 action = REPROBE;
1612 break;
1613 }
1614 /* Perform action. */
1615 ret = 0;
1616 switch (action) {
1617 case UNREGISTER:
1618 case UNREGISTER_PROBE:
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001619 ccw_device_set_notoper(cdev);
Cornelia Huckc820de32008-07-14 09:58:45 +02001620 /* Unregister device (will use subchannel lock). */
1621 spin_unlock_irqrestore(sch->lock, flags);
1622 css_sch_device_unregister(sch);
1623 spin_lock_irqsave(sch->lock, flags);
1624
1625 /* Reset intparm to zeroes. */
1626 sch->schib.pmcw.intparm = 0;
1627 cio_modify(sch);
1628 break;
1629 case REPROBE:
1630 ccw_device_trigger_reprobe(cdev);
1631 break;
Peter Oberparleiter91c36912008-08-21 19:46:39 +02001632 case DISC:
1633 device_set_disconnected(cdev);
1634 break;
Cornelia Huckc820de32008-07-14 09:58:45 +02001635 default:
1636 break;
1637 }
1638 spin_unlock_irqrestore(sch->lock, flags);
1639 /* Probe if necessary. */
1640 if (action == UNREGISTER_PROBE)
1641 ret = css_probe_device(sch->schid);
1642
1643 return ret;
1644}
1645
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646#ifdef CONFIG_CCW_CONSOLE
1647static struct ccw_device console_cdev;
Cornelia Huck1f4e7ed2008-10-10 21:33:14 +02001648static char console_cdev_name[10] = "0.x.xxxx";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649static struct ccw_device_private console_private;
1650static int console_cdev_in_use;
1651
Cornelia Huck2ec22982006-12-08 15:54:26 +01001652static DEFINE_SPINLOCK(ccw_console_lock);
1653
1654spinlock_t * cio_get_console_lock(void)
1655{
1656 return &ccw_console_lock;
1657}
1658
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001659static int ccw_device_console_enable(struct ccw_device *cdev,
1660 struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
1662 int rc;
1663
Cornelia Huckcd6b4f22008-01-26 14:10:43 +01001664 /* Attach subchannel private data. */
1665 sch->private = cio_get_console_priv();
1666 memset(sch->private, 0, sizeof(struct io_subchannel_private));
Cornelia Huck0ae7a7b2008-07-14 09:58:43 +02001667 io_subchannel_init_fields(sch);
1668 sch->driver = &io_subchannel_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 /* Initialize the ccw_device structure. */
Heiko Carstens292888c2006-08-30 14:33:35 +02001670 cdev->dev.parent= &sch->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 rc = io_subchannel_recog(cdev, sch);
1672 if (rc)
1673 return rc;
1674
1675 /* Now wait for the async. recognition to come to an end. */
1676 spin_lock_irq(cdev->ccwlock);
1677 while (!dev_fsm_final_state(cdev))
1678 wait_cons_dev();
1679 rc = -EIO;
1680 if (cdev->private->state != DEV_STATE_OFFLINE)
1681 goto out_unlock;
1682 ccw_device_online(cdev);
1683 while (!dev_fsm_final_state(cdev))
1684 wait_cons_dev();
1685 if (cdev->private->state != DEV_STATE_ONLINE)
1686 goto out_unlock;
1687 rc = 0;
1688out_unlock:
1689 spin_unlock_irq(cdev->ccwlock);
1690 return 0;
1691}
1692
1693struct ccw_device *
1694ccw_device_probe_console(void)
1695{
1696 struct subchannel *sch;
1697 int ret;
1698
1699 if (xchg(&console_cdev_in_use, 1) != 0)
Peter Oberparleiter600b5d12006-02-01 03:06:35 -08001700 return ERR_PTR(-EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 sch = cio_probe_console();
1702 if (IS_ERR(sch)) {
1703 console_cdev_in_use = 0;
1704 return (void *) sch;
1705 }
1706 memset(&console_cdev, 0, sizeof(struct ccw_device));
1707 memset(&console_private, 0, sizeof(struct ccw_device_private));
1708 console_cdev.private = &console_private;
Martin Schwidefskyc1637532006-12-08 15:53:57 +01001709 console_private.cdev = &console_cdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 ret = ccw_device_console_enable(&console_cdev, sch);
1711 if (ret) {
1712 cio_release_console();
1713 console_cdev_in_use = 0;
1714 return ERR_PTR(ret);
1715 }
1716 console_cdev.online = 1;
1717 return &console_cdev;
1718}
Cornelia Huck1f4e7ed2008-10-10 21:33:14 +02001719
1720
1721const char *cio_get_console_cdev_name(struct subchannel *sch)
1722{
1723 snprintf(console_cdev_name, 10, "0.%x.%04x",
1724 sch->schid.ssid, sch->schib.pmcw.dev);
1725 return (const char *)console_cdev_name;
1726}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727#endif
1728
1729/*
1730 * get ccw_device matching the busid, but only if owned by cdrv
1731 */
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001732static int
1733__ccwdev_check_busid(struct device *dev, void *id)
1734{
1735 char *bus_id;
1736
Cornelia Huck12975ae2006-10-11 15:31:47 +02001737 bus_id = id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001738
Kay Sievers98df67b2008-12-25 13:38:55 +01001739 return (strcmp(bus_id, dev_name(dev)) == 0);
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001740}
1741
1742
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02001743/**
1744 * get_ccwdev_by_busid() - obtain device from a bus id
1745 * @cdrv: driver the device is owned by
1746 * @bus_id: bus id of the device to be searched
1747 *
1748 * This function searches all devices owned by @cdrv for a device with a bus
1749 * id matching @bus_id.
1750 * Returns:
1751 * If a match is found, its reference count of the found device is increased
1752 * and it is returned; else %NULL is returned.
1753 */
1754struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1755 const char *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001757 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 struct device_driver *drv;
1759
1760 drv = get_driver(&cdrv->driver);
1761 if (!drv)
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001762 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001764 dev = driver_find_device(drv, NULL, (void *)bus_id,
1765 __ccwdev_check_busid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 put_driver(drv);
1767
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001768 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
1770
1771/************************** device driver handling ************************/
1772
1773/* This is the implementation of the ccw_driver class. The probe, remove
1774 * and release methods are initially very similar to the device_driver
1775 * implementations, with the difference that they have ccw_device
1776 * arguments.
1777 *
1778 * A ccw driver also contains the information that is needed for
1779 * device matching.
1780 */
1781static int
1782ccw_device_probe (struct device *dev)
1783{
1784 struct ccw_device *cdev = to_ccwdev(dev);
1785 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1786 int ret;
1787
1788 cdev->drv = cdrv; /* to let the driver call _set_online */
1789
1790 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1791
1792 if (ret) {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001793 cdev->drv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 return ret;
1795 }
1796
1797 return 0;
1798}
1799
1800static int
1801ccw_device_remove (struct device *dev)
1802{
1803 struct ccw_device *cdev = to_ccwdev(dev);
1804 struct ccw_driver *cdrv = cdev->drv;
1805 int ret;
1806
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 if (cdrv->remove)
1808 cdrv->remove(cdev);
1809 if (cdev->online) {
1810 cdev->online = 0;
1811 spin_lock_irq(cdev->ccwlock);
1812 ret = ccw_device_offline(cdev);
1813 spin_unlock_irq(cdev->ccwlock);
1814 if (ret == 0)
1815 wait_event(cdev->private->wait_q,
1816 dev_fsm_final_state(cdev));
1817 else
Michael Ernst139b83d2008-05-07 09:22:54 +02001818 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
Cornelia Hucke556bbb2007-07-27 12:29:19 +02001819 "device 0.%x.%04x\n",
1820 ret, cdev->private->dev_id.ssid,
1821 cdev->private->dev_id.devno);
Cornelia Huck9cd67422008-12-25 13:39:06 +01001822 /* Give up reference obtained in ccw_device_set_online(). */
1823 put_device(&cdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 }
1825 ccw_device_set_timeout(cdev, 0);
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001826 cdev->drv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 return 0;
1828}
1829
Cornelia Huck958974f2007-10-12 16:11:21 +02001830static void ccw_device_shutdown(struct device *dev)
1831{
1832 struct ccw_device *cdev;
1833
1834 cdev = to_ccwdev(dev);
1835 if (cdev->drv && cdev->drv->shutdown)
1836 cdev->drv->shutdown(cdev);
Cornelia Huck1842f2b2007-10-12 16:11:22 +02001837 disable_cmf(cdev);
Cornelia Huck958974f2007-10-12 16:11:21 +02001838}
1839
Cornelia Huck8bbace72006-01-11 10:56:22 +01001840struct bus_type ccw_bus_type = {
1841 .name = "ccw",
1842 .match = ccw_bus_match,
1843 .uevent = ccw_uevent,
1844 .probe = ccw_device_probe,
1845 .remove = ccw_device_remove,
Cornelia Huck958974f2007-10-12 16:11:21 +02001846 .shutdown = ccw_device_shutdown,
Cornelia Huck8bbace72006-01-11 10:56:22 +01001847};
1848
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02001849/**
1850 * ccw_driver_register() - register a ccw driver
1851 * @cdriver: driver to be registered
1852 *
1853 * This function is mainly a wrapper around driver_register().
1854 * Returns:
1855 * %0 on success and a negative error value on failure.
1856 */
1857int ccw_driver_register(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858{
1859 struct device_driver *drv = &cdriver->driver;
1860
1861 drv->bus = &ccw_bus_type;
1862 drv->name = cdriver->name;
Cornelia Huck4beee642008-01-26 14:10:47 +01001863 drv->owner = cdriver->owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 return driver_register(drv);
1866}
1867
Cornelia Huckb2ffd8e2007-10-12 16:11:17 +02001868/**
1869 * ccw_driver_unregister() - deregister a ccw driver
1870 * @cdriver: driver to be deregistered
1871 *
1872 * This function is mainly a wrapper around driver_unregister().
1873 */
1874void ccw_driver_unregister(struct ccw_driver *cdriver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875{
1876 driver_unregister(&cdriver->driver);
1877}
1878
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001879/* Helper func for qdio. */
1880struct subchannel_id
1881ccw_device_get_subchannel_id(struct ccw_device *cdev)
1882{
1883 struct subchannel *sch;
1884
1885 sch = to_subchannel(cdev->dev.parent);
1886 return sch->schid;
1887}
1888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889MODULE_LICENSE("GPL");
1890EXPORT_SYMBOL(ccw_device_set_online);
1891EXPORT_SYMBOL(ccw_device_set_offline);
1892EXPORT_SYMBOL(ccw_driver_register);
1893EXPORT_SYMBOL(ccw_driver_unregister);
1894EXPORT_SYMBOL(get_ccwdev_by_busid);
1895EXPORT_SYMBOL(ccw_bus_type);
1896EXPORT_SYMBOL(ccw_device_work);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001897EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);