2 * drivers/s390/cio/device.c
3 * bus driver for ccw devices
5 * Copyright IBM Corp. 2002,2008
6 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
7 * Cornelia Huck (cornelia.huck@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 #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>
19 #include <linux/timer.h>
21 #include <asm/ccwdev.h>
23 #include <asm/param.h> /* HZ */
29 #include "cio_debug.h"
35 static struct timer_list recovery_timer;
36 static DEFINE_SPINLOCK(recovery_lock);
37 static int recovery_phase;
38 static const unsigned long recovery_delay[] = { 3, 30, 300 };
40 /******************* bus type handling ***********************/
42 /* The Linux driver model distinguishes between a bus type and
43 * the bus itself. Of course we only have one channel
44 * subsystem driver and one channel system per machine, but
45 * we still use the abstraction. T.R. says it's a good idea. */
47 ccw_bus_match (struct device * dev, struct device_driver * drv)
49 struct ccw_device *cdev = to_ccwdev(dev);
50 struct ccw_driver *cdrv = to_ccwdrv(drv);
51 const struct ccw_device_id *ids = cdrv->ids, *found;
56 found = ccw_device_id_match(ids, &cdev->id);
60 cdev->id.driver_info = found->driver_info;
65 /* Store modalias string delimited by prefix/suffix string into buffer with
66 * specified size. Return length of resulting string (excluding trailing '\0')
67 * even if string doesn't fit buffer (snprintf semantics). */
68 static int snprint_alias(char *buf, size_t size,
69 struct ccw_device_id *id, const char *suffix)
73 len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
79 if (id->dev_type != 0)
80 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
81 id->dev_model, suffix);
83 len += snprintf(buf, size, "dtdm%s", suffix);
88 /* Set up environment variables for ccw device uevent. Return 0 on success,
89 * non-zero otherwise. */
90 static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env)
92 struct ccw_device *cdev = to_ccwdev(dev);
93 struct ccw_device_id *id = &(cdev->id);
95 char modalias_buf[30];
98 ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type);
103 ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model);
107 /* The next two can be zero, that's ok for us */
109 ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type);
114 ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model);
119 snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
120 ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf);
124 struct bus_type ccw_bus_type;
126 static void io_subchannel_irq(struct subchannel *);
127 static int io_subchannel_probe(struct subchannel *);
128 static int io_subchannel_remove(struct subchannel *);
129 static void io_subchannel_shutdown(struct subchannel *);
130 static int io_subchannel_sch_event(struct subchannel *, int);
131 static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
134 static struct css_driver io_subchannel_driver = {
135 .owner = THIS_MODULE,
136 .subchannel_type = SUBCHANNEL_TYPE_IO,
137 .name = "io_subchannel",
138 .irq = io_subchannel_irq,
139 .sch_event = io_subchannel_sch_event,
140 .chp_event = io_subchannel_chp_event,
141 .probe = io_subchannel_probe,
142 .remove = io_subchannel_remove,
143 .shutdown = io_subchannel_shutdown,
146 struct workqueue_struct *ccw_device_work;
147 struct workqueue_struct *ccw_device_notify_work;
148 wait_queue_head_t ccw_device_init_wq;
149 atomic_t ccw_device_init_count;
151 static void recovery_func(unsigned long data);
154 init_ccw_bus_type (void)
158 init_waitqueue_head(&ccw_device_init_wq);
159 atomic_set(&ccw_device_init_count, 0);
160 setup_timer(&recovery_timer, recovery_func, 0);
162 ccw_device_work = create_singlethread_workqueue("cio");
163 if (!ccw_device_work)
164 return -ENOMEM; /* FIXME: better errno ? */
165 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
166 if (!ccw_device_notify_work) {
167 ret = -ENOMEM; /* FIXME: better errno ? */
170 slow_path_wq = create_singlethread_workqueue("kslowcrw");
172 ret = -ENOMEM; /* FIXME: better errno ? */
175 if ((ret = bus_register (&ccw_bus_type)))
178 ret = css_driver_register(&io_subchannel_driver);
182 wait_event(ccw_device_init_wq,
183 atomic_read(&ccw_device_init_count) == 0);
184 flush_workqueue(ccw_device_work);
188 destroy_workqueue(ccw_device_work);
189 if (ccw_device_notify_work)
190 destroy_workqueue(ccw_device_notify_work);
192 destroy_workqueue(slow_path_wq);
197 cleanup_ccw_bus_type (void)
199 css_driver_unregister(&io_subchannel_driver);
200 bus_unregister(&ccw_bus_type);
201 destroy_workqueue(ccw_device_notify_work);
202 destroy_workqueue(ccw_device_work);
205 subsys_initcall(init_ccw_bus_type);
206 module_exit(cleanup_ccw_bus_type);
208 /************************ device handling **************************/
211 * A ccw_device has some interfaces in sysfs in addition to the
213 * The following entries are designed to export the information which
214 * resided in 2.4 in /proc/subchannels. Subchannel and device number
215 * are obvious, so they don't have an entry :)
216 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
219 chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
221 struct subchannel *sch = to_subchannel(dev);
222 struct chsc_ssd_info *ssd = &sch->ssd_info;
227 for (chp = 0; chp < 8; chp++) {
229 if (ssd->path_mask & mask)
230 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
232 ret += sprintf(buf + ret, "00 ");
234 ret += sprintf (buf+ret, "\n");
235 return min((ssize_t)PAGE_SIZE, ret);
239 pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
241 struct subchannel *sch = to_subchannel(dev);
242 struct pmcw *pmcw = &sch->schib.pmcw;
244 return sprintf (buf, "%02x %02x %02x\n",
245 pmcw->pim, pmcw->pam, pmcw->pom);
249 devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
251 struct ccw_device *cdev = to_ccwdev(dev);
252 struct ccw_device_id *id = &(cdev->id);
254 if (id->dev_type != 0)
255 return sprintf(buf, "%04x/%02x\n",
256 id->dev_type, id->dev_model);
258 return sprintf(buf, "n/a\n");
262 cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
264 struct ccw_device *cdev = to_ccwdev(dev);
265 struct ccw_device_id *id = &(cdev->id);
267 return sprintf(buf, "%04x/%02x\n",
268 id->cu_type, id->cu_model);
272 modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
274 struct ccw_device *cdev = to_ccwdev(dev);
275 struct ccw_device_id *id = &(cdev->id);
278 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
280 return len > PAGE_SIZE ? PAGE_SIZE : len;
284 online_show (struct device *dev, struct device_attribute *attr, char *buf)
286 struct ccw_device *cdev = to_ccwdev(dev);
288 return sprintf(buf, cdev->online ? "1\n" : "0\n");
291 int ccw_device_is_orphan(struct ccw_device *cdev)
293 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
296 static void ccw_device_unregister(struct ccw_device *cdev)
298 if (test_and_clear_bit(1, &cdev->private->registered))
299 device_del(&cdev->dev);
302 static void ccw_device_remove_orphan_cb(struct device *dev)
304 struct ccw_device *cdev = to_ccwdev(dev);
306 ccw_device_unregister(cdev);
307 put_device(&cdev->dev);
310 static void ccw_device_remove_sch_cb(struct device *dev)
312 struct subchannel *sch;
314 sch = to_subchannel(dev);
315 css_sch_device_unregister(sch);
316 /* Reset intparm to zeroes. */
317 sch->schib.pmcw.intparm = 0;
319 put_device(&sch->dev);
323 ccw_device_remove_disconnected(struct ccw_device *cdev)
329 * Forced offline in disconnected state means
330 * 'throw away device'.
332 if (ccw_device_is_orphan(cdev)) {
334 * Deregister ccw device.
335 * Unfortunately, we cannot do this directly from the
338 spin_lock_irqsave(cdev->ccwlock, flags);
339 cdev->private->state = DEV_STATE_NOT_OPER;
340 spin_unlock_irqrestore(cdev->ccwlock, flags);
341 rc = device_schedule_callback(&cdev->dev,
342 ccw_device_remove_orphan_cb);
344 CIO_MSG_EVENT(0, "Couldn't unregister orphan "
346 cdev->private->dev_id.ssid,
347 cdev->private->dev_id.devno);
350 /* Deregister subchannel, which will kill the ccw device. */
351 rc = device_schedule_callback(cdev->dev.parent,
352 ccw_device_remove_sch_cb);
354 CIO_MSG_EVENT(0, "Couldn't unregister disconnected device "
356 cdev->private->dev_id.ssid,
357 cdev->private->dev_id.devno);
361 * ccw_device_set_offline() - disable a ccw device for I/O
362 * @cdev: target ccw device
364 * This function calls the driver's set_offline() function for @cdev, if
365 * given, and then disables @cdev.
367 * %0 on success and a negative error value on failure.
369 * enabled, ccw device lock not held
371 int ccw_device_set_offline(struct ccw_device *cdev)
377 if (!cdev->online || !cdev->drv)
380 if (cdev->drv->set_offline) {
381 ret = cdev->drv->set_offline(cdev);
386 spin_lock_irq(cdev->ccwlock);
387 ret = ccw_device_offline(cdev);
388 if (ret == -ENODEV) {
389 if (cdev->private->state != DEV_STATE_NOT_OPER) {
390 cdev->private->state = DEV_STATE_OFFLINE;
391 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
393 spin_unlock_irq(cdev->ccwlock);
396 spin_unlock_irq(cdev->ccwlock);
398 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
400 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
401 "device 0.%x.%04x\n",
402 ret, cdev->private->dev_id.ssid,
403 cdev->private->dev_id.devno);
410 * ccw_device_set_online() - enable a ccw device for I/O
411 * @cdev: target ccw device
413 * This function first enables @cdev and then calls the driver's set_online()
414 * function for @cdev, if given. If set_online() returns an error, @cdev is
417 * %0 on success and a negative error value on failure.
419 * enabled, ccw device lock not held
421 int ccw_device_set_online(struct ccw_device *cdev)
427 if (cdev->online || !cdev->drv)
430 spin_lock_irq(cdev->ccwlock);
431 ret = ccw_device_online(cdev);
432 spin_unlock_irq(cdev->ccwlock);
434 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
436 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
437 "device 0.%x.%04x\n",
438 ret, cdev->private->dev_id.ssid,
439 cdev->private->dev_id.devno);
442 if (cdev->private->state != DEV_STATE_ONLINE)
444 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
448 spin_lock_irq(cdev->ccwlock);
449 ret = ccw_device_offline(cdev);
450 spin_unlock_irq(cdev->ccwlock);
452 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
454 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
455 "device 0.%x.%04x\n",
456 ret, cdev->private->dev_id.ssid,
457 cdev->private->dev_id.devno);
458 return (ret == 0) ? -ENODEV : ret;
461 static void online_store_handle_offline(struct ccw_device *cdev)
463 if (cdev->private->state == DEV_STATE_DISCONNECTED)
464 ccw_device_remove_disconnected(cdev);
465 else if (cdev->drv && cdev->drv->set_offline)
466 ccw_device_set_offline(cdev);
469 static int online_store_recog_and_online(struct ccw_device *cdev)
473 /* Do device recognition, if needed. */
474 if (cdev->id.cu_type == 0) {
475 ret = ccw_device_recognition(cdev);
477 CIO_MSG_EVENT(0, "Couldn't start recognition "
478 "for device 0.%x.%04x (ret=%d)\n",
479 cdev->private->dev_id.ssid,
480 cdev->private->dev_id.devno, ret);
483 wait_event(cdev->private->wait_q,
484 cdev->private->flags.recog_done);
486 if (cdev->drv && cdev->drv->set_online)
487 ccw_device_set_online(cdev);
490 static void online_store_handle_online(struct ccw_device *cdev, int force)
494 ret = online_store_recog_and_online(cdev);
497 if (force && cdev->private->state == DEV_STATE_BOXED) {
498 ret = ccw_device_stlck(cdev);
501 "ccw_device_stlck returned %d!\n", ret);
504 if (cdev->id.cu_type == 0)
505 cdev->private->state = DEV_STATE_NOT_OPER;
506 online_store_recog_and_online(cdev);
511 static ssize_t online_store (struct device *dev, struct device_attribute *attr,
512 const char *buf, size_t count)
514 struct ccw_device *cdev = to_ccwdev(dev);
518 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
521 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
522 atomic_set(&cdev->private->onoff, 0);
525 if (!strncmp(buf, "force\n", count)) {
531 ret = strict_strtoul(buf, 16, &i);
537 online_store_handle_offline(cdev);
541 online_store_handle_online(cdev, force);
549 module_put(cdev->drv->owner);
550 atomic_set(&cdev->private->onoff, 0);
555 available_show (struct device *dev, struct device_attribute *attr, char *buf)
557 struct ccw_device *cdev = to_ccwdev(dev);
558 struct subchannel *sch;
560 if (ccw_device_is_orphan(cdev))
561 return sprintf(buf, "no device\n");
562 switch (cdev->private->state) {
563 case DEV_STATE_BOXED:
564 return sprintf(buf, "boxed\n");
565 case DEV_STATE_DISCONNECTED:
566 case DEV_STATE_DISCONNECTED_SENSE_ID:
567 case DEV_STATE_NOT_OPER:
568 sch = to_subchannel(dev->parent);
570 return sprintf(buf, "no path\n");
572 return sprintf(buf, "no device\n");
574 /* All other states considered fine. */
575 return sprintf(buf, "good\n");
579 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
580 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
581 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
582 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
583 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
584 static DEVICE_ATTR(online, 0644, online_show, online_store);
585 static DEVICE_ATTR(availability, 0444, available_show, NULL);
587 static struct attribute *io_subchannel_attrs[] = {
588 &dev_attr_chpids.attr,
589 &dev_attr_pimpampom.attr,
593 static struct attribute_group io_subchannel_attr_group = {
594 .attrs = io_subchannel_attrs,
597 static struct attribute * ccwdev_attrs[] = {
598 &dev_attr_devtype.attr,
599 &dev_attr_cutype.attr,
600 &dev_attr_modalias.attr,
601 &dev_attr_online.attr,
602 &dev_attr_cmb_enable.attr,
603 &dev_attr_availability.attr,
607 static struct attribute_group ccwdev_attr_group = {
608 .attrs = ccwdev_attrs,
611 static struct attribute_group *ccwdev_attr_groups[] = {
616 /* this is a simple abstraction for device_register that sets the
617 * correct bus type and adds the bus specific files */
618 static int ccw_device_register(struct ccw_device *cdev)
620 struct device *dev = &cdev->dev;
623 dev->bus = &ccw_bus_type;
625 if ((ret = device_add(dev)))
628 set_bit(1, &cdev->private->registered);
633 struct ccw_dev_id dev_id;
634 struct ccw_device * sibling;
638 match_devno(struct device * dev, void * data)
640 struct match_data * d = data;
641 struct ccw_device * cdev;
643 cdev = to_ccwdev(dev);
644 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
645 !ccw_device_is_orphan(cdev) &&
646 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
647 (cdev != d->sibling))
652 static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
653 struct ccw_device *sibling)
656 struct match_data data;
658 data.dev_id = *dev_id;
659 data.sibling = sibling;
660 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
662 return dev ? to_ccwdev(dev) : NULL;
665 static int match_orphan(struct device *dev, void *data)
667 struct ccw_dev_id *dev_id;
668 struct ccw_device *cdev;
671 cdev = to_ccwdev(dev);
672 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
675 static struct ccw_device *
676 get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
677 struct ccw_dev_id *dev_id)
681 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
684 return dev ? to_ccwdev(dev) : NULL;
688 ccw_device_add_changed(struct work_struct *work)
690 struct ccw_device_private *priv;
691 struct ccw_device *cdev;
693 priv = container_of(work, struct ccw_device_private, kick_work);
695 if (device_add(&cdev->dev)) {
696 put_device(&cdev->dev);
699 set_bit(1, &cdev->private->registered);
702 void ccw_device_do_unreg_rereg(struct work_struct *work)
704 struct ccw_device_private *priv;
705 struct ccw_device *cdev;
706 struct subchannel *sch;
708 priv = container_of(work, struct ccw_device_private, kick_work);
710 sch = to_subchannel(cdev->dev.parent);
712 ccw_device_unregister(cdev);
713 PREPARE_WORK(&cdev->private->kick_work,
714 ccw_device_add_changed);
715 queue_work(ccw_device_work, &cdev->private->kick_work);
719 ccw_device_release(struct device *dev)
721 struct ccw_device *cdev;
723 cdev = to_ccwdev(dev);
724 kfree(cdev->private);
728 static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
730 struct ccw_device *cdev;
732 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
734 cdev->private = kzalloc(sizeof(struct ccw_device_private),
735 GFP_KERNEL | GFP_DMA);
740 return ERR_PTR(-ENOMEM);
743 static int io_subchannel_initialize_dev(struct subchannel *sch,
744 struct ccw_device *cdev)
746 cdev->private->cdev = cdev;
747 atomic_set(&cdev->private->onoff, 0);
748 cdev->dev.parent = &sch->dev;
749 cdev->dev.release = ccw_device_release;
750 INIT_WORK(&cdev->private->kick_work, NULL);
751 cdev->dev.groups = ccwdev_attr_groups;
752 /* Do first half of device_register. */
753 device_initialize(&cdev->dev);
754 if (!get_device(&sch->dev)) {
755 if (cdev->dev.release)
756 cdev->dev.release(&cdev->dev);
762 static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
764 struct ccw_device *cdev;
767 cdev = io_subchannel_allocate_dev(sch);
769 ret = io_subchannel_initialize_dev(sch, cdev);
778 static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
780 static void sch_attach_device(struct subchannel *sch,
781 struct ccw_device *cdev)
783 css_update_ssd_info(sch);
784 spin_lock_irq(sch->lock);
785 sch_set_cdev(sch, cdev);
786 cdev->private->schid = sch->schid;
787 cdev->ccwlock = sch->lock;
788 ccw_device_trigger_reprobe(cdev);
789 spin_unlock_irq(sch->lock);
792 static void sch_attach_disconnected_device(struct subchannel *sch,
793 struct ccw_device *cdev)
795 struct subchannel *other_sch;
798 other_sch = to_subchannel(get_device(cdev->dev.parent));
799 ret = device_move(&cdev->dev, &sch->dev);
801 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
802 "(ret=%d)!\n", cdev->private->dev_id.ssid,
803 cdev->private->dev_id.devno, ret);
804 put_device(&other_sch->dev);
807 sch_set_cdev(other_sch, NULL);
808 /* No need to keep a subchannel without ccw device around. */
809 css_sch_device_unregister(other_sch);
810 put_device(&other_sch->dev);
811 sch_attach_device(sch, cdev);
814 static void sch_attach_orphaned_device(struct subchannel *sch,
815 struct ccw_device *cdev)
819 /* Try to move the ccw device to its new subchannel. */
820 ret = device_move(&cdev->dev, &sch->dev);
822 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
823 "failed (ret=%d)!\n",
824 cdev->private->dev_id.ssid,
825 cdev->private->dev_id.devno, ret);
828 sch_attach_device(sch, cdev);
831 static void sch_create_and_recog_new_device(struct subchannel *sch)
833 struct ccw_device *cdev;
835 /* Need to allocate a new ccw device. */
836 cdev = io_subchannel_create_ccwdev(sch);
838 /* OK, we did everything we could... */
839 css_sch_device_unregister(sch);
842 spin_lock_irq(sch->lock);
843 sch_set_cdev(sch, cdev);
844 spin_unlock_irq(sch->lock);
845 /* Start recognition for the new ccw device. */
846 if (io_subchannel_recog(cdev, sch)) {
847 spin_lock_irq(sch->lock);
848 sch_set_cdev(sch, NULL);
849 spin_unlock_irq(sch->lock);
850 if (cdev->dev.release)
851 cdev->dev.release(&cdev->dev);
852 css_sch_device_unregister(sch);
857 void ccw_device_move_to_orphanage(struct work_struct *work)
859 struct ccw_device_private *priv;
860 struct ccw_device *cdev;
861 struct ccw_device *replacing_cdev;
862 struct subchannel *sch;
864 struct channel_subsystem *css;
865 struct ccw_dev_id dev_id;
867 priv = container_of(work, struct ccw_device_private, kick_work);
869 sch = to_subchannel(cdev->dev.parent);
870 css = to_css(sch->dev.parent);
871 dev_id.devno = sch->schib.pmcw.dev;
872 dev_id.ssid = sch->schid.ssid;
875 * Move the orphaned ccw device to the orphanage so the replacing
876 * ccw device can take its place on the subchannel.
878 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
880 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
881 "(ret=%d)!\n", cdev->private->dev_id.ssid,
882 cdev->private->dev_id.devno, ret);
885 cdev->ccwlock = css->pseudo_subchannel->lock;
887 * Search for the replacing ccw device
888 * - among the disconnected devices
891 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
892 if (replacing_cdev) {
893 sch_attach_disconnected_device(sch, replacing_cdev);
896 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
897 if (replacing_cdev) {
898 sch_attach_orphaned_device(sch, replacing_cdev);
901 sch_create_and_recog_new_device(sch);
905 * Register recognized device.
908 io_subchannel_register(struct work_struct *work)
910 struct ccw_device_private *priv;
911 struct ccw_device *cdev;
912 struct subchannel *sch;
916 priv = container_of(work, struct ccw_device_private, kick_work);
918 sch = to_subchannel(cdev->dev.parent);
919 css_update_ssd_info(sch);
921 * io_subchannel_register() will also be called after device
922 * recognition has been done for a boxed device (which will already
923 * be registered). We need to reprobe since we may now have sense id
926 if (klist_node_attached(&cdev->dev.knode_parent)) {
928 ret = device_reprobe(&cdev->dev);
930 /* We can't do much here. */
931 CIO_MSG_EVENT(0, "device_reprobe() returned"
932 " %d for 0.%x.%04x\n", ret,
933 cdev->private->dev_id.ssid,
934 cdev->private->dev_id.devno);
939 * Now we know this subchannel will stay, we can throw
940 * our delayed uevent.
942 sch->dev.uevent_suppress = 0;
943 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
944 /* make it known to the system */
945 ret = ccw_device_register(cdev);
947 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
948 cdev->private->dev_id.ssid,
949 cdev->private->dev_id.devno, ret);
950 put_device(&cdev->dev);
951 spin_lock_irqsave(sch->lock, flags);
952 sch_set_cdev(sch, NULL);
953 spin_unlock_irqrestore(sch->lock, flags);
954 kfree (cdev->private);
956 put_device(&sch->dev);
957 if (atomic_dec_and_test(&ccw_device_init_count))
958 wake_up(&ccw_device_init_wq);
961 put_device(&cdev->dev);
963 cdev->private->flags.recog_done = 1;
964 put_device(&sch->dev);
965 wake_up(&cdev->private->wait_q);
966 if (atomic_dec_and_test(&ccw_device_init_count))
967 wake_up(&ccw_device_init_wq);
970 static void ccw_device_call_sch_unregister(struct work_struct *work)
972 struct ccw_device_private *priv;
973 struct ccw_device *cdev;
974 struct subchannel *sch;
976 priv = container_of(work, struct ccw_device_private, kick_work);
978 sch = to_subchannel(cdev->dev.parent);
979 css_sch_device_unregister(sch);
980 /* Reset intparm to zeroes. */
981 sch->schib.pmcw.intparm = 0;
983 put_device(&cdev->dev);
984 put_device(&sch->dev);
988 * subchannel recognition done. Called from the state machine.
991 io_subchannel_recog_done(struct ccw_device *cdev)
993 struct subchannel *sch;
995 if (css_init_done == 0) {
996 cdev->private->flags.recog_done = 1;
999 switch (cdev->private->state) {
1000 case DEV_STATE_NOT_OPER:
1001 cdev->private->flags.recog_done = 1;
1002 /* Remove device found not operational. */
1003 if (!get_device(&cdev->dev))
1005 sch = to_subchannel(cdev->dev.parent);
1006 PREPARE_WORK(&cdev->private->kick_work,
1007 ccw_device_call_sch_unregister);
1008 queue_work(slow_path_wq, &cdev->private->kick_work);
1009 if (atomic_dec_and_test(&ccw_device_init_count))
1010 wake_up(&ccw_device_init_wq);
1012 case DEV_STATE_BOXED:
1013 /* Device did not respond in time. */
1014 case DEV_STATE_OFFLINE:
1016 * We can't register the device in interrupt context so
1017 * we schedule a work item.
1019 if (!get_device(&cdev->dev))
1021 PREPARE_WORK(&cdev->private->kick_work,
1022 io_subchannel_register);
1023 queue_work(slow_path_wq, &cdev->private->kick_work);
1029 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
1032 struct ccw_device_private *priv;
1034 sch_set_cdev(sch, cdev);
1035 cdev->ccwlock = sch->lock;
1037 /* Init private data. */
1038 priv = cdev->private;
1039 priv->dev_id.devno = sch->schib.pmcw.dev;
1040 priv->dev_id.ssid = sch->schid.ssid;
1041 priv->schid = sch->schid;
1042 priv->state = DEV_STATE_NOT_OPER;
1043 INIT_LIST_HEAD(&priv->cmb_list);
1044 init_waitqueue_head(&priv->wait_q);
1045 init_timer(&priv->timer);
1047 /* Set an initial name for the device. */
1048 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
1049 sch->schid.ssid, sch->schib.pmcw.dev);
1051 /* Increase counter of devices currently in recognition. */
1052 atomic_inc(&ccw_device_init_count);
1054 /* Start async. device sensing. */
1055 spin_lock_irq(sch->lock);
1056 rc = ccw_device_recognition(cdev);
1057 spin_unlock_irq(sch->lock);
1059 if (atomic_dec_and_test(&ccw_device_init_count))
1060 wake_up(&ccw_device_init_wq);
1065 static void ccw_device_move_to_sch(struct work_struct *work)
1067 struct ccw_device_private *priv;
1069 struct subchannel *sch;
1070 struct ccw_device *cdev;
1071 struct subchannel *former_parent;
1073 priv = container_of(work, struct ccw_device_private, kick_work);
1076 former_parent = ccw_device_is_orphan(cdev) ?
1077 NULL : to_subchannel(get_device(cdev->dev.parent));
1078 mutex_lock(&sch->reg_mutex);
1079 /* Try to move the ccw device to its new subchannel. */
1080 rc = device_move(&cdev->dev, &sch->dev);
1081 mutex_unlock(&sch->reg_mutex);
1083 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
1084 "0.%x.%04x failed (ret=%d)!\n",
1085 cdev->private->dev_id.ssid,
1086 cdev->private->dev_id.devno, sch->schid.ssid,
1087 sch->schid.sch_no, rc);
1088 css_sch_device_unregister(sch);
1091 if (former_parent) {
1092 spin_lock_irq(former_parent->lock);
1093 sch_set_cdev(former_parent, NULL);
1094 spin_unlock_irq(former_parent->lock);
1095 css_sch_device_unregister(former_parent);
1096 /* Reset intparm to zeroes. */
1097 former_parent->schib.pmcw.intparm = 0;
1098 cio_modify(former_parent);
1100 sch_attach_device(sch, cdev);
1103 put_device(&former_parent->dev);
1104 put_device(&cdev->dev);
1107 static void io_subchannel_irq(struct subchannel *sch)
1109 struct ccw_device *cdev;
1111 cdev = sch_get_cdev(sch);
1113 CIO_TRACE_EVENT(3, "IRQ");
1114 CIO_TRACE_EVENT(3, sch->dev.bus_id);
1116 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1119 static void io_subchannel_init_fields(struct subchannel *sch)
1121 if (cio_is_console(sch->schid))
1124 sch->opm = chp_get_sch_opm(sch);
1125 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1126 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
1128 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1129 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1130 sch->schib.pmcw.dev, sch->schid.ssid,
1131 sch->schid.sch_no, sch->schib.pmcw.pim,
1132 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
1133 /* Initially set up some fields in the pmcw. */
1134 sch->schib.pmcw.ena = 0;
1135 sch->schib.pmcw.csense = 1; /* concurrent sense */
1136 if ((sch->lpm & (sch->lpm - 1)) != 0)
1137 sch->schib.pmcw.mp = 1; /* multipath mode */
1138 /* clean up possible residual cmf stuff */
1139 sch->schib.pmcw.mme = 0;
1140 sch->schib.pmcw.mbfc = 0;
1141 sch->schib.pmcw.mbi = 0;
1145 static int io_subchannel_probe(struct subchannel *sch)
1147 struct ccw_device *cdev;
1149 unsigned long flags;
1150 struct ccw_dev_id dev_id;
1152 cdev = sch_get_cdev(sch);
1154 rc = sysfs_create_group(&sch->dev.kobj,
1155 &io_subchannel_attr_group);
1157 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1158 "attributes for subchannel "
1159 "0.%x.%04x (rc=%d)\n",
1160 sch->schid.ssid, sch->schid.sch_no, rc);
1162 * This subchannel already has an associated ccw_device.
1163 * Throw the delayed uevent for the subchannel, register
1164 * the ccw_device and exit. This happens for all early
1165 * devices, e.g. the console.
1167 sch->dev.uevent_suppress = 0;
1168 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
1169 cdev->dev.groups = ccwdev_attr_groups;
1170 device_initialize(&cdev->dev);
1171 ccw_device_register(cdev);
1173 * Check if the device is already online. If it is
1174 * the reference count needs to be corrected
1175 * (see ccw_device_online and css_init_done for the
1178 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1179 cdev->private->state != DEV_STATE_OFFLINE &&
1180 cdev->private->state != DEV_STATE_BOXED)
1181 get_device(&cdev->dev);
1184 io_subchannel_init_fields(sch);
1186 * First check if a fitting device may be found amongst the
1187 * disconnected devices or in the orphanage.
1189 dev_id.devno = sch->schib.pmcw.dev;
1190 dev_id.ssid = sch->schid.ssid;
1191 rc = sysfs_create_group(&sch->dev.kobj,
1192 &io_subchannel_attr_group);
1195 /* Allocate I/O subchannel private data. */
1196 sch->private = kzalloc(sizeof(struct io_subchannel_private),
1197 GFP_KERNEL | GFP_DMA);
1198 if (!sch->private) {
1202 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
1204 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
1208 * Schedule moving the device until when we have a registered
1209 * subchannel to move to and succeed the probe. We can
1210 * unregister later again, when the probe is through.
1212 cdev->private->sch = sch;
1213 PREPARE_WORK(&cdev->private->kick_work,
1214 ccw_device_move_to_sch);
1215 queue_work(slow_path_wq, &cdev->private->kick_work);
1218 cdev = io_subchannel_create_ccwdev(sch);
1223 rc = io_subchannel_recog(cdev, sch);
1225 spin_lock_irqsave(sch->lock, flags);
1226 sch_set_cdev(sch, NULL);
1227 spin_unlock_irqrestore(sch->lock, flags);
1228 if (cdev->dev.release)
1229 cdev->dev.release(&cdev->dev);
1234 kfree(sch->private);
1235 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1240 io_subchannel_remove (struct subchannel *sch)
1242 struct ccw_device *cdev;
1243 unsigned long flags;
1245 cdev = sch_get_cdev(sch);
1248 /* Set ccw device to not operational and drop reference. */
1249 spin_lock_irqsave(cdev->ccwlock, flags);
1250 sch_set_cdev(sch, NULL);
1251 cdev->private->state = DEV_STATE_NOT_OPER;
1252 spin_unlock_irqrestore(cdev->ccwlock, flags);
1253 ccw_device_unregister(cdev);
1254 put_device(&cdev->dev);
1255 kfree(sch->private);
1256 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1260 static int io_subchannel_notify(struct subchannel *sch, int event)
1262 struct ccw_device *cdev;
1264 cdev = sch_get_cdev(sch);
1267 return ccw_device_notify(cdev, event);
1270 static void io_subchannel_verify(struct subchannel *sch)
1272 struct ccw_device *cdev;
1274 cdev = sch_get_cdev(sch);
1276 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1279 static int check_for_io_on_path(struct subchannel *sch, int mask)
1283 cc = stsch(sch->schid, &sch->schib);
1286 if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
1291 static void terminate_internal_io(struct subchannel *sch,
1292 struct ccw_device *cdev)
1294 if (cio_clear(sch)) {
1295 /* Recheck device in case clear failed. */
1298 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1300 css_schedule_eval(sch->schid);
1303 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
1304 /* Request retry of internal operation. */
1305 cdev->private->flags.intretry = 1;
1308 cdev->handler(cdev, cdev->private->intparm,
1312 static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
1314 struct ccw_device *cdev;
1316 cdev = sch_get_cdev(sch);
1319 if (check_for_io_on_path(sch, mask)) {
1320 if (cdev->private->state == DEV_STATE_ONLINE)
1321 ccw_device_kill_io(cdev);
1323 terminate_internal_io(sch, cdev);
1324 /* Re-start path verification. */
1325 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1328 /* trigger path verification. */
1329 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1333 static int io_subchannel_chp_event(struct subchannel *sch,
1334 struct chp_link *link, int event)
1338 mask = chp_ssd_get_mask(&sch->ssd_info, link);
1345 io_subchannel_terminate_path(sch, mask);
1350 io_subchannel_verify(sch);
1353 if (stsch(sch->schid, &sch->schib))
1355 if (!css_sch_is_valid(&sch->schib))
1357 io_subchannel_terminate_path(sch, mask);
1360 if (stsch(sch->schid, &sch->schib))
1362 sch->lpm |= mask & sch->opm;
1363 io_subchannel_verify(sch);
1370 io_subchannel_shutdown(struct subchannel *sch)
1372 struct ccw_device *cdev;
1375 cdev = sch_get_cdev(sch);
1377 if (cio_is_console(sch->schid))
1379 if (!sch->schib.pmcw.ena)
1380 /* Nothing to do. */
1382 ret = cio_disable_subchannel(sch);
1384 /* Subchannel is disabled, we're done. */
1386 cdev->private->state = DEV_STATE_QUIESCE;
1388 cdev->handler(cdev, cdev->private->intparm,
1390 ret = ccw_device_cancel_halt_clear(cdev);
1391 if (ret == -EBUSY) {
1392 ccw_device_set_timeout(cdev, HZ/10);
1393 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1395 cio_disable_subchannel(sch);
1398 static int io_subchannel_get_status(struct subchannel *sch)
1402 if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
1404 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
1405 return CIO_REVALIDATE;
1411 static int device_is_disconnected(struct ccw_device *cdev)
1415 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1416 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1419 static int recovery_check(struct device *dev, void *data)
1421 struct ccw_device *cdev = to_ccwdev(dev);
1424 spin_lock_irq(cdev->ccwlock);
1425 switch (cdev->private->state) {
1426 case DEV_STATE_DISCONNECTED:
1427 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1428 cdev->private->dev_id.ssid,
1429 cdev->private->dev_id.devno);
1430 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1433 case DEV_STATE_DISCONNECTED_SENSE_ID:
1437 spin_unlock_irq(cdev->ccwlock);
1442 static void recovery_work_func(struct work_struct *unused)
1446 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1448 spin_lock_irq(&recovery_lock);
1449 if (!timer_pending(&recovery_timer)) {
1450 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1452 mod_timer(&recovery_timer, jiffies +
1453 recovery_delay[recovery_phase] * HZ);
1455 spin_unlock_irq(&recovery_lock);
1457 CIO_MSG_EVENT(4, "recovery: end\n");
1460 static DECLARE_WORK(recovery_work, recovery_work_func);
1462 static void recovery_func(unsigned long data)
1465 * We can't do our recovery in softirq context and it's not
1466 * performance critical, so we schedule it.
1468 schedule_work(&recovery_work);
1471 static void ccw_device_schedule_recovery(void)
1473 unsigned long flags;
1475 CIO_MSG_EVENT(4, "recovery: schedule\n");
1476 spin_lock_irqsave(&recovery_lock, flags);
1477 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1479 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1481 spin_unlock_irqrestore(&recovery_lock, flags);
1484 static void device_set_disconnected(struct ccw_device *cdev)
1488 ccw_device_set_timeout(cdev, 0);
1489 cdev->private->flags.fake_irb = 0;
1490 cdev->private->state = DEV_STATE_DISCONNECTED;
1492 ccw_device_schedule_recovery();
1495 static int io_subchannel_sch_event(struct subchannel *sch, int slow)
1497 int event, ret, disc;
1498 unsigned long flags;
1499 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
1500 struct ccw_device *cdev;
1502 spin_lock_irqsave(sch->lock, flags);
1503 cdev = sch_get_cdev(sch);
1504 disc = device_is_disconnected(cdev);
1506 /* Disconnected devices are evaluated directly only.*/
1507 spin_unlock_irqrestore(sch->lock, flags);
1510 /* No interrupt after machine check - kill pending timers. */
1512 ccw_device_set_timeout(cdev, 0);
1513 if (!disc && !slow) {
1514 /* Non-disconnected devices are evaluated on the slow path. */
1515 spin_unlock_irqrestore(sch->lock, flags);
1518 event = io_subchannel_get_status(sch);
1519 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
1520 sch->schid.ssid, sch->schid.sch_no, event,
1521 disc ? "disconnected" : "normal",
1522 slow ? "slow" : "fast");
1523 /* Analyze subchannel status. */
1528 /* Check if paths have become available. */
1534 /* Prevent unwanted effects when opening lock. */
1535 cio_disable_subchannel(sch);
1536 device_set_disconnected(cdev);
1537 /* Ask driver what to do with device. */
1538 action = UNREGISTER;
1539 spin_unlock_irqrestore(sch->lock, flags);
1540 ret = io_subchannel_notify(sch, event);
1541 spin_lock_irqsave(sch->lock, flags);
1545 case CIO_REVALIDATE:
1546 /* Device will be removed, so no notify necessary. */
1548 /* Reprobe because immediate unregister might block. */
1551 action = UNREGISTER_PROBE;
1555 /* Get device operational again. */
1559 /* Perform action. */
1563 case UNREGISTER_PROBE:
1564 /* Unregister device (will use subchannel lock). */
1565 spin_unlock_irqrestore(sch->lock, flags);
1566 css_sch_device_unregister(sch);
1567 spin_lock_irqsave(sch->lock, flags);
1569 /* Reset intparm to zeroes. */
1570 sch->schib.pmcw.intparm = 0;
1574 ccw_device_trigger_reprobe(cdev);
1579 spin_unlock_irqrestore(sch->lock, flags);
1580 /* Probe if necessary. */
1581 if (action == UNREGISTER_PROBE)
1582 ret = css_probe_device(sch->schid);
1587 #ifdef CONFIG_CCW_CONSOLE
1588 static struct ccw_device console_cdev;
1589 static struct ccw_device_private console_private;
1590 static int console_cdev_in_use;
1592 static DEFINE_SPINLOCK(ccw_console_lock);
1594 spinlock_t * cio_get_console_lock(void)
1596 return &ccw_console_lock;
1599 static int ccw_device_console_enable(struct ccw_device *cdev,
1600 struct subchannel *sch)
1604 /* Attach subchannel private data. */
1605 sch->private = cio_get_console_priv();
1606 memset(sch->private, 0, sizeof(struct io_subchannel_private));
1607 io_subchannel_init_fields(sch);
1608 sch->driver = &io_subchannel_driver;
1609 /* Initialize the ccw_device structure. */
1610 cdev->dev.parent= &sch->dev;
1611 rc = io_subchannel_recog(cdev, sch);
1615 /* Now wait for the async. recognition to come to an end. */
1616 spin_lock_irq(cdev->ccwlock);
1617 while (!dev_fsm_final_state(cdev))
1620 if (cdev->private->state != DEV_STATE_OFFLINE)
1622 ccw_device_online(cdev);
1623 while (!dev_fsm_final_state(cdev))
1625 if (cdev->private->state != DEV_STATE_ONLINE)
1629 spin_unlock_irq(cdev->ccwlock);
1634 ccw_device_probe_console(void)
1636 struct subchannel *sch;
1639 if (xchg(&console_cdev_in_use, 1) != 0)
1640 return ERR_PTR(-EBUSY);
1641 sch = cio_probe_console();
1643 console_cdev_in_use = 0;
1644 return (void *) sch;
1646 memset(&console_cdev, 0, sizeof(struct ccw_device));
1647 memset(&console_private, 0, sizeof(struct ccw_device_private));
1648 console_cdev.private = &console_private;
1649 console_private.cdev = &console_cdev;
1650 ret = ccw_device_console_enable(&console_cdev, sch);
1652 cio_release_console();
1653 console_cdev_in_use = 0;
1654 return ERR_PTR(ret);
1656 console_cdev.online = 1;
1657 return &console_cdev;
1662 * get ccw_device matching the busid, but only if owned by cdrv
1665 __ccwdev_check_busid(struct device *dev, void *id)
1671 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1676 * get_ccwdev_by_busid() - obtain device from a bus id
1677 * @cdrv: driver the device is owned by
1678 * @bus_id: bus id of the device to be searched
1680 * This function searches all devices owned by @cdrv for a device with a bus
1681 * id matching @bus_id.
1683 * If a match is found, its reference count of the found device is increased
1684 * and it is returned; else %NULL is returned.
1686 struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1690 struct device_driver *drv;
1692 drv = get_driver(&cdrv->driver);
1696 dev = driver_find_device(drv, NULL, (void *)bus_id,
1697 __ccwdev_check_busid);
1700 return dev ? to_ccwdev(dev) : NULL;
1703 /************************** device driver handling ************************/
1705 /* This is the implementation of the ccw_driver class. The probe, remove
1706 * and release methods are initially very similar to the device_driver
1707 * implementations, with the difference that they have ccw_device
1710 * A ccw driver also contains the information that is needed for
1714 ccw_device_probe (struct device *dev)
1716 struct ccw_device *cdev = to_ccwdev(dev);
1717 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1720 cdev->drv = cdrv; /* to let the driver call _set_online */
1722 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1733 ccw_device_remove (struct device *dev)
1735 struct ccw_device *cdev = to_ccwdev(dev);
1736 struct ccw_driver *cdrv = cdev->drv;
1743 spin_lock_irq(cdev->ccwlock);
1744 ret = ccw_device_offline(cdev);
1745 spin_unlock_irq(cdev->ccwlock);
1747 wait_event(cdev->private->wait_q,
1748 dev_fsm_final_state(cdev));
1750 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
1751 "device 0.%x.%04x\n",
1752 ret, cdev->private->dev_id.ssid,
1753 cdev->private->dev_id.devno);
1755 ccw_device_set_timeout(cdev, 0);
1760 static void ccw_device_shutdown(struct device *dev)
1762 struct ccw_device *cdev;
1764 cdev = to_ccwdev(dev);
1765 if (cdev->drv && cdev->drv->shutdown)
1766 cdev->drv->shutdown(cdev);
1770 struct bus_type ccw_bus_type = {
1772 .match = ccw_bus_match,
1773 .uevent = ccw_uevent,
1774 .probe = ccw_device_probe,
1775 .remove = ccw_device_remove,
1776 .shutdown = ccw_device_shutdown,
1780 * ccw_driver_register() - register a ccw driver
1781 * @cdriver: driver to be registered
1783 * This function is mainly a wrapper around driver_register().
1785 * %0 on success and a negative error value on failure.
1787 int ccw_driver_register(struct ccw_driver *cdriver)
1789 struct device_driver *drv = &cdriver->driver;
1791 drv->bus = &ccw_bus_type;
1792 drv->name = cdriver->name;
1793 drv->owner = cdriver->owner;
1795 return driver_register(drv);
1799 * ccw_driver_unregister() - deregister a ccw driver
1800 * @cdriver: driver to be deregistered
1802 * This function is mainly a wrapper around driver_unregister().
1804 void ccw_driver_unregister(struct ccw_driver *cdriver)
1806 driver_unregister(&cdriver->driver);
1809 /* Helper func for qdio. */
1810 struct subchannel_id
1811 ccw_device_get_subchannel_id(struct ccw_device *cdev)
1813 struct subchannel *sch;
1815 sch = to_subchannel(cdev->dev.parent);
1819 MODULE_LICENSE("GPL");
1820 EXPORT_SYMBOL(ccw_device_set_online);
1821 EXPORT_SYMBOL(ccw_device_set_offline);
1822 EXPORT_SYMBOL(ccw_driver_register);
1823 EXPORT_SYMBOL(ccw_driver_unregister);
1824 EXPORT_SYMBOL(get_ccwdev_by_busid);
1825 EXPORT_SYMBOL(ccw_bus_type);
1826 EXPORT_SYMBOL(ccw_device_work);
1827 EXPORT_SYMBOL(ccw_device_notify_work);
1828 EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);