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 if ((ret = bus_register (&ccw_bus_type)))
165 if ((ret = driver_register(&io_subchannel_driver.drv)))
168 wait_event(ccw_device_init_wq,
169 atomic_read(&ccw_device_init_count) == 0);
170 flush_workqueue(ccw_device_work);
174 destroy_workqueue(ccw_device_work);
175 if (ccw_device_notify_work)
176 destroy_workqueue(ccw_device_notify_work);
181 cleanup_ccw_bus_type (void)
183 driver_unregister(&io_subchannel_driver.drv);
184 bus_unregister(&ccw_bus_type);
185 destroy_workqueue(ccw_device_notify_work);
186 destroy_workqueue(ccw_device_work);
189 subsys_initcall(init_ccw_bus_type);
190 module_exit(cleanup_ccw_bus_type);
192 /************************ device handling **************************/
195 * A ccw_device has some interfaces in sysfs in addition to the
197 * The following entries are designed to export the information which
198 * resided in 2.4 in /proc/subchannels. Subchannel and device number
199 * are obvious, so they don't have an entry :)
200 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
203 chpids_show (struct device * dev, char * buf)
205 struct subchannel *sch = to_subchannel(dev);
206 struct ssd_info *ssd = &sch->ssd_info;
210 for (chp = 0; chp < 8; chp++)
211 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]);
213 ret += sprintf (buf+ret, "\n");
214 return min((ssize_t)PAGE_SIZE, ret);
218 pimpampom_show (struct device * dev, char * buf)
220 struct subchannel *sch = to_subchannel(dev);
221 struct pmcw *pmcw = &sch->schib.pmcw;
223 return sprintf (buf, "%02x %02x %02x\n",
224 pmcw->pim, pmcw->pam, pmcw->pom);
228 devtype_show (struct device *dev, char *buf)
230 struct ccw_device *cdev = to_ccwdev(dev);
231 struct ccw_device_id *id = &(cdev->id);
233 if (id->dev_type != 0)
234 return sprintf(buf, "%04x/%02x\n",
235 id->dev_type, id->dev_model);
237 return sprintf(buf, "n/a\n");
241 cutype_show (struct device *dev, char *buf)
243 struct ccw_device *cdev = to_ccwdev(dev);
244 struct ccw_device_id *id = &(cdev->id);
246 return sprintf(buf, "%04x/%02x\n",
247 id->cu_type, id->cu_model);
251 online_show (struct device *dev, char *buf)
253 struct ccw_device *cdev = to_ccwdev(dev);
255 return sprintf(buf, cdev->online ? "1\n" : "0\n");
259 ccw_device_remove_disconnected(struct ccw_device *cdev)
261 struct subchannel *sch;
263 * Forced offline in disconnected state means
264 * 'throw away device'.
266 sch = to_subchannel(cdev->dev.parent);
267 device_unregister(&sch->dev);
268 /* Reset intparm to zeroes. */
269 sch->schib.pmcw.intparm = 0;
271 put_device(&sch->dev);
275 ccw_device_set_offline(struct ccw_device *cdev)
281 if (!cdev->online || !cdev->drv)
284 if (cdev->drv->set_offline) {
285 ret = cdev->drv->set_offline(cdev);
290 spin_lock_irq(cdev->ccwlock);
291 ret = ccw_device_offline(cdev);
292 spin_unlock_irq(cdev->ccwlock);
294 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
296 pr_debug("ccw_device_offline returned %d, device %s\n",
297 ret, cdev->dev.bus_id);
304 ccw_device_set_online(struct ccw_device *cdev)
310 if (cdev->online || !cdev->drv)
313 spin_lock_irq(cdev->ccwlock);
314 ret = ccw_device_online(cdev);
315 spin_unlock_irq(cdev->ccwlock);
317 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
319 pr_debug("ccw_device_online returned %d, device %s\n",
320 ret, cdev->dev.bus_id);
323 if (cdev->private->state != DEV_STATE_ONLINE)
325 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
329 spin_lock_irq(cdev->ccwlock);
330 ret = ccw_device_offline(cdev);
331 spin_unlock_irq(cdev->ccwlock);
333 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
335 pr_debug("ccw_device_offline returned %d, device %s\n",
336 ret, cdev->dev.bus_id);
337 return (ret = 0) ? -ENODEV : ret;
341 online_store (struct device *dev, const char *buf, size_t count)
343 struct ccw_device *cdev = to_ccwdev(dev);
347 if (atomic_compare_and_swap(0, 1, &cdev->private->onoff))
350 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
351 atomic_set(&cdev->private->onoff, 0);
354 if (!strncmp(buf, "force\n", count)) {
359 i = simple_strtoul(buf, &tmp, 16);
362 /* Do device recognition, if needed. */
363 if (cdev->id.cu_type == 0) {
364 ret = ccw_device_recognition(cdev);
366 printk(KERN_WARNING"Couldn't start recognition "
367 "for device %s (ret=%d)\n",
368 cdev->dev.bus_id, ret);
371 wait_event(cdev->private->wait_q,
372 cdev->private->flags.recog_done);
374 if (cdev->drv && cdev->drv->set_online)
375 ccw_device_set_online(cdev);
377 if (cdev->private->state == DEV_STATE_DISCONNECTED)
378 ccw_device_remove_disconnected(cdev);
379 else if (cdev->drv && cdev->drv->set_offline)
380 ccw_device_set_offline(cdev);
382 if (force && cdev->private->state == DEV_STATE_BOXED) {
383 ret = ccw_device_stlck(cdev);
385 printk(KERN_WARNING"ccw_device_stlck for device %s "
386 "returned %d!\n", cdev->dev.bus_id, ret);
389 /* Do device recognition, if needed. */
390 if (cdev->id.cu_type == 0) {
391 cdev->private->state = DEV_STATE_NOT_OPER;
392 ret = ccw_device_recognition(cdev);
394 printk(KERN_WARNING"Couldn't start recognition "
395 "for device %s (ret=%d)\n",
396 cdev->dev.bus_id, ret);
399 wait_event(cdev->private->wait_q,
400 cdev->private->flags.recog_done);
402 if (cdev->drv && cdev->drv->set_online)
403 ccw_device_set_online(cdev);
407 module_put(cdev->drv->owner);
408 atomic_set(&cdev->private->onoff, 0);
413 available_show (struct device *dev, char *buf)
415 struct ccw_device *cdev = to_ccwdev(dev);
416 struct subchannel *sch;
418 switch (cdev->private->state) {
419 case DEV_STATE_BOXED:
420 return sprintf(buf, "boxed\n");
421 case DEV_STATE_DISCONNECTED:
422 case DEV_STATE_DISCONNECTED_SENSE_ID:
423 case DEV_STATE_NOT_OPER:
424 sch = to_subchannel(dev->parent);
426 return sprintf(buf, "no path\n");
428 return sprintf(buf, "no device\n");
430 /* All other states considered fine. */
431 return sprintf(buf, "good\n");
435 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
436 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
437 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
438 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
439 static DEVICE_ATTR(online, 0644, online_show, online_store);
440 extern struct device_attribute dev_attr_cmb_enable;
441 static DEVICE_ATTR(availability, 0444, available_show, NULL);
443 static struct attribute * subch_attrs[] = {
444 &dev_attr_chpids.attr,
445 &dev_attr_pimpampom.attr,
449 static struct attribute_group subch_attr_group = {
450 .attrs = subch_attrs,
454 subchannel_add_files (struct device *dev)
456 return sysfs_create_group(&dev->kobj, &subch_attr_group);
459 static struct attribute * ccwdev_attrs[] = {
460 &dev_attr_devtype.attr,
461 &dev_attr_cutype.attr,
462 &dev_attr_online.attr,
463 &dev_attr_cmb_enable.attr,
464 &dev_attr_availability.attr,
468 static struct attribute_group ccwdev_attr_group = {
469 .attrs = ccwdev_attrs,
473 device_add_files (struct device *dev)
475 return sysfs_create_group(&dev->kobj, &ccwdev_attr_group);
479 device_remove_files(struct device *dev)
481 sysfs_remove_group(&dev->kobj, &ccwdev_attr_group);
484 /* this is a simple abstraction for device_register that sets the
485 * correct bus type and adds the bus specific files */
487 ccw_device_register(struct ccw_device *cdev)
489 struct device *dev = &cdev->dev;
492 dev->bus = &ccw_bus_type;
494 if ((ret = device_add(dev)))
497 if ((ret = device_add_files(dev)))
503 static struct ccw_device *
504 get_disc_ccwdev_by_devno(unsigned int devno, struct ccw_device *sibling)
506 struct ccw_device *cdev;
507 struct list_head *entry;
510 if (!get_bus(&ccw_bus_type))
512 down_read(&ccw_bus_type.subsys.rwsem);
514 list_for_each(entry, &ccw_bus_type.devices.list) {
515 dev = get_device(container_of(entry,
516 struct device, bus_list));
519 cdev = to_ccwdev(dev);
520 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
521 (cdev->private->devno == devno) &&
522 (!strncmp(cdev->dev.bus_id, sibling->dev.bus_id, 4))) {
523 cdev->private->state = DEV_STATE_NOT_OPER;
529 up_read(&ccw_bus_type.subsys.rwsem);
530 put_bus(&ccw_bus_type);
536 ccw_device_do_unreg_rereg(void *data)
538 struct ccw_device *cdev;
539 struct subchannel *sch;
542 cdev = (struct ccw_device *)data;
543 sch = to_subchannel(cdev->dev.parent);
544 if (cdev->private->devno != sch->schib.pmcw.dev) {
546 * The device number has changed. This is usually only when
547 * a device has been detached under VM and then re-appeared
548 * on another subchannel because of a different attachment
549 * order than before. Ideally, we should should just switch
550 * subchannels, but unfortunately, this is not possible with
551 * the current implementation.
552 * Instead, we search for the old subchannel for this device
553 * number and deregister so there are no collisions with the
554 * newly registered ccw_device.
555 * FIXME: Find another solution so the block layer doesn't
556 * get possibly sick...
558 struct ccw_device *other_cdev;
561 other_cdev = get_disc_ccwdev_by_devno(sch->schib.pmcw.dev,
564 struct subchannel *other_sch;
566 other_sch = to_subchannel(other_cdev->dev.parent);
567 if (get_device(&other_sch->dev)) {
568 stsch(other_sch->irq, &other_sch->schib);
569 if (other_sch->schib.pmcw.dnv) {
570 other_sch->schib.pmcw.intparm = 0;
571 cio_modify(other_sch);
573 device_unregister(&other_sch->dev);
576 cdev->private->devno = sch->schib.pmcw.dev;
579 device_remove_files(&cdev->dev);
580 device_del(&cdev->dev);
582 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
583 sch->schib.pmcw.dev);
584 if (device_add(&cdev->dev)) {
585 put_device(&cdev->dev);
588 if (device_add_files(&cdev->dev))
589 device_unregister(&cdev->dev);
593 ccw_device_release(struct device *dev)
595 struct ccw_device *cdev;
597 cdev = to_ccwdev(dev);
598 kfree(cdev->private);
603 * Register recognized device.
606 io_subchannel_register(void *data)
608 struct ccw_device *cdev;
609 struct subchannel *sch;
612 cdev = (struct ccw_device *) data;
613 sch = to_subchannel(cdev->dev.parent);
615 if (!list_empty(&sch->dev.children)) {
616 bus_rescan_devices(&ccw_bus_type);
619 /* make it known to the system */
620 ret = ccw_device_register(cdev);
622 printk (KERN_WARNING "%s: could not register %s\n",
623 __func__, cdev->dev.bus_id);
624 put_device(&cdev->dev);
625 sch->dev.driver_data = 0;
626 kfree (cdev->private);
631 ret = subchannel_add_files(cdev->dev.parent);
633 printk(KERN_WARNING "%s: could not add attributes to %s\n",
634 __func__, sch->dev.bus_id);
635 put_device(&cdev->dev);
637 cdev->private->flags.recog_done = 1;
638 put_device(&sch->dev);
639 wake_up(&cdev->private->wait_q);
643 ccw_device_call_sch_unregister(void *data)
645 struct ccw_device *cdev = data;
646 struct subchannel *sch;
648 sch = to_subchannel(cdev->dev.parent);
649 /* Check if device is registered. */
650 if (!list_empty(&sch->dev.node))
651 device_unregister(&sch->dev);
652 /* Reset intparm to zeroes. */
653 sch->schib.pmcw.intparm = 0;
655 put_device(&cdev->dev);
656 put_device(&sch->dev);
660 * subchannel recognition done. Called from the state machine.
663 io_subchannel_recog_done(struct ccw_device *cdev)
665 struct subchannel *sch;
667 if (css_init_done == 0) {
668 cdev->private->flags.recog_done = 1;
671 switch (cdev->private->state) {
672 case DEV_STATE_NOT_OPER:
673 cdev->private->flags.recog_done = 1;
674 /* Remove device found not operational. */
675 if (!get_device(&cdev->dev))
677 sch = to_subchannel(cdev->dev.parent);
678 INIT_WORK(&cdev->private->kick_work,
679 ccw_device_call_sch_unregister, (void *) cdev);
680 queue_work(ccw_device_work, &cdev->private->kick_work);
682 case DEV_STATE_BOXED:
683 /* Device did not respond in time. */
684 case DEV_STATE_OFFLINE:
686 * We can't register the device in interrupt context so
687 * we schedule a work item.
689 if (!get_device(&cdev->dev))
691 INIT_WORK(&cdev->private->kick_work,
692 io_subchannel_register, (void *) cdev);
693 queue_work(ccw_device_work, &cdev->private->kick_work);
696 if (atomic_dec_and_test(&ccw_device_init_count))
697 wake_up(&ccw_device_init_wq);
701 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
705 sch->dev.driver_data = cdev;
706 sch->driver = &io_subchannel_driver;
707 cdev->ccwlock = &sch->lock;
708 *cdev->private = (struct ccw_device_private) {
709 .devno = sch->schib.pmcw.dev,
711 .state = DEV_STATE_NOT_OPER,
712 .cmb_list = LIST_HEAD_INIT(cdev->private->cmb_list),
714 init_waitqueue_head(&cdev->private->wait_q);
715 init_timer(&cdev->private->timer);
717 /* Set an initial name for the device. */
718 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
719 sch->schib.pmcw.dev);
721 /* Increase counter of devices currently in recognition. */
722 atomic_inc(&ccw_device_init_count);
724 /* Start async. device sensing. */
725 spin_lock_irq(&sch->lock);
726 rc = ccw_device_recognition(cdev);
727 spin_unlock_irq(&sch->lock);
729 if (atomic_dec_and_test(&ccw_device_init_count))
730 wake_up(&ccw_device_init_wq);
736 io_subchannel_probe (struct device *pdev)
738 struct subchannel *sch;
739 struct ccw_device *cdev;
742 sch = to_subchannel(pdev);
743 if (sch->dev.driver_data) {
745 * This subchannel already has an associated ccw_device.
746 * Register it and exit. This happens for all early
747 * device, e.g. the console.
749 cdev = sch->dev.driver_data;
750 device_initialize(&cdev->dev);
751 ccw_device_register(cdev);
752 subchannel_add_files(&sch->dev);
754 * Check if the device is already online. If it is
755 * the reference count needs to be corrected
756 * (see ccw_device_online and css_init_done for the
759 if (cdev->private->state != DEV_STATE_NOT_OPER &&
760 cdev->private->state != DEV_STATE_OFFLINE &&
761 cdev->private->state != DEV_STATE_BOXED)
762 get_device(&cdev->dev);
765 cdev = kmalloc (sizeof(*cdev), GFP_KERNEL);
768 memset(cdev, 0, sizeof(struct ccw_device));
769 cdev->private = kmalloc(sizeof(struct ccw_device_private),
770 GFP_KERNEL | GFP_DMA);
771 if (!cdev->private) {
775 memset(cdev->private, 0, sizeof(struct ccw_device_private));
776 atomic_set(&cdev->private->onoff, 0);
777 cdev->dev = (struct device) {
779 .release = ccw_device_release,
781 /* Do first half of device_register. */
782 device_initialize(&cdev->dev);
784 if (!get_device(&sch->dev)) {
785 if (cdev->dev.release)
786 cdev->dev.release(&cdev->dev);
790 rc = io_subchannel_recog(cdev, to_subchannel(pdev));
792 sch->dev.driver_data = 0;
793 if (cdev->dev.release)
794 cdev->dev.release(&cdev->dev);
801 io_subchannel_remove (struct device *dev)
803 struct ccw_device *cdev;
805 if (!dev->driver_data)
807 cdev = dev->driver_data;
808 /* Set ccw device to not operational and drop reference. */
809 cdev->private->state = DEV_STATE_NOT_OPER;
811 * Careful here. Our ccw device might be yet unregistered when
812 * de-registering its subchannel (machine check during device
813 * recognition). Better look if the subchannel has children.
815 if (!list_empty(&dev->children))
816 device_unregister(&cdev->dev);
817 dev->driver_data = NULL;
822 io_subchannel_notify(struct device *dev, int event)
824 struct ccw_device *cdev;
826 cdev = dev->driver_data;
833 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
837 io_subchannel_verify(struct device *dev)
839 struct ccw_device *cdev;
841 cdev = dev->driver_data;
843 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
847 io_subchannel_ioterm(struct device *dev)
849 struct ccw_device *cdev;
851 cdev = dev->driver_data;
854 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
856 cdev->handler(cdev, cdev->private->intparm,
861 io_subchannel_shutdown(struct device *dev)
863 struct subchannel *sch;
864 struct ccw_device *cdev;
867 sch = to_subchannel(dev);
868 cdev = dev->driver_data;
870 if (cio_is_console(sch->irq))
872 if (!sch->schib.pmcw.ena)
875 ret = cio_disable_subchannel(sch);
877 /* Subchannel is disabled, we're done. */
879 cdev->private->state = DEV_STATE_QUIESCE;
881 cdev->handler(cdev, cdev->private->intparm,
883 ret = ccw_device_cancel_halt_clear(cdev);
885 ccw_device_set_timeout(cdev, HZ/10);
886 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
888 cio_disable_subchannel(sch);
891 #ifdef CONFIG_CCW_CONSOLE
892 static struct ccw_device console_cdev;
893 static struct ccw_device_private console_private;
894 static int console_cdev_in_use;
897 ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
901 /* Initialize the ccw_device structure. */
902 cdev->dev = (struct device) {
905 /* Initialize the subchannel structure */
906 sch->dev.parent = &css_bus_device;
907 sch->dev.bus = &css_bus_type;
909 rc = io_subchannel_recog(cdev, sch);
913 /* Now wait for the async. recognition to come to an end. */
914 spin_lock_irq(cdev->ccwlock);
915 while (!dev_fsm_final_state(cdev))
918 if (cdev->private->state != DEV_STATE_OFFLINE)
920 ccw_device_online(cdev);
921 while (!dev_fsm_final_state(cdev))
923 if (cdev->private->state != DEV_STATE_ONLINE)
927 spin_unlock_irq(cdev->ccwlock);
932 ccw_device_probe_console(void)
934 struct subchannel *sch;
937 if (xchg(&console_cdev_in_use, 1) != 0)
939 sch = cio_probe_console();
941 console_cdev_in_use = 0;
944 memset(&console_cdev, 0, sizeof(struct ccw_device));
945 memset(&console_private, 0, sizeof(struct ccw_device_private));
946 console_cdev.private = &console_private;
947 ret = ccw_device_console_enable(&console_cdev, sch);
949 cio_release_console();
950 console_cdev_in_use = 0;
953 console_cdev.online = 1;
954 return &console_cdev;
959 * get ccw_device matching the busid, but only if owned by cdrv
962 get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
964 struct device *d, *dev;
965 struct device_driver *drv;
967 drv = get_driver(&cdrv->driver);
971 down_read(&drv->bus->subsys.rwsem);
974 list_for_each_entry(d, &drv->devices, driver_list) {
977 if (dev && !strncmp(bus_id, dev->bus_id, BUS_ID_SIZE))
984 up_read(&drv->bus->subsys.rwsem);
987 return dev ? to_ccwdev(dev) : 0;
990 /************************** device driver handling ************************/
992 /* This is the implementation of the ccw_driver class. The probe, remove
993 * and release methods are initially very similar to the device_driver
994 * implementations, with the difference that they have ccw_device
997 * A ccw driver also contains the information that is needed for
1001 ccw_device_probe (struct device *dev)
1003 struct ccw_device *cdev = to_ccwdev(dev);
1004 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1007 cdev->drv = cdrv; /* to let the driver call _set_online */
1009 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1020 ccw_device_remove (struct device *dev)
1022 struct ccw_device *cdev = to_ccwdev(dev);
1023 struct ccw_driver *cdrv = cdev->drv;
1026 pr_debug("removing device %s\n", cdev->dev.bus_id);
1031 spin_lock_irq(cdev->ccwlock);
1032 ret = ccw_device_offline(cdev);
1033 spin_unlock_irq(cdev->ccwlock);
1035 wait_event(cdev->private->wait_q,
1036 dev_fsm_final_state(cdev));
1038 //FIXME: we can't fail!
1039 pr_debug("ccw_device_offline returned %d, device %s\n",
1040 ret, cdev->dev.bus_id);
1042 ccw_device_set_timeout(cdev, 0);
1048 ccw_driver_register (struct ccw_driver *cdriver)
1050 struct device_driver *drv = &cdriver->driver;
1052 drv->bus = &ccw_bus_type;
1053 drv->name = cdriver->name;
1054 drv->probe = ccw_device_probe;
1055 drv->remove = ccw_device_remove;
1057 return driver_register(drv);
1061 ccw_driver_unregister (struct ccw_driver *cdriver)
1063 driver_unregister(&cdriver->driver);
1066 MODULE_LICENSE("GPL");
1067 EXPORT_SYMBOL(ccw_device_set_online);
1068 EXPORT_SYMBOL(ccw_device_set_offline);
1069 EXPORT_SYMBOL(ccw_driver_register);
1070 EXPORT_SYMBOL(ccw_driver_unregister);
1071 EXPORT_SYMBOL(get_ccwdev_by_busid);
1072 EXPORT_SYMBOL(ccw_bus_type);
1073 EXPORT_SYMBOL(ccw_device_work);
1074 EXPORT_SYMBOL(ccw_device_notify_work);