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_device_id io_subchannel_ids[] = {
135 { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, },
136 { /* end of list */ },
138 MODULE_DEVICE_TABLE(css, io_subchannel_ids);
140 static struct css_driver io_subchannel_driver = {
141 .owner = THIS_MODULE,
142 .subchannel_type = io_subchannel_ids,
143 .name = "io_subchannel",
144 .irq = io_subchannel_irq,
145 .sch_event = io_subchannel_sch_event,
146 .chp_event = io_subchannel_chp_event,
147 .probe = io_subchannel_probe,
148 .remove = io_subchannel_remove,
149 .shutdown = io_subchannel_shutdown,
152 struct workqueue_struct *ccw_device_work;
153 struct workqueue_struct *ccw_device_notify_work;
154 wait_queue_head_t ccw_device_init_wq;
155 atomic_t ccw_device_init_count;
157 static void recovery_func(unsigned long data);
160 init_ccw_bus_type (void)
164 init_waitqueue_head(&ccw_device_init_wq);
165 atomic_set(&ccw_device_init_count, 0);
166 setup_timer(&recovery_timer, recovery_func, 0);
168 ccw_device_work = create_singlethread_workqueue("cio");
169 if (!ccw_device_work)
170 return -ENOMEM; /* FIXME: better errno ? */
171 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
172 if (!ccw_device_notify_work) {
173 ret = -ENOMEM; /* FIXME: better errno ? */
176 slow_path_wq = create_singlethread_workqueue("kslowcrw");
178 ret = -ENOMEM; /* FIXME: better errno ? */
181 if ((ret = bus_register (&ccw_bus_type)))
184 ret = css_driver_register(&io_subchannel_driver);
188 wait_event(ccw_device_init_wq,
189 atomic_read(&ccw_device_init_count) == 0);
190 flush_workqueue(ccw_device_work);
194 destroy_workqueue(ccw_device_work);
195 if (ccw_device_notify_work)
196 destroy_workqueue(ccw_device_notify_work);
198 destroy_workqueue(slow_path_wq);
203 cleanup_ccw_bus_type (void)
205 css_driver_unregister(&io_subchannel_driver);
206 bus_unregister(&ccw_bus_type);
207 destroy_workqueue(ccw_device_notify_work);
208 destroy_workqueue(ccw_device_work);
211 subsys_initcall(init_ccw_bus_type);
212 module_exit(cleanup_ccw_bus_type);
214 /************************ device handling **************************/
217 * A ccw_device has some interfaces in sysfs in addition to the
219 * The following entries are designed to export the information which
220 * resided in 2.4 in /proc/subchannels. Subchannel and device number
221 * are obvious, so they don't have an entry :)
222 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
225 chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
227 struct subchannel *sch = to_subchannel(dev);
228 struct chsc_ssd_info *ssd = &sch->ssd_info;
233 for (chp = 0; chp < 8; chp++) {
235 if (ssd->path_mask & mask)
236 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
238 ret += sprintf(buf + ret, "00 ");
240 ret += sprintf (buf+ret, "\n");
241 return min((ssize_t)PAGE_SIZE, ret);
245 pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
247 struct subchannel *sch = to_subchannel(dev);
248 struct pmcw *pmcw = &sch->schib.pmcw;
250 return sprintf (buf, "%02x %02x %02x\n",
251 pmcw->pim, pmcw->pam, pmcw->pom);
255 devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
257 struct ccw_device *cdev = to_ccwdev(dev);
258 struct ccw_device_id *id = &(cdev->id);
260 if (id->dev_type != 0)
261 return sprintf(buf, "%04x/%02x\n",
262 id->dev_type, id->dev_model);
264 return sprintf(buf, "n/a\n");
268 cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
270 struct ccw_device *cdev = to_ccwdev(dev);
271 struct ccw_device_id *id = &(cdev->id);
273 return sprintf(buf, "%04x/%02x\n",
274 id->cu_type, id->cu_model);
278 modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
280 struct ccw_device *cdev = to_ccwdev(dev);
281 struct ccw_device_id *id = &(cdev->id);
284 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
286 return len > PAGE_SIZE ? PAGE_SIZE : len;
290 online_show (struct device *dev, struct device_attribute *attr, char *buf)
292 struct ccw_device *cdev = to_ccwdev(dev);
294 return sprintf(buf, cdev->online ? "1\n" : "0\n");
297 int ccw_device_is_orphan(struct ccw_device *cdev)
299 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
302 static void ccw_device_unregister(struct ccw_device *cdev)
304 if (test_and_clear_bit(1, &cdev->private->registered))
305 device_del(&cdev->dev);
308 static void ccw_device_remove_orphan_cb(struct device *dev)
310 struct ccw_device *cdev = to_ccwdev(dev);
312 ccw_device_unregister(cdev);
313 put_device(&cdev->dev);
316 static void ccw_device_remove_sch_cb(struct device *dev)
318 struct subchannel *sch;
320 sch = to_subchannel(dev);
321 css_sch_device_unregister(sch);
322 /* Reset intparm to zeroes. */
323 sch->schib.pmcw.intparm = 0;
325 put_device(&sch->dev);
329 ccw_device_remove_disconnected(struct ccw_device *cdev)
335 * Forced offline in disconnected state means
336 * 'throw away device'.
338 if (ccw_device_is_orphan(cdev)) {
340 * Deregister ccw device.
341 * Unfortunately, we cannot do this directly from the
344 spin_lock_irqsave(cdev->ccwlock, flags);
345 cdev->private->state = DEV_STATE_NOT_OPER;
346 spin_unlock_irqrestore(cdev->ccwlock, flags);
347 rc = device_schedule_callback(&cdev->dev,
348 ccw_device_remove_orphan_cb);
350 CIO_MSG_EVENT(0, "Couldn't unregister orphan "
352 cdev->private->dev_id.ssid,
353 cdev->private->dev_id.devno);
356 /* Deregister subchannel, which will kill the ccw device. */
357 rc = device_schedule_callback(cdev->dev.parent,
358 ccw_device_remove_sch_cb);
360 CIO_MSG_EVENT(0, "Couldn't unregister disconnected device "
362 cdev->private->dev_id.ssid,
363 cdev->private->dev_id.devno);
367 * ccw_device_set_offline() - disable a ccw device for I/O
368 * @cdev: target ccw device
370 * This function calls the driver's set_offline() function for @cdev, if
371 * given, and then disables @cdev.
373 * %0 on success and a negative error value on failure.
375 * enabled, ccw device lock not held
377 int ccw_device_set_offline(struct ccw_device *cdev)
383 if (!cdev->online || !cdev->drv)
386 if (cdev->drv->set_offline) {
387 ret = cdev->drv->set_offline(cdev);
392 spin_lock_irq(cdev->ccwlock);
393 ret = ccw_device_offline(cdev);
394 if (ret == -ENODEV) {
395 if (cdev->private->state != DEV_STATE_NOT_OPER) {
396 cdev->private->state = DEV_STATE_OFFLINE;
397 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
399 spin_unlock_irq(cdev->ccwlock);
402 spin_unlock_irq(cdev->ccwlock);
404 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
406 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
407 "device 0.%x.%04x\n",
408 ret, cdev->private->dev_id.ssid,
409 cdev->private->dev_id.devno);
416 * ccw_device_set_online() - enable a ccw device for I/O
417 * @cdev: target ccw device
419 * This function first enables @cdev and then calls the driver's set_online()
420 * function for @cdev, if given. If set_online() returns an error, @cdev is
423 * %0 on success and a negative error value on failure.
425 * enabled, ccw device lock not held
427 int ccw_device_set_online(struct ccw_device *cdev)
433 if (cdev->online || !cdev->drv)
436 spin_lock_irq(cdev->ccwlock);
437 ret = ccw_device_online(cdev);
438 spin_unlock_irq(cdev->ccwlock);
440 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
442 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
443 "device 0.%x.%04x\n",
444 ret, cdev->private->dev_id.ssid,
445 cdev->private->dev_id.devno);
448 if (cdev->private->state != DEV_STATE_ONLINE)
450 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
454 spin_lock_irq(cdev->ccwlock);
455 ret = ccw_device_offline(cdev);
456 spin_unlock_irq(cdev->ccwlock);
458 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
460 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
461 "device 0.%x.%04x\n",
462 ret, cdev->private->dev_id.ssid,
463 cdev->private->dev_id.devno);
464 return (ret == 0) ? -ENODEV : ret;
467 static void online_store_handle_offline(struct ccw_device *cdev)
469 if (cdev->private->state == DEV_STATE_DISCONNECTED)
470 ccw_device_remove_disconnected(cdev);
471 else if (cdev->drv && cdev->drv->set_offline)
472 ccw_device_set_offline(cdev);
475 static int online_store_recog_and_online(struct ccw_device *cdev)
479 /* Do device recognition, if needed. */
480 if (cdev->id.cu_type == 0) {
481 ret = ccw_device_recognition(cdev);
483 CIO_MSG_EVENT(0, "Couldn't start recognition "
484 "for device 0.%x.%04x (ret=%d)\n",
485 cdev->private->dev_id.ssid,
486 cdev->private->dev_id.devno, ret);
489 wait_event(cdev->private->wait_q,
490 cdev->private->flags.recog_done);
492 if (cdev->drv && cdev->drv->set_online)
493 ccw_device_set_online(cdev);
496 static int online_store_handle_online(struct ccw_device *cdev, int force)
500 ret = online_store_recog_and_online(cdev);
503 if (force && cdev->private->state == DEV_STATE_BOXED) {
504 ret = ccw_device_stlck(cdev);
507 if (cdev->id.cu_type == 0)
508 cdev->private->state = DEV_STATE_NOT_OPER;
509 online_store_recog_and_online(cdev);
514 static ssize_t online_store (struct device *dev, struct device_attribute *attr,
515 const char *buf, size_t count)
517 struct ccw_device *cdev = to_ccwdev(dev);
521 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
524 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
525 atomic_set(&cdev->private->onoff, 0);
528 if (!strncmp(buf, "force\n", count)) {
534 ret = strict_strtoul(buf, 16, &i);
540 online_store_handle_offline(cdev);
544 ret = online_store_handle_online(cdev, force);
553 module_put(cdev->drv->owner);
554 atomic_set(&cdev->private->onoff, 0);
559 available_show (struct device *dev, struct device_attribute *attr, char *buf)
561 struct ccw_device *cdev = to_ccwdev(dev);
562 struct subchannel *sch;
564 if (ccw_device_is_orphan(cdev))
565 return sprintf(buf, "no device\n");
566 switch (cdev->private->state) {
567 case DEV_STATE_BOXED:
568 return sprintf(buf, "boxed\n");
569 case DEV_STATE_DISCONNECTED:
570 case DEV_STATE_DISCONNECTED_SENSE_ID:
571 case DEV_STATE_NOT_OPER:
572 sch = to_subchannel(dev->parent);
574 return sprintf(buf, "no path\n");
576 return sprintf(buf, "no device\n");
578 /* All other states considered fine. */
579 return sprintf(buf, "good\n");
583 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
584 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
585 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
586 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
587 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
588 static DEVICE_ATTR(online, 0644, online_show, online_store);
589 static DEVICE_ATTR(availability, 0444, available_show, NULL);
591 static struct attribute *io_subchannel_attrs[] = {
592 &dev_attr_chpids.attr,
593 &dev_attr_pimpampom.attr,
597 static struct attribute_group io_subchannel_attr_group = {
598 .attrs = io_subchannel_attrs,
601 static struct attribute * ccwdev_attrs[] = {
602 &dev_attr_devtype.attr,
603 &dev_attr_cutype.attr,
604 &dev_attr_modalias.attr,
605 &dev_attr_online.attr,
606 &dev_attr_cmb_enable.attr,
607 &dev_attr_availability.attr,
611 static struct attribute_group ccwdev_attr_group = {
612 .attrs = ccwdev_attrs,
615 static struct attribute_group *ccwdev_attr_groups[] = {
620 /* this is a simple abstraction for device_register that sets the
621 * correct bus type and adds the bus specific files */
622 static int ccw_device_register(struct ccw_device *cdev)
624 struct device *dev = &cdev->dev;
627 dev->bus = &ccw_bus_type;
629 if ((ret = device_add(dev)))
632 set_bit(1, &cdev->private->registered);
637 struct ccw_dev_id dev_id;
638 struct ccw_device * sibling;
642 match_devno(struct device * dev, void * data)
644 struct match_data * d = data;
645 struct ccw_device * cdev;
647 cdev = to_ccwdev(dev);
648 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
649 !ccw_device_is_orphan(cdev) &&
650 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
651 (cdev != d->sibling))
656 static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
657 struct ccw_device *sibling)
660 struct match_data data;
662 data.dev_id = *dev_id;
663 data.sibling = sibling;
664 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
666 return dev ? to_ccwdev(dev) : NULL;
669 static int match_orphan(struct device *dev, void *data)
671 struct ccw_dev_id *dev_id;
672 struct ccw_device *cdev;
675 cdev = to_ccwdev(dev);
676 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
679 static struct ccw_device *
680 get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
681 struct ccw_dev_id *dev_id)
685 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
688 return dev ? to_ccwdev(dev) : NULL;
692 ccw_device_add_changed(struct work_struct *work)
694 struct ccw_device_private *priv;
695 struct ccw_device *cdev;
697 priv = container_of(work, struct ccw_device_private, kick_work);
699 if (device_add(&cdev->dev)) {
700 put_device(&cdev->dev);
703 set_bit(1, &cdev->private->registered);
706 void ccw_device_do_unreg_rereg(struct work_struct *work)
708 struct ccw_device_private *priv;
709 struct ccw_device *cdev;
710 struct subchannel *sch;
712 priv = container_of(work, struct ccw_device_private, kick_work);
714 sch = to_subchannel(cdev->dev.parent);
716 ccw_device_unregister(cdev);
717 PREPARE_WORK(&cdev->private->kick_work,
718 ccw_device_add_changed);
719 queue_work(ccw_device_work, &cdev->private->kick_work);
723 ccw_device_release(struct device *dev)
725 struct ccw_device *cdev;
727 cdev = to_ccwdev(dev);
728 kfree(cdev->private);
732 static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
734 struct ccw_device *cdev;
736 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
738 cdev->private = kzalloc(sizeof(struct ccw_device_private),
739 GFP_KERNEL | GFP_DMA);
744 return ERR_PTR(-ENOMEM);
747 static int io_subchannel_initialize_dev(struct subchannel *sch,
748 struct ccw_device *cdev)
750 cdev->private->cdev = cdev;
751 atomic_set(&cdev->private->onoff, 0);
752 cdev->dev.parent = &sch->dev;
753 cdev->dev.release = ccw_device_release;
754 INIT_WORK(&cdev->private->kick_work, NULL);
755 cdev->dev.groups = ccwdev_attr_groups;
756 /* Do first half of device_register. */
757 device_initialize(&cdev->dev);
758 if (!get_device(&sch->dev)) {
759 if (cdev->dev.release)
760 cdev->dev.release(&cdev->dev);
766 static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
768 struct ccw_device *cdev;
771 cdev = io_subchannel_allocate_dev(sch);
773 ret = io_subchannel_initialize_dev(sch, cdev);
782 static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
784 static void sch_attach_device(struct subchannel *sch,
785 struct ccw_device *cdev)
787 css_update_ssd_info(sch);
788 spin_lock_irq(sch->lock);
789 sch_set_cdev(sch, cdev);
790 cdev->private->schid = sch->schid;
791 cdev->ccwlock = sch->lock;
792 ccw_device_trigger_reprobe(cdev);
793 spin_unlock_irq(sch->lock);
796 static void sch_attach_disconnected_device(struct subchannel *sch,
797 struct ccw_device *cdev)
799 struct subchannel *other_sch;
802 other_sch = to_subchannel(get_device(cdev->dev.parent));
803 ret = device_move(&cdev->dev, &sch->dev);
805 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
806 "(ret=%d)!\n", cdev->private->dev_id.ssid,
807 cdev->private->dev_id.devno, ret);
808 put_device(&other_sch->dev);
811 sch_set_cdev(other_sch, NULL);
812 /* No need to keep a subchannel without ccw device around. */
813 css_sch_device_unregister(other_sch);
814 put_device(&other_sch->dev);
815 sch_attach_device(sch, cdev);
818 static void sch_attach_orphaned_device(struct subchannel *sch,
819 struct ccw_device *cdev)
823 /* Try to move the ccw device to its new subchannel. */
824 ret = device_move(&cdev->dev, &sch->dev);
826 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
827 "failed (ret=%d)!\n",
828 cdev->private->dev_id.ssid,
829 cdev->private->dev_id.devno, ret);
832 sch_attach_device(sch, cdev);
835 static void sch_create_and_recog_new_device(struct subchannel *sch)
837 struct ccw_device *cdev;
839 /* Need to allocate a new ccw device. */
840 cdev = io_subchannel_create_ccwdev(sch);
842 /* OK, we did everything we could... */
843 css_sch_device_unregister(sch);
846 spin_lock_irq(sch->lock);
847 sch_set_cdev(sch, cdev);
848 spin_unlock_irq(sch->lock);
849 /* Start recognition for the new ccw device. */
850 if (io_subchannel_recog(cdev, sch)) {
851 spin_lock_irq(sch->lock);
852 sch_set_cdev(sch, NULL);
853 spin_unlock_irq(sch->lock);
854 if (cdev->dev.release)
855 cdev->dev.release(&cdev->dev);
856 css_sch_device_unregister(sch);
861 void ccw_device_move_to_orphanage(struct work_struct *work)
863 struct ccw_device_private *priv;
864 struct ccw_device *cdev;
865 struct ccw_device *replacing_cdev;
866 struct subchannel *sch;
868 struct channel_subsystem *css;
869 struct ccw_dev_id dev_id;
871 priv = container_of(work, struct ccw_device_private, kick_work);
873 sch = to_subchannel(cdev->dev.parent);
874 css = to_css(sch->dev.parent);
875 dev_id.devno = sch->schib.pmcw.dev;
876 dev_id.ssid = sch->schid.ssid;
879 * Move the orphaned ccw device to the orphanage so the replacing
880 * ccw device can take its place on the subchannel.
882 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
884 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
885 "(ret=%d)!\n", cdev->private->dev_id.ssid,
886 cdev->private->dev_id.devno, ret);
889 cdev->ccwlock = css->pseudo_subchannel->lock;
891 * Search for the replacing ccw device
892 * - among the disconnected devices
895 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
896 if (replacing_cdev) {
897 sch_attach_disconnected_device(sch, replacing_cdev);
900 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
901 if (replacing_cdev) {
902 sch_attach_orphaned_device(sch, replacing_cdev);
905 sch_create_and_recog_new_device(sch);
909 * Register recognized device.
912 io_subchannel_register(struct work_struct *work)
914 struct ccw_device_private *priv;
915 struct ccw_device *cdev;
916 struct subchannel *sch;
920 priv = container_of(work, struct ccw_device_private, kick_work);
922 sch = to_subchannel(cdev->dev.parent);
923 css_update_ssd_info(sch);
925 * io_subchannel_register() will also be called after device
926 * recognition has been done for a boxed device (which will already
927 * be registered). We need to reprobe since we may now have sense id
930 if (klist_node_attached(&cdev->dev.knode_parent)) {
932 ret = device_reprobe(&cdev->dev);
934 /* We can't do much here. */
935 CIO_MSG_EVENT(0, "device_reprobe() returned"
936 " %d for 0.%x.%04x\n", ret,
937 cdev->private->dev_id.ssid,
938 cdev->private->dev_id.devno);
943 * Now we know this subchannel will stay, we can throw
944 * our delayed uevent.
946 sch->dev.uevent_suppress = 0;
947 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
948 /* make it known to the system */
949 ret = ccw_device_register(cdev);
951 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
952 cdev->private->dev_id.ssid,
953 cdev->private->dev_id.devno, ret);
954 put_device(&cdev->dev);
955 spin_lock_irqsave(sch->lock, flags);
956 sch_set_cdev(sch, NULL);
957 spin_unlock_irqrestore(sch->lock, flags);
958 kfree (cdev->private);
960 put_device(&sch->dev);
961 if (atomic_dec_and_test(&ccw_device_init_count))
962 wake_up(&ccw_device_init_wq);
965 put_device(&cdev->dev);
967 cdev->private->flags.recog_done = 1;
968 put_device(&sch->dev);
969 wake_up(&cdev->private->wait_q);
970 if (atomic_dec_and_test(&ccw_device_init_count))
971 wake_up(&ccw_device_init_wq);
974 static void ccw_device_call_sch_unregister(struct work_struct *work)
976 struct ccw_device_private *priv;
977 struct ccw_device *cdev;
978 struct subchannel *sch;
980 priv = container_of(work, struct ccw_device_private, kick_work);
982 sch = to_subchannel(cdev->dev.parent);
983 css_sch_device_unregister(sch);
984 /* Reset intparm to zeroes. */
985 sch->schib.pmcw.intparm = 0;
987 put_device(&cdev->dev);
988 put_device(&sch->dev);
992 * subchannel recognition done. Called from the state machine.
995 io_subchannel_recog_done(struct ccw_device *cdev)
997 struct subchannel *sch;
999 if (css_init_done == 0) {
1000 cdev->private->flags.recog_done = 1;
1003 switch (cdev->private->state) {
1004 case DEV_STATE_NOT_OPER:
1005 cdev->private->flags.recog_done = 1;
1006 /* Remove device found not operational. */
1007 if (!get_device(&cdev->dev))
1009 sch = to_subchannel(cdev->dev.parent);
1010 PREPARE_WORK(&cdev->private->kick_work,
1011 ccw_device_call_sch_unregister);
1012 queue_work(slow_path_wq, &cdev->private->kick_work);
1013 if (atomic_dec_and_test(&ccw_device_init_count))
1014 wake_up(&ccw_device_init_wq);
1016 case DEV_STATE_BOXED:
1017 /* Device did not respond in time. */
1018 case DEV_STATE_OFFLINE:
1020 * We can't register the device in interrupt context so
1021 * we schedule a work item.
1023 if (!get_device(&cdev->dev))
1025 PREPARE_WORK(&cdev->private->kick_work,
1026 io_subchannel_register);
1027 queue_work(slow_path_wq, &cdev->private->kick_work);
1033 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
1036 struct ccw_device_private *priv;
1038 sch_set_cdev(sch, cdev);
1039 cdev->ccwlock = sch->lock;
1041 /* Init private data. */
1042 priv = cdev->private;
1043 priv->dev_id.devno = sch->schib.pmcw.dev;
1044 priv->dev_id.ssid = sch->schid.ssid;
1045 priv->schid = sch->schid;
1046 priv->state = DEV_STATE_NOT_OPER;
1047 INIT_LIST_HEAD(&priv->cmb_list);
1048 init_waitqueue_head(&priv->wait_q);
1049 init_timer(&priv->timer);
1051 /* Set an initial name for the device. */
1052 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
1053 sch->schid.ssid, sch->schib.pmcw.dev);
1055 /* Increase counter of devices currently in recognition. */
1056 atomic_inc(&ccw_device_init_count);
1058 /* Start async. device sensing. */
1059 spin_lock_irq(sch->lock);
1060 rc = ccw_device_recognition(cdev);
1061 spin_unlock_irq(sch->lock);
1063 if (atomic_dec_and_test(&ccw_device_init_count))
1064 wake_up(&ccw_device_init_wq);
1069 static void ccw_device_move_to_sch(struct work_struct *work)
1071 struct ccw_device_private *priv;
1073 struct subchannel *sch;
1074 struct ccw_device *cdev;
1075 struct subchannel *former_parent;
1077 priv = container_of(work, struct ccw_device_private, kick_work);
1080 former_parent = ccw_device_is_orphan(cdev) ?
1081 NULL : to_subchannel(get_device(cdev->dev.parent));
1082 mutex_lock(&sch->reg_mutex);
1083 /* Try to move the ccw device to its new subchannel. */
1084 rc = device_move(&cdev->dev, &sch->dev);
1085 mutex_unlock(&sch->reg_mutex);
1087 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
1088 "0.%x.%04x failed (ret=%d)!\n",
1089 cdev->private->dev_id.ssid,
1090 cdev->private->dev_id.devno, sch->schid.ssid,
1091 sch->schid.sch_no, rc);
1092 css_sch_device_unregister(sch);
1095 if (former_parent) {
1096 spin_lock_irq(former_parent->lock);
1097 sch_set_cdev(former_parent, NULL);
1098 spin_unlock_irq(former_parent->lock);
1099 css_sch_device_unregister(former_parent);
1100 /* Reset intparm to zeroes. */
1101 former_parent->schib.pmcw.intparm = 0;
1102 cio_modify(former_parent);
1104 sch_attach_device(sch, cdev);
1107 put_device(&former_parent->dev);
1108 put_device(&cdev->dev);
1111 static void io_subchannel_irq(struct subchannel *sch)
1113 struct ccw_device *cdev;
1115 cdev = sch_get_cdev(sch);
1117 CIO_TRACE_EVENT(3, "IRQ");
1118 CIO_TRACE_EVENT(3, sch->dev.bus_id);
1120 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1123 static void io_subchannel_init_fields(struct subchannel *sch)
1125 if (cio_is_console(sch->schid))
1128 sch->opm = chp_get_sch_opm(sch);
1129 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1130 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
1132 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1133 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1134 sch->schib.pmcw.dev, sch->schid.ssid,
1135 sch->schid.sch_no, sch->schib.pmcw.pim,
1136 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
1137 /* Initially set up some fields in the pmcw. */
1138 sch->schib.pmcw.ena = 0;
1139 sch->schib.pmcw.csense = 1; /* concurrent sense */
1140 if ((sch->lpm & (sch->lpm - 1)) != 0)
1141 sch->schib.pmcw.mp = 1; /* multipath mode */
1142 /* clean up possible residual cmf stuff */
1143 sch->schib.pmcw.mme = 0;
1144 sch->schib.pmcw.mbfc = 0;
1145 sch->schib.pmcw.mbi = 0;
1149 static int io_subchannel_probe(struct subchannel *sch)
1151 struct ccw_device *cdev;
1153 unsigned long flags;
1154 struct ccw_dev_id dev_id;
1156 cdev = sch_get_cdev(sch);
1158 rc = sysfs_create_group(&sch->dev.kobj,
1159 &io_subchannel_attr_group);
1161 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1162 "attributes for subchannel "
1163 "0.%x.%04x (rc=%d)\n",
1164 sch->schid.ssid, sch->schid.sch_no, rc);
1166 * This subchannel already has an associated ccw_device.
1167 * Throw the delayed uevent for the subchannel, register
1168 * the ccw_device and exit. This happens for all early
1169 * devices, e.g. the console.
1171 sch->dev.uevent_suppress = 0;
1172 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
1173 cdev->dev.groups = ccwdev_attr_groups;
1174 device_initialize(&cdev->dev);
1175 ccw_device_register(cdev);
1177 * Check if the device is already online. If it is
1178 * the reference count needs to be corrected
1179 * (see ccw_device_online and css_init_done for the
1182 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1183 cdev->private->state != DEV_STATE_OFFLINE &&
1184 cdev->private->state != DEV_STATE_BOXED)
1185 get_device(&cdev->dev);
1188 io_subchannel_init_fields(sch);
1190 * First check if a fitting device may be found amongst the
1191 * disconnected devices or in the orphanage.
1193 dev_id.devno = sch->schib.pmcw.dev;
1194 dev_id.ssid = sch->schid.ssid;
1195 rc = sysfs_create_group(&sch->dev.kobj,
1196 &io_subchannel_attr_group);
1199 /* Allocate I/O subchannel private data. */
1200 sch->private = kzalloc(sizeof(struct io_subchannel_private),
1201 GFP_KERNEL | GFP_DMA);
1202 if (!sch->private) {
1206 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
1208 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
1212 * Schedule moving the device until when we have a registered
1213 * subchannel to move to and succeed the probe. We can
1214 * unregister later again, when the probe is through.
1216 cdev->private->sch = sch;
1217 PREPARE_WORK(&cdev->private->kick_work,
1218 ccw_device_move_to_sch);
1219 queue_work(slow_path_wq, &cdev->private->kick_work);
1222 cdev = io_subchannel_create_ccwdev(sch);
1227 rc = io_subchannel_recog(cdev, sch);
1229 spin_lock_irqsave(sch->lock, flags);
1230 sch_set_cdev(sch, NULL);
1231 spin_unlock_irqrestore(sch->lock, flags);
1232 if (cdev->dev.release)
1233 cdev->dev.release(&cdev->dev);
1238 kfree(sch->private);
1239 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1244 io_subchannel_remove (struct subchannel *sch)
1246 struct ccw_device *cdev;
1247 unsigned long flags;
1249 cdev = sch_get_cdev(sch);
1252 /* Set ccw device to not operational and drop reference. */
1253 spin_lock_irqsave(cdev->ccwlock, flags);
1254 sch_set_cdev(sch, NULL);
1255 cdev->private->state = DEV_STATE_NOT_OPER;
1256 spin_unlock_irqrestore(cdev->ccwlock, flags);
1257 ccw_device_unregister(cdev);
1258 put_device(&cdev->dev);
1259 kfree(sch->private);
1260 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1264 static int io_subchannel_notify(struct subchannel *sch, int event)
1266 struct ccw_device *cdev;
1268 cdev = sch_get_cdev(sch);
1271 return ccw_device_notify(cdev, event);
1274 static void io_subchannel_verify(struct subchannel *sch)
1276 struct ccw_device *cdev;
1278 cdev = sch_get_cdev(sch);
1280 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1283 static int check_for_io_on_path(struct subchannel *sch, int mask)
1287 cc = stsch(sch->schid, &sch->schib);
1290 if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
1295 static void terminate_internal_io(struct subchannel *sch,
1296 struct ccw_device *cdev)
1298 if (cio_clear(sch)) {
1299 /* Recheck device in case clear failed. */
1302 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1304 css_schedule_eval(sch->schid);
1307 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
1308 /* Request retry of internal operation. */
1309 cdev->private->flags.intretry = 1;
1312 cdev->handler(cdev, cdev->private->intparm,
1316 static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
1318 struct ccw_device *cdev;
1320 cdev = sch_get_cdev(sch);
1323 if (check_for_io_on_path(sch, mask)) {
1324 if (cdev->private->state == DEV_STATE_ONLINE)
1325 ccw_device_kill_io(cdev);
1327 terminate_internal_io(sch, cdev);
1328 /* Re-start path verification. */
1329 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1332 /* trigger path verification. */
1333 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1337 static int io_subchannel_chp_event(struct subchannel *sch,
1338 struct chp_link *link, int event)
1342 mask = chp_ssd_get_mask(&sch->ssd_info, link);
1349 io_subchannel_terminate_path(sch, mask);
1354 io_subchannel_verify(sch);
1357 if (stsch(sch->schid, &sch->schib))
1359 if (!css_sch_is_valid(&sch->schib))
1361 io_subchannel_terminate_path(sch, mask);
1364 if (stsch(sch->schid, &sch->schib))
1366 sch->lpm |= mask & sch->opm;
1367 io_subchannel_verify(sch);
1374 io_subchannel_shutdown(struct subchannel *sch)
1376 struct ccw_device *cdev;
1379 cdev = sch_get_cdev(sch);
1381 if (cio_is_console(sch->schid))
1383 if (!sch->schib.pmcw.ena)
1384 /* Nothing to do. */
1386 ret = cio_disable_subchannel(sch);
1388 /* Subchannel is disabled, we're done. */
1390 cdev->private->state = DEV_STATE_QUIESCE;
1392 cdev->handler(cdev, cdev->private->intparm,
1394 ret = ccw_device_cancel_halt_clear(cdev);
1395 if (ret == -EBUSY) {
1396 ccw_device_set_timeout(cdev, HZ/10);
1397 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1399 cio_disable_subchannel(sch);
1402 static int io_subchannel_get_status(struct subchannel *sch)
1406 if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
1408 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
1409 return CIO_REVALIDATE;
1415 static int device_is_disconnected(struct ccw_device *cdev)
1419 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1420 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1423 static int recovery_check(struct device *dev, void *data)
1425 struct ccw_device *cdev = to_ccwdev(dev);
1428 spin_lock_irq(cdev->ccwlock);
1429 switch (cdev->private->state) {
1430 case DEV_STATE_DISCONNECTED:
1431 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1432 cdev->private->dev_id.ssid,
1433 cdev->private->dev_id.devno);
1434 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1437 case DEV_STATE_DISCONNECTED_SENSE_ID:
1441 spin_unlock_irq(cdev->ccwlock);
1446 static void recovery_work_func(struct work_struct *unused)
1450 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1452 spin_lock_irq(&recovery_lock);
1453 if (!timer_pending(&recovery_timer)) {
1454 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1456 mod_timer(&recovery_timer, jiffies +
1457 recovery_delay[recovery_phase] * HZ);
1459 spin_unlock_irq(&recovery_lock);
1461 CIO_MSG_EVENT(4, "recovery: end\n");
1464 static DECLARE_WORK(recovery_work, recovery_work_func);
1466 static void recovery_func(unsigned long data)
1469 * We can't do our recovery in softirq context and it's not
1470 * performance critical, so we schedule it.
1472 schedule_work(&recovery_work);
1475 static void ccw_device_schedule_recovery(void)
1477 unsigned long flags;
1479 CIO_MSG_EVENT(4, "recovery: schedule\n");
1480 spin_lock_irqsave(&recovery_lock, flags);
1481 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1483 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1485 spin_unlock_irqrestore(&recovery_lock, flags);
1488 static void device_set_disconnected(struct ccw_device *cdev)
1492 ccw_device_set_timeout(cdev, 0);
1493 cdev->private->flags.fake_irb = 0;
1494 cdev->private->state = DEV_STATE_DISCONNECTED;
1496 ccw_device_schedule_recovery();
1499 static int io_subchannel_sch_event(struct subchannel *sch, int slow)
1501 int event, ret, disc;
1502 unsigned long flags;
1503 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
1504 struct ccw_device *cdev;
1506 spin_lock_irqsave(sch->lock, flags);
1507 cdev = sch_get_cdev(sch);
1508 disc = device_is_disconnected(cdev);
1510 /* Disconnected devices are evaluated directly only.*/
1511 spin_unlock_irqrestore(sch->lock, flags);
1514 /* No interrupt after machine check - kill pending timers. */
1516 ccw_device_set_timeout(cdev, 0);
1517 if (!disc && !slow) {
1518 /* Non-disconnected devices are evaluated on the slow path. */
1519 spin_unlock_irqrestore(sch->lock, flags);
1522 event = io_subchannel_get_status(sch);
1523 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
1524 sch->schid.ssid, sch->schid.sch_no, event,
1525 disc ? "disconnected" : "normal",
1526 slow ? "slow" : "fast");
1527 /* Analyze subchannel status. */
1532 /* Check if paths have become available. */
1538 /* Prevent unwanted effects when opening lock. */
1539 cio_disable_subchannel(sch);
1540 device_set_disconnected(cdev);
1541 /* Ask driver what to do with device. */
1542 action = UNREGISTER;
1543 spin_unlock_irqrestore(sch->lock, flags);
1544 ret = io_subchannel_notify(sch, event);
1545 spin_lock_irqsave(sch->lock, flags);
1549 case CIO_REVALIDATE:
1550 /* Device will be removed, so no notify necessary. */
1552 /* Reprobe because immediate unregister might block. */
1555 action = UNREGISTER_PROBE;
1559 /* Get device operational again. */
1563 /* Perform action. */
1567 case UNREGISTER_PROBE:
1568 /* Unregister device (will use subchannel lock). */
1569 spin_unlock_irqrestore(sch->lock, flags);
1570 css_sch_device_unregister(sch);
1571 spin_lock_irqsave(sch->lock, flags);
1573 /* Reset intparm to zeroes. */
1574 sch->schib.pmcw.intparm = 0;
1578 ccw_device_trigger_reprobe(cdev);
1583 spin_unlock_irqrestore(sch->lock, flags);
1584 /* Probe if necessary. */
1585 if (action == UNREGISTER_PROBE)
1586 ret = css_probe_device(sch->schid);
1591 #ifdef CONFIG_CCW_CONSOLE
1592 static struct ccw_device console_cdev;
1593 static struct ccw_device_private console_private;
1594 static int console_cdev_in_use;
1596 static DEFINE_SPINLOCK(ccw_console_lock);
1598 spinlock_t * cio_get_console_lock(void)
1600 return &ccw_console_lock;
1603 static int ccw_device_console_enable(struct ccw_device *cdev,
1604 struct subchannel *sch)
1608 /* Attach subchannel private data. */
1609 sch->private = cio_get_console_priv();
1610 memset(sch->private, 0, sizeof(struct io_subchannel_private));
1611 io_subchannel_init_fields(sch);
1612 sch->driver = &io_subchannel_driver;
1613 /* Initialize the ccw_device structure. */
1614 cdev->dev.parent= &sch->dev;
1615 rc = io_subchannel_recog(cdev, sch);
1619 /* Now wait for the async. recognition to come to an end. */
1620 spin_lock_irq(cdev->ccwlock);
1621 while (!dev_fsm_final_state(cdev))
1624 if (cdev->private->state != DEV_STATE_OFFLINE)
1626 ccw_device_online(cdev);
1627 while (!dev_fsm_final_state(cdev))
1629 if (cdev->private->state != DEV_STATE_ONLINE)
1633 spin_unlock_irq(cdev->ccwlock);
1638 ccw_device_probe_console(void)
1640 struct subchannel *sch;
1643 if (xchg(&console_cdev_in_use, 1) != 0)
1644 return ERR_PTR(-EBUSY);
1645 sch = cio_probe_console();
1647 console_cdev_in_use = 0;
1648 return (void *) sch;
1650 memset(&console_cdev, 0, sizeof(struct ccw_device));
1651 memset(&console_private, 0, sizeof(struct ccw_device_private));
1652 console_cdev.private = &console_private;
1653 console_private.cdev = &console_cdev;
1654 ret = ccw_device_console_enable(&console_cdev, sch);
1656 cio_release_console();
1657 console_cdev_in_use = 0;
1658 return ERR_PTR(ret);
1660 console_cdev.online = 1;
1661 return &console_cdev;
1666 * get ccw_device matching the busid, but only if owned by cdrv
1669 __ccwdev_check_busid(struct device *dev, void *id)
1675 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1680 * get_ccwdev_by_busid() - obtain device from a bus id
1681 * @cdrv: driver the device is owned by
1682 * @bus_id: bus id of the device to be searched
1684 * This function searches all devices owned by @cdrv for a device with a bus
1685 * id matching @bus_id.
1687 * If a match is found, its reference count of the found device is increased
1688 * and it is returned; else %NULL is returned.
1690 struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1694 struct device_driver *drv;
1696 drv = get_driver(&cdrv->driver);
1700 dev = driver_find_device(drv, NULL, (void *)bus_id,
1701 __ccwdev_check_busid);
1704 return dev ? to_ccwdev(dev) : NULL;
1707 /************************** device driver handling ************************/
1709 /* This is the implementation of the ccw_driver class. The probe, remove
1710 * and release methods are initially very similar to the device_driver
1711 * implementations, with the difference that they have ccw_device
1714 * A ccw driver also contains the information that is needed for
1718 ccw_device_probe (struct device *dev)
1720 struct ccw_device *cdev = to_ccwdev(dev);
1721 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1724 cdev->drv = cdrv; /* to let the driver call _set_online */
1726 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1737 ccw_device_remove (struct device *dev)
1739 struct ccw_device *cdev = to_ccwdev(dev);
1740 struct ccw_driver *cdrv = cdev->drv;
1747 spin_lock_irq(cdev->ccwlock);
1748 ret = ccw_device_offline(cdev);
1749 spin_unlock_irq(cdev->ccwlock);
1751 wait_event(cdev->private->wait_q,
1752 dev_fsm_final_state(cdev));
1754 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
1755 "device 0.%x.%04x\n",
1756 ret, cdev->private->dev_id.ssid,
1757 cdev->private->dev_id.devno);
1759 ccw_device_set_timeout(cdev, 0);
1764 static void ccw_device_shutdown(struct device *dev)
1766 struct ccw_device *cdev;
1768 cdev = to_ccwdev(dev);
1769 if (cdev->drv && cdev->drv->shutdown)
1770 cdev->drv->shutdown(cdev);
1774 struct bus_type ccw_bus_type = {
1776 .match = ccw_bus_match,
1777 .uevent = ccw_uevent,
1778 .probe = ccw_device_probe,
1779 .remove = ccw_device_remove,
1780 .shutdown = ccw_device_shutdown,
1784 * ccw_driver_register() - register a ccw driver
1785 * @cdriver: driver to be registered
1787 * This function is mainly a wrapper around driver_register().
1789 * %0 on success and a negative error value on failure.
1791 int ccw_driver_register(struct ccw_driver *cdriver)
1793 struct device_driver *drv = &cdriver->driver;
1795 drv->bus = &ccw_bus_type;
1796 drv->name = cdriver->name;
1797 drv->owner = cdriver->owner;
1799 return driver_register(drv);
1803 * ccw_driver_unregister() - deregister a ccw driver
1804 * @cdriver: driver to be deregistered
1806 * This function is mainly a wrapper around driver_unregister().
1808 void ccw_driver_unregister(struct ccw_driver *cdriver)
1810 driver_unregister(&cdriver->driver);
1813 /* Helper func for qdio. */
1814 struct subchannel_id
1815 ccw_device_get_subchannel_id(struct ccw_device *cdev)
1817 struct subchannel *sch;
1819 sch = to_subchannel(cdev->dev.parent);
1823 MODULE_LICENSE("GPL");
1824 EXPORT_SYMBOL(ccw_device_set_online);
1825 EXPORT_SYMBOL(ccw_device_set_offline);
1826 EXPORT_SYMBOL(ccw_driver_register);
1827 EXPORT_SYMBOL(ccw_driver_unregister);
1828 EXPORT_SYMBOL(get_ccwdev_by_busid);
1829 EXPORT_SYMBOL(ccw_bus_type);
1830 EXPORT_SYMBOL(ccw_device_work);
1831 EXPORT_SYMBOL(ccw_device_notify_work);
1832 EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);