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 wait_queue_head_t ccw_device_init_wq;
154 atomic_t ccw_device_init_count;
156 static void recovery_func(unsigned long data);
159 init_ccw_bus_type (void)
163 init_waitqueue_head(&ccw_device_init_wq);
164 atomic_set(&ccw_device_init_count, 0);
165 setup_timer(&recovery_timer, recovery_func, 0);
167 ccw_device_work = create_singlethread_workqueue("cio");
168 if (!ccw_device_work)
169 return -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);
190 destroy_workqueue(slow_path_wq);
195 cleanup_ccw_bus_type (void)
197 css_driver_unregister(&io_subchannel_driver);
198 bus_unregister(&ccw_bus_type);
199 destroy_workqueue(ccw_device_work);
202 subsys_initcall(init_ccw_bus_type);
203 module_exit(cleanup_ccw_bus_type);
205 /************************ device handling **************************/
208 * A ccw_device has some interfaces in sysfs in addition to the
210 * The following entries are designed to export the information which
211 * resided in 2.4 in /proc/subchannels. Subchannel and device number
212 * are obvious, so they don't have an entry :)
213 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
216 chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
218 struct subchannel *sch = to_subchannel(dev);
219 struct chsc_ssd_info *ssd = &sch->ssd_info;
224 for (chp = 0; chp < 8; chp++) {
226 if (ssd->path_mask & mask)
227 ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
229 ret += sprintf(buf + ret, "00 ");
231 ret += sprintf (buf+ret, "\n");
232 return min((ssize_t)PAGE_SIZE, ret);
236 pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
238 struct subchannel *sch = to_subchannel(dev);
239 struct pmcw *pmcw = &sch->schib.pmcw;
241 return sprintf (buf, "%02x %02x %02x\n",
242 pmcw->pim, pmcw->pam, pmcw->pom);
246 devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
248 struct ccw_device *cdev = to_ccwdev(dev);
249 struct ccw_device_id *id = &(cdev->id);
251 if (id->dev_type != 0)
252 return sprintf(buf, "%04x/%02x\n",
253 id->dev_type, id->dev_model);
255 return sprintf(buf, "n/a\n");
259 cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
261 struct ccw_device *cdev = to_ccwdev(dev);
262 struct ccw_device_id *id = &(cdev->id);
264 return sprintf(buf, "%04x/%02x\n",
265 id->cu_type, id->cu_model);
269 modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
271 struct ccw_device *cdev = to_ccwdev(dev);
272 struct ccw_device_id *id = &(cdev->id);
275 len = snprint_alias(buf, PAGE_SIZE, id, "\n");
277 return len > PAGE_SIZE ? PAGE_SIZE : len;
281 online_show (struct device *dev, struct device_attribute *attr, char *buf)
283 struct ccw_device *cdev = to_ccwdev(dev);
285 return sprintf(buf, cdev->online ? "1\n" : "0\n");
288 int ccw_device_is_orphan(struct ccw_device *cdev)
290 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
293 static void ccw_device_unregister(struct ccw_device *cdev)
295 if (test_and_clear_bit(1, &cdev->private->registered))
296 device_del(&cdev->dev);
299 static void ccw_device_remove_orphan_cb(struct device *dev)
301 struct ccw_device *cdev = to_ccwdev(dev);
303 ccw_device_unregister(cdev);
304 put_device(&cdev->dev);
307 static void ccw_device_remove_sch_cb(struct device *dev)
309 struct subchannel *sch;
311 sch = to_subchannel(dev);
312 css_sch_device_unregister(sch);
313 /* Reset intparm to zeroes. */
314 sch->schib.pmcw.intparm = 0;
316 put_device(&sch->dev);
320 ccw_device_remove_disconnected(struct ccw_device *cdev)
326 * Forced offline in disconnected state means
327 * 'throw away device'.
329 if (ccw_device_is_orphan(cdev)) {
331 * Deregister ccw device.
332 * Unfortunately, we cannot do this directly from the
335 spin_lock_irqsave(cdev->ccwlock, flags);
336 cdev->private->state = DEV_STATE_NOT_OPER;
337 spin_unlock_irqrestore(cdev->ccwlock, flags);
338 rc = device_schedule_callback(&cdev->dev,
339 ccw_device_remove_orphan_cb);
341 CIO_MSG_EVENT(0, "Couldn't unregister orphan "
343 cdev->private->dev_id.ssid,
344 cdev->private->dev_id.devno);
347 /* Deregister subchannel, which will kill the ccw device. */
348 rc = device_schedule_callback(cdev->dev.parent,
349 ccw_device_remove_sch_cb);
351 CIO_MSG_EVENT(0, "Couldn't unregister disconnected device "
353 cdev->private->dev_id.ssid,
354 cdev->private->dev_id.devno);
358 * ccw_device_set_offline() - disable a ccw device for I/O
359 * @cdev: target ccw device
361 * This function calls the driver's set_offline() function for @cdev, if
362 * given, and then disables @cdev.
364 * %0 on success and a negative error value on failure.
366 * enabled, ccw device lock not held
368 int ccw_device_set_offline(struct ccw_device *cdev)
374 if (!cdev->online || !cdev->drv)
377 if (cdev->drv->set_offline) {
378 ret = cdev->drv->set_offline(cdev);
383 spin_lock_irq(cdev->ccwlock);
384 ret = ccw_device_offline(cdev);
385 if (ret == -ENODEV) {
386 if (cdev->private->state != DEV_STATE_NOT_OPER) {
387 cdev->private->state = DEV_STATE_OFFLINE;
388 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
390 spin_unlock_irq(cdev->ccwlock);
393 spin_unlock_irq(cdev->ccwlock);
395 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
397 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
398 "device 0.%x.%04x\n",
399 ret, cdev->private->dev_id.ssid,
400 cdev->private->dev_id.devno);
407 * ccw_device_set_online() - enable a ccw device for I/O
408 * @cdev: target ccw device
410 * This function first enables @cdev and then calls the driver's set_online()
411 * function for @cdev, if given. If set_online() returns an error, @cdev is
414 * %0 on success and a negative error value on failure.
416 * enabled, ccw device lock not held
418 int ccw_device_set_online(struct ccw_device *cdev)
424 if (cdev->online || !cdev->drv)
427 spin_lock_irq(cdev->ccwlock);
428 ret = ccw_device_online(cdev);
429 spin_unlock_irq(cdev->ccwlock);
431 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
433 CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
434 "device 0.%x.%04x\n",
435 ret, cdev->private->dev_id.ssid,
436 cdev->private->dev_id.devno);
439 if (cdev->private->state != DEV_STATE_ONLINE)
441 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
445 spin_lock_irq(cdev->ccwlock);
446 ret = ccw_device_offline(cdev);
447 spin_unlock_irq(cdev->ccwlock);
449 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
451 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
452 "device 0.%x.%04x\n",
453 ret, cdev->private->dev_id.ssid,
454 cdev->private->dev_id.devno);
455 return (ret == 0) ? -ENODEV : ret;
458 static void online_store_handle_offline(struct ccw_device *cdev)
460 if (cdev->private->state == DEV_STATE_DISCONNECTED)
461 ccw_device_remove_disconnected(cdev);
462 else if (cdev->drv && cdev->drv->set_offline)
463 ccw_device_set_offline(cdev);
466 static int online_store_recog_and_online(struct ccw_device *cdev)
470 /* Do device recognition, if needed. */
471 if (cdev->id.cu_type == 0) {
472 ret = ccw_device_recognition(cdev);
474 CIO_MSG_EVENT(0, "Couldn't start recognition "
475 "for device 0.%x.%04x (ret=%d)\n",
476 cdev->private->dev_id.ssid,
477 cdev->private->dev_id.devno, ret);
480 wait_event(cdev->private->wait_q,
481 cdev->private->flags.recog_done);
483 if (cdev->drv && cdev->drv->set_online)
484 ccw_device_set_online(cdev);
487 static int online_store_handle_online(struct ccw_device *cdev, int force)
491 ret = online_store_recog_and_online(cdev);
494 if (force && cdev->private->state == DEV_STATE_BOXED) {
495 ret = ccw_device_stlck(cdev);
498 if (cdev->id.cu_type == 0)
499 cdev->private->state = DEV_STATE_NOT_OPER;
500 online_store_recog_and_online(cdev);
505 static ssize_t online_store (struct device *dev, struct device_attribute *attr,
506 const char *buf, size_t count)
508 struct ccw_device *cdev = to_ccwdev(dev);
512 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
515 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
516 atomic_set(&cdev->private->onoff, 0);
519 if (!strncmp(buf, "force\n", count)) {
525 ret = strict_strtoul(buf, 16, &i);
531 online_store_handle_offline(cdev);
535 ret = online_store_handle_online(cdev, force);
544 module_put(cdev->drv->owner);
545 atomic_set(&cdev->private->onoff, 0);
550 available_show (struct device *dev, struct device_attribute *attr, char *buf)
552 struct ccw_device *cdev = to_ccwdev(dev);
553 struct subchannel *sch;
555 if (ccw_device_is_orphan(cdev))
556 return sprintf(buf, "no device\n");
557 switch (cdev->private->state) {
558 case DEV_STATE_BOXED:
559 return sprintf(buf, "boxed\n");
560 case DEV_STATE_DISCONNECTED:
561 case DEV_STATE_DISCONNECTED_SENSE_ID:
562 case DEV_STATE_NOT_OPER:
563 sch = to_subchannel(dev->parent);
565 return sprintf(buf, "no path\n");
567 return sprintf(buf, "no device\n");
569 /* All other states considered fine. */
570 return sprintf(buf, "good\n");
574 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
575 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
576 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
577 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
578 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
579 static DEVICE_ATTR(online, 0644, online_show, online_store);
580 static DEVICE_ATTR(availability, 0444, available_show, NULL);
582 static struct attribute *io_subchannel_attrs[] = {
583 &dev_attr_chpids.attr,
584 &dev_attr_pimpampom.attr,
588 static struct attribute_group io_subchannel_attr_group = {
589 .attrs = io_subchannel_attrs,
592 static struct attribute * ccwdev_attrs[] = {
593 &dev_attr_devtype.attr,
594 &dev_attr_cutype.attr,
595 &dev_attr_modalias.attr,
596 &dev_attr_online.attr,
597 &dev_attr_cmb_enable.attr,
598 &dev_attr_availability.attr,
602 static struct attribute_group ccwdev_attr_group = {
603 .attrs = ccwdev_attrs,
606 static struct attribute_group *ccwdev_attr_groups[] = {
611 /* this is a simple abstraction for device_register that sets the
612 * correct bus type and adds the bus specific files */
613 static int ccw_device_register(struct ccw_device *cdev)
615 struct device *dev = &cdev->dev;
618 dev->bus = &ccw_bus_type;
620 if ((ret = device_add(dev)))
623 set_bit(1, &cdev->private->registered);
628 struct ccw_dev_id dev_id;
629 struct ccw_device * sibling;
633 match_devno(struct device * dev, void * data)
635 struct match_data * d = data;
636 struct ccw_device * cdev;
638 cdev = to_ccwdev(dev);
639 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
640 !ccw_device_is_orphan(cdev) &&
641 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
642 (cdev != d->sibling))
647 static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
648 struct ccw_device *sibling)
651 struct match_data data;
653 data.dev_id = *dev_id;
654 data.sibling = sibling;
655 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
657 return dev ? to_ccwdev(dev) : NULL;
660 static int match_orphan(struct device *dev, void *data)
662 struct ccw_dev_id *dev_id;
663 struct ccw_device *cdev;
666 cdev = to_ccwdev(dev);
667 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
670 static struct ccw_device *
671 get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
672 struct ccw_dev_id *dev_id)
676 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
679 return dev ? to_ccwdev(dev) : NULL;
683 ccw_device_add_changed(struct work_struct *work)
685 struct ccw_device_private *priv;
686 struct ccw_device *cdev;
688 priv = container_of(work, struct ccw_device_private, kick_work);
690 if (device_add(&cdev->dev)) {
691 put_device(&cdev->dev);
694 set_bit(1, &cdev->private->registered);
697 void ccw_device_do_unreg_rereg(struct work_struct *work)
699 struct ccw_device_private *priv;
700 struct ccw_device *cdev;
701 struct subchannel *sch;
703 priv = container_of(work, struct ccw_device_private, kick_work);
705 sch = to_subchannel(cdev->dev.parent);
707 ccw_device_unregister(cdev);
708 PREPARE_WORK(&cdev->private->kick_work,
709 ccw_device_add_changed);
710 queue_work(ccw_device_work, &cdev->private->kick_work);
714 ccw_device_release(struct device *dev)
716 struct ccw_device *cdev;
718 cdev = to_ccwdev(dev);
719 kfree(cdev->private);
723 static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
725 struct ccw_device *cdev;
727 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
729 cdev->private = kzalloc(sizeof(struct ccw_device_private),
730 GFP_KERNEL | GFP_DMA);
735 return ERR_PTR(-ENOMEM);
738 static int io_subchannel_initialize_dev(struct subchannel *sch,
739 struct ccw_device *cdev)
741 cdev->private->cdev = cdev;
742 atomic_set(&cdev->private->onoff, 0);
743 cdev->dev.parent = &sch->dev;
744 cdev->dev.release = ccw_device_release;
745 INIT_WORK(&cdev->private->kick_work, NULL);
746 cdev->dev.groups = ccwdev_attr_groups;
747 /* Do first half of device_register. */
748 device_initialize(&cdev->dev);
749 if (!get_device(&sch->dev)) {
750 if (cdev->dev.release)
751 cdev->dev.release(&cdev->dev);
757 static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
759 struct ccw_device *cdev;
762 cdev = io_subchannel_allocate_dev(sch);
764 ret = io_subchannel_initialize_dev(sch, cdev);
773 static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
775 static void sch_attach_device(struct subchannel *sch,
776 struct ccw_device *cdev)
778 css_update_ssd_info(sch);
779 spin_lock_irq(sch->lock);
780 sch_set_cdev(sch, cdev);
781 cdev->private->schid = sch->schid;
782 cdev->ccwlock = sch->lock;
783 ccw_device_trigger_reprobe(cdev);
784 spin_unlock_irq(sch->lock);
787 static void sch_attach_disconnected_device(struct subchannel *sch,
788 struct ccw_device *cdev)
790 struct subchannel *other_sch;
793 other_sch = to_subchannel(get_device(cdev->dev.parent));
794 ret = device_move(&cdev->dev, &sch->dev);
796 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
797 "(ret=%d)!\n", cdev->private->dev_id.ssid,
798 cdev->private->dev_id.devno, ret);
799 put_device(&other_sch->dev);
802 sch_set_cdev(other_sch, NULL);
803 /* No need to keep a subchannel without ccw device around. */
804 css_sch_device_unregister(other_sch);
805 put_device(&other_sch->dev);
806 sch_attach_device(sch, cdev);
809 static void sch_attach_orphaned_device(struct subchannel *sch,
810 struct ccw_device *cdev)
814 /* Try to move the ccw device to its new subchannel. */
815 ret = device_move(&cdev->dev, &sch->dev);
817 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
818 "failed (ret=%d)!\n",
819 cdev->private->dev_id.ssid,
820 cdev->private->dev_id.devno, ret);
823 sch_attach_device(sch, cdev);
826 static void sch_create_and_recog_new_device(struct subchannel *sch)
828 struct ccw_device *cdev;
830 /* Need to allocate a new ccw device. */
831 cdev = io_subchannel_create_ccwdev(sch);
833 /* OK, we did everything we could... */
834 css_sch_device_unregister(sch);
837 spin_lock_irq(sch->lock);
838 sch_set_cdev(sch, cdev);
839 spin_unlock_irq(sch->lock);
840 /* Start recognition for the new ccw device. */
841 if (io_subchannel_recog(cdev, sch)) {
842 spin_lock_irq(sch->lock);
843 sch_set_cdev(sch, NULL);
844 spin_unlock_irq(sch->lock);
845 if (cdev->dev.release)
846 cdev->dev.release(&cdev->dev);
847 css_sch_device_unregister(sch);
852 void ccw_device_move_to_orphanage(struct work_struct *work)
854 struct ccw_device_private *priv;
855 struct ccw_device *cdev;
856 struct ccw_device *replacing_cdev;
857 struct subchannel *sch;
859 struct channel_subsystem *css;
860 struct ccw_dev_id dev_id;
862 priv = container_of(work, struct ccw_device_private, kick_work);
864 sch = to_subchannel(cdev->dev.parent);
865 css = to_css(sch->dev.parent);
866 dev_id.devno = sch->schib.pmcw.dev;
867 dev_id.ssid = sch->schid.ssid;
870 * Move the orphaned ccw device to the orphanage so the replacing
871 * ccw device can take its place on the subchannel.
873 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
875 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
876 "(ret=%d)!\n", cdev->private->dev_id.ssid,
877 cdev->private->dev_id.devno, ret);
880 cdev->ccwlock = css->pseudo_subchannel->lock;
882 * Search for the replacing ccw device
883 * - among the disconnected devices
886 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
887 if (replacing_cdev) {
888 sch_attach_disconnected_device(sch, replacing_cdev);
891 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
892 if (replacing_cdev) {
893 sch_attach_orphaned_device(sch, replacing_cdev);
896 sch_create_and_recog_new_device(sch);
900 * Register recognized device.
903 io_subchannel_register(struct work_struct *work)
905 struct ccw_device_private *priv;
906 struct ccw_device *cdev;
907 struct subchannel *sch;
911 priv = container_of(work, struct ccw_device_private, kick_work);
913 sch = to_subchannel(cdev->dev.parent);
914 css_update_ssd_info(sch);
916 * io_subchannel_register() will also be called after device
917 * recognition has been done for a boxed device (which will already
918 * be registered). We need to reprobe since we may now have sense id
921 if (klist_node_attached(&cdev->dev.knode_parent)) {
923 ret = device_reprobe(&cdev->dev);
925 /* We can't do much here. */
926 CIO_MSG_EVENT(0, "device_reprobe() returned"
927 " %d for 0.%x.%04x\n", ret,
928 cdev->private->dev_id.ssid,
929 cdev->private->dev_id.devno);
934 * Now we know this subchannel will stay, we can throw
935 * our delayed uevent.
937 sch->dev.uevent_suppress = 0;
938 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
939 /* make it known to the system */
940 ret = ccw_device_register(cdev);
942 CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
943 cdev->private->dev_id.ssid,
944 cdev->private->dev_id.devno, ret);
945 put_device(&cdev->dev);
946 spin_lock_irqsave(sch->lock, flags);
947 sch_set_cdev(sch, NULL);
948 spin_unlock_irqrestore(sch->lock, flags);
949 kfree (cdev->private);
951 put_device(&sch->dev);
952 if (atomic_dec_and_test(&ccw_device_init_count))
953 wake_up(&ccw_device_init_wq);
956 put_device(&cdev->dev);
958 cdev->private->flags.recog_done = 1;
959 put_device(&sch->dev);
960 wake_up(&cdev->private->wait_q);
961 if (atomic_dec_and_test(&ccw_device_init_count))
962 wake_up(&ccw_device_init_wq);
965 static void ccw_device_call_sch_unregister(struct work_struct *work)
967 struct ccw_device_private *priv;
968 struct ccw_device *cdev;
969 struct subchannel *sch;
971 priv = container_of(work, struct ccw_device_private, kick_work);
973 sch = to_subchannel(cdev->dev.parent);
974 css_sch_device_unregister(sch);
975 /* Reset intparm to zeroes. */
976 sch->schib.pmcw.intparm = 0;
978 put_device(&cdev->dev);
979 put_device(&sch->dev);
983 * subchannel recognition done. Called from the state machine.
986 io_subchannel_recog_done(struct ccw_device *cdev)
988 struct subchannel *sch;
990 if (css_init_done == 0) {
991 cdev->private->flags.recog_done = 1;
994 switch (cdev->private->state) {
995 case DEV_STATE_NOT_OPER:
996 cdev->private->flags.recog_done = 1;
997 /* Remove device found not operational. */
998 if (!get_device(&cdev->dev))
1000 sch = to_subchannel(cdev->dev.parent);
1001 PREPARE_WORK(&cdev->private->kick_work,
1002 ccw_device_call_sch_unregister);
1003 queue_work(slow_path_wq, &cdev->private->kick_work);
1004 if (atomic_dec_and_test(&ccw_device_init_count))
1005 wake_up(&ccw_device_init_wq);
1007 case DEV_STATE_BOXED:
1008 /* Device did not respond in time. */
1009 case DEV_STATE_OFFLINE:
1011 * We can't register the device in interrupt context so
1012 * we schedule a work item.
1014 if (!get_device(&cdev->dev))
1016 PREPARE_WORK(&cdev->private->kick_work,
1017 io_subchannel_register);
1018 queue_work(slow_path_wq, &cdev->private->kick_work);
1024 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
1027 struct ccw_device_private *priv;
1029 sch_set_cdev(sch, cdev);
1030 cdev->ccwlock = sch->lock;
1032 /* Init private data. */
1033 priv = cdev->private;
1034 priv->dev_id.devno = sch->schib.pmcw.dev;
1035 priv->dev_id.ssid = sch->schid.ssid;
1036 priv->schid = sch->schid;
1037 priv->state = DEV_STATE_NOT_OPER;
1038 INIT_LIST_HEAD(&priv->cmb_list);
1039 init_waitqueue_head(&priv->wait_q);
1040 init_timer(&priv->timer);
1042 /* Set an initial name for the device. */
1043 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
1044 sch->schid.ssid, sch->schib.pmcw.dev);
1046 /* Increase counter of devices currently in recognition. */
1047 atomic_inc(&ccw_device_init_count);
1049 /* Start async. device sensing. */
1050 spin_lock_irq(sch->lock);
1051 rc = ccw_device_recognition(cdev);
1052 spin_unlock_irq(sch->lock);
1054 if (atomic_dec_and_test(&ccw_device_init_count))
1055 wake_up(&ccw_device_init_wq);
1060 static void ccw_device_move_to_sch(struct work_struct *work)
1062 struct ccw_device_private *priv;
1064 struct subchannel *sch;
1065 struct ccw_device *cdev;
1066 struct subchannel *former_parent;
1068 priv = container_of(work, struct ccw_device_private, kick_work);
1071 former_parent = ccw_device_is_orphan(cdev) ?
1072 NULL : to_subchannel(get_device(cdev->dev.parent));
1073 mutex_lock(&sch->reg_mutex);
1074 /* Try to move the ccw device to its new subchannel. */
1075 rc = device_move(&cdev->dev, &sch->dev);
1076 mutex_unlock(&sch->reg_mutex);
1078 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
1079 "0.%x.%04x failed (ret=%d)!\n",
1080 cdev->private->dev_id.ssid,
1081 cdev->private->dev_id.devno, sch->schid.ssid,
1082 sch->schid.sch_no, rc);
1083 css_sch_device_unregister(sch);
1086 if (former_parent) {
1087 spin_lock_irq(former_parent->lock);
1088 sch_set_cdev(former_parent, NULL);
1089 spin_unlock_irq(former_parent->lock);
1090 css_sch_device_unregister(former_parent);
1091 /* Reset intparm to zeroes. */
1092 former_parent->schib.pmcw.intparm = 0;
1093 cio_modify(former_parent);
1095 sch_attach_device(sch, cdev);
1098 put_device(&former_parent->dev);
1099 put_device(&cdev->dev);
1102 static void io_subchannel_irq(struct subchannel *sch)
1104 struct ccw_device *cdev;
1106 cdev = sch_get_cdev(sch);
1108 CIO_TRACE_EVENT(3, "IRQ");
1109 CIO_TRACE_EVENT(3, sch->dev.bus_id);
1111 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1114 static void io_subchannel_init_fields(struct subchannel *sch)
1116 if (cio_is_console(sch->schid))
1119 sch->opm = chp_get_sch_opm(sch);
1120 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1121 sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
1123 CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
1124 " - PIM = %02X, PAM = %02X, POM = %02X\n",
1125 sch->schib.pmcw.dev, sch->schid.ssid,
1126 sch->schid.sch_no, sch->schib.pmcw.pim,
1127 sch->schib.pmcw.pam, sch->schib.pmcw.pom);
1128 /* Initially set up some fields in the pmcw. */
1129 sch->schib.pmcw.ena = 0;
1130 sch->schib.pmcw.csense = 1; /* concurrent sense */
1131 if ((sch->lpm & (sch->lpm - 1)) != 0)
1132 sch->schib.pmcw.mp = 1; /* multipath mode */
1133 /* clean up possible residual cmf stuff */
1134 sch->schib.pmcw.mme = 0;
1135 sch->schib.pmcw.mbfc = 0;
1136 sch->schib.pmcw.mbi = 0;
1140 static int io_subchannel_probe(struct subchannel *sch)
1142 struct ccw_device *cdev;
1144 unsigned long flags;
1145 struct ccw_dev_id dev_id;
1147 cdev = sch_get_cdev(sch);
1149 rc = sysfs_create_group(&sch->dev.kobj,
1150 &io_subchannel_attr_group);
1152 CIO_MSG_EVENT(0, "Failed to create io subchannel "
1153 "attributes for subchannel "
1154 "0.%x.%04x (rc=%d)\n",
1155 sch->schid.ssid, sch->schid.sch_no, rc);
1157 * This subchannel already has an associated ccw_device.
1158 * Throw the delayed uevent for the subchannel, register
1159 * the ccw_device and exit. This happens for all early
1160 * devices, e.g. the console.
1162 sch->dev.uevent_suppress = 0;
1163 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
1164 cdev->dev.groups = ccwdev_attr_groups;
1165 device_initialize(&cdev->dev);
1166 ccw_device_register(cdev);
1168 * Check if the device is already online. If it is
1169 * the reference count needs to be corrected
1170 * (see ccw_device_online and css_init_done for the
1173 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1174 cdev->private->state != DEV_STATE_OFFLINE &&
1175 cdev->private->state != DEV_STATE_BOXED)
1176 get_device(&cdev->dev);
1179 io_subchannel_init_fields(sch);
1181 * First check if a fitting device may be found amongst the
1182 * disconnected devices or in the orphanage.
1184 dev_id.devno = sch->schib.pmcw.dev;
1185 dev_id.ssid = sch->schid.ssid;
1186 rc = sysfs_create_group(&sch->dev.kobj,
1187 &io_subchannel_attr_group);
1190 /* Allocate I/O subchannel private data. */
1191 sch->private = kzalloc(sizeof(struct io_subchannel_private),
1192 GFP_KERNEL | GFP_DMA);
1193 if (!sch->private) {
1197 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
1199 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
1203 * Schedule moving the device until when we have a registered
1204 * subchannel to move to and succeed the probe. We can
1205 * unregister later again, when the probe is through.
1207 cdev->private->sch = sch;
1208 PREPARE_WORK(&cdev->private->kick_work,
1209 ccw_device_move_to_sch);
1210 queue_work(slow_path_wq, &cdev->private->kick_work);
1213 cdev = io_subchannel_create_ccwdev(sch);
1218 rc = io_subchannel_recog(cdev, sch);
1220 spin_lock_irqsave(sch->lock, flags);
1221 sch_set_cdev(sch, NULL);
1222 spin_unlock_irqrestore(sch->lock, flags);
1223 if (cdev->dev.release)
1224 cdev->dev.release(&cdev->dev);
1229 kfree(sch->private);
1230 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1235 io_subchannel_remove (struct subchannel *sch)
1237 struct ccw_device *cdev;
1238 unsigned long flags;
1240 cdev = sch_get_cdev(sch);
1243 /* Set ccw device to not operational and drop reference. */
1244 spin_lock_irqsave(cdev->ccwlock, flags);
1245 sch_set_cdev(sch, NULL);
1246 cdev->private->state = DEV_STATE_NOT_OPER;
1247 spin_unlock_irqrestore(cdev->ccwlock, flags);
1248 ccw_device_unregister(cdev);
1249 put_device(&cdev->dev);
1250 kfree(sch->private);
1251 sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
1255 static int io_subchannel_notify(struct subchannel *sch, int event)
1257 struct ccw_device *cdev;
1259 cdev = sch_get_cdev(sch);
1262 return ccw_device_notify(cdev, event);
1265 static void io_subchannel_verify(struct subchannel *sch)
1267 struct ccw_device *cdev;
1269 cdev = sch_get_cdev(sch);
1271 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1274 static int check_for_io_on_path(struct subchannel *sch, int mask)
1278 cc = stsch(sch->schid, &sch->schib);
1281 if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
1286 static void terminate_internal_io(struct subchannel *sch,
1287 struct ccw_device *cdev)
1289 if (cio_clear(sch)) {
1290 /* Recheck device in case clear failed. */
1293 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1295 css_schedule_eval(sch->schid);
1298 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
1299 /* Request retry of internal operation. */
1300 cdev->private->flags.intretry = 1;
1303 cdev->handler(cdev, cdev->private->intparm,
1307 static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
1309 struct ccw_device *cdev;
1311 cdev = sch_get_cdev(sch);
1314 if (check_for_io_on_path(sch, mask)) {
1315 if (cdev->private->state == DEV_STATE_ONLINE)
1316 ccw_device_kill_io(cdev);
1318 terminate_internal_io(sch, cdev);
1319 /* Re-start path verification. */
1320 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1323 /* trigger path verification. */
1324 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1328 static int io_subchannel_chp_event(struct subchannel *sch,
1329 struct chp_link *link, int event)
1333 mask = chp_ssd_get_mask(&sch->ssd_info, link);
1340 io_subchannel_terminate_path(sch, mask);
1345 io_subchannel_verify(sch);
1348 if (stsch(sch->schid, &sch->schib))
1350 if (!css_sch_is_valid(&sch->schib))
1352 io_subchannel_terminate_path(sch, mask);
1355 if (stsch(sch->schid, &sch->schib))
1357 sch->lpm |= mask & sch->opm;
1358 io_subchannel_verify(sch);
1365 io_subchannel_shutdown(struct subchannel *sch)
1367 struct ccw_device *cdev;
1370 cdev = sch_get_cdev(sch);
1372 if (cio_is_console(sch->schid))
1374 if (!sch->schib.pmcw.ena)
1375 /* Nothing to do. */
1377 ret = cio_disable_subchannel(sch);
1379 /* Subchannel is disabled, we're done. */
1381 cdev->private->state = DEV_STATE_QUIESCE;
1383 cdev->handler(cdev, cdev->private->intparm,
1385 ret = ccw_device_cancel_halt_clear(cdev);
1386 if (ret == -EBUSY) {
1387 ccw_device_set_timeout(cdev, HZ/10);
1388 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1390 cio_disable_subchannel(sch);
1393 static int io_subchannel_get_status(struct subchannel *sch)
1397 if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
1399 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
1400 return CIO_REVALIDATE;
1406 static int device_is_disconnected(struct ccw_device *cdev)
1410 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
1411 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
1414 static int recovery_check(struct device *dev, void *data)
1416 struct ccw_device *cdev = to_ccwdev(dev);
1419 spin_lock_irq(cdev->ccwlock);
1420 switch (cdev->private->state) {
1421 case DEV_STATE_DISCONNECTED:
1422 CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
1423 cdev->private->dev_id.ssid,
1424 cdev->private->dev_id.devno);
1425 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1428 case DEV_STATE_DISCONNECTED_SENSE_ID:
1432 spin_unlock_irq(cdev->ccwlock);
1437 static void recovery_work_func(struct work_struct *unused)
1441 bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
1443 spin_lock_irq(&recovery_lock);
1444 if (!timer_pending(&recovery_timer)) {
1445 if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
1447 mod_timer(&recovery_timer, jiffies +
1448 recovery_delay[recovery_phase] * HZ);
1450 spin_unlock_irq(&recovery_lock);
1452 CIO_MSG_EVENT(4, "recovery: end\n");
1455 static DECLARE_WORK(recovery_work, recovery_work_func);
1457 static void recovery_func(unsigned long data)
1460 * We can't do our recovery in softirq context and it's not
1461 * performance critical, so we schedule it.
1463 schedule_work(&recovery_work);
1466 static void ccw_device_schedule_recovery(void)
1468 unsigned long flags;
1470 CIO_MSG_EVENT(4, "recovery: schedule\n");
1471 spin_lock_irqsave(&recovery_lock, flags);
1472 if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
1474 mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
1476 spin_unlock_irqrestore(&recovery_lock, flags);
1479 static void device_set_disconnected(struct ccw_device *cdev)
1483 ccw_device_set_timeout(cdev, 0);
1484 cdev->private->flags.fake_irb = 0;
1485 cdev->private->state = DEV_STATE_DISCONNECTED;
1487 ccw_device_schedule_recovery();
1490 void ccw_device_set_notoper(struct ccw_device *cdev)
1492 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1494 CIO_TRACE_EVENT(2, "notoper");
1495 CIO_TRACE_EVENT(2, sch->dev.bus_id);
1496 ccw_device_set_timeout(cdev, 0);
1497 cio_disable_subchannel(sch);
1498 cdev->private->state = DEV_STATE_NOT_OPER;
1501 static int io_subchannel_sch_event(struct subchannel *sch, int slow)
1503 int event, ret, disc;
1504 unsigned long flags;
1505 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action;
1506 struct ccw_device *cdev;
1508 spin_lock_irqsave(sch->lock, flags);
1509 cdev = sch_get_cdev(sch);
1510 disc = device_is_disconnected(cdev);
1512 /* Disconnected devices are evaluated directly only.*/
1513 spin_unlock_irqrestore(sch->lock, flags);
1516 /* No interrupt after machine check - kill pending timers. */
1518 ccw_device_set_timeout(cdev, 0);
1519 if (!disc && !slow) {
1520 /* Non-disconnected devices are evaluated on the slow path. */
1521 spin_unlock_irqrestore(sch->lock, flags);
1524 event = io_subchannel_get_status(sch);
1525 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
1526 sch->schid.ssid, sch->schid.sch_no, event,
1527 disc ? "disconnected" : "normal",
1528 slow ? "slow" : "fast");
1529 /* Analyze subchannel status. */
1534 /* Check if paths have become available. */
1540 /* Ask driver what to do with device. */
1541 if (io_subchannel_notify(sch, event))
1544 action = UNREGISTER;
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 ccw_device_set_notoper(cdev);
1566 /* Unregister device (will use subchannel lock). */
1567 spin_unlock_irqrestore(sch->lock, flags);
1568 css_sch_device_unregister(sch);
1569 spin_lock_irqsave(sch->lock, flags);
1571 /* Reset intparm to zeroes. */
1572 sch->schib.pmcw.intparm = 0;
1576 ccw_device_trigger_reprobe(cdev);
1579 device_set_disconnected(cdev);
1584 spin_unlock_irqrestore(sch->lock, flags);
1585 /* Probe if necessary. */
1586 if (action == UNREGISTER_PROBE)
1587 ret = css_probe_device(sch->schid);
1592 #ifdef CONFIG_CCW_CONSOLE
1593 static struct ccw_device console_cdev;
1594 static struct ccw_device_private console_private;
1595 static int console_cdev_in_use;
1597 static DEFINE_SPINLOCK(ccw_console_lock);
1599 spinlock_t * cio_get_console_lock(void)
1601 return &ccw_console_lock;
1604 static int ccw_device_console_enable(struct ccw_device *cdev,
1605 struct subchannel *sch)
1609 /* Attach subchannel private data. */
1610 sch->private = cio_get_console_priv();
1611 memset(sch->private, 0, sizeof(struct io_subchannel_private));
1612 io_subchannel_init_fields(sch);
1613 sch->driver = &io_subchannel_driver;
1614 /* Initialize the ccw_device structure. */
1615 cdev->dev.parent= &sch->dev;
1616 rc = io_subchannel_recog(cdev, sch);
1620 /* Now wait for the async. recognition to come to an end. */
1621 spin_lock_irq(cdev->ccwlock);
1622 while (!dev_fsm_final_state(cdev))
1625 if (cdev->private->state != DEV_STATE_OFFLINE)
1627 ccw_device_online(cdev);
1628 while (!dev_fsm_final_state(cdev))
1630 if (cdev->private->state != DEV_STATE_ONLINE)
1634 spin_unlock_irq(cdev->ccwlock);
1639 ccw_device_probe_console(void)
1641 struct subchannel *sch;
1644 if (xchg(&console_cdev_in_use, 1) != 0)
1645 return ERR_PTR(-EBUSY);
1646 sch = cio_probe_console();
1648 console_cdev_in_use = 0;
1649 return (void *) sch;
1651 memset(&console_cdev, 0, sizeof(struct ccw_device));
1652 memset(&console_private, 0, sizeof(struct ccw_device_private));
1653 console_cdev.private = &console_private;
1654 console_private.cdev = &console_cdev;
1655 ret = ccw_device_console_enable(&console_cdev, sch);
1657 cio_release_console();
1658 console_cdev_in_use = 0;
1659 return ERR_PTR(ret);
1661 console_cdev.online = 1;
1662 return &console_cdev;
1667 * get ccw_device matching the busid, but only if owned by cdrv
1670 __ccwdev_check_busid(struct device *dev, void *id)
1676 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1681 * get_ccwdev_by_busid() - obtain device from a bus id
1682 * @cdrv: driver the device is owned by
1683 * @bus_id: bus id of the device to be searched
1685 * This function searches all devices owned by @cdrv for a device with a bus
1686 * id matching @bus_id.
1688 * If a match is found, its reference count of the found device is increased
1689 * and it is returned; else %NULL is returned.
1691 struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
1695 struct device_driver *drv;
1697 drv = get_driver(&cdrv->driver);
1701 dev = driver_find_device(drv, NULL, (void *)bus_id,
1702 __ccwdev_check_busid);
1705 return dev ? to_ccwdev(dev) : NULL;
1708 /************************** device driver handling ************************/
1710 /* This is the implementation of the ccw_driver class. The probe, remove
1711 * and release methods are initially very similar to the device_driver
1712 * implementations, with the difference that they have ccw_device
1715 * A ccw driver also contains the information that is needed for
1719 ccw_device_probe (struct device *dev)
1721 struct ccw_device *cdev = to_ccwdev(dev);
1722 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1725 cdev->drv = cdrv; /* to let the driver call _set_online */
1727 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1738 ccw_device_remove (struct device *dev)
1740 struct ccw_device *cdev = to_ccwdev(dev);
1741 struct ccw_driver *cdrv = cdev->drv;
1748 spin_lock_irq(cdev->ccwlock);
1749 ret = ccw_device_offline(cdev);
1750 spin_unlock_irq(cdev->ccwlock);
1752 wait_event(cdev->private->wait_q,
1753 dev_fsm_final_state(cdev));
1755 CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
1756 "device 0.%x.%04x\n",
1757 ret, cdev->private->dev_id.ssid,
1758 cdev->private->dev_id.devno);
1760 ccw_device_set_timeout(cdev, 0);
1765 static void ccw_device_shutdown(struct device *dev)
1767 struct ccw_device *cdev;
1769 cdev = to_ccwdev(dev);
1770 if (cdev->drv && cdev->drv->shutdown)
1771 cdev->drv->shutdown(cdev);
1775 struct bus_type ccw_bus_type = {
1777 .match = ccw_bus_match,
1778 .uevent = ccw_uevent,
1779 .probe = ccw_device_probe,
1780 .remove = ccw_device_remove,
1781 .shutdown = ccw_device_shutdown,
1785 * ccw_driver_register() - register a ccw driver
1786 * @cdriver: driver to be registered
1788 * This function is mainly a wrapper around driver_register().
1790 * %0 on success and a negative error value on failure.
1792 int ccw_driver_register(struct ccw_driver *cdriver)
1794 struct device_driver *drv = &cdriver->driver;
1796 drv->bus = &ccw_bus_type;
1797 drv->name = cdriver->name;
1798 drv->owner = cdriver->owner;
1800 return driver_register(drv);
1804 * ccw_driver_unregister() - deregister a ccw driver
1805 * @cdriver: driver to be deregistered
1807 * This function is mainly a wrapper around driver_unregister().
1809 void ccw_driver_unregister(struct ccw_driver *cdriver)
1811 driver_unregister(&cdriver->driver);
1814 /* Helper func for qdio. */
1815 struct subchannel_id
1816 ccw_device_get_subchannel_id(struct ccw_device *cdev)
1818 struct subchannel *sch;
1820 sch = to_subchannel(cdev->dev.parent);
1824 MODULE_LICENSE("GPL");
1825 EXPORT_SYMBOL(ccw_device_set_online);
1826 EXPORT_SYMBOL(ccw_device_set_offline);
1827 EXPORT_SYMBOL(ccw_driver_register);
1828 EXPORT_SYMBOL(ccw_driver_unregister);
1829 EXPORT_SYMBOL(get_ccwdev_by_busid);
1830 EXPORT_SYMBOL(ccw_bus_type);
1831 EXPORT_SYMBOL(ccw_device_work);
1832 EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);