blob: 94bdd4d8a4c9c205b72ef1b92dc598fb37b38d0e [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 *
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * IBM Corporation
7 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
Cornelia Huck4ce3b302006-01-14 13:21:04 -08008 * Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/spinlock.h>
14#include <linux/errno.h>
15#include <linux/err.h>
16#include <linux/slab.h>
17#include <linux/list.h>
18#include <linux/device.h>
19#include <linux/workqueue.h>
20
21#include <asm/ccwdev.h>
22#include <asm/cio.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080023#include <asm/param.h> /* HZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "cio.h"
26#include "css.h"
27#include "device.h"
28#include "ioasm.h"
29
30/******************* bus type handling ***********************/
31
32/* The Linux driver model distinguishes between a bus type and
33 * the bus itself. Of course we only have one channel
34 * subsystem driver and one channel system per machine, but
35 * we still use the abstraction. T.R. says it's a good idea. */
36static int
37ccw_bus_match (struct device * dev, struct device_driver * drv)
38{
39 struct ccw_device *cdev = to_ccwdev(dev);
40 struct ccw_driver *cdrv = to_ccwdrv(drv);
41 const struct ccw_device_id *ids = cdrv->ids, *found;
42
43 if (!ids)
44 return 0;
45
46 found = ccw_device_id_match(ids, &cdev->id);
47 if (!found)
48 return 0;
49
50 cdev->id.driver_info = found->driver_info;
51
52 return 1;
53}
54
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020055/* Store modalias string delimited by prefix/suffix string into buffer with
56 * specified size. Return length of resulting string (excluding trailing '\0')
57 * even if string doesn't fit buffer (snprintf semantics). */
58static int snprint_alias(char *buf, size_t size, const char *prefix,
59 struct ccw_device_id *id, const char *suffix)
60{
61 int len;
62
63 len = snprintf(buf, size, "%sccw:t%04Xm%02X", prefix, id->cu_type,
64 id->cu_model);
65 if (len > size)
66 return len;
67 buf += len;
68 size -= len;
69
70 if (id->dev_type != 0)
71 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
72 id->dev_model, suffix);
73 else
74 len += snprintf(buf, size, "dtdm%s", suffix);
75
76 return len;
77}
78
79/* Set up environment variables for ccw device uevent. Return 0 on success,
80 * non-zero otherwise. */
81static int ccw_uevent(struct device *dev, char **envp, int num_envp,
82 char *buffer, int buffer_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 struct ccw_device *cdev = to_ccwdev(dev);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020085 struct ccw_device_id *id = &(cdev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int i = 0;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020087 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020089 /* CU_TYPE= */
90 len = snprintf(buffer, buffer_size, "CU_TYPE=%04X", id->cu_type) + 1;
91 if (len > buffer_size || i >= num_envp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 envp[i++] = buffer;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +020094 buffer += len;
95 buffer_size -= len;
96
97 /* CU_MODEL= */
98 len = snprintf(buffer, buffer_size, "CU_MODEL=%02X", id->cu_model) + 1;
99 if (len > buffer_size || i >= num_envp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return -ENOMEM;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200101 envp[i++] = buffer;
102 buffer += len;
103 buffer_size -= len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /* The next two can be zero, that's ok for us */
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200106 /* DEV_TYPE= */
107 len = snprintf(buffer, buffer_size, "DEV_TYPE=%04X", id->dev_type) + 1;
108 if (len > buffer_size || i >= num_envp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return -ENOMEM;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200110 envp[i++] = buffer;
111 buffer += len;
112 buffer_size -= len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200114 /* DEV_MODEL= */
115 len = snprintf(buffer, buffer_size, "DEV_MODEL=%02X",
116 (unsigned char) id->dev_model) + 1;
117 if (len > buffer_size || i >= num_envp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return -ENOMEM;
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200119 envp[i++] = buffer;
120 buffer += len;
121 buffer_size -= len;
122
123 /* MODALIAS= */
124 len = snprint_alias(buffer, buffer_size, "MODALIAS=", id, "") + 1;
125 if (len > buffer_size || i >= num_envp)
126 return -ENOMEM;
127 envp[i++] = buffer;
128 buffer += len;
129 buffer_size -= len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200131 envp[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 return 0;
134}
135
Cornelia Huck8bbace72006-01-11 10:56:22 +0100136struct bus_type ccw_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Cornelia Huck8bbace72006-01-11 10:56:22 +0100138static int io_subchannel_probe (struct subchannel *);
139static int io_subchannel_remove (struct subchannel *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140void io_subchannel_irq (struct device *);
141static int io_subchannel_notify(struct device *, int);
142static void io_subchannel_verify(struct device *);
143static void io_subchannel_ioterm(struct device *);
Cornelia Huck8bbace72006-01-11 10:56:22 +0100144static void io_subchannel_shutdown(struct subchannel *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146struct css_driver io_subchannel_driver = {
147 .subchannel_type = SUBCHANNEL_TYPE_IO,
148 .drv = {
149 .name = "io_subchannel",
150 .bus = &css_bus_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 },
152 .irq = io_subchannel_irq,
153 .notify = io_subchannel_notify,
154 .verify = io_subchannel_verify,
155 .termination = io_subchannel_ioterm,
Cornelia Huck8bbace72006-01-11 10:56:22 +0100156 .probe = io_subchannel_probe,
157 .remove = io_subchannel_remove,
158 .shutdown = io_subchannel_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161struct workqueue_struct *ccw_device_work;
162struct workqueue_struct *ccw_device_notify_work;
Peter Oberparleiter40154b82006-06-29 14:57:03 +0200163wait_queue_head_t ccw_device_init_wq;
164atomic_t ccw_device_init_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166static int __init
167init_ccw_bus_type (void)
168{
169 int ret;
170
171 init_waitqueue_head(&ccw_device_init_wq);
172 atomic_set(&ccw_device_init_count, 0);
173
174 ccw_device_work = create_singlethread_workqueue("cio");
175 if (!ccw_device_work)
176 return -ENOMEM; /* FIXME: better errno ? */
177 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
178 if (!ccw_device_notify_work) {
179 ret = -ENOMEM; /* FIXME: better errno ? */
180 goto out_err;
181 }
182 slow_path_wq = create_singlethread_workqueue("kslowcrw");
183 if (!slow_path_wq) {
184 ret = -ENOMEM; /* FIXME: better errno ? */
185 goto out_err;
186 }
187 if ((ret = bus_register (&ccw_bus_type)))
188 goto out_err;
189
190 if ((ret = driver_register(&io_subchannel_driver.drv)))
191 goto out_err;
192
193 wait_event(ccw_device_init_wq,
194 atomic_read(&ccw_device_init_count) == 0);
195 flush_workqueue(ccw_device_work);
196 return 0;
197out_err:
198 if (ccw_device_work)
199 destroy_workqueue(ccw_device_work);
200 if (ccw_device_notify_work)
201 destroy_workqueue(ccw_device_notify_work);
202 if (slow_path_wq)
203 destroy_workqueue(slow_path_wq);
204 return ret;
205}
206
207static void __exit
208cleanup_ccw_bus_type (void)
209{
210 driver_unregister(&io_subchannel_driver.drv);
211 bus_unregister(&ccw_bus_type);
212 destroy_workqueue(ccw_device_notify_work);
213 destroy_workqueue(ccw_device_work);
214}
215
216subsys_initcall(init_ccw_bus_type);
217module_exit(cleanup_ccw_bus_type);
218
219/************************ device handling **************************/
220
221/*
222 * A ccw_device has some interfaces in sysfs in addition to the
223 * standard ones.
224 * The following entries are designed to export the information which
225 * resided in 2.4 in /proc/subchannels. Subchannel and device number
226 * are obvious, so they don't have an entry :)
227 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
228 */
229static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400230chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 struct subchannel *sch = to_subchannel(dev);
233 struct ssd_info *ssd = &sch->ssd_info;
234 ssize_t ret = 0;
235 int chp;
236
237 for (chp = 0; chp < 8; chp++)
238 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]);
239
240 ret += sprintf (buf+ret, "\n");
241 return min((ssize_t)PAGE_SIZE, ret);
242}
243
244static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400245pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 struct subchannel *sch = to_subchannel(dev);
248 struct pmcw *pmcw = &sch->schib.pmcw;
249
250 return sprintf (buf, "%02x %02x %02x\n",
251 pmcw->pim, pmcw->pam, pmcw->pom);
252}
253
254static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400255devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 struct ccw_device *cdev = to_ccwdev(dev);
258 struct ccw_device_id *id = &(cdev->id);
259
260 if (id->dev_type != 0)
261 return sprintf(buf, "%04x/%02x\n",
262 id->dev_type, id->dev_model);
263 else
264 return sprintf(buf, "n/a\n");
265}
266
267static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400268cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
270 struct ccw_device *cdev = to_ccwdev(dev);
271 struct ccw_device_id *id = &(cdev->id);
272
273 return sprintf(buf, "%04x/%02x\n",
274 id->cu_type, id->cu_model);
275}
276
277static ssize_t
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800278modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
279{
280 struct ccw_device *cdev = to_ccwdev(dev);
281 struct ccw_device_id *id = &(cdev->id);
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200282 int len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800283
Peter Oberparleiterdb0c2d52006-09-20 15:59:49 +0200284 len = snprint_alias(buf, PAGE_SIZE, "", id, "\n") + 1;
285
286 return len > PAGE_SIZE ? PAGE_SIZE : len;
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800287}
288
289static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400290online_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
292 struct ccw_device *cdev = to_ccwdev(dev);
293
294 return sprintf(buf, cdev->online ? "1\n" : "0\n");
295}
296
297static void
298ccw_device_remove_disconnected(struct ccw_device *cdev)
299{
300 struct subchannel *sch;
301 /*
302 * Forced offline in disconnected state means
303 * 'throw away device'.
304 */
305 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200306 css_sch_device_unregister(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /* Reset intparm to zeroes. */
308 sch->schib.pmcw.intparm = 0;
309 cio_modify(sch);
310 put_device(&sch->dev);
311}
312
313int
314ccw_device_set_offline(struct ccw_device *cdev)
315{
316 int ret;
317
318 if (!cdev)
319 return -ENODEV;
320 if (!cdev->online || !cdev->drv)
321 return -EINVAL;
322
323 if (cdev->drv->set_offline) {
324 ret = cdev->drv->set_offline(cdev);
325 if (ret != 0)
326 return ret;
327 }
328 cdev->online = 0;
329 spin_lock_irq(cdev->ccwlock);
330 ret = ccw_device_offline(cdev);
331 if (ret == -ENODEV) {
332 if (cdev->private->state != DEV_STATE_NOT_OPER) {
333 cdev->private->state = DEV_STATE_OFFLINE;
334 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
335 }
336 spin_unlock_irq(cdev->ccwlock);
337 return ret;
338 }
339 spin_unlock_irq(cdev->ccwlock);
340 if (ret == 0)
341 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
342 else {
343 pr_debug("ccw_device_offline returned %d, device %s\n",
344 ret, cdev->dev.bus_id);
345 cdev->online = 1;
346 }
347 return ret;
348}
349
350int
351ccw_device_set_online(struct ccw_device *cdev)
352{
353 int ret;
354
355 if (!cdev)
356 return -ENODEV;
357 if (cdev->online || !cdev->drv)
358 return -EINVAL;
359
360 spin_lock_irq(cdev->ccwlock);
361 ret = ccw_device_online(cdev);
362 spin_unlock_irq(cdev->ccwlock);
363 if (ret == 0)
364 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
365 else {
366 pr_debug("ccw_device_online returned %d, device %s\n",
367 ret, cdev->dev.bus_id);
368 return ret;
369 }
370 if (cdev->private->state != DEV_STATE_ONLINE)
371 return -ENODEV;
372 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
373 cdev->online = 1;
374 return 0;
375 }
376 spin_lock_irq(cdev->ccwlock);
377 ret = ccw_device_offline(cdev);
378 spin_unlock_irq(cdev->ccwlock);
379 if (ret == 0)
380 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
381 else
382 pr_debug("ccw_device_offline returned %d, device %s\n",
383 ret, cdev->dev.bus_id);
Cornelia Huck6cadb782006-02-17 13:52:49 -0800384 return (ret == 0) ? -ENODEV : ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
387static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400388online_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 struct ccw_device *cdev = to_ccwdev(dev);
391 int i, force, ret;
392 char *tmp;
393
Martin Schwidefsky973bd992006-01-06 00:19:07 -0800394 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return -EAGAIN;
396
397 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
398 atomic_set(&cdev->private->onoff, 0);
399 return -EINVAL;
400 }
401 if (!strncmp(buf, "force\n", count)) {
402 force = 1;
403 i = 1;
404 } else {
405 force = 0;
406 i = simple_strtoul(buf, &tmp, 16);
407 }
408 if (i == 1) {
409 /* Do device recognition, if needed. */
410 if (cdev->id.cu_type == 0) {
411 ret = ccw_device_recognition(cdev);
412 if (ret) {
413 printk(KERN_WARNING"Couldn't start recognition "
414 "for device %s (ret=%d)\n",
415 cdev->dev.bus_id, ret);
416 goto out;
417 }
418 wait_event(cdev->private->wait_q,
419 cdev->private->flags.recog_done);
420 }
421 if (cdev->drv && cdev->drv->set_online)
422 ccw_device_set_online(cdev);
423 } else if (i == 0) {
424 if (cdev->private->state == DEV_STATE_DISCONNECTED)
425 ccw_device_remove_disconnected(cdev);
426 else if (cdev->drv && cdev->drv->set_offline)
427 ccw_device_set_offline(cdev);
428 }
429 if (force && cdev->private->state == DEV_STATE_BOXED) {
430 ret = ccw_device_stlck(cdev);
431 if (ret) {
432 printk(KERN_WARNING"ccw_device_stlck for device %s "
433 "returned %d!\n", cdev->dev.bus_id, ret);
434 goto out;
435 }
436 /* Do device recognition, if needed. */
437 if (cdev->id.cu_type == 0) {
438 cdev->private->state = DEV_STATE_NOT_OPER;
439 ret = ccw_device_recognition(cdev);
440 if (ret) {
441 printk(KERN_WARNING"Couldn't start recognition "
442 "for device %s (ret=%d)\n",
443 cdev->dev.bus_id, ret);
444 goto out;
445 }
446 wait_event(cdev->private->wait_q,
447 cdev->private->flags.recog_done);
448 }
449 if (cdev->drv && cdev->drv->set_online)
450 ccw_device_set_online(cdev);
451 }
452 out:
453 if (cdev->drv)
454 module_put(cdev->drv->owner);
455 atomic_set(&cdev->private->onoff, 0);
456 return count;
457}
458
459static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -0400460available_show (struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 struct ccw_device *cdev = to_ccwdev(dev);
463 struct subchannel *sch;
464
465 switch (cdev->private->state) {
466 case DEV_STATE_BOXED:
467 return sprintf(buf, "boxed\n");
468 case DEV_STATE_DISCONNECTED:
469 case DEV_STATE_DISCONNECTED_SENSE_ID:
470 case DEV_STATE_NOT_OPER:
471 sch = to_subchannel(dev->parent);
472 if (!sch->lpm)
473 return sprintf(buf, "no path\n");
474 else
475 return sprintf(buf, "no device\n");
476 default:
477 /* All other states considered fine. */
478 return sprintf(buf, "good\n");
479 }
480}
481
482static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
483static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
484static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
485static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800486static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487static DEVICE_ATTR(online, 0644, online_show, online_store);
488extern struct device_attribute dev_attr_cmb_enable;
489static DEVICE_ATTR(availability, 0444, available_show, NULL);
490
491static struct attribute * subch_attrs[] = {
492 &dev_attr_chpids.attr,
493 &dev_attr_pimpampom.attr,
494 NULL,
495};
496
497static struct attribute_group subch_attr_group = {
498 .attrs = subch_attrs,
499};
500
501static inline int
502subchannel_add_files (struct device *dev)
503{
504 return sysfs_create_group(&dev->kobj, &subch_attr_group);
505}
506
507static struct attribute * ccwdev_attrs[] = {
508 &dev_attr_devtype.attr,
509 &dev_attr_cutype.attr,
Bastian Blankf1fc78a2005-10-30 15:00:12 -0800510 &dev_attr_modalias.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 &dev_attr_online.attr,
512 &dev_attr_cmb_enable.attr,
513 &dev_attr_availability.attr,
514 NULL,
515};
516
517static struct attribute_group ccwdev_attr_group = {
518 .attrs = ccwdev_attrs,
519};
520
521static inline int
522device_add_files (struct device *dev)
523{
524 return sysfs_create_group(&dev->kobj, &ccwdev_attr_group);
525}
526
527static inline void
528device_remove_files(struct device *dev)
529{
530 sysfs_remove_group(&dev->kobj, &ccwdev_attr_group);
531}
532
533/* this is a simple abstraction for device_register that sets the
534 * correct bus type and adds the bus specific files */
535int
536ccw_device_register(struct ccw_device *cdev)
537{
538 struct device *dev = &cdev->dev;
539 int ret;
540
541 dev->bus = &ccw_bus_type;
542
543 if ((ret = device_add(dev)))
544 return ret;
545
546 set_bit(1, &cdev->private->registered);
547 if ((ret = device_add_files(dev))) {
548 if (test_and_clear_bit(1, &cdev->private->registered))
549 device_del(dev);
550 }
551 return ret;
552}
553
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700554struct match_data {
Cornelia Huck78964262006-10-11 15:31:38 +0200555 struct ccw_dev_id dev_id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700556 struct ccw_device * sibling;
557};
558
559static int
560match_devno(struct device * dev, void * data)
561{
Cornelia Huck78964262006-10-11 15:31:38 +0200562 struct match_data * d = data;
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700563 struct ccw_device * cdev;
564
565 cdev = to_ccwdev(dev);
566 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
Cornelia Huck78964262006-10-11 15:31:38 +0200567 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700568 (cdev != d->sibling)) {
569 cdev->private->state = DEV_STATE_NOT_OPER;
570 return 1;
571 }
572 return 0;
573}
574
Cornelia Huck78964262006-10-11 15:31:38 +0200575static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
576 struct ccw_device *sibling)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 struct device *dev;
Heiko Carstens292888c2006-08-30 14:33:35 +0200579 struct match_data data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Cornelia Huck78964262006-10-11 15:31:38 +0200581 data.dev_id = *dev_id;
Heiko Carstens292888c2006-08-30 14:33:35 +0200582 data.sibling = sibling;
Cornelia Hucke5945b42005-10-11 08:28:59 -0700583 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700585 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588static void
589ccw_device_add_changed(void *data)
590{
591
592 struct ccw_device *cdev;
593
Cornelia Huck12975ae2006-10-11 15:31:47 +0200594 cdev = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 if (device_add(&cdev->dev)) {
596 put_device(&cdev->dev);
597 return;
598 }
599 set_bit(1, &cdev->private->registered);
600 if (device_add_files(&cdev->dev)) {
601 if (test_and_clear_bit(1, &cdev->private->registered))
602 device_unregister(&cdev->dev);
603 }
604}
605
606extern int css_get_ssd_info(struct subchannel *sch);
607
608void
609ccw_device_do_unreg_rereg(void *data)
610{
611 struct ccw_device *cdev;
612 struct subchannel *sch;
613 int need_rename;
614
Cornelia Huck12975ae2006-10-11 15:31:47 +0200615 cdev = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck78964262006-10-11 15:31:38 +0200617 if (cdev->private->dev_id.devno != sch->schib.pmcw.dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 /*
619 * The device number has changed. This is usually only when
620 * a device has been detached under VM and then re-appeared
621 * on another subchannel because of a different attachment
622 * order than before. Ideally, we should should just switch
623 * subchannels, but unfortunately, this is not possible with
624 * the current implementation.
625 * Instead, we search for the old subchannel for this device
626 * number and deregister so there are no collisions with the
627 * newly registered ccw_device.
628 * FIXME: Find another solution so the block layer doesn't
629 * get possibly sick...
630 */
631 struct ccw_device *other_cdev;
Cornelia Huck78964262006-10-11 15:31:38 +0200632 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 need_rename = 1;
Cornelia Huck78964262006-10-11 15:31:38 +0200635 dev_id.devno = sch->schib.pmcw.dev;
636 dev_id.ssid = sch->schid.ssid;
637 other_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 if (other_cdev) {
639 struct subchannel *other_sch;
640
641 other_sch = to_subchannel(other_cdev->dev.parent);
642 if (get_device(&other_sch->dev)) {
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800643 stsch(other_sch->schid, &other_sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (other_sch->schib.pmcw.dnv) {
645 other_sch->schib.pmcw.intparm = 0;
646 cio_modify(other_sch);
647 }
Cornelia Huck6ab48792006-07-12 16:39:50 +0200648 css_sch_device_unregister(other_sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 }
651 /* Update ssd info here. */
652 css_get_ssd_info(sch);
Cornelia Huck78964262006-10-11 15:31:38 +0200653 cdev->private->dev_id.devno = sch->schib.pmcw.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 } else
655 need_rename = 0;
656 device_remove_files(&cdev->dev);
657 if (test_and_clear_bit(1, &cdev->private->registered))
658 device_del(&cdev->dev);
659 if (need_rename)
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800660 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
661 sch->schid.ssid, sch->schib.pmcw.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 PREPARE_WORK(&cdev->private->kick_work,
Cornelia Huck12975ae2006-10-11 15:31:47 +0200663 ccw_device_add_changed, cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 queue_work(ccw_device_work, &cdev->private->kick_work);
665}
666
667static void
668ccw_device_release(struct device *dev)
669{
670 struct ccw_device *cdev;
671
672 cdev = to_ccwdev(dev);
673 kfree(cdev->private);
674 kfree(cdev);
675}
676
677/*
678 * Register recognized device.
679 */
680static void
681io_subchannel_register(void *data)
682{
683 struct ccw_device *cdev;
684 struct subchannel *sch;
685 int ret;
686 unsigned long flags;
687
Cornelia Huck12975ae2006-10-11 15:31:47 +0200688 cdev = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 sch = to_subchannel(cdev->dev.parent);
690
Cornelia Huckb0744bd2005-06-25 14:55:27 -0700691 if (klist_node_attached(&cdev->dev.knode_parent)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 bus_rescan_devices(&ccw_bus_type);
693 goto out;
694 }
695 /* make it known to the system */
696 ret = ccw_device_register(cdev);
697 if (ret) {
698 printk (KERN_WARNING "%s: could not register %s\n",
699 __func__, cdev->dev.bus_id);
700 put_device(&cdev->dev);
701 spin_lock_irqsave(&sch->lock, flags);
702 sch->dev.driver_data = NULL;
703 spin_unlock_irqrestore(&sch->lock, flags);
704 kfree (cdev->private);
705 kfree (cdev);
706 put_device(&sch->dev);
707 if (atomic_dec_and_test(&ccw_device_init_count))
708 wake_up(&ccw_device_init_wq);
709 return;
710 }
711
712 ret = subchannel_add_files(cdev->dev.parent);
713 if (ret)
714 printk(KERN_WARNING "%s: could not add attributes to %s\n",
715 __func__, sch->dev.bus_id);
716 put_device(&cdev->dev);
717out:
718 cdev->private->flags.recog_done = 1;
719 put_device(&sch->dev);
720 wake_up(&cdev->private->wait_q);
721 if (atomic_dec_and_test(&ccw_device_init_count))
722 wake_up(&ccw_device_init_wq);
723}
724
725void
726ccw_device_call_sch_unregister(void *data)
727{
728 struct ccw_device *cdev = data;
729 struct subchannel *sch;
730
731 sch = to_subchannel(cdev->dev.parent);
Cornelia Huck6ab48792006-07-12 16:39:50 +0200732 css_sch_device_unregister(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 /* Reset intparm to zeroes. */
734 sch->schib.pmcw.intparm = 0;
735 cio_modify(sch);
736 put_device(&cdev->dev);
737 put_device(&sch->dev);
738}
739
740/*
741 * subchannel recognition done. Called from the state machine.
742 */
743void
744io_subchannel_recog_done(struct ccw_device *cdev)
745{
746 struct subchannel *sch;
747
748 if (css_init_done == 0) {
749 cdev->private->flags.recog_done = 1;
750 return;
751 }
752 switch (cdev->private->state) {
753 case DEV_STATE_NOT_OPER:
754 cdev->private->flags.recog_done = 1;
755 /* Remove device found not operational. */
756 if (!get_device(&cdev->dev))
757 break;
758 sch = to_subchannel(cdev->dev.parent);
759 PREPARE_WORK(&cdev->private->kick_work,
Cornelia Huck12975ae2006-10-11 15:31:47 +0200760 ccw_device_call_sch_unregister, cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 queue_work(slow_path_wq, &cdev->private->kick_work);
762 if (atomic_dec_and_test(&ccw_device_init_count))
763 wake_up(&ccw_device_init_wq);
764 break;
765 case DEV_STATE_BOXED:
766 /* Device did not respond in time. */
767 case DEV_STATE_OFFLINE:
768 /*
769 * We can't register the device in interrupt context so
770 * we schedule a work item.
771 */
772 if (!get_device(&cdev->dev))
773 break;
774 PREPARE_WORK(&cdev->private->kick_work,
Cornelia Huck12975ae2006-10-11 15:31:47 +0200775 io_subchannel_register, cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 queue_work(slow_path_wq, &cdev->private->kick_work);
777 break;
778 }
779}
780
781static int
782io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
783{
784 int rc;
785 struct ccw_device_private *priv;
786
787 sch->dev.driver_data = cdev;
788 sch->driver = &io_subchannel_driver;
789 cdev->ccwlock = &sch->lock;
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 /* Init private data. */
792 priv = cdev->private;
Cornelia Huck78964262006-10-11 15:31:38 +0200793 priv->dev_id.devno = sch->schib.pmcw.dev;
794 priv->dev_id.ssid = sch->schid.ssid;
795 priv->schid = sch->schid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 priv->state = DEV_STATE_NOT_OPER;
797 INIT_LIST_HEAD(&priv->cmb_list);
798 init_waitqueue_head(&priv->wait_q);
799 init_timer(&priv->timer);
800
801 /* Set an initial name for the device. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800802 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
803 sch->schid.ssid, sch->schib.pmcw.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 /* Increase counter of devices currently in recognition. */
806 atomic_inc(&ccw_device_init_count);
807
808 /* Start async. device sensing. */
809 spin_lock_irq(&sch->lock);
810 rc = ccw_device_recognition(cdev);
811 spin_unlock_irq(&sch->lock);
812 if (rc) {
813 if (atomic_dec_and_test(&ccw_device_init_count))
814 wake_up(&ccw_device_init_wq);
815 }
816 return rc;
817}
818
819static int
Cornelia Huck8bbace72006-01-11 10:56:22 +0100820io_subchannel_probe (struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 struct ccw_device *cdev;
823 int rc;
824 unsigned long flags;
825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (sch->dev.driver_data) {
827 /*
828 * This subchannel already has an associated ccw_device.
829 * Register it and exit. This happens for all early
830 * device, e.g. the console.
831 */
832 cdev = sch->dev.driver_data;
833 device_initialize(&cdev->dev);
834 ccw_device_register(cdev);
835 subchannel_add_files(&sch->dev);
836 /*
837 * Check if the device is already online. If it is
838 * the reference count needs to be corrected
839 * (see ccw_device_online and css_init_done for the
840 * ugly details).
841 */
842 if (cdev->private->state != DEV_STATE_NOT_OPER &&
843 cdev->private->state != DEV_STATE_OFFLINE &&
844 cdev->private->state != DEV_STATE_BOXED)
845 get_device(&cdev->dev);
846 return 0;
847 }
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800848 cdev = kzalloc (sizeof(*cdev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (!cdev)
850 return -ENOMEM;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800851 cdev->private = kzalloc(sizeof(struct ccw_device_private),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 GFP_KERNEL | GFP_DMA);
853 if (!cdev->private) {
854 kfree(cdev);
855 return -ENOMEM;
856 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 atomic_set(&cdev->private->onoff, 0);
Heiko Carstens292888c2006-08-30 14:33:35 +0200858 cdev->dev.parent = &sch->dev;
859 cdev->dev.release = ccw_device_release;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 INIT_LIST_HEAD(&cdev->private->kick_work.entry);
861 /* Do first half of device_register. */
862 device_initialize(&cdev->dev);
863
864 if (!get_device(&sch->dev)) {
865 if (cdev->dev.release)
866 cdev->dev.release(&cdev->dev);
867 return -ENODEV;
868 }
869
Cornelia Huck8bbace72006-01-11 10:56:22 +0100870 rc = io_subchannel_recog(cdev, sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (rc) {
872 spin_lock_irqsave(&sch->lock, flags);
873 sch->dev.driver_data = NULL;
874 spin_unlock_irqrestore(&sch->lock, flags);
875 if (cdev->dev.release)
876 cdev->dev.release(&cdev->dev);
877 }
878
879 return rc;
880}
881
882static void
883ccw_device_unregister(void *data)
884{
885 struct ccw_device *cdev;
886
887 cdev = (struct ccw_device *)data;
888 if (test_and_clear_bit(1, &cdev->private->registered))
889 device_unregister(&cdev->dev);
890 put_device(&cdev->dev);
891}
892
893static int
Cornelia Huck8bbace72006-01-11 10:56:22 +0100894io_subchannel_remove (struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 struct ccw_device *cdev;
897 unsigned long flags;
898
Cornelia Huck8bbace72006-01-11 10:56:22 +0100899 if (!sch->dev.driver_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 return 0;
Cornelia Huck8bbace72006-01-11 10:56:22 +0100901 cdev = sch->dev.driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /* Set ccw device to not operational and drop reference. */
903 spin_lock_irqsave(cdev->ccwlock, flags);
Cornelia Huck8bbace72006-01-11 10:56:22 +0100904 sch->dev.driver_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 cdev->private->state = DEV_STATE_NOT_OPER;
906 spin_unlock_irqrestore(cdev->ccwlock, flags);
907 /*
908 * Put unregistration on workqueue to avoid livelocks on the css bus
909 * semaphore.
910 */
911 if (get_device(&cdev->dev)) {
912 PREPARE_WORK(&cdev->private->kick_work,
Cornelia Huck12975ae2006-10-11 15:31:47 +0200913 ccw_device_unregister, cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 queue_work(ccw_device_work, &cdev->private->kick_work);
915 }
916 return 0;
917}
918
919static int
920io_subchannel_notify(struct device *dev, int event)
921{
922 struct ccw_device *cdev;
923
924 cdev = dev->driver_data;
925 if (!cdev)
926 return 0;
927 if (!cdev->drv)
928 return 0;
929 if (!cdev->online)
930 return 0;
931 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
932}
933
934static void
935io_subchannel_verify(struct device *dev)
936{
937 struct ccw_device *cdev;
938
939 cdev = dev->driver_data;
940 if (cdev)
941 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
942}
943
944static void
945io_subchannel_ioterm(struct device *dev)
946{
947 struct ccw_device *cdev;
948
949 cdev = dev->driver_data;
950 if (!cdev)
951 return;
952 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
953 if (cdev->handler)
954 cdev->handler(cdev, cdev->private->intparm,
955 ERR_PTR(-EIO));
956}
957
958static void
Cornelia Huck8bbace72006-01-11 10:56:22 +0100959io_subchannel_shutdown(struct subchannel *sch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 struct ccw_device *cdev;
962 int ret;
963
Cornelia Huck8bbace72006-01-11 10:56:22 +0100964 cdev = sch->dev.driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800966 if (cio_is_console(sch->schid))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 return;
968 if (!sch->schib.pmcw.ena)
969 /* Nothing to do. */
970 return;
971 ret = cio_disable_subchannel(sch);
972 if (ret != -EBUSY)
973 /* Subchannel is disabled, we're done. */
974 return;
975 cdev->private->state = DEV_STATE_QUIESCE;
976 if (cdev->handler)
977 cdev->handler(cdev, cdev->private->intparm,
978 ERR_PTR(-EIO));
979 ret = ccw_device_cancel_halt_clear(cdev);
980 if (ret == -EBUSY) {
981 ccw_device_set_timeout(cdev, HZ/10);
982 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
983 }
984 cio_disable_subchannel(sch);
985}
986
987#ifdef CONFIG_CCW_CONSOLE
988static struct ccw_device console_cdev;
989static struct ccw_device_private console_private;
990static int console_cdev_in_use;
991
992static int
993ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
994{
995 int rc;
996
997 /* Initialize the ccw_device structure. */
Heiko Carstens292888c2006-08-30 14:33:35 +0200998 cdev->dev.parent= &sch->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 rc = io_subchannel_recog(cdev, sch);
1000 if (rc)
1001 return rc;
1002
1003 /* Now wait for the async. recognition to come to an end. */
1004 spin_lock_irq(cdev->ccwlock);
1005 while (!dev_fsm_final_state(cdev))
1006 wait_cons_dev();
1007 rc = -EIO;
1008 if (cdev->private->state != DEV_STATE_OFFLINE)
1009 goto out_unlock;
1010 ccw_device_online(cdev);
1011 while (!dev_fsm_final_state(cdev))
1012 wait_cons_dev();
1013 if (cdev->private->state != DEV_STATE_ONLINE)
1014 goto out_unlock;
1015 rc = 0;
1016out_unlock:
1017 spin_unlock_irq(cdev->ccwlock);
1018 return 0;
1019}
1020
1021struct ccw_device *
1022ccw_device_probe_console(void)
1023{
1024 struct subchannel *sch;
1025 int ret;
1026
1027 if (xchg(&console_cdev_in_use, 1) != 0)
Peter Oberparleiter600b5d12006-02-01 03:06:35 -08001028 return ERR_PTR(-EBUSY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 sch = cio_probe_console();
1030 if (IS_ERR(sch)) {
1031 console_cdev_in_use = 0;
1032 return (void *) sch;
1033 }
1034 memset(&console_cdev, 0, sizeof(struct ccw_device));
1035 memset(&console_private, 0, sizeof(struct ccw_device_private));
1036 console_cdev.private = &console_private;
1037 ret = ccw_device_console_enable(&console_cdev, sch);
1038 if (ret) {
1039 cio_release_console();
1040 console_cdev_in_use = 0;
1041 return ERR_PTR(ret);
1042 }
1043 console_cdev.online = 1;
1044 return &console_cdev;
1045}
1046#endif
1047
1048/*
1049 * get ccw_device matching the busid, but only if owned by cdrv
1050 */
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001051static int
1052__ccwdev_check_busid(struct device *dev, void *id)
1053{
1054 char *bus_id;
1055
Cornelia Huck12975ae2006-10-11 15:31:47 +02001056 bus_id = id;
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001057
1058 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1059}
1060
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062struct ccw_device *
1063get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
1064{
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001065 struct device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 struct device_driver *drv;
1067
1068 drv = get_driver(&cdrv->driver);
1069 if (!drv)
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001070 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Cornelia Huckb0744bd2005-06-25 14:55:27 -07001072 dev = driver_find_device(drv, NULL, (void *)bus_id,
1073 __ccwdev_check_busid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 put_driver(drv);
1075
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001076 return dev ? to_ccwdev(dev) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
1079/************************** device driver handling ************************/
1080
1081/* This is the implementation of the ccw_driver class. The probe, remove
1082 * and release methods are initially very similar to the device_driver
1083 * implementations, with the difference that they have ccw_device
1084 * arguments.
1085 *
1086 * A ccw driver also contains the information that is needed for
1087 * device matching.
1088 */
1089static int
1090ccw_device_probe (struct device *dev)
1091{
1092 struct ccw_device *cdev = to_ccwdev(dev);
1093 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1094 int ret;
1095
1096 cdev->drv = cdrv; /* to let the driver call _set_online */
1097
1098 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1099
1100 if (ret) {
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001101 cdev->drv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return ret;
1103 }
1104
1105 return 0;
1106}
1107
1108static int
1109ccw_device_remove (struct device *dev)
1110{
1111 struct ccw_device *cdev = to_ccwdev(dev);
1112 struct ccw_driver *cdrv = cdev->drv;
1113 int ret;
1114
1115 pr_debug("removing device %s\n", cdev->dev.bus_id);
1116 if (cdrv->remove)
1117 cdrv->remove(cdev);
1118 if (cdev->online) {
1119 cdev->online = 0;
1120 spin_lock_irq(cdev->ccwlock);
1121 ret = ccw_device_offline(cdev);
1122 spin_unlock_irq(cdev->ccwlock);
1123 if (ret == 0)
1124 wait_event(cdev->private->wait_q,
1125 dev_fsm_final_state(cdev));
1126 else
1127 //FIXME: we can't fail!
1128 pr_debug("ccw_device_offline returned %d, device %s\n",
1129 ret, cdev->dev.bus_id);
1130 }
1131 ccw_device_set_timeout(cdev, 0);
Heiko Carstensd2c993d2006-07-12 16:41:55 +02001132 cdev->drv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 return 0;
1134}
1135
Cornelia Huck8bbace72006-01-11 10:56:22 +01001136struct bus_type ccw_bus_type = {
1137 .name = "ccw",
1138 .match = ccw_bus_match,
1139 .uevent = ccw_uevent,
1140 .probe = ccw_device_probe,
1141 .remove = ccw_device_remove,
1142};
1143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144int
1145ccw_driver_register (struct ccw_driver *cdriver)
1146{
1147 struct device_driver *drv = &cdriver->driver;
1148
1149 drv->bus = &ccw_bus_type;
1150 drv->name = cdriver->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 return driver_register(drv);
1153}
1154
1155void
1156ccw_driver_unregister (struct ccw_driver *cdriver)
1157{
1158 driver_unregister(&cdriver->driver);
1159}
1160
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001161/* Helper func for qdio. */
1162struct subchannel_id
1163ccw_device_get_subchannel_id(struct ccw_device *cdev)
1164{
1165 struct subchannel *sch;
1166
1167 sch = to_subchannel(cdev->dev.parent);
1168 return sch->schid;
1169}
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171MODULE_LICENSE("GPL");
1172EXPORT_SYMBOL(ccw_device_set_online);
1173EXPORT_SYMBOL(ccw_device_set_offline);
1174EXPORT_SYMBOL(ccw_driver_register);
1175EXPORT_SYMBOL(ccw_driver_unregister);
1176EXPORT_SYMBOL(get_ccwdev_by_busid);
1177EXPORT_SYMBOL(ccw_bus_type);
1178EXPORT_SYMBOL(ccw_device_work);
1179EXPORT_SYMBOL(ccw_device_notify_work);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001180EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);