2 * drivers/s390/cio/device.c
3 * bus driver for ccw devices
6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
8 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
9 * Cornelia Huck (cohuck@de.ibm.com)
10 * Martin Schwidefsky (schwidefsky@de.ibm.com)
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/spinlock.h>
16 #include <linux/errno.h>
17 #include <linux/err.h>
18 #include <linux/slab.h>
19 #include <linux/list.h>
20 #include <linux/device.h>
21 #include <linux/workqueue.h>
23 #include <asm/ccwdev.h>
31 /******************* bus type handling ***********************/
33 /* The Linux driver model distinguishes between a bus type and
34 * the bus itself. Of course we only have one channel
35 * subsystem driver and one channel system per machine, but
36 * we still use the abstraction. T.R. says it's a good idea. */
38 ccw_bus_match (struct device * dev, struct device_driver * drv)
40 struct ccw_device *cdev = to_ccwdev(dev);
41 struct ccw_driver *cdrv = to_ccwdrv(drv);
42 const struct ccw_device_id *ids = cdrv->ids, *found;
47 found = ccw_device_id_match(ids, &cdev->id);
51 cdev->id.driver_info = found->driver_info;
57 * Hotplugging interface for ccw devices.
58 * Heavily modeled on pci and usb hotplug.
61 ccw_hotplug (struct device *dev, char **envp, int num_envp,
62 char *buffer, int buffer_size)
64 struct ccw_device *cdev = to_ccwdev(dev);
71 /* what we want to pass to /sbin/hotplug */
74 length += scnprintf(buffer, buffer_size - length, "CU_TYPE=%04X",
76 if ((buffer_size - length <= 0) || (i >= num_envp))
82 length += scnprintf(buffer, buffer_size - length, "CU_MODEL=%02X",
84 if ((buffer_size - length <= 0) || (i >= num_envp))
89 /* The next two can be zero, that's ok for us */
91 length += scnprintf(buffer, buffer_size - length, "DEV_TYPE=%04X",
93 if ((buffer_size - length <= 0) || (i >= num_envp))
99 length += scnprintf(buffer, buffer_size - length, "DEV_MODEL=%02X",
101 if ((buffer_size - length <= 0) || (i >= num_envp))
109 struct bus_type ccw_bus_type = {
111 .match = &ccw_bus_match,
112 .hotplug = &ccw_hotplug,
115 static int io_subchannel_probe (struct device *);
116 static int io_subchannel_remove (struct device *);
117 void io_subchannel_irq (struct device *);
118 static int io_subchannel_notify(struct device *, int);
119 static void io_subchannel_verify(struct device *);
120 static void io_subchannel_ioterm(struct device *);
121 static void io_subchannel_shutdown(struct device *);
123 struct css_driver io_subchannel_driver = {
124 .subchannel_type = SUBCHANNEL_TYPE_IO,
126 .name = "io_subchannel",
127 .bus = &css_bus_type,
128 .probe = &io_subchannel_probe,
129 .remove = &io_subchannel_remove,
130 .shutdown = &io_subchannel_shutdown,
132 .irq = io_subchannel_irq,
133 .notify = io_subchannel_notify,
134 .verify = io_subchannel_verify,
135 .termination = io_subchannel_ioterm,
138 struct workqueue_struct *ccw_device_work;
139 struct workqueue_struct *ccw_device_notify_work;
140 static wait_queue_head_t ccw_device_init_wq;
141 static atomic_t ccw_device_init_count;
144 init_ccw_bus_type (void)
148 init_waitqueue_head(&ccw_device_init_wq);
149 atomic_set(&ccw_device_init_count, 0);
151 ccw_device_work = create_singlethread_workqueue("cio");
152 if (!ccw_device_work)
153 return -ENOMEM; /* FIXME: better errno ? */
154 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
155 if (!ccw_device_notify_work) {
156 ret = -ENOMEM; /* FIXME: better errno ? */
159 slow_path_wq = create_singlethread_workqueue("kslowcrw");
161 ret = -ENOMEM; /* FIXME: better errno ? */
164 if ((ret = bus_register (&ccw_bus_type)))
167 if ((ret = driver_register(&io_subchannel_driver.drv)))
170 wait_event(ccw_device_init_wq,
171 atomic_read(&ccw_device_init_count) == 0);
172 flush_workqueue(ccw_device_work);
176 destroy_workqueue(ccw_device_work);
177 if (ccw_device_notify_work)
178 destroy_workqueue(ccw_device_notify_work);
180 destroy_workqueue(slow_path_wq);
185 cleanup_ccw_bus_type (void)
187 driver_unregister(&io_subchannel_driver.drv);
188 bus_unregister(&ccw_bus_type);
189 destroy_workqueue(ccw_device_notify_work);
190 destroy_workqueue(ccw_device_work);
193 subsys_initcall(init_ccw_bus_type);
194 module_exit(cleanup_ccw_bus_type);
196 /************************ device handling **************************/
199 * A ccw_device has some interfaces in sysfs in addition to the
201 * The following entries are designed to export the information which
202 * resided in 2.4 in /proc/subchannels. Subchannel and device number
203 * are obvious, so they don't have an entry :)
204 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
207 chpids_show (struct device * dev, char * buf)
209 struct subchannel *sch = to_subchannel(dev);
210 struct ssd_info *ssd = &sch->ssd_info;
214 for (chp = 0; chp < 8; chp++)
215 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]);
217 ret += sprintf (buf+ret, "\n");
218 return min((ssize_t)PAGE_SIZE, ret);
222 pimpampom_show (struct device * dev, char * buf)
224 struct subchannel *sch = to_subchannel(dev);
225 struct pmcw *pmcw = &sch->schib.pmcw;
227 return sprintf (buf, "%02x %02x %02x\n",
228 pmcw->pim, pmcw->pam, pmcw->pom);
232 devtype_show (struct device *dev, char *buf)
234 struct ccw_device *cdev = to_ccwdev(dev);
235 struct ccw_device_id *id = &(cdev->id);
237 if (id->dev_type != 0)
238 return sprintf(buf, "%04x/%02x\n",
239 id->dev_type, id->dev_model);
241 return sprintf(buf, "n/a\n");
245 cutype_show (struct device *dev, char *buf)
247 struct ccw_device *cdev = to_ccwdev(dev);
248 struct ccw_device_id *id = &(cdev->id);
250 return sprintf(buf, "%04x/%02x\n",
251 id->cu_type, id->cu_model);
255 online_show (struct device *dev, char *buf)
257 struct ccw_device *cdev = to_ccwdev(dev);
259 return sprintf(buf, cdev->online ? "1\n" : "0\n");
263 ccw_device_remove_disconnected(struct ccw_device *cdev)
265 struct subchannel *sch;
267 * Forced offline in disconnected state means
268 * 'throw away device'.
270 sch = to_subchannel(cdev->dev.parent);
271 device_unregister(&sch->dev);
272 /* Reset intparm to zeroes. */
273 sch->schib.pmcw.intparm = 0;
275 put_device(&sch->dev);
279 ccw_device_set_offline(struct ccw_device *cdev)
285 if (!cdev->online || !cdev->drv)
288 if (cdev->drv->set_offline) {
289 ret = cdev->drv->set_offline(cdev);
294 spin_lock_irq(cdev->ccwlock);
295 ret = ccw_device_offline(cdev);
296 spin_unlock_irq(cdev->ccwlock);
298 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
300 pr_debug("ccw_device_offline returned %d, device %s\n",
301 ret, cdev->dev.bus_id);
308 ccw_device_set_online(struct ccw_device *cdev)
314 if (cdev->online || !cdev->drv)
317 spin_lock_irq(cdev->ccwlock);
318 ret = ccw_device_online(cdev);
319 spin_unlock_irq(cdev->ccwlock);
321 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
323 pr_debug("ccw_device_online returned %d, device %s\n",
324 ret, cdev->dev.bus_id);
327 if (cdev->private->state != DEV_STATE_ONLINE)
329 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
333 spin_lock_irq(cdev->ccwlock);
334 ret = ccw_device_offline(cdev);
335 spin_unlock_irq(cdev->ccwlock);
337 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
339 pr_debug("ccw_device_offline returned %d, device %s\n",
340 ret, cdev->dev.bus_id);
341 return (ret = 0) ? -ENODEV : ret;
345 online_store (struct device *dev, const char *buf, size_t count)
347 struct ccw_device *cdev = to_ccwdev(dev);
351 if (atomic_compare_and_swap(0, 1, &cdev->private->onoff))
354 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
355 atomic_set(&cdev->private->onoff, 0);
358 if (!strncmp(buf, "force\n", count)) {
363 i = simple_strtoul(buf, &tmp, 16);
366 /* Do device recognition, if needed. */
367 if (cdev->id.cu_type == 0) {
368 ret = ccw_device_recognition(cdev);
370 printk(KERN_WARNING"Couldn't start recognition "
371 "for device %s (ret=%d)\n",
372 cdev->dev.bus_id, ret);
375 wait_event(cdev->private->wait_q,
376 cdev->private->flags.recog_done);
378 if (cdev->drv && cdev->drv->set_online)
379 ccw_device_set_online(cdev);
381 if (cdev->private->state == DEV_STATE_DISCONNECTED)
382 ccw_device_remove_disconnected(cdev);
383 else if (cdev->drv && cdev->drv->set_offline)
384 ccw_device_set_offline(cdev);
386 if (force && cdev->private->state == DEV_STATE_BOXED) {
387 ret = ccw_device_stlck(cdev);
389 printk(KERN_WARNING"ccw_device_stlck for device %s "
390 "returned %d!\n", cdev->dev.bus_id, ret);
393 /* Do device recognition, if needed. */
394 if (cdev->id.cu_type == 0) {
395 cdev->private->state = DEV_STATE_NOT_OPER;
396 ret = ccw_device_recognition(cdev);
398 printk(KERN_WARNING"Couldn't start recognition "
399 "for device %s (ret=%d)\n",
400 cdev->dev.bus_id, ret);
403 wait_event(cdev->private->wait_q,
404 cdev->private->flags.recog_done);
406 if (cdev->drv && cdev->drv->set_online)
407 ccw_device_set_online(cdev);
411 module_put(cdev->drv->owner);
412 atomic_set(&cdev->private->onoff, 0);
417 available_show (struct device *dev, char *buf)
419 struct ccw_device *cdev = to_ccwdev(dev);
420 struct subchannel *sch;
422 switch (cdev->private->state) {
423 case DEV_STATE_BOXED:
424 return sprintf(buf, "boxed\n");
425 case DEV_STATE_DISCONNECTED:
426 case DEV_STATE_DISCONNECTED_SENSE_ID:
427 case DEV_STATE_NOT_OPER:
428 sch = to_subchannel(dev->parent);
430 return sprintf(buf, "no path\n");
432 return sprintf(buf, "no device\n");
434 /* All other states considered fine. */
435 return sprintf(buf, "good\n");
439 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
440 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
441 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
442 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
443 static DEVICE_ATTR(online, 0644, online_show, online_store);
444 extern struct device_attribute dev_attr_cmb_enable;
445 static DEVICE_ATTR(availability, 0444, available_show, NULL);
447 static struct attribute * subch_attrs[] = {
448 &dev_attr_chpids.attr,
449 &dev_attr_pimpampom.attr,
453 static struct attribute_group subch_attr_group = {
454 .attrs = subch_attrs,
458 subchannel_add_files (struct device *dev)
460 return sysfs_create_group(&dev->kobj, &subch_attr_group);
463 static struct attribute * ccwdev_attrs[] = {
464 &dev_attr_devtype.attr,
465 &dev_attr_cutype.attr,
466 &dev_attr_online.attr,
467 &dev_attr_cmb_enable.attr,
468 &dev_attr_availability.attr,
472 static struct attribute_group ccwdev_attr_group = {
473 .attrs = ccwdev_attrs,
477 device_add_files (struct device *dev)
479 return sysfs_create_group(&dev->kobj, &ccwdev_attr_group);
483 device_remove_files(struct device *dev)
485 sysfs_remove_group(&dev->kobj, &ccwdev_attr_group);
488 /* this is a simple abstraction for device_register that sets the
489 * correct bus type and adds the bus specific files */
491 ccw_device_register(struct ccw_device *cdev)
493 struct device *dev = &cdev->dev;
496 dev->bus = &ccw_bus_type;
498 if ((ret = device_add(dev)))
501 set_bit(1, &cdev->private->registered);
502 if ((ret = device_add_files(dev))) {
503 if (test_and_clear_bit(1, &cdev->private->registered))
509 static struct ccw_device *
510 get_disc_ccwdev_by_devno(unsigned int devno, struct ccw_device *sibling)
512 struct ccw_device *cdev;
513 struct list_head *entry;
516 if (!get_bus(&ccw_bus_type))
518 down_read(&ccw_bus_type.subsys.rwsem);
520 list_for_each(entry, &ccw_bus_type.devices.list) {
521 dev = get_device(container_of(entry,
522 struct device, bus_list));
525 cdev = to_ccwdev(dev);
526 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
527 (cdev->private->devno == devno) &&
529 cdev->private->state = DEV_STATE_NOT_OPER;
535 up_read(&ccw_bus_type.subsys.rwsem);
536 put_bus(&ccw_bus_type);
542 ccw_device_add_changed(void *data)
545 struct ccw_device *cdev;
547 cdev = (struct ccw_device *)data;
548 if (device_add(&cdev->dev)) {
549 put_device(&cdev->dev);
552 set_bit(1, &cdev->private->registered);
553 if (device_add_files(&cdev->dev)) {
554 if (test_and_clear_bit(1, &cdev->private->registered))
555 device_unregister(&cdev->dev);
559 extern int css_get_ssd_info(struct subchannel *sch);
562 ccw_device_do_unreg_rereg(void *data)
564 struct ccw_device *cdev;
565 struct subchannel *sch;
568 cdev = (struct ccw_device *)data;
569 sch = to_subchannel(cdev->dev.parent);
570 if (cdev->private->devno != sch->schib.pmcw.dev) {
572 * The device number has changed. This is usually only when
573 * a device has been detached under VM and then re-appeared
574 * on another subchannel because of a different attachment
575 * order than before. Ideally, we should should just switch
576 * subchannels, but unfortunately, this is not possible with
577 * the current implementation.
578 * Instead, we search for the old subchannel for this device
579 * number and deregister so there are no collisions with the
580 * newly registered ccw_device.
581 * FIXME: Find another solution so the block layer doesn't
582 * get possibly sick...
584 struct ccw_device *other_cdev;
587 other_cdev = get_disc_ccwdev_by_devno(sch->schib.pmcw.dev,
590 struct subchannel *other_sch;
592 other_sch = to_subchannel(other_cdev->dev.parent);
593 if (get_device(&other_sch->dev)) {
594 stsch(other_sch->irq, &other_sch->schib);
595 if (other_sch->schib.pmcw.dnv) {
596 other_sch->schib.pmcw.intparm = 0;
597 cio_modify(other_sch);
599 device_unregister(&other_sch->dev);
602 /* Update ssd info here. */
603 css_get_ssd_info(sch);
604 cdev->private->devno = sch->schib.pmcw.dev;
607 device_remove_files(&cdev->dev);
608 if (test_and_clear_bit(1, &cdev->private->registered))
609 device_del(&cdev->dev);
611 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
612 sch->schib.pmcw.dev);
613 PREPARE_WORK(&cdev->private->kick_work,
614 ccw_device_add_changed, (void *)cdev);
615 queue_work(ccw_device_work, &cdev->private->kick_work);
619 ccw_device_release(struct device *dev)
621 struct ccw_device *cdev;
623 cdev = to_ccwdev(dev);
624 kfree(cdev->private);
629 * Register recognized device.
632 io_subchannel_register(void *data)
634 struct ccw_device *cdev;
635 struct subchannel *sch;
639 cdev = (struct ccw_device *) data;
640 sch = to_subchannel(cdev->dev.parent);
642 if (!list_empty(&sch->dev.children)) {
643 bus_rescan_devices(&ccw_bus_type);
646 /* make it known to the system */
647 ret = ccw_device_register(cdev);
649 printk (KERN_WARNING "%s: could not register %s\n",
650 __func__, cdev->dev.bus_id);
651 put_device(&cdev->dev);
652 spin_lock_irqsave(&sch->lock, flags);
653 sch->dev.driver_data = NULL;
654 spin_unlock_irqrestore(&sch->lock, flags);
655 kfree (cdev->private);
657 put_device(&sch->dev);
658 if (atomic_dec_and_test(&ccw_device_init_count))
659 wake_up(&ccw_device_init_wq);
663 ret = subchannel_add_files(cdev->dev.parent);
665 printk(KERN_WARNING "%s: could not add attributes to %s\n",
666 __func__, sch->dev.bus_id);
667 put_device(&cdev->dev);
669 cdev->private->flags.recog_done = 1;
670 put_device(&sch->dev);
671 wake_up(&cdev->private->wait_q);
672 if (atomic_dec_and_test(&ccw_device_init_count))
673 wake_up(&ccw_device_init_wq);
677 ccw_device_call_sch_unregister(void *data)
679 struct ccw_device *cdev = data;
680 struct subchannel *sch;
682 sch = to_subchannel(cdev->dev.parent);
683 device_unregister(&sch->dev);
684 /* Reset intparm to zeroes. */
685 sch->schib.pmcw.intparm = 0;
687 put_device(&cdev->dev);
688 put_device(&sch->dev);
692 * subchannel recognition done. Called from the state machine.
695 io_subchannel_recog_done(struct ccw_device *cdev)
697 struct subchannel *sch;
699 if (css_init_done == 0) {
700 cdev->private->flags.recog_done = 1;
703 switch (cdev->private->state) {
704 case DEV_STATE_NOT_OPER:
705 cdev->private->flags.recog_done = 1;
706 /* Remove device found not operational. */
707 if (!get_device(&cdev->dev))
709 sch = to_subchannel(cdev->dev.parent);
710 PREPARE_WORK(&cdev->private->kick_work,
711 ccw_device_call_sch_unregister, (void *) cdev);
712 queue_work(slow_path_wq, &cdev->private->kick_work);
713 if (atomic_dec_and_test(&ccw_device_init_count))
714 wake_up(&ccw_device_init_wq);
716 case DEV_STATE_BOXED:
717 /* Device did not respond in time. */
718 case DEV_STATE_OFFLINE:
720 * We can't register the device in interrupt context so
721 * we schedule a work item.
723 if (!get_device(&cdev->dev))
725 PREPARE_WORK(&cdev->private->kick_work,
726 io_subchannel_register, (void *) cdev);
727 queue_work(slow_path_wq, &cdev->private->kick_work);
733 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
736 struct ccw_device_private *priv;
738 sch->dev.driver_data = cdev;
739 sch->driver = &io_subchannel_driver;
740 cdev->ccwlock = &sch->lock;
741 /* Init private data. */
742 priv = cdev->private;
743 priv->devno = sch->schib.pmcw.dev;
744 priv->irq = sch->irq;
745 priv->state = DEV_STATE_NOT_OPER;
746 INIT_LIST_HEAD(&priv->cmb_list);
747 init_waitqueue_head(&priv->wait_q);
748 init_timer(&priv->timer);
750 /* Set an initial name for the device. */
751 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
752 sch->schib.pmcw.dev);
754 /* Increase counter of devices currently in recognition. */
755 atomic_inc(&ccw_device_init_count);
757 /* Start async. device sensing. */
758 spin_lock_irq(&sch->lock);
759 rc = ccw_device_recognition(cdev);
760 spin_unlock_irq(&sch->lock);
762 if (atomic_dec_and_test(&ccw_device_init_count))
763 wake_up(&ccw_device_init_wq);
769 io_subchannel_probe (struct device *pdev)
771 struct subchannel *sch;
772 struct ccw_device *cdev;
776 sch = to_subchannel(pdev);
777 if (sch->dev.driver_data) {
779 * This subchannel already has an associated ccw_device.
780 * Register it and exit. This happens for all early
781 * device, e.g. the console.
783 cdev = sch->dev.driver_data;
784 device_initialize(&cdev->dev);
785 ccw_device_register(cdev);
786 subchannel_add_files(&sch->dev);
788 * Check if the device is already online. If it is
789 * the reference count needs to be corrected
790 * (see ccw_device_online and css_init_done for the
793 if (cdev->private->state != DEV_STATE_NOT_OPER &&
794 cdev->private->state != DEV_STATE_OFFLINE &&
795 cdev->private->state != DEV_STATE_BOXED)
796 get_device(&cdev->dev);
799 cdev = kmalloc (sizeof(*cdev), GFP_KERNEL);
802 memset(cdev, 0, sizeof(struct ccw_device));
803 cdev->private = kmalloc(sizeof(struct ccw_device_private),
804 GFP_KERNEL | GFP_DMA);
805 if (!cdev->private) {
809 memset(cdev->private, 0, sizeof(struct ccw_device_private));
810 atomic_set(&cdev->private->onoff, 0);
811 cdev->dev = (struct device) {
813 .release = ccw_device_release,
815 INIT_LIST_HEAD(&cdev->private->kick_work.entry);
816 /* Do first half of device_register. */
817 device_initialize(&cdev->dev);
819 if (!get_device(&sch->dev)) {
820 if (cdev->dev.release)
821 cdev->dev.release(&cdev->dev);
825 rc = io_subchannel_recog(cdev, to_subchannel(pdev));
827 spin_lock_irqsave(&sch->lock, flags);
828 sch->dev.driver_data = NULL;
829 spin_unlock_irqrestore(&sch->lock, flags);
830 if (cdev->dev.release)
831 cdev->dev.release(&cdev->dev);
838 ccw_device_unregister(void *data)
840 struct ccw_device *cdev;
842 cdev = (struct ccw_device *)data;
843 if (test_and_clear_bit(1, &cdev->private->registered))
844 device_unregister(&cdev->dev);
845 put_device(&cdev->dev);
849 io_subchannel_remove (struct device *dev)
851 struct ccw_device *cdev;
854 if (!dev->driver_data)
856 cdev = dev->driver_data;
857 /* Set ccw device to not operational and drop reference. */
858 spin_lock_irqsave(cdev->ccwlock, flags);
859 dev->driver_data = NULL;
860 cdev->private->state = DEV_STATE_NOT_OPER;
861 spin_unlock_irqrestore(cdev->ccwlock, flags);
863 * Put unregistration on workqueue to avoid livelocks on the css bus
866 if (get_device(&cdev->dev)) {
867 PREPARE_WORK(&cdev->private->kick_work,
868 ccw_device_unregister, (void *) cdev);
869 queue_work(ccw_device_work, &cdev->private->kick_work);
875 io_subchannel_notify(struct device *dev, int event)
877 struct ccw_device *cdev;
879 cdev = dev->driver_data;
886 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
890 io_subchannel_verify(struct device *dev)
892 struct ccw_device *cdev;
894 cdev = dev->driver_data;
896 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
900 io_subchannel_ioterm(struct device *dev)
902 struct ccw_device *cdev;
904 cdev = dev->driver_data;
907 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
909 cdev->handler(cdev, cdev->private->intparm,
914 io_subchannel_shutdown(struct device *dev)
916 struct subchannel *sch;
917 struct ccw_device *cdev;
920 sch = to_subchannel(dev);
921 cdev = dev->driver_data;
923 if (cio_is_console(sch->irq))
925 if (!sch->schib.pmcw.ena)
928 ret = cio_disable_subchannel(sch);
930 /* Subchannel is disabled, we're done. */
932 cdev->private->state = DEV_STATE_QUIESCE;
934 cdev->handler(cdev, cdev->private->intparm,
936 ret = ccw_device_cancel_halt_clear(cdev);
938 ccw_device_set_timeout(cdev, HZ/10);
939 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
941 cio_disable_subchannel(sch);
944 #ifdef CONFIG_CCW_CONSOLE
945 static struct ccw_device console_cdev;
946 static struct ccw_device_private console_private;
947 static int console_cdev_in_use;
950 ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
954 /* Initialize the ccw_device structure. */
955 cdev->dev = (struct device) {
958 /* Initialize the subchannel structure */
959 sch->dev.parent = &css_bus_device;
960 sch->dev.bus = &css_bus_type;
962 rc = io_subchannel_recog(cdev, sch);
966 /* Now wait for the async. recognition to come to an end. */
967 spin_lock_irq(cdev->ccwlock);
968 while (!dev_fsm_final_state(cdev))
971 if (cdev->private->state != DEV_STATE_OFFLINE)
973 ccw_device_online(cdev);
974 while (!dev_fsm_final_state(cdev))
976 if (cdev->private->state != DEV_STATE_ONLINE)
980 spin_unlock_irq(cdev->ccwlock);
985 ccw_device_probe_console(void)
987 struct subchannel *sch;
990 if (xchg(&console_cdev_in_use, 1) != 0)
992 sch = cio_probe_console();
994 console_cdev_in_use = 0;
997 memset(&console_cdev, 0, sizeof(struct ccw_device));
998 memset(&console_private, 0, sizeof(struct ccw_device_private));
999 console_cdev.private = &console_private;
1000 ret = ccw_device_console_enable(&console_cdev, sch);
1002 cio_release_console();
1003 console_cdev_in_use = 0;
1004 return ERR_PTR(ret);
1006 console_cdev.online = 1;
1007 return &console_cdev;
1012 * get ccw_device matching the busid, but only if owned by cdrv
1015 get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
1017 struct device *d, *dev;
1018 struct device_driver *drv;
1020 drv = get_driver(&cdrv->driver);
1024 down_read(&drv->bus->subsys.rwsem);
1027 list_for_each_entry(d, &drv->devices, driver_list) {
1028 dev = get_device(d);
1030 if (dev && !strncmp(bus_id, dev->bus_id, BUS_ID_SIZE))
1037 up_read(&drv->bus->subsys.rwsem);
1040 return dev ? to_ccwdev(dev) : 0;
1043 /************************** device driver handling ************************/
1045 /* This is the implementation of the ccw_driver class. The probe, remove
1046 * and release methods are initially very similar to the device_driver
1047 * implementations, with the difference that they have ccw_device
1050 * A ccw driver also contains the information that is needed for
1054 ccw_device_probe (struct device *dev)
1056 struct ccw_device *cdev = to_ccwdev(dev);
1057 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1060 cdev->drv = cdrv; /* to let the driver call _set_online */
1062 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1073 ccw_device_remove (struct device *dev)
1075 struct ccw_device *cdev = to_ccwdev(dev);
1076 struct ccw_driver *cdrv = cdev->drv;
1079 pr_debug("removing device %s\n", cdev->dev.bus_id);
1084 spin_lock_irq(cdev->ccwlock);
1085 ret = ccw_device_offline(cdev);
1086 spin_unlock_irq(cdev->ccwlock);
1088 wait_event(cdev->private->wait_q,
1089 dev_fsm_final_state(cdev));
1091 //FIXME: we can't fail!
1092 pr_debug("ccw_device_offline returned %d, device %s\n",
1093 ret, cdev->dev.bus_id);
1095 ccw_device_set_timeout(cdev, 0);
1101 ccw_driver_register (struct ccw_driver *cdriver)
1103 struct device_driver *drv = &cdriver->driver;
1105 drv->bus = &ccw_bus_type;
1106 drv->name = cdriver->name;
1107 drv->probe = ccw_device_probe;
1108 drv->remove = ccw_device_remove;
1110 return driver_register(drv);
1114 ccw_driver_unregister (struct ccw_driver *cdriver)
1116 driver_unregister(&cdriver->driver);
1119 MODULE_LICENSE("GPL");
1120 EXPORT_SYMBOL(ccw_device_set_online);
1121 EXPORT_SYMBOL(ccw_device_set_offline);
1122 EXPORT_SYMBOL(ccw_driver_register);
1123 EXPORT_SYMBOL(ccw_driver_unregister);
1124 EXPORT_SYMBOL(get_ccwdev_by_busid);
1125 EXPORT_SYMBOL(ccw_bus_type);
1126 EXPORT_SYMBOL(ccw_device_work);
1127 EXPORT_SYMBOL(ccw_device_notify_work);