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 if (cdev->private->state == DEV_STATE_NOT_OPER)
74 /* what we want to pass to /sbin/hotplug */
77 length += scnprintf(buffer, buffer_size - length, "CU_TYPE=%04X",
79 if ((buffer_size - length <= 0) || (i >= num_envp))
85 length += scnprintf(buffer, buffer_size - length, "CU_MODEL=%02X",
87 if ((buffer_size - length <= 0) || (i >= num_envp))
92 /* The next two can be zero, that's ok for us */
94 length += scnprintf(buffer, buffer_size - length, "DEV_TYPE=%04X",
96 if ((buffer_size - length <= 0) || (i >= num_envp))
102 length += scnprintf(buffer, buffer_size - length, "DEV_MODEL=%02X",
104 if ((buffer_size - length <= 0) || (i >= num_envp))
112 struct bus_type ccw_bus_type = {
114 .match = &ccw_bus_match,
115 .hotplug = &ccw_hotplug,
118 static int io_subchannel_probe (struct device *);
119 static int io_subchannel_remove (struct device *);
120 void io_subchannel_irq (struct device *);
121 static int io_subchannel_notify(struct device *, int);
122 static void io_subchannel_verify(struct device *);
123 static void io_subchannel_ioterm(struct device *);
124 static void io_subchannel_shutdown(struct device *);
126 struct css_driver io_subchannel_driver = {
127 .subchannel_type = SUBCHANNEL_TYPE_IO,
129 .name = "io_subchannel",
130 .bus = &css_bus_type,
131 .probe = &io_subchannel_probe,
132 .remove = &io_subchannel_remove,
133 .shutdown = &io_subchannel_shutdown,
135 .irq = io_subchannel_irq,
136 .notify = io_subchannel_notify,
137 .verify = io_subchannel_verify,
138 .termination = io_subchannel_ioterm,
141 struct workqueue_struct *ccw_device_work;
142 struct workqueue_struct *ccw_device_notify_work;
143 static wait_queue_head_t ccw_device_init_wq;
144 static atomic_t ccw_device_init_count;
147 init_ccw_bus_type (void)
151 init_waitqueue_head(&ccw_device_init_wq);
152 atomic_set(&ccw_device_init_count, 0);
154 ccw_device_work = create_singlethread_workqueue("cio");
155 if (!ccw_device_work)
156 return -ENOMEM; /* FIXME: better errno ? */
157 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
158 if (!ccw_device_notify_work) {
159 ret = -ENOMEM; /* FIXME: better errno ? */
162 slow_path_wq = create_singlethread_workqueue("kslowcrw");
164 ret = -ENOMEM; /* FIXME: better errno ? */
167 if ((ret = bus_register (&ccw_bus_type)))
170 if ((ret = driver_register(&io_subchannel_driver.drv)))
173 wait_event(ccw_device_init_wq,
174 atomic_read(&ccw_device_init_count) == 0);
175 flush_workqueue(ccw_device_work);
179 destroy_workqueue(ccw_device_work);
180 if (ccw_device_notify_work)
181 destroy_workqueue(ccw_device_notify_work);
183 destroy_workqueue(slow_path_wq);
188 cleanup_ccw_bus_type (void)
190 driver_unregister(&io_subchannel_driver.drv);
191 bus_unregister(&ccw_bus_type);
192 destroy_workqueue(ccw_device_notify_work);
193 destroy_workqueue(ccw_device_work);
196 subsys_initcall(init_ccw_bus_type);
197 module_exit(cleanup_ccw_bus_type);
199 /************************ device handling **************************/
202 * A ccw_device has some interfaces in sysfs in addition to the
204 * The following entries are designed to export the information which
205 * resided in 2.4 in /proc/subchannels. Subchannel and device number
206 * are obvious, so they don't have an entry :)
207 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
210 chpids_show (struct device * dev, char * buf)
212 struct subchannel *sch = to_subchannel(dev);
213 struct ssd_info *ssd = &sch->ssd_info;
217 for (chp = 0; chp < 8; chp++)
218 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]);
220 ret += sprintf (buf+ret, "\n");
221 return min((ssize_t)PAGE_SIZE, ret);
225 pimpampom_show (struct device * dev, char * buf)
227 struct subchannel *sch = to_subchannel(dev);
228 struct pmcw *pmcw = &sch->schib.pmcw;
230 return sprintf (buf, "%02x %02x %02x\n",
231 pmcw->pim, pmcw->pam, pmcw->pom);
235 devtype_show (struct device *dev, char *buf)
237 struct ccw_device *cdev = to_ccwdev(dev);
238 struct ccw_device_id *id = &(cdev->id);
240 if (id->dev_type != 0)
241 return sprintf(buf, "%04x/%02x\n",
242 id->dev_type, id->dev_model);
244 return sprintf(buf, "n/a\n");
248 cutype_show (struct device *dev, char *buf)
250 struct ccw_device *cdev = to_ccwdev(dev);
251 struct ccw_device_id *id = &(cdev->id);
253 return sprintf(buf, "%04x/%02x\n",
254 id->cu_type, id->cu_model);
258 online_show (struct device *dev, char *buf)
260 struct ccw_device *cdev = to_ccwdev(dev);
262 return sprintf(buf, cdev->online ? "1\n" : "0\n");
266 ccw_device_remove_disconnected(struct ccw_device *cdev)
268 struct subchannel *sch;
270 * Forced offline in disconnected state means
271 * 'throw away device'.
273 sch = to_subchannel(cdev->dev.parent);
274 device_unregister(&sch->dev);
275 /* Reset intparm to zeroes. */
276 sch->schib.pmcw.intparm = 0;
278 put_device(&sch->dev);
282 ccw_device_set_offline(struct ccw_device *cdev)
288 if (!cdev->online || !cdev->drv)
291 if (cdev->drv->set_offline) {
292 ret = cdev->drv->set_offline(cdev);
297 spin_lock_irq(cdev->ccwlock);
298 ret = ccw_device_offline(cdev);
299 spin_unlock_irq(cdev->ccwlock);
301 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
303 pr_debug("ccw_device_offline returned %d, device %s\n",
304 ret, cdev->dev.bus_id);
311 ccw_device_set_online(struct ccw_device *cdev)
317 if (cdev->online || !cdev->drv)
320 spin_lock_irq(cdev->ccwlock);
321 ret = ccw_device_online(cdev);
322 spin_unlock_irq(cdev->ccwlock);
324 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
326 pr_debug("ccw_device_online returned %d, device %s\n",
327 ret, cdev->dev.bus_id);
330 if (cdev->private->state != DEV_STATE_ONLINE)
332 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
336 spin_lock_irq(cdev->ccwlock);
337 ret = ccw_device_offline(cdev);
338 spin_unlock_irq(cdev->ccwlock);
340 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
342 pr_debug("ccw_device_offline returned %d, device %s\n",
343 ret, cdev->dev.bus_id);
344 return (ret = 0) ? -ENODEV : ret;
348 online_store (struct device *dev, const char *buf, size_t count)
350 struct ccw_device *cdev = to_ccwdev(dev);
354 if (atomic_compare_and_swap(0, 1, &cdev->private->onoff))
357 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
358 atomic_set(&cdev->private->onoff, 0);
361 if (!strncmp(buf, "force\n", count)) {
366 i = simple_strtoul(buf, &tmp, 16);
369 /* Do device recognition, if needed. */
370 if (cdev->id.cu_type == 0) {
371 ret = ccw_device_recognition(cdev);
373 printk(KERN_WARNING"Couldn't start recognition "
374 "for device %s (ret=%d)\n",
375 cdev->dev.bus_id, ret);
378 wait_event(cdev->private->wait_q,
379 cdev->private->flags.recog_done);
381 if (cdev->drv && cdev->drv->set_online)
382 ccw_device_set_online(cdev);
384 if (cdev->private->state == DEV_STATE_DISCONNECTED)
385 ccw_device_remove_disconnected(cdev);
386 else if (cdev->drv && cdev->drv->set_offline)
387 ccw_device_set_offline(cdev);
389 if (force && cdev->private->state == DEV_STATE_BOXED) {
390 ret = ccw_device_stlck(cdev);
392 printk(KERN_WARNING"ccw_device_stlck for device %s "
393 "returned %d!\n", cdev->dev.bus_id, ret);
396 /* Do device recognition, if needed. */
397 if (cdev->id.cu_type == 0) {
398 cdev->private->state = DEV_STATE_NOT_OPER;
399 ret = ccw_device_recognition(cdev);
401 printk(KERN_WARNING"Couldn't start recognition "
402 "for device %s (ret=%d)\n",
403 cdev->dev.bus_id, ret);
406 wait_event(cdev->private->wait_q,
407 cdev->private->flags.recog_done);
409 if (cdev->drv && cdev->drv->set_online)
410 ccw_device_set_online(cdev);
414 module_put(cdev->drv->owner);
415 atomic_set(&cdev->private->onoff, 0);
420 available_show (struct device *dev, char *buf)
422 struct ccw_device *cdev = to_ccwdev(dev);
423 struct subchannel *sch;
425 switch (cdev->private->state) {
426 case DEV_STATE_BOXED:
427 return sprintf(buf, "boxed\n");
428 case DEV_STATE_DISCONNECTED:
429 case DEV_STATE_DISCONNECTED_SENSE_ID:
430 case DEV_STATE_NOT_OPER:
431 sch = to_subchannel(dev->parent);
433 return sprintf(buf, "no path\n");
435 return sprintf(buf, "no device\n");
437 /* All other states considered fine. */
438 return sprintf(buf, "good\n");
442 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
443 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
444 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
445 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
446 static DEVICE_ATTR(online, 0644, online_show, online_store);
447 extern struct device_attribute dev_attr_cmb_enable;
448 static DEVICE_ATTR(availability, 0444, available_show, NULL);
450 static struct attribute * subch_attrs[] = {
451 &dev_attr_chpids.attr,
452 &dev_attr_pimpampom.attr,
456 static struct attribute_group subch_attr_group = {
457 .attrs = subch_attrs,
461 subchannel_add_files (struct device *dev)
463 return sysfs_create_group(&dev->kobj, &subch_attr_group);
466 static struct attribute * ccwdev_attrs[] = {
467 &dev_attr_devtype.attr,
468 &dev_attr_cutype.attr,
469 &dev_attr_online.attr,
470 &dev_attr_cmb_enable.attr,
471 &dev_attr_availability.attr,
475 static struct attribute_group ccwdev_attr_group = {
476 .attrs = ccwdev_attrs,
480 device_add_files (struct device *dev)
482 return sysfs_create_group(&dev->kobj, &ccwdev_attr_group);
486 device_remove_files(struct device *dev)
488 sysfs_remove_group(&dev->kobj, &ccwdev_attr_group);
491 /* this is a simple abstraction for device_register that sets the
492 * correct bus type and adds the bus specific files */
494 ccw_device_register(struct ccw_device *cdev)
496 struct device *dev = &cdev->dev;
499 dev->bus = &ccw_bus_type;
501 if ((ret = device_add(dev)))
504 if ((ret = device_add_files(dev)))
510 static struct ccw_device *
511 get_disc_ccwdev_by_devno(unsigned int devno, struct ccw_device *sibling)
513 struct ccw_device *cdev;
514 struct list_head *entry;
517 if (!get_bus(&ccw_bus_type))
519 down_read(&ccw_bus_type.subsys.rwsem);
521 list_for_each(entry, &ccw_bus_type.devices.list) {
522 dev = get_device(container_of(entry,
523 struct device, bus_list));
526 cdev = to_ccwdev(dev);
527 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
528 (cdev->private->devno == devno) &&
529 (!strncmp(cdev->dev.bus_id, sibling->dev.bus_id,
531 cdev->private->state = DEV_STATE_NOT_OPER;
537 up_read(&ccw_bus_type.subsys.rwsem);
538 put_bus(&ccw_bus_type);
543 extern int css_get_ssd_info(struct subchannel *sch);
546 ccw_device_do_unreg_rereg(void *data)
548 struct ccw_device *cdev;
549 struct subchannel *sch;
552 cdev = (struct ccw_device *)data;
553 sch = to_subchannel(cdev->dev.parent);
554 if (cdev->private->devno != sch->schib.pmcw.dev) {
556 * The device number has changed. This is usually only when
557 * a device has been detached under VM and then re-appeared
558 * on another subchannel because of a different attachment
559 * order than before. Ideally, we should should just switch
560 * subchannels, but unfortunately, this is not possible with
561 * the current implementation.
562 * Instead, we search for the old subchannel for this device
563 * number and deregister so there are no collisions with the
564 * newly registered ccw_device.
565 * FIXME: Find another solution so the block layer doesn't
566 * get possibly sick...
568 struct ccw_device *other_cdev;
571 other_cdev = get_disc_ccwdev_by_devno(sch->schib.pmcw.dev,
574 struct subchannel *other_sch;
576 other_sch = to_subchannel(other_cdev->dev.parent);
577 if (get_device(&other_sch->dev)) {
578 stsch(other_sch->irq, &other_sch->schib);
579 if (other_sch->schib.pmcw.dnv) {
580 other_sch->schib.pmcw.intparm = 0;
581 cio_modify(other_sch);
583 device_unregister(&other_sch->dev);
586 /* Update ssd info here. */
587 css_get_ssd_info(sch);
588 cdev->private->devno = sch->schib.pmcw.dev;
591 device_remove_files(&cdev->dev);
592 device_del(&cdev->dev);
594 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
595 sch->schib.pmcw.dev);
596 if (device_add(&cdev->dev)) {
597 put_device(&cdev->dev);
600 if (device_add_files(&cdev->dev))
601 device_unregister(&cdev->dev);
605 ccw_device_release(struct device *dev)
607 struct ccw_device *cdev;
609 cdev = to_ccwdev(dev);
610 kfree(cdev->private);
615 * Register recognized device.
618 io_subchannel_register(void *data)
620 struct ccw_device *cdev;
621 struct subchannel *sch;
624 cdev = (struct ccw_device *) data;
625 sch = to_subchannel(cdev->dev.parent);
627 if (!list_empty(&sch->dev.children)) {
628 bus_rescan_devices(&ccw_bus_type);
631 /* make it known to the system */
632 ret = ccw_device_register(cdev);
634 printk (KERN_WARNING "%s: could not register %s\n",
635 __func__, cdev->dev.bus_id);
636 put_device(&cdev->dev);
637 sch->dev.driver_data = 0;
638 kfree (cdev->private);
640 put_device(&sch->dev);
644 ret = subchannel_add_files(cdev->dev.parent);
646 printk(KERN_WARNING "%s: could not add attributes to %s\n",
647 __func__, sch->dev.bus_id);
648 put_device(&cdev->dev);
650 cdev->private->flags.recog_done = 1;
651 put_device(&sch->dev);
652 wake_up(&cdev->private->wait_q);
656 ccw_device_call_sch_unregister(void *data)
658 struct ccw_device *cdev = data;
659 struct subchannel *sch;
661 sch = to_subchannel(cdev->dev.parent);
662 device_unregister(&sch->dev);
663 /* Reset intparm to zeroes. */
664 sch->schib.pmcw.intparm = 0;
666 put_device(&cdev->dev);
667 put_device(&sch->dev);
671 * subchannel recognition done. Called from the state machine.
674 io_subchannel_recog_done(struct ccw_device *cdev)
676 struct subchannel *sch;
678 if (css_init_done == 0) {
679 cdev->private->flags.recog_done = 1;
682 switch (cdev->private->state) {
683 case DEV_STATE_NOT_OPER:
684 cdev->private->flags.recog_done = 1;
685 /* Remove device found not operational. */
686 if (!get_device(&cdev->dev))
688 sch = to_subchannel(cdev->dev.parent);
689 INIT_WORK(&cdev->private->kick_work,
690 ccw_device_call_sch_unregister, (void *) cdev);
691 queue_work(slow_path_wq, &cdev->private->kick_work);
693 case DEV_STATE_BOXED:
694 /* Device did not respond in time. */
695 case DEV_STATE_OFFLINE:
697 * We can't register the device in interrupt context so
698 * we schedule a work item.
700 if (!get_device(&cdev->dev))
702 INIT_WORK(&cdev->private->kick_work,
703 io_subchannel_register, (void *) cdev);
704 queue_work(ccw_device_work, &cdev->private->kick_work);
707 if (atomic_dec_and_test(&ccw_device_init_count))
708 wake_up(&ccw_device_init_wq);
712 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
715 struct ccw_device_private *priv;
717 sch->dev.driver_data = cdev;
718 sch->driver = &io_subchannel_driver;
719 cdev->ccwlock = &sch->lock;
720 /* Init private data. */
721 priv = cdev->private;
722 priv->devno = sch->schib.pmcw.dev;
723 priv->irq = sch->irq;
724 priv->state = DEV_STATE_NOT_OPER;
725 INIT_LIST_HEAD(&priv->cmb_list);
726 init_waitqueue_head(&priv->wait_q);
727 init_timer(&priv->timer);
729 /* Set an initial name for the device. */
730 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
731 sch->schib.pmcw.dev);
733 /* Increase counter of devices currently in recognition. */
734 atomic_inc(&ccw_device_init_count);
736 /* Start async. device sensing. */
737 spin_lock_irq(&sch->lock);
738 rc = ccw_device_recognition(cdev);
739 spin_unlock_irq(&sch->lock);
741 if (atomic_dec_and_test(&ccw_device_init_count))
742 wake_up(&ccw_device_init_wq);
748 io_subchannel_probe (struct device *pdev)
750 struct subchannel *sch;
751 struct ccw_device *cdev;
754 sch = to_subchannel(pdev);
755 if (sch->dev.driver_data) {
757 * This subchannel already has an associated ccw_device.
758 * Register it and exit. This happens for all early
759 * device, e.g. the console.
761 cdev = sch->dev.driver_data;
762 device_initialize(&cdev->dev);
763 ccw_device_register(cdev);
764 subchannel_add_files(&sch->dev);
766 * Check if the device is already online. If it is
767 * the reference count needs to be corrected
768 * (see ccw_device_online and css_init_done for the
771 if (cdev->private->state != DEV_STATE_NOT_OPER &&
772 cdev->private->state != DEV_STATE_OFFLINE &&
773 cdev->private->state != DEV_STATE_BOXED)
774 get_device(&cdev->dev);
777 cdev = kmalloc (sizeof(*cdev), GFP_KERNEL);
780 memset(cdev, 0, sizeof(struct ccw_device));
781 cdev->private = kmalloc(sizeof(struct ccw_device_private),
782 GFP_KERNEL | GFP_DMA);
783 if (!cdev->private) {
787 memset(cdev->private, 0, sizeof(struct ccw_device_private));
788 atomic_set(&cdev->private->onoff, 0);
789 cdev->dev = (struct device) {
791 .release = ccw_device_release,
793 /* Do first half of device_register. */
794 device_initialize(&cdev->dev);
796 if (!get_device(&sch->dev)) {
797 if (cdev->dev.release)
798 cdev->dev.release(&cdev->dev);
802 rc = io_subchannel_recog(cdev, to_subchannel(pdev));
804 sch->dev.driver_data = 0;
805 if (cdev->dev.release)
806 cdev->dev.release(&cdev->dev);
813 io_subchannel_remove (struct device *dev)
815 struct ccw_device *cdev;
817 if (!dev->driver_data)
819 cdev = dev->driver_data;
820 /* Set ccw device to not operational and drop reference. */
821 cdev->private->state = DEV_STATE_NOT_OPER;
823 * Careful here. Our ccw device might be yet unregistered when
824 * de-registering its subchannel (machine check during device
825 * recognition). Better look if the subchannel has children.
827 if (!list_empty(&dev->children))
828 device_unregister(&cdev->dev);
829 dev->driver_data = NULL;
834 io_subchannel_notify(struct device *dev, int event)
836 struct ccw_device *cdev;
838 cdev = dev->driver_data;
845 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
849 io_subchannel_verify(struct device *dev)
851 struct ccw_device *cdev;
853 cdev = dev->driver_data;
855 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
859 io_subchannel_ioterm(struct device *dev)
861 struct ccw_device *cdev;
863 cdev = dev->driver_data;
866 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
868 cdev->handler(cdev, cdev->private->intparm,
873 io_subchannel_shutdown(struct device *dev)
875 struct subchannel *sch;
876 struct ccw_device *cdev;
879 sch = to_subchannel(dev);
880 cdev = dev->driver_data;
882 if (cio_is_console(sch->irq))
884 if (!sch->schib.pmcw.ena)
887 ret = cio_disable_subchannel(sch);
889 /* Subchannel is disabled, we're done. */
891 cdev->private->state = DEV_STATE_QUIESCE;
893 cdev->handler(cdev, cdev->private->intparm,
895 ret = ccw_device_cancel_halt_clear(cdev);
897 ccw_device_set_timeout(cdev, HZ/10);
898 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
900 cio_disable_subchannel(sch);
903 #ifdef CONFIG_CCW_CONSOLE
904 static struct ccw_device console_cdev;
905 static struct ccw_device_private console_private;
906 static int console_cdev_in_use;
909 ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
913 /* Initialize the ccw_device structure. */
914 cdev->dev = (struct device) {
917 /* Initialize the subchannel structure */
918 sch->dev.parent = &css_bus_device;
919 sch->dev.bus = &css_bus_type;
921 rc = io_subchannel_recog(cdev, sch);
925 /* Now wait for the async. recognition to come to an end. */
926 spin_lock_irq(cdev->ccwlock);
927 while (!dev_fsm_final_state(cdev))
930 if (cdev->private->state != DEV_STATE_OFFLINE)
932 ccw_device_online(cdev);
933 while (!dev_fsm_final_state(cdev))
935 if (cdev->private->state != DEV_STATE_ONLINE)
939 spin_unlock_irq(cdev->ccwlock);
944 ccw_device_probe_console(void)
946 struct subchannel *sch;
949 if (xchg(&console_cdev_in_use, 1) != 0)
951 sch = cio_probe_console();
953 console_cdev_in_use = 0;
956 memset(&console_cdev, 0, sizeof(struct ccw_device));
957 memset(&console_private, 0, sizeof(struct ccw_device_private));
958 console_cdev.private = &console_private;
959 ret = ccw_device_console_enable(&console_cdev, sch);
961 cio_release_console();
962 console_cdev_in_use = 0;
965 console_cdev.online = 1;
966 return &console_cdev;
971 * get ccw_device matching the busid, but only if owned by cdrv
974 get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
976 struct device *d, *dev;
977 struct device_driver *drv;
979 drv = get_driver(&cdrv->driver);
983 down_read(&drv->bus->subsys.rwsem);
986 list_for_each_entry(d, &drv->devices, driver_list) {
989 if (dev && !strncmp(bus_id, dev->bus_id, BUS_ID_SIZE))
996 up_read(&drv->bus->subsys.rwsem);
999 return dev ? to_ccwdev(dev) : 0;
1002 /************************** device driver handling ************************/
1004 /* This is the implementation of the ccw_driver class. The probe, remove
1005 * and release methods are initially very similar to the device_driver
1006 * implementations, with the difference that they have ccw_device
1009 * A ccw driver also contains the information that is needed for
1013 ccw_device_probe (struct device *dev)
1015 struct ccw_device *cdev = to_ccwdev(dev);
1016 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1019 cdev->drv = cdrv; /* to let the driver call _set_online */
1021 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1032 ccw_device_remove (struct device *dev)
1034 struct ccw_device *cdev = to_ccwdev(dev);
1035 struct ccw_driver *cdrv = cdev->drv;
1038 pr_debug("removing device %s\n", cdev->dev.bus_id);
1043 spin_lock_irq(cdev->ccwlock);
1044 ret = ccw_device_offline(cdev);
1045 spin_unlock_irq(cdev->ccwlock);
1047 wait_event(cdev->private->wait_q,
1048 dev_fsm_final_state(cdev));
1050 //FIXME: we can't fail!
1051 pr_debug("ccw_device_offline returned %d, device %s\n",
1052 ret, cdev->dev.bus_id);
1054 ccw_device_set_timeout(cdev, 0);
1060 ccw_driver_register (struct ccw_driver *cdriver)
1062 struct device_driver *drv = &cdriver->driver;
1064 drv->bus = &ccw_bus_type;
1065 drv->name = cdriver->name;
1066 drv->probe = ccw_device_probe;
1067 drv->remove = ccw_device_remove;
1069 return driver_register(drv);
1073 ccw_driver_unregister (struct ccw_driver *cdriver)
1075 driver_unregister(&cdriver->driver);
1078 MODULE_LICENSE("GPL");
1079 EXPORT_SYMBOL(ccw_device_set_online);
1080 EXPORT_SYMBOL(ccw_device_set_offline);
1081 EXPORT_SYMBOL(ccw_driver_register);
1082 EXPORT_SYMBOL(ccw_driver_unregister);
1083 EXPORT_SYMBOL(get_ccwdev_by_busid);
1084 EXPORT_SYMBOL(ccw_bus_type);
1085 EXPORT_SYMBOL(ccw_device_work);
1086 EXPORT_SYMBOL(ccw_device_notify_work);