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 *, void *, int);
133 static struct css_driver io_subchannel_driver = {
134 .owner = THIS_MODULE,
135 .subchannel_type = SUBCHANNEL_TYPE_IO,
136 .name = "io_subchannel",
137 .irq = io_subchannel_irq,
138 .sch_event = io_subchannel_sch_event,
139 .chp_event = io_subchannel_chp_event,
140 .probe = io_subchannel_probe,
141 .remove = io_subchannel_remove,
142 .shutdown = io_subchannel_shutdown,
145 struct workqueue_struct *ccw_device_work;
146 struct workqueue_struct *ccw_device_notify_work;
147 wait_queue_head_t ccw_device_init_wq;
148 atomic_t ccw_device_init_count;
150 static void recovery_func(unsigned long data);
153 init_ccw_bus_type (void)
157 init_waitqueue_head(&ccw_device_init_wq);
158 atomic_set(&ccw_device_init_count, 0);
159 setup_timer(&recovery_timer, recovery_func, 0);
161 ccw_device_work = create_singlethread_workqueue("cio");
162 if (!ccw_device_work)
163 return -ENOMEM; /* FIXME: better errno ? */
164 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
165 if (!ccw_device_notify_work) {
166 ret = -ENOMEM; /* FIXME: better errno ? */
169 slow_path_wq = create_singlethread_workqueue("kslowcrw");
171 ret = -ENOMEM; /* FIXME: better errno ? */
174 if ((ret = bus_register (&ccw_bus_type)))
177 ret = css_driver_register(&io_subchannel_driver);
181 wait_event(ccw_device_init_wq,
182 atomic_read(&ccw_device_init_count) == 0);
183 flush_workqueue(ccw_device_work);
187 destroy_workqueue(ccw_device_work);
188 if (ccw_device_notify_work)
189 destroy_workqueue(ccw_device_notify_work);
191 destroy_workqueue(slow_path_wq);
196 cleanup_ccw_bus_type (void)
198 css_driver_unregister(&io_subchannel_driver);
199 bus_unregister(&ccw_bus_type);
200 destroy_workqueue(ccw_device_notify_work);
201 destroy_workqueue(ccw_device_work);
204 subsys_initcall(init_ccw_bus_type);
205 module_exit(cleanup_ccw_bus_type);
207 /************************ device handling **************************/
210 * A ccw_device has some interfaces in sysfs in addition to the
212 * The following entries are designed to export the information which
213 * resided in 2.4 in /proc/subchannels. Subchannel and device number
214 * are obvious, so they don't have an entry :)
215 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
218 chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
220 struct subchannel *sch = to_subchannel(dev);
221 struct chsc_ssd_info *ssd = &sch->ssd_info;
226 for (chp = 0; chp < 8; chp++) {
228 if (ssd->path_mask & mask)
229 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
231 ret += sprintf(buf + ret, "00 ");
233 ret += sprintf (buf+ret, "\n");
234 return min((ssize_t)PAGE_SIZE, ret);
238 pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
240 struct subchannel *sch = to_subchannel(dev);
241 struct pmcw *pmcw = &sch->schib.pmcw;
243 return sprintf (buf, "%02x %02x %02x\n",
244 pmcw->pim, pmcw->pam, pmcw->pom);
248 devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
250 struct ccw_device *cdev = to_ccwdev(dev);
251 struct ccw_device_id *id = &(cdev->id);
253 if (id->dev_type != 0)
254 return sprintf(buf, "%04x/%02x\n",
255 id->dev_type, id->dev_model);
257 return sprintf(buf, "n/a\n");
261 cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
263 struct ccw_device *cdev = to_ccwdev(dev);
264 struct ccw_device_id *id = &(cdev->id);
266 return sprintf(buf, "%04x/%02x\n",
267 id->cu_type, id->cu_model);
271 modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
273 struct ccw_device *cdev = to_ccwdev(dev);
274 struct ccw_device_id *id = &(cdev->id);
277 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
279 return len > PAGE_SIZE ? PAGE_SIZE : len;
283 online_show (struct device *dev, struct device_attribute *attr, char *buf)
285 struct ccw_device *cdev = to_ccwdev(dev);
287 return sprintf(buf, cdev->online ? "1\n" : "0\n");
290 int ccw_device_is_orphan(struct ccw_device *cdev)
292 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
295 static void ccw_device_unregister(struct ccw_device *cdev)
297 if (test_and_clear_bit(1, &cdev->private->registered))
298 device_del(&cdev->dev);
301 static void ccw_device_remove_orphan_cb(struct device *dev)
303 struct ccw_device *cdev = to_ccwdev(dev);
305 ccw_device_unregister(cdev);
306 put_device(&cdev->dev);
309 static void ccw_device_remove_sch_cb(struct device *dev)
311 struct subchannel *sch;
313 sch = to_subchannel(dev);
314 css_sch_device_unregister(sch);
315 /* Reset intparm to zeroes. */
316 sch->schib.pmcw.intparm = 0;
318 put_device(&sch->dev);
322 ccw_device_remove_disconnected(struct ccw_device *cdev)
328 * Forced offline in disconnected state means
329 * 'throw away device'.
331 if (ccw_device_is_orphan(cdev)) {
333 * Deregister ccw device.
334 * Unfortunately, we cannot do this directly from the
337 spin_lock_irqsave(cdev->ccwlock, flags);
338 cdev->private->state = DEV_STATE_NOT_OPER;
339 spin_unlock_irqrestore(cdev->ccwlock, flags);
340 rc = device_schedule_callback(&cdev->dev,
341 ccw_device_remove_orphan_cb);
343 CIO_MSG_EVENT(0, "Couldn't unregister orphan "
345 cdev->private->dev_id.ssid,
346 cdev->private->dev_id.devno);
349 /* Deregister subchannel, which will kill the ccw device. */
350 rc = device_schedule_callback(cdev->dev.parent,
351 ccw_device_remove_sch_cb);
353 CIO_MSG_EVENT(0, "Couldn't unregister disconnected device "
355 cdev->private->dev_id.ssid,
356 cdev->private->dev_id.devno);
360 * ccw_device_set_offline() - disable a ccw device for I/O
361 * @cdev: target ccw device
363 * This function calls the driver's set_offline() function for @cdev, if
364 * given, and then disables @cdev.
366 * %0 on success and a negative error value on failure.
368 * enabled, ccw device lock not held
370 int ccw_device_set_offline(struct ccw_device *cdev)
376 if (!cdev->online || !cdev->drv)
379 if (cdev->drv->set_offline) {
380 ret = cdev->drv->set_offline(cdev);
385 spin_lock_irq(cdev->ccwlock);
386 ret = ccw_device_offline(cdev);
387 if (ret == -ENODEV) {
388 if (cdev->private->state != DEV_STATE_NOT_OPER) {
389 cdev->private->state = DEV_STATE_OFFLINE;
390 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
392 spin_unlock_irq(cdev->ccwlock);
395 spin_unlock_irq(cdev->ccwlock);
397 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
399 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
400 "device 0.%x.%04x\n",
401 ret, cdev->private->dev_id.ssid,
402 cdev->private->dev_id.devno);
409 * ccw_device_set_online() - enable a ccw device for I/O
410 * @cdev: target ccw device
412 * This function first enables @cdev and then calls the driver's set_online()
413 * function for @cdev, if given. If set_online() returns an error, @cdev is
416 * %0 on success and a negative error value on failure.
418 * enabled, ccw device lock not held
420 int ccw_device_set_online(struct ccw_device *cdev)
426 if (cdev->online || !cdev->drv)
429 spin_lock_irq(cdev->ccwlock);
430 ret = ccw_device_online(cdev);
431 spin_unlock_irq(cdev->ccwlock);
433 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
435 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
436 "device 0.%x.%04x\n",
437 ret, cdev->private->dev_id.ssid,
438 cdev->private->dev_id.devno);
441 if (cdev->private->state != DEV_STATE_ONLINE)
443 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
447 spin_lock_irq(cdev->ccwlock);
448 ret = ccw_device_offline(cdev);
449 spin_unlock_irq(cdev->ccwlock);
451 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
453 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
454 "device 0.%x.%04x\n",
455 ret, cdev->private->dev_id.ssid,
456 cdev->private->dev_id.devno);
457 return (ret == 0) ? -ENODEV : ret;
460 static void online_store_handle_offline(struct ccw_device *cdev)
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);
468 static int online_store_recog_and_online(struct ccw_device *cdev)
472 /* Do device recognition, if needed. */
473 if (cdev->id.cu_type == 0) {
474 ret = ccw_device_recognition(cdev);
476 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);
482 wait_event(cdev->private->wait_q,
483 cdev->private->flags.recog_done);
485 if (cdev->drv && cdev->drv->set_online)
486 ccw_device_set_online(cdev);
489 static void online_store_handle_online(struct ccw_device *cdev, int force)
493 ret = online_store_recog_and_online(cdev);
496 if (force && cdev->private->state == DEV_STATE_BOXED) {
497 ret = ccw_device_stlck(cdev);
500 "ccw_device_stlck returned %d!\n", ret);
503 if (cdev->id.cu_type == 0)
504 cdev->private->state = DEV_STATE_NOT_OPER;
505 online_store_recog_and_online(cdev);
510 static ssize_t online_store (struct device *dev, struct device_attribute *attr,
511 const char *buf, size_t count)
513 struct ccw_device *cdev = to_ccwdev(dev);
517 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
520 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
521 atomic_set(&cdev->private->onoff, 0);
524 if (!strncmp(buf, "force\n", count)) {
530 ret = strict_strtoul(buf, 16, &i);
536 online_store_handle_offline(cdev);
540 online_store_handle_online(cdev, force);
548 module_put(cdev->drv->owner);
549 atomic_set(&cdev->private->onoff, 0);
554 available_show (struct device *dev, struct device_attribute *attr, char *buf)
556 struct ccw_device *cdev = to_ccwdev(dev);
557 struct subchannel *sch;
559 if (ccw_device_is_orphan(cdev))
560 return sprintf(buf, "no device\n");
561 switch (cdev->private->state) {
562 case DEV_STATE_BOXED:
563 return sprintf(buf, "boxed\n");
564 case DEV_STATE_DISCONNECTED:
565 case DEV_STATE_DISCONNECTED_SENSE_ID:
566 case DEV_STATE_NOT_OPER:
567 sch = to_subchannel(dev->parent);
569 return sprintf(buf, "no path\n");
571 return sprintf(buf, "no device\n");
573 /* All other states considered fine. */
574 return sprintf(buf, "good\n");
578 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
579 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
580 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
581 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
582 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
583 static DEVICE_ATTR(online, 0644, online_show, online_store);
584 static DEVICE_ATTR(availability, 0444, available_show, NULL);
586 static struct attribute *io_subchannel_attrs[] = {
587 &dev_attr_chpids.attr,
588 &dev_attr_pimpampom.attr,
592 static struct attribute_group io_subchannel_attr_group = {
593 .attrs = io_subchannel_attrs,
596 static struct attribute * ccwdev_attrs[] = {
597 &dev_attr_devtype.attr,
598 &dev_attr_cutype.attr,
599 &dev_attr_modalias.attr,
600 &dev_attr_online.attr,
601 &dev_attr_cmb_enable.attr,
602 &dev_attr_availability.attr,
606 static struct attribute_group ccwdev_attr_group = {
607 .attrs = ccwdev_attrs,
610 static struct attribute_group *ccwdev_attr_groups[] = {
615 /* this is a simple abstraction for device_register that sets the
616 * correct bus type and adds the bus specific files */
617 static int ccw_device_register(struct ccw_device *cdev)
619 struct device *dev = &cdev->dev;
622 dev->bus = &ccw_bus_type;
624 if ((ret = device_add(dev)))
627 set_bit(1, &cdev->private->registered);
632 struct ccw_dev_id dev_id;
633 struct ccw_device * sibling;
637 match_devno(struct device * dev, void * data)
639 struct match_data * d = data;
640 struct ccw_device * cdev;
642 cdev = to_ccwdev(dev);
643 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
644 !ccw_device_is_orphan(cdev) &&
645 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
646 (cdev != d->sibling))
651 static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
652 struct ccw_device *sibling)
655 struct match_data data;
657 data.dev_id = *dev_id;
658 data.sibling = sibling;
659 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
661 return dev ? to_ccwdev(dev) : NULL;
664 static int match_orphan(struct device *dev, void *data)
666 struct ccw_dev_id *dev_id;
667 struct ccw_device *cdev;
670 cdev = to_ccwdev(dev);
671 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
674 static struct ccw_device *
675 get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
676 struct ccw_dev_id *dev_id)
680 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
683 return dev ? to_ccwdev(dev) : NULL;
687 ccw_device_add_changed(struct work_struct *work)
689 struct ccw_device_private *priv;
690 struct ccw_device *cdev;
692 priv = container_of(work, struct ccw_device_private, kick_work);
694 if (device_add(&cdev->dev)) {
695 put_device(&cdev->dev);
698 set_bit(1, &cdev->private->registered);
701 void ccw_device_do_unreg_rereg(struct work_struct *work)
703 struct ccw_device_private *priv;
704 struct ccw_device *cdev;
705 struct subchannel *sch;
707 priv = container_of(work, struct ccw_device_private, kick_work);
709 sch = to_subchannel(cdev->dev.parent);
711 ccw_device_unregister(cdev);
712 PREPARE_WORK(&cdev->private->kick_work,
713 ccw_device_add_changed);
714 queue_work(ccw_device_work, &cdev->private->kick_work);
718 ccw_device_release(struct device *dev)
720 struct ccw_device *cdev;
722 cdev = to_ccwdev(dev);
723 kfree(cdev->private);
727 static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
729 struct ccw_device *cdev;
731 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
733 cdev->private = kzalloc(sizeof(struct ccw_device_private),
734 GFP_KERNEL | GFP_DMA);
739 return ERR_PTR(-ENOMEM);
742 static int io_subchannel_initialize_dev(struct subchannel *sch,
743 struct ccw_device *cdev)
745 cdev->private->cdev = cdev;
746 atomic_set(&cdev->private->onoff, 0);
747 cdev->dev.parent = &sch->dev;
748 cdev->dev.release = ccw_device_release;
749 INIT_WORK(&cdev->private->kick_work, NULL);
750 cdev->dev.groups = ccwdev_attr_groups;
751 /* Do first half of device_register. */
752 device_initialize(&cdev->dev);
753 if (!get_device(&sch->dev)) {
754 if (cdev->dev.release)
755 cdev->dev.release(&cdev->dev);
761 static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
763 struct ccw_device *cdev;
766 cdev = io_subchannel_allocate_dev(sch);
768 ret = io_subchannel_initialize_dev(sch, cdev);
777 static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
779 static void sch_attach_device(struct subchannel *sch,
780 struct ccw_device *cdev)
782 css_update_ssd_info(sch);
783 spin_lock_irq(sch->lock);
784 sch_set_cdev(sch, cdev);
785 cdev->private->schid = sch->schid;
786 cdev->ccwlock = sch->lock;
787 ccw_device_trigger_reprobe(cdev);
788 spin_unlock_irq(sch->lock);
791 static void sch_attach_disconnected_device(struct subchannel *sch,
792 struct ccw_device *cdev)
794 struct subchannel *other_sch;
797 other_sch = to_subchannel(get_device(cdev->dev.parent));
798 ret = device_move(&cdev->dev, &sch->dev);
800 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
801 "(ret=%d)!\n", cdev->private->dev_id.ssid,
802 cdev->private->dev_id.devno, ret);
803 put_device(&other_sch->dev);
806 sch_set_cdev(other_sch, NULL);
807 /* No need to keep a subchannel without ccw device around. */
808 css_sch_device_unregister(other_sch);
809 put_device(&other_sch->dev);
810 sch_attach_device(sch, cdev);
813 static void sch_attach_orphaned_device(struct subchannel *sch,
814 struct ccw_device *cdev)
818 /* Try to move the ccw device to its new subchannel. */
819 ret = device_move(&cdev->dev, &sch->dev);
821 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
822 "failed (ret=%d)!\n",
823 cdev->private->dev_id.ssid,
824 cdev->private->dev_id.devno, ret);
827 sch_attach_device(sch, cdev);
830 static void sch_create_and_recog_new_device(struct subchannel *sch)
832 struct ccw_device *cdev;
834 /* Need to allocate a new ccw device. */
835 cdev = io_subchannel_create_ccwdev(sch);
837 /* OK, we did everything we could... */
838 css_sch_device_unregister(sch);
841 spin_lock_irq(sch->lock);
842 sch_set_cdev(sch, cdev);
843 spin_unlock_irq(sch->lock);
844 /* Start recognition for the new ccw device. */
845 if (io_subchannel_recog(cdev, sch)) {
846 spin_lock_irq(sch->lock);
847 sch_set_cdev(sch, NULL);
848 spin_unlock_irq(sch->lock);
849 if (cdev->dev.release)
850 cdev->dev.release(&cdev->dev);
851 css_sch_device_unregister(sch);
856 void ccw_device_move_to_orphanage(struct work_struct *work)
858 struct ccw_device_private *priv;
859 struct ccw_device *cdev;
860 struct ccw_device *replacing_cdev;
861 struct subchannel *sch;
863 struct channel_subsystem *css;
864 struct ccw_dev_id dev_id;
866 priv = container_of(work, struct ccw_device_private, kick_work);
868 sch = to_subchannel(cdev->dev.parent);
869 css = to_css(sch->dev.parent);
870 dev_id.devno = sch->schib.pmcw.dev;
871 dev_id.ssid = sch->schid.ssid;
874 * Move the orphaned ccw device to the orphanage so the replacing
875 * ccw device can take its place on the subchannel.
877 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
879 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
880 "(ret=%d)!\n", cdev->private->dev_id.ssid,
881 cdev->private->dev_id.devno, ret);
884 cdev->ccwlock = css->pseudo_subchannel->lock;
886 * Search for the replacing ccw device
887 * - among the disconnected devices
890 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
891 if (replacing_cdev) {
892 sch_attach_disconnected_device(sch, replacing_cdev);
895 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
896 if (replacing_cdev) {
897 sch_attach_orphaned_device(sch, replacing_cdev);
900 sch_create_and_recog_new_device(sch);
904 * Register recognized device.
907 io_subchannel_register(struct work_struct *work)
909 struct ccw_device_private *priv;
910 struct ccw_device *cdev;
911 struct subchannel *sch;
915 priv = container_of(work, struct ccw_device_private, kick_work);
917 sch = to_subchannel(cdev->dev.parent);
918 css_update_ssd_info(sch);
920 * io_subchannel_register() will also be called after device
921 * recognition has been done for a boxed device (which will already
922 * be registered). We need to reprobe since we may now have sense id
925 if (klist_node_attached(&cdev->dev.knode_parent)) {
927 ret = device_reprobe(&cdev->dev);
929 /* We can't do much here. */
930 CIO_MSG_EVENT(0, "device_reprobe() returned"
931 " %d for 0.%x.%04x\n", ret,
932 cdev->private->dev_id.ssid,
933 cdev->private->dev_id.devno);
938 * Now we know this subchannel will stay, we can throw
939 * our delayed uevent.
941 sch->dev.uevent_suppress = 0;
942 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
943 /* make it known to the system */
944 ret = ccw_device_register(cdev);
946 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
947 cdev->private->dev_id.ssid,
948 cdev->private->dev_id.devno, ret);
949 put_device(&cdev->dev);
950 spin_lock_irqsave(sch->lock, flags);
951 sch_set_cdev(sch, NULL);
952 spin_unlock_irqrestore(sch->lock, flags);
953 kfree (cdev->private);
955 put_device(&sch->dev);
956 if (atomic_dec_and_test(&ccw_device_init_count))
957 wake_up(&ccw_device_init_wq);
960 put_device(&cdev->dev);
962 cdev->private->flags.recog_done = 1;
963 put_device(&sch->dev);
964 wake_up(&cdev->private->wait_q);
965 if (atomic_dec_and_test(&ccw_device_init_count))
966 wake_up(&ccw_device_init_wq);
969 static void ccw_device_call_sch_unregister(struct work_struct *work)
971 struct ccw_device_private *priv;
972 struct ccw_device *cdev;
973 struct subchannel *sch;
975 priv = container_of(work, struct ccw_device_private, kick_work);
977 sch = to_subchannel(cdev->dev.parent);
978 css_sch_device_unregister(sch);
979 /* Reset intparm to zeroes. */
980 sch->schib.pmcw.intparm = 0;
982 put_device(&cdev->dev);
983 put_device(&sch->dev);
987 * subchannel recognition done. Called from the state machine.
990 io_subchannel_recog_done(struct ccw_device *cdev)
992 struct subchannel *sch;
994 if (css_init_done == 0) {
995 cdev->private->flags.recog_done = 1;
998 switch (cdev->private->state) {
999 case DEV_STATE_NOT_OPER:
1000 cdev->private->flags.recog_done = 1;
1001 /* Remove device found not operational. */
1002 if (!get_device(&cdev->dev))
1004 sch = to_subchannel(cdev->dev.parent);
1005 PREPARE_WORK(&cdev->private->kick_work,
1006 ccw_device_call_sch_unregister);
1007 queue_work(slow_path_wq, &cdev->private->kick_work);
1008 if (atomic_dec_and_test(&ccw_device_init_count))
1009 wake_up(&ccw_device_init_wq);
1011 case DEV_STATE_BOXED:
1012 /* Device did not respond in time. */
1013 case DEV_STATE_OFFLINE:
1015 * We can't register the device in interrupt context so
1016 * we schedule a work item.
1018 if (!get_device(&cdev->dev))
1020 PREPARE_WORK(&cdev->private->kick_work,
1021 io_subchannel_register);
1022 queue_work(slow_path_wq, &cdev->private->kick_work);
1028 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
1031 struct ccw_device_private *priv;
1033 sch_set_cdev(sch, cdev);
1034 cdev->ccwlock = sch->lock;
1036 /* Init private data. */
1037 priv = cdev->private;
1038 priv->dev_id.devno = sch->schib.pmcw.dev;
1039 priv->dev_id.ssid = sch->schid.ssid;
1040 priv->schid = sch->schid;
1041 priv->state = DEV_STATE_NOT_OPER;
1042 INIT_LIST_HEAD(&priv->cmb_list);
1043 init_waitqueue_head(&priv->wait_q);
1044 init_timer(&priv->timer);
1046 /* Set an initial name for the device. */
1047 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
1048 sch->schid.ssid, sch->schib.pmcw.dev);
1050 /* Increase counter of devices currently in recognition. */
1051 atomic_inc(&ccw_device_init_count);
1053 /* Start async. device sensing. */
1054 spin_lock_irq(sch->lock);
1055 rc = ccw_device_recognition(cdev);
1056 spin_unlock_irq(sch->lock);
1058 if (atomic_dec_and_test(&ccw_device_init_count))
1059 wake_up(&ccw_device_init_wq);
1064 static void ccw_device_move_to_sch(struct work_struct *work)
1066 struct ccw_device_private *priv;
1068 struct subchannel *sch;
1069 struct ccw_device *cdev;
1070 struct subchannel *former_parent;
1072 priv = container_of(work, struct ccw_device_private, kick_work);
1075 former_parent = ccw_device_is_orphan(cdev) ?
1076 NULL : to_subchannel(get_device(cdev->dev.parent));
1077 mutex_lock(&sch->reg_mutex);
1078 /* Try to move the ccw device to its new subchannel. */
1079 rc = device_move(&cdev->dev, &sch->dev);
1080 mutex_unlock(&sch->reg_mutex);
1082 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
1083 "0.%x.%04x failed (ret=%d)!\n",
1084 cdev->private->dev_id.ssid,
1085 cdev->private->dev_id.devno, sch->schid.ssid,
1086 sch->schid.sch_no, rc);
1087 css_sch_device_unregister(sch);
1090 if (former_parent) {
1091 spin_lock_irq(former_parent->lock);
1092 sch_set_cdev(former_parent, NULL);
1093 spin_unlock_irq(former_parent->lock);
1094 css_sch_device_unregister(former_parent);
1095 /* Reset intparm to zeroes. */
1096 former_parent->schib.pmcw.intparm = 0;
1097 cio_modify(former_parent);
1099 sch_attach_device(sch, cdev);
1102 put_device(&former_parent->dev);
1103 put_device(&cdev->dev);
1106 static void io_subchannel_irq(struct subchannel *sch)
1108 struct ccw_device *cdev;
1110 cdev = sch_get_cdev(sch);
1112 CIO_TRACE_EVENT(3, "IRQ");
1113 CIO_TRACE_EVENT(3, sch->dev.bus_id);
1115 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1118 static void io_subchannel_init_fields(struct subchannel *sch)
1120 if (cio_is_console(sch->schid))
1123 sch->opm = chp_get_sch_opm(sch);
1124 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1125 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
1127 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1128 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1129 sch->schib.pmcw.dev, sch->schid.ssid,
1130 sch->schid.sch_no, sch->schib.pmcw.pim,
1131 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
1132 /* Initially set up some fields in the pmcw. */
1133 sch->schib.pmcw.ena = 0;
1134 sch->schib.pmcw.csense = 1; /* concurrent sense */
1135 if ((sch->lpm & (sch->lpm - 1)) != 0)
1136 sch->schib.pmcw.mp = 1; /* multipath mode */
1137 /* clean up possible residual cmf stuff */
1138 sch->schib.pmcw.mme = 0;
1139 sch->schib.pmcw.mbfc = 0;
1140 sch->schib.pmcw.mbi = 0;
1144 static int io_subchannel_probe(struct subchannel *sch)
1146 struct ccw_device *cdev;
1148 unsigned long flags;
1149 struct ccw_dev_id dev_id;
1151 cdev = sch_get_cdev(sch);
1153 rc = sysfs_create_group(&sch->dev.kobj,
1154 &io_subchannel_attr_group);
1156 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1157 "attributes for subchannel "
1158 "0.%x.%04x (rc=%d)\n",
1159 sch->schid.ssid, sch->schid.sch_no, rc);
1161 * This subchannel already has an associated ccw_device.
1162 * Throw the delayed uevent for the subchannel, register
1163 * the ccw_device and exit. This happens for all early
1164 * devices, e.g. the console.
1166 sch->dev.uevent_suppress = 0;
1167 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
1168 cdev->dev.groups = ccwdev_attr_groups;
1169 device_initialize(&cdev->dev);
1170 ccw_device_register(cdev);
1172 * Check if the device is already online. If it is
1173 * the reference count needs to be corrected
1174 * (see ccw_device_online and css_init_done for the
1177 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1178 cdev->private->state != DEV_STATE_OFFLINE &&
1179 cdev->private->state != DEV_STATE_BOXED)
1180 get_device(&cdev->dev);
1183 io_subchannel_init_fields(sch);
1185 * First check if a fitting device may be found amongst the
1186 * disconnected devices or in the orphanage.
1188 dev_id.devno = sch->schib.pmcw.dev;
1189 dev_id.ssid = sch->schid.ssid;
1190 rc = sysfs_create_group(&sch->dev.kobj,
1191 &io_subchannel_attr_group);
1194 /* Allocate I/O subchannel private data. */
1195 sch->private = kzalloc(sizeof(struct io_subchannel_private),
1196 GFP_KERNEL | GFP_DMA);
1197 if (!sch->private) {
1201 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
1203 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
1207 * Schedule moving the device until when we have a registered
1208 * subchannel to move to and succeed the probe. We can
1209 * unregister later again, when the probe is through.
1211 cdev->private->sch = sch;
1212 PREPARE_WORK(&cdev->private->kick_work,
1213 ccw_device_move_to_sch);
1214 queue_work(slow_path_wq, &cdev->private->kick_work);
1217 cdev = io_subchannel_create_ccwdev(sch);
1222 rc = io_subchannel_recog(cdev, sch);
1224 spin_lock_irqsave(sch->lock, flags);
1225 sch_set_cdev(sch, NULL);
1226 spin_unlock_irqrestore(sch->lock, flags);
1227 if (cdev->dev.release)
1228 cdev->dev.release(&cdev->dev);
1233 kfree(sch->private);
1234 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1239 io_subchannel_remove (struct subchannel *sch)
1241 struct ccw_device *cdev;
1242 unsigned long flags;
1244 cdev = sch_get_cdev(sch);
1247 /* Set ccw device to not operational and drop reference. */
1248 spin_lock_irqsave(cdev->ccwlock, flags);
1249 sch_set_cdev(sch, NULL);
1250 cdev->private->state = DEV_STATE_NOT_OPER;
1251 spin_unlock_irqrestore(cdev->ccwlock, flags);
1252 ccw_device_unregister(cdev);
1253 put_device(&cdev->dev);
1254 kfree(sch->private);
1255 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1259 static int io_subchannel_notify(struct subchannel *sch, int event)
1261 struct ccw_device *cdev;
1263 cdev = sch_get_cdev(sch);
1266 return ccw_device_notify(cdev, event);
1269 static void io_subchannel_verify(struct subchannel *sch)
1271 struct ccw_device *cdev;
1273 cdev = sch_get_cdev(sch);
1275 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1278 static int check_for_io_on_path(struct subchannel *sch, int mask)
1282 cc = stsch(sch->schid, &sch->schib);
1285 if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
1290 static void terminate_internal_io(struct subchannel *sch,
1291 struct ccw_device *cdev)
1293 if (cio_clear(sch)) {
1294 /* Recheck device in case clear failed. */
1297 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1299 css_schedule_eval(sch->schid);
1302 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
1303 /* Request retry of internal operation. */
1304 cdev->private->flags.intretry = 1;
1307 cdev->handler(cdev, cdev->private->intparm,
1311 static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
1313 struct ccw_device *cdev;
1315 cdev = sch_get_cdev(sch);
1318 if (check_for_io_on_path(sch, mask)) {
1319 if (cdev->private->state == DEV_STATE_ONLINE)
1320 ccw_device_kill_io(cdev);
1322 terminate_internal_io(sch, cdev);
1323 /* Re-start path verification. */
1324 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1327 /* trigger path verification. */
1328 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1332 static int io_subchannel_chp_event(struct subchannel *sch, void *data,
1336 struct res_acc_data *res_data;
1339 mask = chp_ssd_get_mask(&sch->ssd_info, res_data);
1346 io_subchannel_terminate_path(sch, mask);
1351 io_subchannel_verify(sch);
1354 if (stsch(sch->schid, &sch->schib))
1356 if (!css_sch_is_valid(&sch->schib))
1358 io_subchannel_terminate_path(sch, mask);
1361 if (stsch(sch->schid, &sch->schib))
1363 sch->lpm |= mask & sch->opm;
1364 io_subchannel_verify(sch);
1371 io_subchannel_shutdown(struct subchannel *sch)
1373 struct ccw_device *cdev;
1376 cdev = sch_get_cdev(sch);
1378 if (cio_is_console(sch->schid))
1380 if (!sch->schib.pmcw.ena)
1381 /* Nothing to do. */
1383 ret = cio_disable_subchannel(sch);
1385 /* Subchannel is disabled, we're done. */
1387 cdev->private->state = DEV_STATE_QUIESCE;
1389 cdev->handler(cdev, cdev->private->intparm,
1391 ret = ccw_device_cancel_halt_clear(cdev);
1392 if (ret == -EBUSY) {
1393 ccw_device_set_timeout(cdev, HZ/10);
1394 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1396 cio_disable_subchannel(sch);
1399 static int io_subchannel_get_status(struct subchannel *sch)
1403 if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
1405 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
1406 return CIO_REVALIDATE;
1412 static int device_is_disconnected(struct ccw_device *cdev)
1416 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1417 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1420 static int recovery_check(struct device *dev, void *data)
1422 struct ccw_device *cdev = to_ccwdev(dev);
1425 spin_lock_irq(cdev->ccwlock);
1426 switch (cdev->private->state) {
1427 case DEV_STATE_DISCONNECTED:
1428 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1429 cdev->private->dev_id.ssid,
1430 cdev->private->dev_id.devno);
1431 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1434 case DEV_STATE_DISCONNECTED_SENSE_ID:
1438 spin_unlock_irq(cdev->ccwlock);
1443 static void recovery_work_func(struct work_struct *unused)
1447 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1449 spin_lock_irq(&recovery_lock);
1450 if (!timer_pending(&recovery_timer)) {
1451 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1453 mod_timer(&recovery_timer, jiffies +
1454 recovery_delay[recovery_phase] * HZ);
1456 spin_unlock_irq(&recovery_lock);
1458 CIO_MSG_EVENT(4, "recovery: end\n");
1461 static DECLARE_WORK(recovery_work, recovery_work_func);
1463 static void recovery_func(unsigned long data)
1466 * We can't do our recovery in softirq context and it's not
1467 * performance critical, so we schedule it.
1469 schedule_work(&recovery_work);
1472 static void ccw_device_schedule_recovery(void)
1474 unsigned long flags;
1476 CIO_MSG_EVENT(4, "recovery: schedule\n");
1477 spin_lock_irqsave(&recovery_lock, flags);
1478 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1480 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1482 spin_unlock_irqrestore(&recovery_lock, flags);
1485 static void device_set_disconnected(struct ccw_device *cdev)
1489 ccw_device_set_timeout(cdev, 0);
1490 cdev->private->flags.fake_irb = 0;
1491 cdev->private->state = DEV_STATE_DISCONNECTED;
1493 ccw_device_schedule_recovery();
1496 static int io_subchannel_sch_event(struct subchannel *sch, int slow)
1498 int event, ret, disc;
1499 unsigned long flags;
1500 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
1501 struct ccw_device *cdev;
1503 spin_lock_irqsave(sch->lock, flags);
1504 cdev = sch_get_cdev(sch);
1505 disc = device_is_disconnected(cdev);
1507 /* Disconnected devices are evaluated directly only.*/
1508 spin_unlock_irqrestore(sch->lock, flags);
1511 /* No interrupt after machine check - kill pending timers. */
1513 ccw_device_set_timeout(cdev, 0);
1514 if (!disc && !slow) {
1515 /* Non-disconnected devices are evaluated on the slow path. */
1516 spin_unlock_irqrestore(sch->lock, flags);
1519 event = io_subchannel_get_status(sch);
1520 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
1521 sch->schid.ssid, sch->schid.sch_no, event,
1522 disc ? "disconnected" : "normal",
1523 slow ? "slow" : "fast");
1524 /* Analyze subchannel status. */
1529 /* Check if paths have become available. */
1535 /* Prevent unwanted effects when opening lock. */
1536 cio_disable_subchannel(sch);
1537 device_set_disconnected(cdev);
1538 /* Ask driver what to do with device. */
1539 action = UNREGISTER;
1540 spin_unlock_irqrestore(sch->lock, flags);
1541 ret = io_subchannel_notify(sch, event);
1542 spin_lock_irqsave(sch->lock, flags);
1546 case CIO_REVALIDATE:
1547 /* Device will be removed, so no notify necessary. */
1549 /* Reprobe because immediate unregister might block. */
1552 action = UNREGISTER_PROBE;
1556 /* Get device operational again. */
1560 /* Perform action. */
1564 case UNREGISTER_PROBE:
1565 /* Unregister device (will use subchannel lock). */
1566 spin_unlock_irqrestore(sch->lock, flags);
1567 css_sch_device_unregister(sch);
1568 spin_lock_irqsave(sch->lock, flags);
1570 /* Reset intparm to zeroes. */
1571 sch->schib.pmcw.intparm = 0;
1575 ccw_device_trigger_reprobe(cdev);
1580 spin_unlock_irqrestore(sch->lock, flags);
1581 /* Probe if necessary. */
1582 if (action == UNREGISTER_PROBE)
1583 ret = css_probe_device(sch->schid);
1588 #ifdef CONFIG_CCW_CONSOLE
1589 static struct ccw_device console_cdev;
1590 static struct ccw_device_private console_private;
1591 static int console_cdev_in_use;
1593 static DEFINE_SPINLOCK(ccw_console_lock);
1595 spinlock_t * cio_get_console_lock(void)
1597 return &ccw_console_lock;
1600 static int ccw_device_console_enable(struct ccw_device *cdev,
1601 struct subchannel *sch)
1605 /* Attach subchannel private data. */
1606 sch->private = cio_get_console_priv();
1607 memset(sch->private, 0, sizeof(struct io_subchannel_private));
1608 io_subchannel_init_fields(sch);
1609 sch->driver = &io_subchannel_driver;
1610 /* Initialize the ccw_device structure. */
1611 cdev->dev.parent= &sch->dev;
1612 rc = io_subchannel_recog(cdev, sch);
1616 /* Now wait for the async. recognition to come to an end. */
1617 spin_lock_irq(cdev->ccwlock);
1618 while (!dev_fsm_final_state(cdev))
1621 if (cdev->private->state != DEV_STATE_OFFLINE)
1623 ccw_device_online(cdev);
1624 while (!dev_fsm_final_state(cdev))
1626 if (cdev->private->state != DEV_STATE_ONLINE)
1630 spin_unlock_irq(cdev->ccwlock);
1635 ccw_device_probe_console(void)
1637 struct subchannel *sch;
1640 if (xchg(&console_cdev_in_use, 1) != 0)
1641 return ERR_PTR(-EBUSY);
1642 sch = cio_probe_console();
1644 console_cdev_in_use = 0;
1645 return (void *) sch;
1647 memset(&console_cdev, 0, sizeof(struct ccw_device));
1648 memset(&console_private, 0, sizeof(struct ccw_device_private));
1649 console_cdev.private = &console_private;
1650 console_private.cdev = &console_cdev;
1651 ret = ccw_device_console_enable(&console_cdev, sch);
1653 cio_release_console();
1654 console_cdev_in_use = 0;
1655 return ERR_PTR(ret);
1657 console_cdev.online = 1;
1658 return &console_cdev;
1663 * get ccw_device matching the busid, but only if owned by cdrv
1666 __ccwdev_check_busid(struct device *dev, void *id)
1672 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1677 * get_ccwdev_by_busid() - obtain device from a bus id
1678 * @cdrv: driver the device is owned by
1679 * @bus_id: bus id of the device to be searched
1681 * This function searches all devices owned by @cdrv for a device with a bus
1682 * id matching @bus_id.
1684 * If a match is found, its reference count of the found device is increased
1685 * and it is returned; else %NULL is returned.
1687 struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1691 struct device_driver *drv;
1693 drv = get_driver(&cdrv->driver);
1697 dev = driver_find_device(drv, NULL, (void *)bus_id,
1698 __ccwdev_check_busid);
1701 return dev ? to_ccwdev(dev) : NULL;
1704 /************************** device driver handling ************************/
1706 /* This is the implementation of the ccw_driver class. The probe, remove
1707 * and release methods are initially very similar to the device_driver
1708 * implementations, with the difference that they have ccw_device
1711 * A ccw driver also contains the information that is needed for
1715 ccw_device_probe (struct device *dev)
1717 struct ccw_device *cdev = to_ccwdev(dev);
1718 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1721 cdev->drv = cdrv; /* to let the driver call _set_online */
1723 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1734 ccw_device_remove (struct device *dev)
1736 struct ccw_device *cdev = to_ccwdev(dev);
1737 struct ccw_driver *cdrv = cdev->drv;
1744 spin_lock_irq(cdev->ccwlock);
1745 ret = ccw_device_offline(cdev);
1746 spin_unlock_irq(cdev->ccwlock);
1748 wait_event(cdev->private->wait_q,
1749 dev_fsm_final_state(cdev));
1751 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
1752 "device 0.%x.%04x\n",
1753 ret, cdev->private->dev_id.ssid,
1754 cdev->private->dev_id.devno);
1756 ccw_device_set_timeout(cdev, 0);
1761 static void ccw_device_shutdown(struct device *dev)
1763 struct ccw_device *cdev;
1765 cdev = to_ccwdev(dev);
1766 if (cdev->drv && cdev->drv->shutdown)
1767 cdev->drv->shutdown(cdev);
1771 struct bus_type ccw_bus_type = {
1773 .match = ccw_bus_match,
1774 .uevent = ccw_uevent,
1775 .probe = ccw_device_probe,
1776 .remove = ccw_device_remove,
1777 .shutdown = ccw_device_shutdown,
1781 * ccw_driver_register() - register a ccw driver
1782 * @cdriver: driver to be registered
1784 * This function is mainly a wrapper around driver_register().
1786 * %0 on success and a negative error value on failure.
1788 int ccw_driver_register(struct ccw_driver *cdriver)
1790 struct device_driver *drv = &cdriver->driver;
1792 drv->bus = &ccw_bus_type;
1793 drv->name = cdriver->name;
1794 drv->owner = cdriver->owner;
1796 return driver_register(drv);
1800 * ccw_driver_unregister() - deregister a ccw driver
1801 * @cdriver: driver to be deregistered
1803 * This function is mainly a wrapper around driver_unregister().
1805 void ccw_driver_unregister(struct ccw_driver *cdriver)
1807 driver_unregister(&cdriver->driver);
1810 /* Helper func for qdio. */
1811 struct subchannel_id
1812 ccw_device_get_subchannel_id(struct ccw_device *cdev)
1814 struct subchannel *sch;
1816 sch = to_subchannel(cdev->dev.parent);
1820 MODULE_LICENSE("GPL");
1821 EXPORT_SYMBOL(ccw_device_set_online);
1822 EXPORT_SYMBOL(ccw_device_set_offline);
1823 EXPORT_SYMBOL(ccw_driver_register);
1824 EXPORT_SYMBOL(ccw_driver_unregister);
1825 EXPORT_SYMBOL(get_ccwdev_by_busid);
1826 EXPORT_SYMBOL(ccw_bus_type);
1827 EXPORT_SYMBOL(ccw_device_work);
1828 EXPORT_SYMBOL(ccw_device_notify_work);
1829 EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);